Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
new PolarisEclipseLinkMetaStoreSessionImpl(
store, Mockito.mock(), realmContext, null, "polaris", RANDOM_SECRETS);
TransactionalMetaStoreManagerImpl metaStoreManager =
new TransactionalMetaStoreManagerImpl(clock);
PolarisCallContext callCtx = new PolarisCallContext(realmContext, session, diagServices);
new TransactionalMetaStoreManagerImpl(clock, () -> session);
PolarisCallContext callCtx = new PolarisCallContext(realmContext, diagServices);
return new PolarisTestMetaStoreManager(metaStoreManager, callCtx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ protected PrincipalSecretsGenerator secretsGenerator(
}
}

protected PolarisMetaStoreManager createNewMetaStoreManager() {
return new AtomicOperationMetaStoreManager(clock);
protected PolarisMetaStoreManager createNewMetaStoreManager(
Supplier<BasePersistence> metaStoreSupplier) {
return new AtomicOperationMetaStoreManager(clock, metaStoreSupplier);
}

private void initializeForRealm(
Expand All @@ -99,17 +100,17 @@ private void initializeForRealm(
String realmId = realmContext.getRealmIdentifier();
// determine schemaVersion once per realm
final int schemaVersion = JdbcBasePersistenceImpl.loadSchemaVersion(datasourceOperations);
sessionSupplierMap.put(
realmId,
Supplier<BasePersistence> metaStoreSupplier =
() ->
new JdbcBasePersistenceImpl(
datasourceOperations,
secretsGenerator(realmId, rootCredentialsSet),
storageIntegrationProvider,
realmId,
schemaVersion));
schemaVersion);
sessionSupplierMap.put(realmId, metaStoreSupplier);

PolarisMetaStoreManager metaStoreManager = createNewMetaStoreManager();
PolarisMetaStoreManager metaStoreManager = createNewMetaStoreManager(metaStoreSupplier);
metaStoreManagerMap.put(realmId, metaStoreManager);
}

Expand Down Expand Up @@ -175,9 +176,8 @@ public Map<String, BaseResult> purgeRealms(Iterable<String> realms) {
for (String realm : realms) {
RealmContext realmContext = () -> realm;
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
BasePersistence session = getOrCreateSession(realmContext);

PolarisCallContext callContext = new PolarisCallContext(realmContext, session, diagnostics);
PolarisCallContext callContext = new PolarisCallContext(realmContext, diagnostics);
BaseResult result = metaStoreManager.purge(callContext);
results.put(realm, result);

Expand All @@ -199,16 +199,6 @@ public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager(
return metaStoreManagerMap.get(realmContext.getRealmIdentifier());
}

@Override
public synchronized BasePersistence getOrCreateSession(RealmContext realmContext) {
if (!sessionSupplierMap.containsKey(realmContext.getRealmIdentifier())) {
DatasourceOperations datasourceOperations = getDatasourceOperations();
initializeForRealm(datasourceOperations, realmContext, null);
}
checkPolarisServiceBootstrappedForRealm(realmContext);
return sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
}

@Override
public synchronized EntityCache getOrCreateEntityCache(
RealmContext realmContext, RealmConfig realmConfig) {
Expand All @@ -232,9 +222,7 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
// CallContext may not have been resolved yet.
PolarisMetaStoreManager metaStoreManager =
metaStoreManagerMap.get(realmContext.getRealmIdentifier());
BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
PolarisCallContext polarisContext =
new PolarisCallContext(realmContext, metaStore, diagnostics);
PolarisCallContext polarisContext = new PolarisCallContext(realmContext, diagnostics);

Optional<PrincipalEntity> preliminaryRootPrincipal =
metaStoreManager.findRootPrincipal(polarisContext);
Expand Down Expand Up @@ -267,9 +255,7 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
private void checkPolarisServiceBootstrappedForRealm(RealmContext realmContext) {
PolarisMetaStoreManager metaStoreManager =
metaStoreManagerMap.get(realmContext.getRealmIdentifier());
BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
PolarisCallContext polarisContext =
new PolarisCallContext(realmContext, metaStore, diagnostics);
PolarisCallContext polarisContext = new PolarisCallContext(realmContext, diagnostics);

Optional<PrincipalEntity> rootPrincipal = metaStoreManager.findRootPrincipal(polarisContext);
if (rootPrincipal.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
}

RealmContext realmContext = () -> "REALM";
JdbcBasePersistenceImpl basePersistence =
JdbcBasePersistenceImpl metaStore =
new JdbcBasePersistenceImpl(
datasourceOperations,
RANDOM_SECRETS,
Mockito.mock(),
realmContext.getRealmIdentifier(),
schemaVersion);
AtomicOperationMetaStoreManager metaStoreManager = new AtomicOperationMetaStoreManager(clock);
PolarisCallContext callCtx =
new PolarisCallContext(realmContext, basePersistence, diagServices);
AtomicOperationMetaStoreManager metaStoreManager =
new AtomicOperationMetaStoreManager(clock, () -> metaStore);
PolarisCallContext callCtx = new PolarisCallContext(realmContext, diagServices);
return new PolarisTestMetaStoreManager(metaStoreManager, callCtx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,31 @@
import org.apache.polaris.core.config.RealmConfigImpl;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.persistence.BasePersistence;

/**
* The Call context is allocated each time a new REST request is processed. It contains instances of
* low-level services required to process that request
*/
public class PolarisCallContext implements CallContext {

// meta store which is used to persist Polaris entity metadata
private final BasePersistence metaStore;
private final PolarisDiagnostics diagServices;
private final PolarisConfigurationStore configurationStore;
private final RealmContext realmContext;
private final RealmConfig realmConfig;

public PolarisCallContext(
@Nonnull RealmContext realmContext,
@Nonnull BasePersistence metaStore,
@Nonnull PolarisDiagnostics diagServices,
@Nonnull PolarisConfigurationStore configurationStore) {
this.realmContext = realmContext;
this.metaStore = metaStore;
this.diagServices = diagServices;
this.configurationStore = configurationStore;
this.realmConfig = new RealmConfigImpl(this.configurationStore, this.realmContext);
}

public PolarisCallContext(
@Nonnull RealmContext realmContext,
@Nonnull BasePersistence metaStore,
@Nonnull PolarisDiagnostics diagServices) {
this(realmContext, metaStore, diagServices, new PolarisConfigurationStore() {});
}

public BasePersistence getMetaStore() {
return metaStore;
@Nonnull RealmContext realmContext, @Nonnull PolarisDiagnostics diagServices) {
this(realmContext, diagServices, new PolarisConfigurationStore() {});
}

public PolarisDiagnostics getDiagServices() {
Expand Down Expand Up @@ -90,7 +79,6 @@ public PolarisCallContext copy() {
// copy of the RealmContext to ensure the access during the task executor.
String realmId = this.realmContext.getRealmIdentifier();
RealmContext realmContext = () -> realmId;
return new PolarisCallContext(
realmContext, this.metaStore, this.diagServices, this.configurationStore);
return new PolarisCallContext(realmContext, this.diagServices, this.configurationStore);
}
}
Loading