Skip to content
Merged
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 @@ -89,7 +89,7 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
diagServices, store, Mockito.mock(), realmContext, null, "polaris", RANDOM_SECRETS);
TransactionalMetaStoreManagerImpl metaStoreManager =
new TransactionalMetaStoreManagerImpl(clock, diagServices);
PolarisCallContext callCtx = new PolarisCallContext(realmContext, session, diagServices);
PolarisCallContext callCtx = new PolarisCallContext(realmContext, session);
return new PolarisTestMetaStoreManager(metaStoreManager, callCtx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.entity.EntityNameLookupRecord;
import org.apache.polaris.core.entity.LocationBasedEntity;
import org.apache.polaris.core.entity.PolarisBaseEntity;
Expand Down Expand Up @@ -77,6 +78,7 @@ public class JdbcBasePersistenceImpl implements BasePersistence, IntegrationPers

private static final Logger LOGGER = LoggerFactory.getLogger(JdbcBasePersistenceImpl.class);

private final PolarisDiagnostics diagnostics;
private final DatasourceOperations datasourceOperations;
private final PrincipalSecretsGenerator secretsGenerator;
private final PolarisStorageIntegrationProvider storageIntegrationProvider;
Expand All @@ -87,11 +89,13 @@ public class JdbcBasePersistenceImpl implements BasePersistence, IntegrationPers
private static final int MAX_LOCATION_COMPONENTS = 40;

public JdbcBasePersistenceImpl(
PolarisDiagnostics diagnostics,
DatasourceOperations databaseOperations,
PrincipalSecretsGenerator secretsGenerator,
PolarisStorageIntegrationProvider storageIntegrationProvider,
String realmId,
int schemaVersion) {
this.diagnostics = diagnostics;
this.datasourceOperations = databaseOperations;
this.secretsGenerator = secretsGenerator;
this.storageIntegrationProvider = storageIntegrationProvider;
Expand Down Expand Up @@ -785,24 +789,20 @@ public PolarisPrincipalSecrets rotatePrincipalSecrets(
PolarisPrincipalSecrets principalSecrets = loadPrincipalSecrets(callCtx, clientId);

// should be found
callCtx
.getDiagServices()
.checkNotNull(
principalSecrets,
"cannot_find_secrets",
"client_id={} principalId={}",
clientId,
principalId);
diagnostics.checkNotNull(
principalSecrets,
"cannot_find_secrets",
"client_id={} principalId={}",
clientId,
principalId);

// ensure principal id is matching
callCtx
.getDiagServices()
.check(
principalId == principalSecrets.getPrincipalId(),
"principal_id_mismatch",
"expectedId={} id={}",
principalId,
principalSecrets.getPrincipalId());
diagnostics.check(
principalId == principalSecrets.getPrincipalId(),
"principal_id_mismatch",
"expectedId={} id={}",
principalId,
principalSecrets.getPrincipalId());

// rotate the secrets
principalSecrets.rotateSecrets(oldSecretHash);
Expand Down Expand Up @@ -1119,7 +1119,7 @@ public <T extends PolarisStorageConfigurationInfo> void persistStorageIntegratio
PolarisStorageIntegration<T> loadPolarisStorageIntegration(
@Nonnull PolarisCallContext callContext, @Nonnull PolarisBaseEntity entity) {
PolarisStorageConfigurationInfo storageConfig =
BaseMetaStoreManager.extractStorageConfiguration(callContext.getDiagServices(), entity);
BaseMetaStoreManager.extractStorageConfiguration(diagnostics, entity);
return storageIntegrationProvider.getStorageIntegrationForConfig(storageConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private void initializeForRealm(
realmId,
() ->
new JdbcBasePersistenceImpl(
diagnostics,
datasourceOperations,
secretsGenerator(realmId, rootCredentialsSet),
storageIntegrationProvider,
Expand Down Expand Up @@ -177,7 +178,7 @@ public Map<String, BaseResult> purgeRealms(Iterable<String> realms) {
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
BasePersistence session = getOrCreateSession(realmContext);

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

Expand Down Expand Up @@ -216,7 +217,7 @@ public synchronized EntityCache getOrCreateEntityCache(
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
entityCacheMap.put(
realmContext.getRealmIdentifier(),
new InMemoryEntityCache(realmConfig, metaStoreManager));
new InMemoryEntityCache(diagnostics, realmConfig, metaStoreManager));
}

return entityCacheMap.get(realmContext.getRealmIdentifier());
Expand All @@ -233,8 +234,7 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
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, metaStore);

Optional<PrincipalEntity> preliminaryRootPrincipal =
metaStoreManager.findRootPrincipal(polarisContext);
Expand Down Expand Up @@ -268,8 +268,7 @@ 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, metaStore);

Optional<PrincipalEntity> rootPrincipal = metaStoreManager.findRootPrincipal(polarisContext);
if (rootPrincipal.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
RealmContext realmContext = () -> "REALM";
JdbcBasePersistenceImpl basePersistence =
new JdbcBasePersistenceImpl(
diagServices,
datasourceOperations,
RANDOM_SECRETS,
Mockito.mock(),
realmContext.getRealmIdentifier(),
schemaVersion);
AtomicOperationMetaStoreManager metaStoreManager =
new AtomicOperationMetaStoreManager(clock, diagServices);
PolarisCallContext callCtx =
new PolarisCallContext(realmContext, basePersistence, diagServices);
PolarisCallContext callCtx = new PolarisCallContext(realmContext, basePersistence);
return new PolarisTestMetaStoreManager(metaStoreManager, callCtx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,29 @@ 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() {});
@Nonnull RealmContext realmContext, @Nonnull BasePersistence metaStore) {
this(realmContext, metaStore, new PolarisConfigurationStore() {});
}

public BasePersistence getMetaStore() {
return metaStore;
}

public PolarisDiagnostics getDiagServices() {
return diagServices;
}

@Override
public RealmContext getRealmContext() {
return realmContext;
Expand All @@ -90,7 +81,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.metaStore, this.configurationStore);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Map<String, BaseResult> purgeRealms(Iterable<String> realms) {
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
TransactionalPersistence session = getOrCreateSession(realmContext);

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

Expand Down Expand Up @@ -169,7 +169,7 @@ public synchronized EntityCache getOrCreateEntityCache(
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
entityCacheMap.put(
realmContext.getRealmIdentifier(),
new InMemoryEntityCache(realmConfig, metaStoreManager));
new InMemoryEntityCache(diagnostics, realmConfig, metaStoreManager));
}

return entityCacheMap.get(realmContext.getRealmIdentifier());
Expand All @@ -186,8 +186,7 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
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, metaStore);

Optional<PrincipalEntity> preliminaryRootPrincipal =
metaStoreManager.findRootPrincipal(polarisContext);
Expand Down Expand Up @@ -221,8 +220,7 @@ 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, metaStore);

Optional<PrincipalEntity> rootPrincipal = metaStoreManager.findRootPrincipal(polarisContext);
if (rootPrincipal.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public EntityResult readEntityByName(
@Nonnull PolarisEntityType entityType,
@Nonnull PolarisEntitySubType entitySubType,
@Nonnull PageToken pageToken) {
callCtx.getDiagServices().fail("illegal_method_in_transaction_workspace", "loadEntities");
diagnostics.fail("illegal_method_in_transaction_workspace", "loadEntities");
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.config.BehaviorChangeConfiguration;
import org.apache.polaris.core.config.FeatureConfiguration;
import org.apache.polaris.core.config.RealmConfig;
Expand All @@ -41,16 +42,10 @@
/** An in-memory entity cache with a limit of 100k entities and a 1h TTL. */
public class InMemoryEntityCache implements EntityCache {

// cache mode
private EntityCacheMode cacheMode;

// the meta store manager
private final PolarisDiagnostics diagnostics;
private final PolarisMetaStoreManager polarisMetaStoreManager;

// Caffeine cache to keep entries by id
private final Cache<Long, ResolvedPolarisEntity> byId;

// index by name
private final AbstractMap<EntityCacheByNameKey, ResolvedPolarisEntity> byName;

/**
Expand All @@ -59,7 +54,10 @@ public class InMemoryEntityCache implements EntityCache {
* @param polarisMetaStoreManager the meta store manager implementation
*/
public InMemoryEntityCache(
@Nonnull RealmConfig realmConfig, @Nonnull PolarisMetaStoreManager polarisMetaStoreManager) {
@Nonnull PolarisDiagnostics diagnostics,
@Nonnull RealmConfig realmConfig,
@Nonnull PolarisMetaStoreManager polarisMetaStoreManager) {
this.diagnostics = diagnostics;

// by name cache
this.byName = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -344,16 +342,13 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) {
}

// assert that entity, grant records and version are all set
callContext.getDiagServices().checkNotNull(entity, "unexpected_null_entity");
callContext.getDiagServices().checkNotNull(grantRecords, "unexpected_null_grant_records");
callContext
.getDiagServices()
.check(grantRecordsVersion > 0, "unexpected_null_grant_records_version");
diagnostics.checkNotNull(entity, "unexpected_null_entity");
diagnostics.checkNotNull(grantRecords, "unexpected_null_grant_records");
diagnostics.check(grantRecordsVersion > 0, "unexpected_null_grant_records_version");

// create new cache entry
newCacheEntry =
new ResolvedPolarisEntity(
callContext.getDiagServices(), entity, grantRecords, grantRecordsVersion);
new ResolvedPolarisEntity(diagnostics, entity, grantRecords, grantRecordsVersion);

// insert cache entry
this.replaceCacheEntry(existingCacheEntry, newCacheEntry);
Expand Down Expand Up @@ -401,13 +396,12 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) {
}

// if found, setup entry
callContext.getDiagServices().checkNotNull(result.getEntity(), "entity_should_loaded");
callContext
.getDiagServices()
.checkNotNull(result.getEntityGrantRecords(), "entity_grant_records_should_loaded");
diagnostics.checkNotNull(result.getEntity(), "entity_should_loaded");
diagnostics.checkNotNull(
result.getEntityGrantRecords(), "entity_grant_records_should_loaded");
entry =
new ResolvedPolarisEntity(
callContext.getDiagServices(),
diagnostics,
result.getEntity(),
result.getEntityGrantRecords(),
result.getGrantRecordsVersion());
Expand Down Expand Up @@ -458,15 +452,14 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) {
}

// validate return
callContext.getDiagServices().checkNotNull(result.getEntity(), "entity_should_loaded");
callContext
.getDiagServices()
.checkNotNull(result.getEntityGrantRecords(), "entity_grant_records_should_loaded");
diagnostics.checkNotNull(result.getEntity(), "entity_should_loaded");
diagnostics.checkNotNull(
result.getEntityGrantRecords(), "entity_grant_records_should_loaded");

// if found, setup entry
entry =
new ResolvedPolarisEntity(
callContext.getDiagServices(),
diagnostics,
result.getEntity(),
result.getEntityGrantRecords(),
result.getGrantRecordsVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class PolarisResolutionManifest implements PolarisResolutionManifestCatal
private ResolverStatus primaryResolverStatus = null;

public PolarisResolutionManifest(
PolarisDiagnostics diagnostics,
CallContext callContext,
ResolverFactory resolverFactory,
SecurityContext securityContext,
Expand All @@ -79,7 +80,7 @@ public PolarisResolutionManifest(
this.catalogName = catalogName;
this.primaryResolver =
resolverFactory.createResolver(callContext, securityContext, catalogName);
this.diagnostics = callContext.getPolarisCallContext().getDiagServices();
this.diagnostics = diagnostics;
this.diagnostics.checkNotNull(securityContext, "null_security_context_for_resolution_manifest");
this.securityContext = securityContext;
diagnostics.check(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import jakarta.ws.rs.core.SecurityContext;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.context.CallContext;

public class ResolutionManifestFactoryImpl implements ResolutionManifestFactory {

private final PolarisDiagnostics diagnostics;
private final ResolverFactory resolverFactory;

public ResolutionManifestFactoryImpl(@Nonnull ResolverFactory resolverFactory) {
public ResolutionManifestFactoryImpl(
@Nonnull PolarisDiagnostics diagnostics, @Nonnull ResolverFactory resolverFactory) {
this.diagnostics = diagnostics;
this.resolverFactory = resolverFactory;
}

Expand All @@ -39,6 +43,6 @@ public PolarisResolutionManifest createResolutionManifest(
@Nonnull SecurityContext securityContext,
@Nullable String referenceCatalogName) {
return new PolarisResolutionManifest(
callContext, resolverFactory, securityContext, referenceCatalogName);
diagnostics, callContext, resolverFactory, securityContext, referenceCatalogName);
}
}
Loading