diff --git a/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/EclipseLinkPolarisMetaStoreManagerFactory.java b/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/EclipseLinkPolarisMetaStoreManagerFactory.java index de121d8565..e9765cfe82 100644 --- a/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/EclipseLinkPolarisMetaStoreManagerFactory.java +++ b/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/EclipseLinkPolarisMetaStoreManagerFactory.java @@ -26,6 +26,7 @@ import java.nio.file.Path; import java.time.Clock; import org.apache.polaris.core.PolarisDiagnostics; +import org.apache.polaris.core.config.PolarisConfigurationStore; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; @@ -48,12 +49,13 @@ public class EclipseLinkPolarisMetaStoreManagerFactory @SuppressWarnings("unused") // Required by CDI protected EclipseLinkPolarisMetaStoreManagerFactory() { - this(null, null); + this(null, null, null); } @Inject - protected EclipseLinkPolarisMetaStoreManagerFactory(Clock clock, PolarisDiagnostics diagnostics) { - super(clock, diagnostics); + protected EclipseLinkPolarisMetaStoreManagerFactory( + Clock clock, PolarisDiagnostics diagnostics, PolarisConfigurationStore configurationStore) { + super(clock, diagnostics, configurationStore); } @Override diff --git a/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java b/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java index ccaf16cf0c..ad044b07f0 100644 --- a/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java +++ b/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java @@ -38,7 +38,6 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.EntityNameLookupRecord; @@ -160,8 +159,7 @@ static void clearEntityManagerFactories() { /** {@inheritDoc} */ @Override - public T runInTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Supplier transactionCode) { + public T runInTransaction(@Nonnull Supplier transactionCode) { getDiagnostics().check(localSession.get() == null, "cannot nest transaction"); try (EntityManager session = emf.createEntityManager()) { @@ -207,8 +205,7 @@ public T runInTransaction( /** {@inheritDoc} */ @Override - public void runActionInTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) { + public void runActionInTransaction(@Nonnull Runnable transactionCode) { getDiagnostics().check(localSession.get() == null, "cannot nest transaction"); try (EntityManager session = emf.createEntityManager()) { @@ -246,36 +243,33 @@ public void runActionInTransaction( /** {@inheritDoc} */ @Override - public T runInReadTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Supplier transactionCode) { + public T runInReadTransaction(@Nonnull Supplier transactionCode) { // EclipseLink doesn't support readOnly transaction - return runInTransaction(callCtx, transactionCode); + return runInTransaction(transactionCode); } /** {@inheritDoc} */ @Override - public void runActionInReadTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) { + public void runActionInReadTransaction(@Nonnull Runnable transactionCode) { // EclipseLink doesn't support readOnly transaction - runActionInTransaction(callCtx, transactionCode); + runActionInTransaction(transactionCode); } /** * @return new unique entity identifier */ @Override - public long generateNewIdInCurrentTxn(@Nonnull PolarisCallContext callCtx) { + public long generateNewIdInCurrentTxn() { // This function can be called within a transaction or out of transaction. // If called out of transaction, create a new transaction, otherwise run in current transaction return localSession.get() != null ? this.store.getNextSequence(localSession.get()) - : runInReadTransaction(callCtx, () -> generateNewIdInCurrentTxn(callCtx)); + : runInReadTransaction(this::generateNewIdInCurrentTxn); } /** {@inheritDoc} */ @Override - public void writeToEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { + public void writeToEntitiesInCurrentTxn(@Nonnull PolarisBaseEntity entity) { this.store.writeToEntities(localSession.get(), entity); } @@ -283,7 +277,6 @@ public void writeToEntitiesInCurrentTxn( @Override public void persistStorageIntegrationIfNeededInCurrentTxn( - @Nonnull PolarisCallContext callContext, @Nonnull PolarisBaseEntity entity, @Nullable PolarisStorageIntegration storageIntegration) { // not implemented for eclipselink store @@ -291,32 +284,28 @@ void persistStorageIntegrationIfNeededInCurrentTxn( /** {@inheritDoc} */ @Override - public void writeToEntitiesActiveInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { + public void writeToEntitiesActiveInCurrentTxn(@Nonnull PolarisBaseEntity entity) { // write it this.store.writeToEntitiesActive(localSession.get(), entity); } /** {@inheritDoc} */ @Override - public void writeToEntitiesChangeTrackingInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { + public void writeToEntitiesChangeTrackingInCurrentTxn(@Nonnull PolarisBaseEntity entity) { // write it this.store.writeToEntitiesChangeTracking(localSession.get(), entity); } /** {@inheritDoc} */ @Override - public void writeToGrantRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec) { + public void writeToGrantRecordsInCurrentTxn(@Nonnull PolarisGrantRecord grantRec) { // write it this.store.writeToGrantRecords(localSession.get(), grantRec); } /** {@inheritDoc} */ @Override - public void deleteFromEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity) { + public void deleteFromEntitiesInCurrentTxn(@Nonnull PolarisEntityCore entity) { // delete it this.store.deleteFromEntities( @@ -325,8 +314,7 @@ public void deleteFromEntitiesInCurrentTxn( /** {@inheritDoc} */ @Override - public void deleteFromEntitiesActiveInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity) { + public void deleteFromEntitiesActiveInCurrentTxn(@Nonnull PolarisEntityCore entity) { // delete it this.store.deleteFromEntitiesActive(localSession.get(), new PolarisEntitiesActiveKey(entity)); } @@ -334,27 +322,23 @@ public void deleteFromEntitiesActiveInCurrentTxn( /** * {@inheritDoc} * - * @param callCtx * @param entity entity record to delete */ @Override - public void deleteFromEntitiesChangeTrackingInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity) { + public void deleteFromEntitiesChangeTrackingInCurrentTxn(@Nonnull PolarisEntityCore entity) { // delete it this.store.deleteFromEntitiesChangeTracking(localSession.get(), entity); } /** {@inheritDoc} */ @Override - public void deleteFromGrantRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec) { + public void deleteFromGrantRecordsInCurrentTxn(@Nonnull PolarisGrantRecord grantRec) { this.store.deleteFromGrantRecords(localSession.get(), grantRec); } /** {@inheritDoc} */ @Override public void deleteAllEntityGrantRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity, @Nonnull List grantsOnGrantee, @Nonnull List grantsOnSecurable) { @@ -363,21 +347,21 @@ public void deleteAllEntityGrantRecordsInCurrentTxn( /** {@inheritDoc} */ @Override - public void deleteAllInCurrentTxn(@Nonnull PolarisCallContext callCtx) { + public void deleteAllInCurrentTxn() { this.store.deleteAll(localSession.get()); } /** {@inheritDoc} */ @Override public @Nullable PolarisBaseEntity lookupEntityInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, int typeCode) { + long catalogId, long entityId, int typeCode) { return ModelEntity.toEntity( this.store.lookupEntity(localSession.get(), catalogId, entityId, typeCode)); } @Override public @Nonnull List lookupEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, List entityIds) { + List entityIds) { return this.store.lookupEntities(localSession.get(), entityIds).stream() .map(ModelEntity::toEntity) .toList(); @@ -386,7 +370,7 @@ public void deleteAllInCurrentTxn(@Nonnull PolarisCallContext callCtx) { /** {@inheritDoc} */ @Override public @Nonnull List lookupEntityVersionsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, List entityIds) { + List entityIds) { Map idToEntityMap = this.store.lookupEntities(localSession.get(), entityIds).stream() .collect( @@ -409,7 +393,7 @@ public void deleteAllInCurrentTxn(@Nonnull PolarisCallContext callCtx) { @Override @Nullable public EntityNameLookupRecord lookupEntityActiveInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntitiesActiveKey entityActiveKey) { + @Nonnull PolarisEntitiesActiveKey entityActiveKey) { // lookup the active entity slice return ModelEntityActive.toEntityActive( this.store.lookupEntityActive(localSession.get(), entityActiveKey)); @@ -419,17 +403,15 @@ public EntityNameLookupRecord lookupEntityActiveInCurrentTxn( @Override @Nonnull public List lookupEntityActiveBatchInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull List entityActiveKeys) { // now build a list to quickly verify that nothing has changed return entityActiveKeys.stream() - .map(entityActiveKey -> this.lookupEntityActiveInCurrentTxn(callCtx, entityActiveKey)) + .map(this::lookupEntityActiveInCurrentTxn) .collect(Collectors.toList()); } @Override public @Nonnull Page loadEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long parentId, @Nonnull PolarisEntityType entityType, @@ -452,10 +434,7 @@ public List lookupEntityActiveBatchInCurrentTxn( /** {@inheritDoc} */ @Override public boolean hasChildrenInCurrentTxn( - @Nonnull PolarisCallContext callContext, - @Nullable PolarisEntityType entityType, - long catalogId, - long parentId) { + @Nullable PolarisEntityType entityType, long catalogId, long parentId) { // check if it has children return this.store.countActiveChildEntities(localSession.get(), catalogId, parentId, entityType) > 0; @@ -463,8 +442,7 @@ public boolean hasChildrenInCurrentTxn( /** {@inheritDoc} */ @Override - public int lookupEntityGrantRecordsVersionInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId) { + public int lookupEntityGrantRecordsVersionInCurrentTxn(long catalogId, long entityId) { ModelEntityChangeTracking entity = this.store.lookupEntityChangeTracking(localSession.get(), catalogId, entityId); @@ -475,7 +453,6 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nullable PolarisGrantRecord lookupGrantRecordInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId, long granteeCatalogId, @@ -495,7 +472,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nonnull List loadAllGrantRecordsOnSecurableInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId) { + long securableCatalogId, long securableId) { // now fetch all grants for this securable return this.store .lookupAllGrantRecordsOnSecurable(localSession.get(), securableCatalogId, securableId) @@ -507,7 +484,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nonnull List loadAllGrantRecordsOnGranteeInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long granteeCatalogId, long granteeId) { + long granteeCatalogId, long granteeId) { // now fetch all grants assigned to this grantee return this.store .lookupGrantRecordsOnGrantee(localSession.get(), granteeCatalogId, granteeId) @@ -519,7 +496,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nullable PolarisPrincipalSecrets loadPrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId) { + @Nonnull String clientId) { return ModelPrincipalSecrets.toPrincipalSecrets( this.store.lookupPrincipalSecrets(localSession.get(), clientId)); } @@ -527,7 +504,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nonnull PolarisPrincipalSecrets generateNewPrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull String principalName, long principalId) { + @Nonnull String principalName, long principalId) { // ensure principal client id is unique PolarisPrincipalSecrets principalSecrets; ModelPrincipalSecrets lookupPrincipalSecrets; @@ -551,11 +528,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nonnull PolarisPrincipalSecrets rotatePrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - @Nonnull String clientId, - long principalId, - boolean reset, - @Nonnull String oldSecretHash) { + @Nonnull String clientId, long principalId, boolean reset, @Nonnull String oldSecretHash) { // load the existing secrets PolarisPrincipalSecrets principalSecrets = @@ -595,8 +568,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override - public void deletePrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId, long principalId) { + public void deletePrincipalSecretsInCurrentTxn(@Nonnull String clientId, long principalId) { // load the existing secrets ModelPrincipalSecrets principalSecrets = this.store.lookupPrincipalSecrets(localSession.get(), clientId); @@ -627,7 +599,6 @@ public void deletePrincipalSecretsInCurrentTxn( @Override public @Nullable PolarisStorageIntegration createStorageIntegrationInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, PolarisStorageConfigurationInfo polarisStorageConfigurationInfo) { @@ -639,7 +610,7 @@ PolarisStorageIntegration createStorageIntegrationInCurrentTxn( @Override public @Nullable PolarisStorageIntegration loadPolarisStorageIntegrationInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { + @Nonnull PolarisBaseEntity entity) { PolarisStorageConfigurationInfo storageConfig = BaseMetaStoreManager.extractStorageConfiguration(getDiagnostics(), entity); return storageIntegrationProvider.getStorageIntegrationForConfig(storageConfig); @@ -647,8 +618,7 @@ PolarisStorageIntegration loadPolarisStorageIntegrationInCurrentTxn( /** {@inheritDoc} */ @Override - public void writeToPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + public void writeToPolicyMappingRecordsInCurrentTxn(@Nonnull PolarisPolicyMappingRecord record) { this.store.writeToPolicyMappingRecords(localSession.get(), record); } @@ -656,14 +626,13 @@ public void writeToPolicyMappingRecordsInCurrentTxn( /** {@inheritDoc} */ @Override public void deleteFromPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + @Nonnull PolarisPolicyMappingRecord record) { this.store.deleteFromPolicyMappingRecords(localSession.get(), record); } /** {@inheritDoc} */ @Override public void deleteAllEntityPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, @Nonnull List mappingOnTarget, @Nonnull List mappingOnPolicy) { @@ -674,7 +643,6 @@ public void deleteAllEntityPolicyMappingRecordsInCurrentTxn( @Nullable @Override public PolarisPolicyMappingRecord lookupPolicyMappingRecordInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId, int policyTypeCode, @@ -694,10 +662,7 @@ public PolarisPolicyMappingRecord lookupPolicyMappingRecordInCurrentTxn( @Nonnull @Override public List loadPoliciesOnTargetByTypeInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - long targetCatalogId, - long targetId, - int policyTypeCode) { + long targetCatalogId, long targetId, int policyTypeCode) { return this.store .loadPoliciesOnTargetByType(localSession.get(), targetCatalogId, targetId, policyTypeCode) .stream() @@ -709,7 +674,7 @@ public List loadPoliciesOnTargetByTypeInCurrentTxn( @Nonnull @Override public List loadAllPoliciesOnTargetInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId) { + long targetCatalogId, long targetId) { return this.store .loadAllPoliciesOnTarget(localSession.get(), targetCatalogId, targetId) .stream() @@ -721,10 +686,7 @@ public List loadAllPoliciesOnTargetInCurrentTxn( @Nonnull @Override public List loadAllTargetsOnPolicyInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - long policyCatalogId, - long policyId, - int policyTypeCode) { + long policyCatalogId, long policyId, int policyTypeCode) { return this.store .loadAllTargetsOnPolicy(localSession.get(), policyCatalogId, policyId, policyTypeCode) .stream() @@ -743,18 +705,14 @@ public void rollback() { /** {@inheritDoc} */ @Override public - Optional> hasOverlappingSiblings( - @Nonnull PolarisCallContext callContext, T entity) { + Optional> hasOverlappingSiblings(T entity) { return Optional.empty(); } @Nullable @Override public PolarisPrincipalSecrets storePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - long principalId, - @Nonnull String resolvedClientId, - String customClientSecret) { + long principalId, @Nonnull String resolvedClientId, String customClientSecret) { throw new UnsupportedOperationException( "This method is not supported for EclipseLink as metastore"); } diff --git a/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java b/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java index bf358cca0d..df998a266d 100644 --- a/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java +++ b/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java @@ -32,10 +32,8 @@ import java.nio.file.Path; import java.util.Objects; import java.util.stream.Stream; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest; import org.apache.polaris.core.persistence.PolarisTestMetaStoreManager; @@ -83,14 +81,13 @@ static void prepareConfFiles(@TempDir Path archiveDir) throws IOException { protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() { PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl(); PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices); - RealmContext realmContext = () -> "realm"; PolarisEclipseLinkMetaStoreSessionImpl session = new PolarisEclipseLinkMetaStoreSessionImpl( diagServices, store, Mockito.mock(), realmContext, null, "polaris", RANDOM_SECRETS); TransactionalMetaStoreManagerImpl metaStoreManager = - new TransactionalMetaStoreManagerImpl(clock, diagServices); - PolarisCallContext callCtx = new PolarisCallContext(realmContext, session); - return new PolarisTestMetaStoreManager(metaStoreManager, callCtx); + new TransactionalMetaStoreManagerImpl( + clock, diagServices, realmContext, realmConfig, () -> session); + return new PolarisTestMetaStoreManager(metaStoreManager); } @ParameterizedTest diff --git a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java index 8d6201453f..38db731458 100644 --- a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java +++ b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java @@ -36,7 +36,6 @@ import java.util.function.Function; 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; @@ -107,19 +106,17 @@ public JdbcBasePersistenceImpl( } @Override - public long generateNewId(@Nonnull PolarisCallContext callCtx) { + public long generateNewId() { return IdGenerator.getIdGenerator().nextId(); } @Override public void writeEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, boolean nameOrParentChanged, PolarisBaseEntity originalEntity) { try { persistEntity( - callCtx, entity, originalEntity, null, @@ -133,9 +130,7 @@ public void writeEntity( @Override public void writeEntities( - @Nonnull PolarisCallContext callCtx, - @Nonnull List entities, - List originalEntities) { + @Nonnull List entities, List originalEntities) { try { datasourceOperations.runWithinTransaction( connection -> { @@ -146,16 +141,14 @@ public void writeEntities( // first, check if the entity has already been created, in which case we will simply // return it. PolarisBaseEntity entityFound = - lookupEntity( - callCtx, entity.getCatalogId(), entity.getId(), entity.getTypeCode()); + lookupEntity(entity.getCatalogId(), entity.getId(), entity.getTypeCode()); if (entityFound != null && originalEntity == null) { // probably the client retried, simply return it // TODO: Check correctness of returning entityFound vs entity here. It may have // already been updated after the creation. continue; } - persistEntity( - callCtx, entity, originalEntity, connection, datasourceOperations::execute); + persistEntity(entity, originalEntity, connection, datasourceOperations::execute); } return true; }); @@ -168,7 +161,6 @@ public void writeEntities( } private void persistEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, PolarisBaseEntity originalEntity, Connection connection, @@ -190,7 +182,6 @@ private void persistEntity( if (datasourceOperations.isConstraintViolation(e)) { PolarisBaseEntity existingEntity = lookupEntityByName( - callCtx, entity.getCatalogId(), entity.getParentId(), entity.getTypeCode(), @@ -242,8 +233,7 @@ private void persistEntity( } @Override - public void writeToGrantRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec) { + public void writeToGrantRecords(@Nonnull PolarisGrantRecord grantRec) { ModelGrantRecord modelGrantRecord = ModelGrantRecord.fromGrantRecord(grantRec); try { List values = @@ -315,7 +305,7 @@ public void writeEvents(@Nonnull List events) { } @Override - public void deleteEntity(@Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { + public void deleteEntity(@Nonnull PolarisBaseEntity entity) { ModelEntity modelEntity = ModelEntity.fromEntity(entity, schemaVersion); Map params = Map.of( @@ -336,8 +326,7 @@ public void deleteEntity(@Nonnull PolarisCallContext callCtx, @Nonnull PolarisBa } @Override - public void deleteFromGrantRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec) { + public void deleteFromGrantRecords(@Nonnull PolarisGrantRecord grantRec) { ModelGrantRecord modelGrantRecord = ModelGrantRecord.fromGrantRecord(grantRec); try { Map whereClause = @@ -354,7 +343,6 @@ public void deleteFromGrantRecords( @Override public void deleteAllEntityGrantRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity, @Nonnull List grantsOnGrantee, @Nonnull List grantsOnSecurable) { @@ -368,7 +356,7 @@ public void deleteAllEntityGrantRecords( } @Override - public void deleteAll(@Nonnull PolarisCallContext callCtx) { + public void deleteAll() { try { Map params = Map.of("realm_id", realmId); datasourceOperations.runWithinTransaction( @@ -402,8 +390,7 @@ public void deleteAll(@Nonnull PolarisCallContext callCtx) { } @Override - public PolarisBaseEntity lookupEntity( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, int typeCode) { + public PolarisBaseEntity lookupEntity(long catalogId, long entityId, int typeCode) { Map params = Map.of("catalog_id", catalogId, "id", entityId, "type_code", typeCode, "realm_id", realmId); return getPolarisBaseEntity( @@ -413,11 +400,7 @@ public PolarisBaseEntity lookupEntity( @Override public PolarisBaseEntity lookupEntityByName( - @Nonnull PolarisCallContext callCtx, - long catalogId, - long parentId, - int typeCode, - @Nonnull String name) { + long catalogId, long parentId, int typeCode, @Nonnull String name) { Map params = Map.of( "catalog_id", @@ -457,8 +440,7 @@ private PolarisBaseEntity getPolarisBaseEntity(QueryGenerator.PreparedQuery quer @Nonnull @Override - public List lookupEntities( - @Nonnull PolarisCallContext callCtx, List entityIds) { + public List lookupEntities(List entityIds) { if (entityIds == null || entityIds.isEmpty()) return new ArrayList<>(); PreparedQuery query = QueryGenerator.generateSelectQueryWithEntityIds(realmId, schemaVersion, entityIds); @@ -472,10 +454,9 @@ public List lookupEntities( @Nonnull @Override - public List lookupEntityVersions( - @Nonnull PolarisCallContext callCtx, List entityIds) { + public List lookupEntityVersions(List entityIds) { Map idToEntityMap = - lookupEntities(callCtx, entityIds).stream() + lookupEntities(entityIds).stream() .collect( Collectors.toMap( entry -> new PolarisEntityId(entry.getCatalogId(), entry.getId()), @@ -538,7 +519,6 @@ private PreparedQuery buildEntityQuery( @Nonnull @Override public Page listEntities( - @Nonnull PolarisCallContext callCtx, long catalogId, long parentId, @Nonnull PolarisEntityType entityType, @@ -571,7 +551,6 @@ public Page listEntities( @Nonnull @Override public Page loadEntities( - @Nonnull PolarisCallContext callCtx, long catalogId, long parentId, @Nonnull PolarisEntityType entityType, @@ -604,8 +583,7 @@ public Page loadEntities( } @Override - public int lookupEntityGrantRecordsVersion( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId) { + public int lookupEntityGrantRecordsVersion(long catalogId, long entityId) { Map params = Map.of("catalog_id", catalogId, "id", entityId, "realm_id", realmId); @@ -618,7 +596,6 @@ public int lookupEntityGrantRecordsVersion( @Override public PolarisGrantRecord lookupGrantRecord( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId, long granteeCatalogId, @@ -661,7 +638,7 @@ public PolarisGrantRecord lookupGrantRecord( @Nonnull @Override public List loadAllGrantRecordsOnSecurable( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId) { + long securableCatalogId, long securableId) { Map params = Map.of( "securable_catalog_id", @@ -689,7 +666,7 @@ public List loadAllGrantRecordsOnSecurable( @Nonnull @Override public List loadAllGrantRecordsOnGrantee( - @Nonnull PolarisCallContext callCtx, long granteeCatalogId, long granteeId) { + long granteeCatalogId, long granteeId) { Map params = Map.of( "grantee_catalog_id", granteeCatalogId, "grantee_id", granteeId, "realm_id", realmId); @@ -710,11 +687,7 @@ public List loadAllGrantRecordsOnGrantee( } @Override - public boolean hasChildren( - @Nonnull PolarisCallContext callContext, - PolarisEntityType optionalEntityType, - long catalogId, - long parentId) { + public boolean hasChildren(PolarisEntityType optionalEntityType, long catalogId, long parentId) { Map params = new HashMap<>(); params.put("realm_id", realmId); params.put("catalog_id", catalogId); @@ -773,8 +746,7 @@ static boolean entityTableExists(DatasourceOperations datasourceOperations) { /** {@inheritDoc} */ @Override public - Optional> hasOverlappingSiblings( - @Nonnull PolarisCallContext callContext, T entity) { + Optional> hasOverlappingSiblings(T entity) { if (this.schemaVersion < 2) { return Optional.empty(); } @@ -815,8 +787,7 @@ Optional> hasOverlappingSiblings( @Nullable @Override - public PolarisPrincipalSecrets loadPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId) { + public PolarisPrincipalSecrets loadPrincipalSecrets(@Nonnull String clientId) { Map params = Map.of("principal_client_id", clientId, "realm_id", realmId); try { var results = @@ -841,7 +812,7 @@ public PolarisPrincipalSecrets loadPrincipalSecrets( @Nonnull @Override public PolarisPrincipalSecrets generateNewPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String principalName, long principalId) { + @Nonnull String principalName, long principalId) { // ensure principal client id is unique PolarisPrincipalSecrets principalSecrets; ModelPrincipalAuthenticationData lookupPrincipalSecrets; @@ -852,7 +823,7 @@ public PolarisPrincipalSecrets generateNewPrincipalSecrets( // load the existing secrets lookupPrincipalSecrets = ModelPrincipalAuthenticationData.fromPrincipalAuthenticationData( - loadPrincipalSecrets(callCtx, principalSecrets.getPrincipalClientId())); + loadPrincipalSecrets(principalSecrets.getPrincipalClientId())); } while (lookupPrincipalSecrets != null); lookupPrincipalSecrets = @@ -887,10 +858,7 @@ public PolarisPrincipalSecrets generateNewPrincipalSecrets( @Nullable @Override public PolarisPrincipalSecrets storePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - long principalId, - @Nonnull String resolvedClientId, - String customClientSecret) { + long principalId, @Nonnull String resolvedClientId, String customClientSecret) { PolarisPrincipalSecrets principalSecrets = new PolarisPrincipalSecrets(principalId, resolvedClientId, customClientSecret); try { @@ -923,13 +891,9 @@ public PolarisPrincipalSecrets storePrincipalSecrets( @Nullable @Override public PolarisPrincipalSecrets rotatePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - @Nonnull String clientId, - long principalId, - boolean reset, - @Nonnull String oldSecretHash) { + @Nonnull String clientId, long principalId, boolean reset, @Nonnull String oldSecretHash) { // load the existing secrets - PolarisPrincipalSecrets principalSecrets = loadPrincipalSecrets(callCtx, clientId); + PolarisPrincipalSecrets principalSecrets = loadPrincipalSecrets(clientId); // should be found diagnostics.checkNotNull( @@ -982,8 +946,7 @@ public PolarisPrincipalSecrets rotatePrincipalSecrets( } @Override - public void deletePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId, long principalId) { + public void deletePrincipalSecrets(@Nonnull String clientId, long principalId) { Map params = Map.of("principal_client_id", clientId, "principal_id", principalId, "realm_id", realmId); try { @@ -1004,8 +967,7 @@ public void deletePrincipalSecrets( } @Override - public void writeToPolicyMappingRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + public void writeToPolicyMappingRecords(@Nonnull PolarisPolicyMappingRecord record) { try { datasourceOperations.runWithinTransaction( connection -> { @@ -1027,7 +989,7 @@ public void writeToPolicyMappingRecords( values, realmId); if (policyType.isInheritable()) { - return handleInheritablePolicy(callCtx, record, insertPolicyMappingQuery, connection); + return handleInheritablePolicy(record, insertPolicyMappingQuery, connection); } else { datasourceOperations.execute(connection, insertPolicyMappingQuery); } @@ -1040,14 +1002,13 @@ public void writeToPolicyMappingRecords( } private boolean handleInheritablePolicy( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record, @Nonnull PreparedQuery insertQuery, Connection connection) throws SQLException { List existingRecords = loadPoliciesOnTargetByType( - callCtx, record.getTargetCatalogId(), record.getTargetId(), record.getPolicyTypeCode()); + record.getTargetCatalogId(), record.getTargetId(), record.getPolicyTypeCode()); if (existingRecords.size() > 1) { throw new PolicyMappingAlreadyExistsException(existingRecords.getFirst()); } else if (existingRecords.size() == 1) { @@ -1094,8 +1055,7 @@ private boolean handleInheritablePolicy( } @Override - public void deleteFromPolicyMappingRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + public void deleteFromPolicyMappingRecords(@Nonnull PolarisPolicyMappingRecord record) { var modelPolicyMappingRecord = ModelPolicyMappingRecord.fromPolicyMappingRecord(record); try { Map objectMap = @@ -1114,7 +1074,6 @@ public void deleteFromPolicyMappingRecords( @Override public void deleteAllEntityPolicyMappingRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, @Nonnull List mappingOnTarget, @Nonnull List mappingOnPolicy) { @@ -1144,7 +1103,6 @@ public void deleteAllEntityPolicyMappingRecords( @Nullable @Override public PolarisPolicyMappingRecord lookupPolicyMappingRecord( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId, int policyTypeCode, @@ -1175,10 +1133,7 @@ public PolarisPolicyMappingRecord lookupPolicyMappingRecord( @Nonnull @Override public List loadPoliciesOnTargetByType( - @Nonnull PolarisCallContext callCtx, - long targetCatalogId, - long targetId, - int policyTypeCode) { + long targetCatalogId, long targetId, int policyTypeCode) { Map params = Map.of( "target_catalog_id", @@ -1197,7 +1152,7 @@ public List loadPoliciesOnTargetByType( @Nonnull @Override public List loadAllPoliciesOnTarget( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId) { + long targetCatalogId, long targetId) { Map params = Map.of("target_catalog_id", targetCatalogId, "target_id", targetId, "realm_id", realmId); return fetchPolicyMappingRecords( @@ -1208,10 +1163,7 @@ public List loadAllPoliciesOnTarget( @Nonnull @Override public List loadAllTargetsOnPolicy( - @Nonnull PolarisCallContext callCtx, - long policyCatalogId, - long policyId, - int policyTypeCode) { + long policyCatalogId, long policyId, int policyTypeCode) { Map params = Map.of( "policy_type_code", @@ -1242,7 +1194,6 @@ private List fetchPolicyMappingRecords( @Override public PolarisStorageIntegration createStorageIntegration( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, PolarisStorageConfigurationInfo polarisStorageConfigurationInfo) { @@ -1252,7 +1203,6 @@ PolarisStorageIntegration createStorageIntegration( @Override public void persistStorageIntegrationIfNeeded( - @Nonnull PolarisCallContext callContext, @Nonnull PolarisBaseEntity entity, @Nullable PolarisStorageIntegration storageIntegration) {} @@ -1260,7 +1210,7 @@ public void persistStorageIntegratio @Override public PolarisStorageIntegration loadPolarisStorageIntegration( - @Nonnull PolarisCallContext callContext, @Nonnull PolarisBaseEntity entity) { + @Nonnull PolarisBaseEntity entity) { PolarisStorageConfigurationInfo storageConfig = BaseMetaStoreManager.extractStorageConfiguration(diagnostics, entity); return storageIntegrationProvider.getStorageIntegrationForConfig(storageConfig); diff --git a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java index e46cc7277e..33fc2bc553 100644 --- a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java +++ b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java @@ -30,11 +30,11 @@ import java.util.Optional; import java.util.function.Supplier; import javax.sql.DataSource; -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.PolarisConfigurationStore; import org.apache.polaris.core.config.RealmConfig; +import org.apache.polaris.core.config.RealmConfigImpl; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.persistence.AtomicOperationMetaStoreManager; @@ -66,7 +66,6 @@ public class JdbcMetaStoreManagerFactory implements MetaStoreManagerFactory { private static final Logger LOGGER = LoggerFactory.getLogger(JdbcMetaStoreManagerFactory.class); - final Map metaStoreManagerMap = new HashMap<>(); final Map entityCacheMap = new HashMap<>(); final Map> sessionSupplierMap = new HashMap<>(); @@ -88,10 +87,6 @@ protected PrincipalSecretsGenerator secretsGenerator( } } - protected PolarisMetaStoreManager createNewMetaStoreManager() { - return new AtomicOperationMetaStoreManager(clock, diagnostics); - } - private void initializeForRealm( DatasourceOperations datasourceOperations, RealmContext realmContext, @@ -115,9 +110,6 @@ private void initializeForRealm( storageIntegrationProvider, realmId, schemaVersion)); - - PolarisMetaStoreManager metaStoreManager = createNewMetaStoreManager(); - metaStoreManagerMap.put(realmId, metaStoreManager); } public DatasourceOperations getDatasourceOperations() { @@ -152,7 +144,7 @@ public synchronized Map bootstrapRealms( for (String realm : bootstrapOptions.realms()) { RealmContext realmContext = () -> realm; - if (!metaStoreManagerMap.containsKey(realm)) { + if (!sessionSupplierMap.containsKey(realm)) { DatasourceOperations datasourceOperations = getDatasourceOperations(); int currentSchemaVersion = JdbcBasePersistenceImpl.loadSchemaVersion( @@ -196,52 +188,45 @@ public Map purgeRealms(Iterable realms) { for (String realm : realms) { RealmContext realmContext = () -> realm; - PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext); - BasePersistence session = getOrCreateSession(realmContext); + PolarisMetaStoreManager metaStoreManager = createMetaStoreManager(realmContext); - PolarisCallContext callContext = new PolarisCallContext(realmContext, session); - BaseResult result = metaStoreManager.purge(callContext); + BaseResult result = metaStoreManager.purge(); results.put(realm, result); sessionSupplierMap.remove(realm); - metaStoreManagerMap.remove(realm); } return Map.copyOf(results); } @Override - public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager( - RealmContext realmContext) { - if (!metaStoreManagerMap.containsKey(realmContext.getRealmIdentifier())) { - DatasourceOperations datasourceOperations = getDatasourceOperations(); - initializeForRealm(datasourceOperations, realmContext, null); - checkPolarisServiceBootstrappedForRealm(realmContext); - } - return metaStoreManagerMap.get(realmContext.getRealmIdentifier()); + public PolarisMetaStoreManager createMetaStoreManager(RealmContext realmContext) { + RealmConfig realmConfig = new RealmConfigImpl(configurationStore, realmContext); + return new AtomicOperationMetaStoreManager( + clock, + diagnostics, + realmContext, + realmConfig, + () -> createPersistenceSession(realmContext)); } - @Override - public synchronized BasePersistence getOrCreateSession(RealmContext realmContext) { + protected synchronized BasePersistence createPersistenceSession(RealmContext realmContext) { if (!sessionSupplierMap.containsKey(realmContext.getRealmIdentifier())) { DatasourceOperations datasourceOperations = getDatasourceOperations(); initializeForRealm(datasourceOperations, realmContext, null); + checkPolarisServiceBootstrappedForRealm(realmContext); } - checkPolarisServiceBootstrappedForRealm(realmContext); return sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(); } @Override - public synchronized EntityCache getOrCreateEntityCache( - RealmContext realmContext, RealmConfig realmConfig) { - if (!entityCacheMap.containsKey(realmContext.getRealmIdentifier())) { - PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext); - entityCacheMap.put( - realmContext.getRealmIdentifier(), - new InMemoryEntityCache(diagnostics, realmConfig, metaStoreManager)); - } - - return entityCacheMap.get(realmContext.getRealmIdentifier()); + public synchronized EntityCache getOrCreateEntityCache(RealmContext realmContext) { + return entityCacheMap.computeIfAbsent( + realmContext.getRealmIdentifier(), + realmId -> { + RealmConfig realmConfig = new RealmConfigImpl(configurationStore, realmContext); + return new InMemoryEntityCache(diagnostics, realmConfig); + }); } /** @@ -250,15 +235,9 @@ public synchronized EntityCache getOrCreateEntityCache( */ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm( RealmContext realmContext) { - // While bootstrapping we need to act as a fake privileged context since the real - // 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); + PolarisMetaStoreManager metaStoreManager = createMetaStoreManager(realmContext); - Optional preliminaryRootPrincipal = - metaStoreManager.findRootPrincipal(polarisContext); + Optional preliminaryRootPrincipal = metaStoreManager.findRootPrincipal(); if (preliminaryRootPrincipal.isPresent()) { String overrideMessage = "It appears this metastore manager has already been bootstrapped. " @@ -267,11 +246,10 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm throw new IllegalArgumentException(overrideMessage); } - metaStoreManager.bootstrapPolarisService(polarisContext); + metaStoreManager.bootstrapPolarisService(); - PrincipalEntity rootPrincipal = - metaStoreManager.findRootPrincipal(polarisContext).orElseThrow(); - return metaStoreManager.loadPrincipalSecrets(polarisContext, rootPrincipal.getClientId()); + PrincipalEntity rootPrincipal = metaStoreManager.findRootPrincipal().orElseThrow(); + return metaStoreManager.loadPrincipalSecrets(rootPrincipal.getClientId()); } /** @@ -282,12 +260,9 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm * entities */ private void checkPolarisServiceBootstrappedForRealm(RealmContext realmContext) { - PolarisMetaStoreManager metaStoreManager = - metaStoreManagerMap.get(realmContext.getRealmIdentifier()); - BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(); - PolarisCallContext polarisContext = new PolarisCallContext(realmContext, metaStore); + PolarisMetaStoreManager metaStoreManager = createMetaStoreManager(realmContext); - Optional rootPrincipal = metaStoreManager.findRootPrincipal(polarisContext); + Optional rootPrincipal = metaStoreManager.findRootPrincipal(); if (rootPrincipal.isEmpty()) { LOGGER.error( "\n\n Realm {} is not bootstrapped, could not load root principal. Please run Bootstrap command. \n\n", diff --git a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplTest.java b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplTest.java index dedce84198..2349cc72d3 100644 --- a/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplTest.java +++ b/persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplTest.java @@ -24,10 +24,8 @@ import java.sql.SQLException; import java.util.Optional; import javax.sql.DataSource; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.persistence.AtomicOperationMetaStoreManager; import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest; import org.apache.polaris.core.persistence.PolarisTestMetaStoreManager; @@ -64,7 +62,6 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() { e); } - RealmContext realmContext = () -> "REALM"; JdbcBasePersistenceImpl basePersistence = new JdbcBasePersistenceImpl( diagServices, @@ -74,9 +71,9 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() { realmContext.getRealmIdentifier(), schemaVersion()); AtomicOperationMetaStoreManager metaStoreManager = - new AtomicOperationMetaStoreManager(clock, diagServices); - PolarisCallContext callCtx = new PolarisCallContext(realmContext, basePersistence); - return new PolarisTestMetaStoreManager(metaStoreManager, callCtx); + new AtomicOperationMetaStoreManager( + clock, diagServices, realmContext, realmConfig, () -> basePersistence); + return new PolarisTestMetaStoreManager(metaStoreManager); } private static class H2JdbcConfiguration implements RelationalJdbcConfiguration { diff --git a/polaris-core/src/main/java/org/apache/polaris/core/PolarisCallContext.java b/polaris-core/src/main/java/org/apache/polaris/core/PolarisCallContext.java index 272b455e76..3696239349 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/PolarisCallContext.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/PolarisCallContext.java @@ -24,7 +24,6 @@ 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 @@ -32,29 +31,19 @@ */ public class PolarisCallContext implements CallContext { - // meta store which is used to persist Polaris entity metadata - private final BasePersistence metaStore; private final PolarisConfigurationStore configurationStore; private final RealmContext realmContext; private final RealmConfig realmConfig; public PolarisCallContext( - @Nonnull RealmContext realmContext, - @Nonnull BasePersistence metaStore, - @Nonnull PolarisConfigurationStore configurationStore) { + @Nonnull RealmContext realmContext, @Nonnull PolarisConfigurationStore configurationStore) { this.realmContext = realmContext; - this.metaStore = metaStore; this.configurationStore = configurationStore; this.realmConfig = new RealmConfigImpl(this.configurationStore, this.realmContext); } - public PolarisCallContext( - @Nonnull RealmContext realmContext, @Nonnull BasePersistence metaStore) { - this(realmContext, metaStore, new PolarisConfigurationStore() {}); - } - - public BasePersistence getMetaStore() { - return metaStore; + public PolarisCallContext(@Nonnull RealmContext realmContext) { + this(realmContext, new PolarisConfigurationStore() {}); } @Override @@ -81,6 +70,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.configurationStore); + return new PolarisCallContext(realmContext, this.configurationStore); } } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java index 2583eda6d7..0c6003f0a6 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisGrantManager.java @@ -21,7 +21,6 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import java.util.List; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.PolarisEntityCore; import org.apache.polaris.core.entity.PolarisPrivilege; import org.apache.polaris.core.persistence.dao.entity.LoadGrantsResult; @@ -33,7 +32,6 @@ public interface PolarisGrantManager { * Grant usage on a role to a grantee, for example granting usage on a catalog role to a principal * role or granting a principal role to a principal. * - * @param callCtx call context * @param catalog if the role is a catalog role, the caller needs to pass-in the catalog entity * which was used to resolve that granted. Else null. * @param role resolved catalog or principal role @@ -43,7 +41,6 @@ public interface PolarisGrantManager { */ @Nonnull PrivilegeResult grantUsageOnRoleToGrantee( - @Nonnull PolarisCallContext callCtx, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @Nonnull PolarisEntityCore grantee); @@ -52,7 +49,6 @@ PrivilegeResult grantUsageOnRoleToGrantee( * Revoke usage on a role (a catalog or a principal role) from a grantee (e.g. a principal role or * a principal). * - * @param callCtx call context * @param catalog if the granted is a catalog role, the caller needs to pass-in the catalog entity * which was used to resolve that role. Else null should be passed-in. * @param role a catalog/principal role as resolved by the caller @@ -63,7 +59,6 @@ PrivilegeResult grantUsageOnRoleToGrantee( */ @Nonnull PrivilegeResult revokeUsageOnRoleFromGrantee( - @Nonnull PolarisCallContext callCtx, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @Nonnull PolarisEntityCore grantee); @@ -71,7 +66,6 @@ PrivilegeResult revokeUsageOnRoleFromGrantee( /** * Grant a privilege on a catalog securable to a grantee. * - * @param callCtx call context * @param grantee resolved role, the grantee * @param catalogPath path to that entity, cannot be null or empty unless securable is top-level * @param securable securable entity, must have been resolved by the client. Can be the catalog @@ -82,7 +76,6 @@ PrivilegeResult revokeUsageOnRoleFromGrantee( */ @Nonnull PrivilegeResult grantPrivilegeOnSecurableToRole( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @Nonnull PolarisEntityCore securable, @@ -91,7 +84,6 @@ PrivilegeResult grantPrivilegeOnSecurableToRole( /** * Revoke a privilege on a catalog securable from a grantee. * - * @param callCtx call context * @param grantee resolved role, the grantee * @param catalogPath path to that entity, cannot be null or empty unless securable is top-level * @param securable securable entity, must have been resolved by the client. Can be the catalog @@ -103,7 +95,6 @@ PrivilegeResult grantPrivilegeOnSecurableToRole( */ @Nonnull PrivilegeResult revokePrivilegeOnSecurableFromRole( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @Nonnull PolarisEntityCore securable, @@ -112,25 +103,21 @@ PrivilegeResult revokePrivilegeOnSecurableFromRole( /** * This method should be used by the Polaris app to cache all grant records on a securable. * - * @param callCtx call context * @param securable the securable entity * @return the list of grants and the version of the grant records. We will return * ENTITY_NOT_FOUND if the securable cannot be found */ @Nonnull - LoadGrantsResult loadGrantsOnSecurable( - @Nonnull PolarisCallContext callCtx, PolarisEntityCore securable); + LoadGrantsResult loadGrantsOnSecurable(PolarisEntityCore securable); /** * This method should be used by the Polaris app to load all grants made to a grantee, either a * role or a principal. * - * @param callCtx call context * @param grantee the grantee entity * @return the list of grants and the version of the grant records. We will return NULL if the * grantee does not exist */ @Nonnull - LoadGrantsResult loadGrantsToGrantee( - @Nonnull PolarisCallContext callCtx, PolarisEntityCore grantee); + LoadGrantsResult loadGrantsToGrantee(PolarisEntityCore grantee); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisSecretsManager.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisSecretsManager.java index 28da598ef0..d64f44150c 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisSecretsManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisSecretsManager.java @@ -19,7 +19,6 @@ package org.apache.polaris.core.auth; import jakarta.annotation.Nonnull; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult; /** Manages secrets for Polaris principals. */ @@ -27,18 +26,15 @@ public interface PolarisSecretsManager { /** * Load the principal secrets given the client_id. * - * @param callCtx call context * @param clientId principal client id * @return the secrets associated to that principal, including the entity id of the principal */ @Nonnull - PrincipalSecretsResult loadPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId); + PrincipalSecretsResult loadPrincipalSecrets(@Nonnull String clientId); /** * Rotate secrets * - * @param callCtx call context * @param clientId principal client id * @param principalId id of the principal * @param reset true if the principal's secrets should be disabled and replaced with a one-time @@ -49,11 +45,7 @@ PrincipalSecretsResult loadPrincipalSecrets( */ @Nonnull PrincipalSecretsResult rotatePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - @Nonnull String clientId, - long principalId, - boolean reset, - @Nonnull String oldSecretHash); + @Nonnull String clientId, long principalId, boolean reset, @Nonnull String oldSecretHash); /** * Reset the secrets of a principal entity. @@ -62,7 +54,6 @@ PrincipalSecretsResult rotatePrincipalSecrets( * generated) the active credentials for the principal. It effectively overwrites any previous * secrets and sets the provided values as the new client id/secret for the principal. * - * @param callCtx call context * @param principalId id of the principal * @param resolvedClientId current principal client id * @param customClientSecret optional new client secret to assign (may be {@code null} if @@ -71,21 +62,16 @@ PrincipalSecretsResult rotatePrincipalSecrets( */ @Nonnull PrincipalSecretsResult resetPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - long principalId, - @Nonnull String resolvedClientId, - String customClientSecret); + long principalId, @Nonnull String resolvedClientId, String customClientSecret); /** * Permanently delete the secrets of a principal. * *

This operation removes all stored secrets associated with the given principal * - * @param callCtx call context * @param clientId principal client id * @param principalId id of the principal whose secrets should be deleted */ @Nonnull - void deletePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId, long principalId); + void deletePrincipalSecrets(@Nonnull String clientId, long principalId); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEventManager.java b/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEventManager.java index b4b7891338..f92ab6f53a 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEventManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/entity/PolarisEventManager.java @@ -21,14 +21,7 @@ import jakarta.annotation.Nonnull; import java.util.List; -import org.apache.polaris.core.PolarisCallContext; -import org.apache.polaris.core.persistence.BasePersistence; public interface PolarisEventManager { - @Nonnull - default void writeEvents( - @Nonnull PolarisCallContext callCtx, @Nonnull List polarisEvents) { - BasePersistence ms = callCtx.getMetaStore(); - ms.writeEvents(polarisEvents); - } + void writeEvents(@Nonnull List polarisEvents); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java index c3841486a7..7c2ca17128 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java @@ -18,6 +18,7 @@ */ package org.apache.polaris.core.persistence; +import com.google.common.base.Suppliers; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import java.time.Clock; @@ -31,10 +32,12 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Collectors; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.config.FeatureConfiguration; +import org.apache.polaris.core.config.RealmConfig; +import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.EntityNameLookupRecord; @@ -85,34 +88,43 @@ * Implementation of PolarisMetaStoreManager which only relies on one-shot atomic operations into a * BasePersistence implementation without any kind of open-ended multi-statement transactions. */ -public class AtomicOperationMetaStoreManager extends BaseMetaStoreManager { +public class AtomicOperationMetaStoreManager extends BaseMetaStoreManager { private static final Logger LOGGER = LoggerFactory.getLogger(AtomicOperationMetaStoreManager.class); private final Clock clock; - - public AtomicOperationMetaStoreManager(Clock clock, PolarisDiagnostics diagnostics) { - super(diagnostics); + private final Supplier metaStoreSupplier; + + public AtomicOperationMetaStoreManager( + Clock clock, + PolarisDiagnostics diagnostics, + RealmContext realmContext, + RealmConfig realmConfig, + Supplier metaStoreSupplier) { + super(diagnostics, realmContext, realmConfig); this.clock = clock; + this.metaStoreSupplier = Suppliers.memoize(metaStoreSupplier::get); + } + + @Override + protected BasePersistence getMetaStore() { + return metaStoreSupplier.get(); } /** * Persist the specified new entity. * - * @param callCtx call context * @param ms meta store in read/write mode * @param entity entity we need a new persisted record for */ private EntityResult persistNewEntity( - @Nonnull PolarisCallContext callCtx, - @Nonnull BasePersistence ms, - @Nonnull PolarisBaseEntity entity) { + @Nonnull BasePersistence ms, @Nonnull PolarisBaseEntity entity) { // Invoke shared logic for validation and filling out remaining fields. - entity = prepareToPersistNewEntity(callCtx, ms, entity); + entity = prepareToPersistNewEntity(entity); try { // write it - ms.writeEntity(callCtx, entity, true, null); + ms.writeEntity(entity, true, null); } catch (EntityAlreadyExistsException e) { if (e.getExistingEntity().getId() == entity.getId()) { // Since ids are unique and reserved when generated, a matching id means a low-level retry @@ -136,7 +148,6 @@ private EntityResult persistNewEntity( * Persist the specified entity after it has been changed. We will update the last changed time, * increment the entity version and persist it in one atomic operation. * - * @param callCtx call context * @param ms meta store * @param entity the entity which has been changed * @param nameOrParentChanged indicates if parent or name changed @@ -144,17 +155,15 @@ private EntityResult persistNewEntity( * @return the entity with its version and lastUpdateTimestamp updated */ private @Nonnull PolarisBaseEntity persistEntityAfterChange( - @Nonnull PolarisCallContext callCtx, @Nonnull BasePersistence ms, @Nonnull PolarisBaseEntity entity, boolean nameOrParentChanged, @Nonnull PolarisBaseEntity originalEntity) { // Invoke shared logic for validation and updating expected fields. - entity = - prepareToPersistEntityAfterChange(callCtx, ms, entity, nameOrParentChanged, originalEntity); + entity = prepareToPersistEntityAfterChange(ms, entity, nameOrParentChanged, originalEntity); // persist it to the various slices - ms.writeEntity(callCtx, entity, nameOrParentChanged, originalEntity); + ms.writeEntity(entity, nameOrParentChanged, originalEntity); // return it return entity; @@ -170,14 +179,10 @@ private EntityResult persistNewEntity( * - we will fully delete the entity from persistence store * * - * @param callCtx call context * @param ms meta store * @param entity the entity being dropped */ - private void dropEntity( - @Nonnull PolarisCallContext callCtx, - @Nonnull BasePersistence ms, - @Nonnull PolarisBaseEntity entity) { + private void dropEntity(@Nonnull BasePersistence ms, @Nonnull PolarisBaseEntity entity) { // validate the entity type and subtype getDiagnostics().checkNotNull(entity, "unexpected_null_dpo"); @@ -188,7 +193,7 @@ private void dropEntity( // Remove the main entity itself first-thing; once its id no longer resolves successfully // it will be pruned out of any grant-record lookups anyways. - ms.deleteEntity(callCtx, entity); + ms.deleteEntity(entity); // Best-effort cleanup - drop grant records, update grantRecordVersions for affected // other entities. @@ -202,11 +207,11 @@ private void dropEntity( // delete ALL grant records to (if the entity is a grantee) and from that entity final List grantsOnGrantee = (entity.getType().isGrantee()) - ? ms.loadAllGrantRecordsOnGrantee(callCtx, entity.getCatalogId(), entity.getId()) + ? ms.loadAllGrantRecordsOnGrantee(entity.getCatalogId(), entity.getId()) : List.of(); final List grantsOnSecurable = - ms.loadAllGrantRecordsOnSecurable(callCtx, entity.getCatalogId(), entity.getId()); - ms.deleteAllEntityGrantRecords(callCtx, entity, grantsOnGrantee, grantsOnSecurable); + ms.loadAllGrantRecordsOnSecurable(entity.getCatalogId(), entity.getId()); + ms.deleteAllEntityGrantRecords(entity, grantsOnGrantee, grantsOnSecurable); if (entity.getType() == PolarisEntityType.POLICY || PolicyMappingUtil.isValidTargetEntityType(entity.getType(), entity.getSubType())) { @@ -218,7 +223,6 @@ private void dropEntity( final List mappingOnPolicy = (entity.getType() == PolarisEntityType.POLICY) ? ms.loadAllTargetsOnPolicy( - callCtx, entity.getCatalogId(), entity.getId(), PolicyEntity.of(entity).getPolicyTypeCode()) @@ -226,8 +230,8 @@ private void dropEntity( final List mappingOnTarget = (entity.getType() == PolarisEntityType.POLICY) ? List.of() - : ms.loadAllPoliciesOnTarget(callCtx, entity.getCatalogId(), entity.getId()); - ms.deleteAllEntityPolicyMappingRecords(callCtx, entity, mappingOnTarget, mappingOnPolicy); + : ms.loadAllPoliciesOnTarget(entity.getCatalogId(), entity.getId()); + ms.deleteAllEntityPolicyMappingRecords(entity, mappingOnTarget, mappingOnPolicy); } catch (UnsupportedOperationException e) { // Policy mapping persistence not implemented, but we should not block dropping entities } @@ -247,12 +251,11 @@ private void dropEntity( new PolarisEntityId(gr.getGranteeCatalogId(), gr.getGranteeId()))); // Bump up the grant version of these entities - List entities = - ms.lookupEntities(callCtx, new ArrayList<>(entityIdsGrantChanged)); + List entities = ms.lookupEntities(new ArrayList<>(entityIdsGrantChanged)); for (PolarisBaseEntity originalEntity : entities) { PolarisBaseEntity entityGrantChanged = originalEntity.withGrantRecordsVersion(originalEntity.getGrantRecordsVersion() + 1); - ms.writeEntity(callCtx, entityGrantChanged, false, originalEntity); + ms.writeEntity(entityGrantChanged, false, originalEntity); } // if it is a principal, we also need to drop the secrets @@ -260,7 +263,7 @@ private void dropEntity( PrincipalEntity principalEntity = PrincipalEntity.of(entity); String clientId = principalEntity.getClientId(); // delete it from the secret slice - ((IntegrationPersistence) ms).deletePrincipalSecrets(callCtx, clientId, entity.getId()); + ((IntegrationPersistence) ms).deletePrincipalSecrets(clientId, entity.getId()); } } @@ -268,7 +271,6 @@ private void dropEntity( * Create and persist a new grant record. This will at the same time invalidate the grant records * of the grantee and the securable if the grantee is a catalog role * - * @param callCtx call context * @param ms meta store in read/write mode * @param securable securable * @param grantee grantee, either a catalog role, a principal role or a principal @@ -276,7 +278,6 @@ private void dropEntity( * @return new grant record which was created and persisted */ private @Nonnull PolarisGrantRecord persistNewGrantRecord( - @Nonnull PolarisCallContext callCtx, @Nonnull BasePersistence ms, @Nonnull PolarisEntityCore securable, @Nonnull PolarisEntityCore grantee, @@ -301,29 +302,28 @@ private void dropEntity( priv.getCode()); // persist the new grant - ms.writeToGrantRecords(callCtx, grantRecord); + ms.writeToGrantRecords(grantRecord); // load the grantee (either a catalog/principal role or a principal) and increment its grants // version PolarisBaseEntity granteeEntity = - ms.lookupEntity(callCtx, grantee.getCatalogId(), grantee.getId(), grantee.getTypeCode()); + ms.lookupEntity(grantee.getCatalogId(), grantee.getId(), grantee.getTypeCode()); getDiagnostics().checkNotNull(granteeEntity, "grantee_not_found", "grantee={}", grantee); // grants have changed, we need to bump-up the grants version PolarisBaseEntity updatedGranteeEntity = granteeEntity.withGrantRecordsVersion(granteeEntity.getGrantRecordsVersion() + 1); - ms.writeEntity(callCtx, updatedGranteeEntity, false, granteeEntity); + ms.writeEntity(updatedGranteeEntity, false, granteeEntity); // we also need to invalidate the grants on that securable so that we can reload them. // load the securable and increment its grants version PolarisBaseEntity securableEntity = - ms.lookupEntity( - callCtx, securable.getCatalogId(), securable.getId(), securable.getTypeCode()); + ms.lookupEntity(securable.getCatalogId(), securable.getId(), securable.getTypeCode()); getDiagnostics() .checkNotNull(securableEntity, "securable_not_found", "securable={}", securable); // grants have changed, we need to bump-up the grants version PolarisBaseEntity updatedSecurableEntity = securableEntity.withGrantRecordsVersion(securableEntity.getGrantRecordsVersion() + 1); - ms.writeEntity(callCtx, updatedSecurableEntity, false, securableEntity); + ms.writeEntity(updatedSecurableEntity, false, securableEntity); // TODO: Reorder and/or expose bulk update of both grantRecordsVersions and grant records. In // the meantime, cache can be disabled or configured with a short enough expiry time to @@ -340,14 +340,12 @@ private void dropEntity( * Delete the specified grant record from the GRANT_RECORDS table. This will at the same time * invalidate the grant records of the grantee and the securable if the grantee is a role * - * @param callCtx call context * @param ms meta store * @param securable the securable entity * @param grantee the grantee entity * @param grantRecord the grant record to remove, which was read in the same transaction */ private void revokeGrantRecord( - @Nonnull PolarisCallContext callCtx, @Nonnull BasePersistence ms, @Nonnull PolarisEntityCore securable, @Nonnull PolarisEntityCore grantee, @@ -377,24 +375,23 @@ private void revokeGrantRecord( getDiagnostics().check(grantee.getType().isGrantee(), "not_a_grantee", "grantee={}", grantee); // remove that grant - ms.deleteFromGrantRecords(callCtx, grantRecord); + ms.deleteFromGrantRecords(grantRecord); // load the grantee and increment its grants version PolarisBaseEntity refreshGrantee = - ms.lookupEntity(callCtx, grantee.getCatalogId(), grantee.getId(), grantee.getTypeCode()); + ms.lookupEntity(grantee.getCatalogId(), grantee.getId(), grantee.getTypeCode()); getDiagnostics() .checkNotNull( refreshGrantee, "missing_grantee", "grantRecord={} grantee={}", grantRecord, grantee); // grants have changed, we need to bump-up the grants version PolarisBaseEntity updatedRefreshGrantee = refreshGrantee.withGrantRecordsVersion(refreshGrantee.getGrantRecordsVersion() + 1); - ms.writeEntity(callCtx, updatedRefreshGrantee, false, refreshGrantee); + ms.writeEntity(updatedRefreshGrantee, false, refreshGrantee); // we also need to invalidate the grants on that securable so that we can reload them. // load the securable and increment its grants version PolarisBaseEntity refreshSecurable = - ms.lookupEntity( - callCtx, securable.getCatalogId(), securable.getId(), securable.getTypeCode()); + ms.lookupEntity(securable.getCatalogId(), securable.getId(), securable.getTypeCode()); getDiagnostics() .checkNotNull( refreshSecurable, @@ -405,7 +402,7 @@ private void revokeGrantRecord( // grants have changed, we need to bump-up the grants version PolarisBaseEntity updatedRefreshSecurable = refreshSecurable.withGrantRecordsVersion(refreshSecurable.getGrantRecordsVersion() + 1); - ms.writeEntity(callCtx, updatedRefreshSecurable, false, refreshSecurable); + ms.writeEntity(updatedRefreshSecurable, false, refreshSecurable); // TODO: Reorder and/or expose bulk update of both grantRecordsVersions and grant records. In // the meantime, cache can be disabled or configured with a short enough expiry time to @@ -415,11 +412,8 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull CreateCatalogResult createCatalog( - @Nonnull PolarisCallContext callCtx, - @Nonnull PolarisBaseEntity catalog, - @Nonnull List principalRoles) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + @Nonnull PolarisBaseEntity catalog, @Nonnull List principalRoles) { + BasePersistence ms = getMetaStore(); // validate input getDiagnostics().checkNotNull(catalog, "unexpected_null_catalog"); @@ -436,7 +430,6 @@ private void revokeGrantRecord( integration = ((IntegrationPersistence) ms) .createStorageIntegration( - callCtx, catalog.getCatalogId(), catalog.getId(), PolarisStorageConfigurationInfo.deserialize(storageConfigInfoStr)); @@ -449,7 +442,7 @@ private void revokeGrantRecord( // because same-id idempotent-retry collisions of this sort are necessarily sequential, so // there is no concurrency conflict for something else creating a catalog of this same id. PolarisBaseEntity refreshCatalog = - ms.lookupEntity(callCtx, catalog.getCatalogId(), catalog.getId(), catalog.getTypeCode()); + ms.lookupEntity(catalog.getCatalogId(), catalog.getId(), catalog.getTypeCode()); // if found, probably a retry, simply return the previously created catalog if (refreshCatalog != null) { @@ -464,7 +457,6 @@ private void revokeGrantRecord( // lookup catalog admin role, should exist PolarisBaseEntity catalogAdminRole = ms.lookupEntityByName( - callCtx, refreshCatalog.getId(), refreshCatalog.getId(), PolarisEntityType.CATALOG_ROLE.getCode(), @@ -478,10 +470,10 @@ private void revokeGrantRecord( // done, return the existing catalog return new CreateCatalogResult(refreshCatalog, catalogAdminRole); } - ((IntegrationPersistence) ms).persistStorageIntegrationIfNeeded(callCtx, catalog, integration); + ((IntegrationPersistence) ms).persistStorageIntegrationIfNeeded(catalog, integration); // now create and persist new catalog entity - EntityResult lowLevelResult = this.persistNewEntity(callCtx, ms, catalog); + EntityResult lowLevelResult = this.persistNewEntity(ms, catalog); if (lowLevelResult.getReturnStatus() == BaseResult.ReturnStatus.ENTITY_ALREADY_EXISTS) { // TODO: Garbage-collection should include integrations, and anything else created before // this if the server crashes before being able to do this cleanup. @@ -492,7 +484,7 @@ private void revokeGrantRecord( } // create the catalog admin role for this new catalog - long adminRoleId = ms.generateNewId(callCtx); + long adminRoleId = ms.generateNewId(); PolarisBaseEntity adminRole = new PolarisBaseEntity( catalog.getId(), @@ -501,30 +493,27 @@ private void revokeGrantRecord( PolarisEntitySubType.NULL_SUBTYPE, catalog.getId(), PolarisEntityConstants.getNameOfCatalogAdminRole()); - this.persistNewEntity(callCtx, ms, adminRole); + this.persistNewEntity(ms, adminRole); // grant the catalog admin role access-management on the catalog - this.persistNewGrantRecord( - callCtx, ms, catalog, adminRole, PolarisPrivilege.CATALOG_MANAGE_ACCESS); + this.persistNewGrantRecord(ms, catalog, adminRole, PolarisPrivilege.CATALOG_MANAGE_ACCESS); // grant the catalog admin role metadata-management on the catalog; this one // is revocable - this.persistNewGrantRecord( - callCtx, ms, catalog, adminRole, PolarisPrivilege.CATALOG_MANAGE_METADATA); + this.persistNewGrantRecord(ms, catalog, adminRole, PolarisPrivilege.CATALOG_MANAGE_METADATA); // immediately assign its catalog_admin role if (principalRoles.isEmpty()) { // lookup service admin role, should exist PolarisBaseEntity serviceAdminRole = ms.lookupEntityByName( - callCtx, PolarisEntityConstants.getNullId(), PolarisEntityConstants.getRootEntityId(), PolarisEntityType.PRINCIPAL_ROLE.getCode(), PolarisEntityConstants.getNameOfPrincipalServiceAdminRole()); getDiagnostics().checkNotNull(serviceAdminRole, "missing_service_admin_role"); this.persistNewGrantRecord( - callCtx, ms, adminRole, serviceAdminRole, PolarisPrivilege.CATALOG_ROLE_USAGE); + ms, adminRole, serviceAdminRole, PolarisPrivilege.CATALOG_ROLE_USAGE); } else { // grant to each principal role usage on its catalog_admin role for (PolarisEntityCore principalRole : principalRoles) { @@ -539,7 +528,7 @@ private void revokeGrantRecord( // grant usage on that catalog admin role to this principal this.persistNewGrantRecord( - callCtx, ms, adminRole, principalRole, PolarisPrivilege.CATALOG_ROLE_USAGE); + ms, adminRole, principalRole, PolarisPrivilege.CATALOG_ROLE_USAGE); } } @@ -558,9 +547,8 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override - public @Nonnull BaseResult bootstrapPolarisService(@Nonnull PolarisCallContext callCtx) { - // get meta store we should be using - BasePersistence ms = callCtx.getMetaStore(); + public @Nonnull BaseResult bootstrapPolarisService() { + BasePersistence ms = getMetaStore(); // Create a root container entity that can represent the securable for any top-level grants. PolarisBaseEntity rootContainer = @@ -571,45 +559,37 @@ private void revokeGrantRecord( PolarisEntitySubType.NULL_SUBTYPE, PolarisEntityConstants.getRootEntityId(), PolarisEntityConstants.getRootContainerName()); - this.persistNewEntity(callCtx, ms, rootContainer); + this.persistNewEntity(ms, rootContainer); // Now bootstrap the service by creating the root principal and the service_admin principal // role. The principal role will be granted to that root principal and the root catalog admin // of the root catalog will be granted to that principal role. - long rootPrincipalId = ms.generateNewId(callCtx); + long rootPrincipalId = ms.generateNewId(); PrincipalEntity rootPrincipal = new PrincipalEntity.Builder() .setId(rootPrincipalId) .setName(PolarisEntityConstants.getRootPrincipalName()) .setCreateTimestamp(System.currentTimeMillis()) .build(); - this.createPrincipal(callCtx, rootPrincipal); + this.createPrincipal(rootPrincipal); // now create the account admin principal role - long serviceAdminPrincipalRoleId = ms.generateNewId(callCtx); + long serviceAdminPrincipalRoleId = ms.generateNewId(); PrincipalRoleEntity serviceAdminPrincipalRole = new PrincipalRoleEntity.Builder() .setId(serviceAdminPrincipalRoleId) .setName(PolarisEntityConstants.getNameOfPrincipalServiceAdminRole()) .setCreateTimestamp(System.currentTimeMillis()) .build(); - this.persistNewEntity(callCtx, ms, serviceAdminPrincipalRole); + this.persistNewEntity(ms, serviceAdminPrincipalRole); // we also need to grant usage on the account-admin principal to the principal this.persistNewGrantRecord( - callCtx, - ms, - serviceAdminPrincipalRole, - rootPrincipal, - PolarisPrivilege.PRINCIPAL_ROLE_USAGE); + ms, serviceAdminPrincipalRole, rootPrincipal, PolarisPrivilege.PRINCIPAL_ROLE_USAGE); // grant SERVICE_MANAGE_ACCESS on the rootContainer to the serviceAdminPrincipalRole this.persistNewGrantRecord( - callCtx, - ms, - rootContainer, - serviceAdminPrincipalRole, - PolarisPrivilege.SERVICE_MANAGE_ACCESS); + ms, rootContainer, serviceAdminPrincipalRole, PolarisPrivilege.SERVICE_MANAGE_ACCESS); // TODO: Make idempotent by being able to continue where it left off for the context's realm. // In the meantime, if a realm was only partially initialized before the server crashed, @@ -620,12 +600,11 @@ private void revokeGrantRecord( } @Override - public @Nonnull BaseResult purge(@Nonnull PolarisCallContext callCtx) { - // get meta store we should be using - BasePersistence ms = callCtx.getMetaStore(); + public @Nonnull BaseResult purge() { + BasePersistence ms = getMetaStore(); LOGGER.warn("Deleting all metadata in the metastore..."); - ms.deleteAll(callCtx); + ms.deleteAll(); LOGGER.warn("Finished deleting all metadata in the metastore"); // all good @@ -635,23 +614,21 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull EntityResult readEntityByName( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull String name) { - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // now looking the entity by name // TODO: Clean up shared logic for catalogId/parentId - long catalogId = - catalogPath == null || catalogPath.size() == 0 ? 0l : catalogPath.get(0).getId(); + long catalogId = catalogPath == null || catalogPath.isEmpty() ? 0L : catalogPath.get(0).getId(); long parentId = - catalogPath == null || catalogPath.size() == 0 - ? 0l + catalogPath == null || catalogPath.isEmpty() + ? 0L : catalogPath.get(catalogPath.size() - 1).getId(); PolarisBaseEntity entity = - ms.lookupEntityByName(callCtx, catalogId, parentId, entityType.getCode(), name); + ms.lookupEntityByName(catalogId, parentId, entityType.getCode(), name); // if found, check if subType really matches if (entity != null @@ -675,13 +652,11 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull ListEntitiesResult listEntities( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull PageToken pageToken) { - // get meta store we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // return list of active entities // TODO: Clean up shared logic for catalogId/parentId @@ -692,7 +667,7 @@ private void revokeGrantRecord( : catalogPath.get(catalogPath.size() - 1).getId(); Page resultPage = - ms.listEntities(callCtx, catalogId, parentId, entityType, entitySubType, pageToken); + ms.listEntities(catalogId, parentId, entityType, entitySubType, pageToken); // TODO: Use post-validation to enforce consistent view against catalogPath. In the // meantime, happens-before ordering semantics aren't guaranteed during high-concurrency @@ -706,13 +681,11 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull Page loadEntities( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull PageToken pageToken) { - // get meta store we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // return list of active entities // TODO: Clean up shared logic for catalogId/parentId @@ -729,7 +702,6 @@ private void revokeGrantRecord( // in-flight request (the cache-based resolution follows a different path entirely). return ms.loadEntities( - callCtx, catalogId, parentId, entityType, @@ -741,10 +713,8 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override - public @Nonnull CreatePrincipalResult createPrincipal( - @Nonnull PolarisCallContext callCtx, @Nonnull PrincipalEntity principal) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + public @Nonnull CreatePrincipalResult createPrincipal(@Nonnull PrincipalEntity principal) { + BasePersistence ms = getMetaStore(); // validate input getDiagnostics().checkNotNull(principal, "unexpected_null_principal"); @@ -752,8 +722,7 @@ private void revokeGrantRecord( // check if that catalog has already been created PrincipalEntity refreshPrincipal = PrincipalEntity.of( - ms.lookupEntity( - callCtx, principal.getCatalogId(), principal.getId(), principal.getTypeCode())); + ms.lookupEntity(principal.getCatalogId(), principal.getId(), principal.getTypeCode())); // if found, probably a retry, simply return the previously created principal // This can be done safely as a separate atomic operation before trying to create the principal @@ -767,7 +736,7 @@ private void revokeGrantRecord( // get the main and secondary secrets for that client PolarisPrincipalSecrets principalSecrets = - ((IntegrationPersistence) ms).loadPrincipalSecrets(callCtx, clientId); + ((IntegrationPersistence) ms).loadPrincipalSecrets(clientId); // should not be null getDiagnostics() @@ -785,7 +754,7 @@ private void revokeGrantRecord( // generate new secrets for this principal PolarisPrincipalSecrets principalSecrets = ((IntegrationPersistence) ms) - .generateNewPrincipalSecrets(callCtx, principal.getName(), principal.getId()); + .generateNewPrincipalSecrets(principal.getName(), principal.getId()); // remember client id PrincipalEntity updatedPrincipal = @@ -793,14 +762,14 @@ private void revokeGrantRecord( .setClientId(principalSecrets.getPrincipalClientId()) .build(); // now create and persist new catalog entity - EntityResult lowLevelResult = this.persistNewEntity(callCtx, ms, updatedPrincipal); + EntityResult lowLevelResult = this.persistNewEntity(ms, updatedPrincipal); if (lowLevelResult.getReturnStatus() == BaseResult.ReturnStatus.ENTITY_ALREADY_EXISTS) { // Name collision; do best-effort cleanup of the new principalSecrets we created // TODO: Garbage-collection should include principal secrets if the server crashes // before being able to do this cleanup. ((IntegrationPersistence) ms) .deletePrincipalSecrets( - callCtx, principalSecrets.getPrincipalClientId(), updatedPrincipal.getId()); + principalSecrets.getPrincipalClientId(), updatedPrincipal.getId()); return new CreatePrincipalResult(BaseResult.ReturnStatus.ENTITY_ALREADY_EXISTS, null); } @@ -810,13 +779,10 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override - public @Nonnull PrincipalSecretsResult loadPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + public @Nonnull PrincipalSecretsResult loadPrincipalSecrets(@Nonnull String clientId) { + BasePersistence ms = getMetaStore(); - PolarisPrincipalSecrets secrets = - ((IntegrationPersistence) ms).loadPrincipalSecrets(callCtx, clientId); + PolarisPrincipalSecrets secrets = ((IntegrationPersistence) ms).loadPrincipalSecrets(clientId); return (secrets == null) ? new PrincipalSecretsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null) @@ -825,26 +791,19 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override - public @Nonnull void deletePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId, long principalId) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); - ((IntegrationPersistence) ms).deletePrincipalSecrets(callCtx, clientId, principalId); + public void deletePrincipalSecrets(@Nonnull String clientId, long principalId) { + BasePersistence ms = getMetaStore(); + ((IntegrationPersistence) ms).deletePrincipalSecrets(clientId, principalId); } /** {@inheritDoc} */ @Override public @Nonnull PrincipalSecretsResult rotatePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - @Nonnull String clientId, - long principalId, - boolean reset, - @Nonnull String oldSecretHash) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + @Nonnull String clientId, long principalId, boolean reset, @Nonnull String oldSecretHash) { + BasePersistence ms = getMetaStore(); // if not found, the principal must have been dropped - Optional principalLookup = findPrincipalById(callCtx, principalId); + Optional principalLookup = findPrincipalById(principalId); if (principalLookup.isEmpty()) { return new PrincipalSecretsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); } @@ -859,7 +818,7 @@ private void revokeGrantRecord( != null; PolarisPrincipalSecrets secrets = ((IntegrationPersistence) ms) - .rotatePrincipalSecrets(callCtx, clientId, principalId, doReset, oldSecretHash); + .rotatePrincipalSecrets(clientId, principalId, doReset, oldSecretHash); PolarisBaseEntity.Builder principalBuilder = new PolarisBaseEntity.Builder(principal); if (reset @@ -869,13 +828,13 @@ private void revokeGrantRecord( PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE, "true"); principalBuilder.internalPropertiesAsMap(internalProps); principalBuilder.entityVersion(principal.getEntityVersion() + 1); - ms.writeEntity(callCtx, principalBuilder.build(), true, principal); + ms.writeEntity(principalBuilder.build(), true, principal); } else if (internalProps.containsKey( PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE)) { internalProps.remove(PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE); principalBuilder.internalPropertiesAsMap(internalProps); principalBuilder.entityVersion(principal.getEntityVersion() + 1); - ms.writeEntity(callCtx, principalBuilder.build(), true, principal); + ms.writeEntity(principalBuilder.build(), true, principal); } // TODO: Rethink the atomicity of the relationship between principalSecrets and principal @@ -887,22 +846,17 @@ private void revokeGrantRecord( @Override public @Nonnull PrincipalSecretsResult resetPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - long principalId, - @Nonnull String resolvedClientId, - String customClientSecret) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); - + long principalId, @Nonnull String resolvedClientId, String customClientSecret) { + BasePersistence ms = getMetaStore(); // if not found, the principal must have been dropped - Optional principalEntity = findPrincipalById(callCtx, principalId); + Optional principalEntity = findPrincipalById(principalId); if (principalEntity.isEmpty()) { return new PrincipalSecretsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); } PolarisPrincipalSecrets secrets = ((IntegrationPersistence) ms) - .storePrincipalSecrets(callCtx, principalId, resolvedClientId, customClientSecret); + .storePrincipalSecrets(principalId, resolvedClientId, customClientSecret); return (secrets == null) ? new PrincipalSecretsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null) : new PrincipalSecretsResult(secrets); @@ -911,11 +865,8 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull EntityResult createEntityIfNotExists( - @Nonnull PolarisCallContext callCtx, - @Nullable List catalogPath, - @Nonnull PolarisBaseEntity entity) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity) { + BasePersistence ms = getMetaStore(); // entity cannot be null getDiagnostics().checkNotNull(entity, "unexpected_null_entity"); @@ -928,25 +879,23 @@ private void revokeGrantRecord( // race conditions, such as first revoking a grant on a namespace before adding sensitive // data to a table; but the window of inconsistency is only the duration of a single // in-flight request (the cache-based resolution follows a different path entirely). - return this.persistNewEntity(callCtx, ms, entity); + return this.persistNewEntity(ms, entity); } @Override public @Nonnull EntitiesResult createEntitiesIfNotExist( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull List entities) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); List createdEntities = new ArrayList<>(entities.size()); for (PolarisBaseEntity entity : entities) { PolarisBaseEntity entityToCreate = - prepareToPersistNewEntity(callCtx, ms, new PolarisBaseEntity.Builder(entity).build()); + prepareToPersistNewEntity(new PolarisBaseEntity.Builder(entity).build()); createdEntities.add(entityToCreate); } try { - ms.writeEntities(callCtx, createdEntities, null); + ms.writeEntities(createdEntities, null); // TODO: Use post-validation to enforce consistent view against catalogPath. In the // meantime, happens-before ordering semantics aren't guaranteed during high-concurrency // race conditions, such as first revoking a grant on a namespace before adding sensitive @@ -968,19 +917,15 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull EntityResult updateEntityPropertiesIfNotChanged( - @Nonnull PolarisCallContext callCtx, - @Nullable List catalogPath, - @Nonnull PolarisBaseEntity entity) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity) { + BasePersistence ms = getMetaStore(); // entity cannot be null getDiagnostics().checkNotNull(entity, "unexpected_null_entity"); // persist this entity after changing it. This will update the version and update the last // updated time. Because the entity version is changed, we will update the change tracking table try { - PolarisBaseEntity persistedEntity = - this.persistEntityAfterChange(callCtx, ms, entity, false, entity); + PolarisBaseEntity persistedEntity = this.persistEntityAfterChange(ms, entity, false, entity); // TODO: Revalidate parent-path *after* performing update to fulfill the semantic of returning // a NotFoundException if some element of the parent path was concurrently deleted. @@ -994,9 +939,8 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull EntitiesResult updateEntitiesPropertiesIfNotChanged( - @Nonnull PolarisCallContext callCtx, @Nonnull List entities) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + @Nonnull List entities) { + BasePersistence ms = getMetaStore(); // ensure that the entities list is not null getDiagnostics().checkNotNull(entities, "unexpected_null_entities"); @@ -1008,7 +952,6 @@ private void revokeGrantRecord( for (EntityWithPath entityWithPath : entities) { PolarisBaseEntity updatedEntity = prepareToPersistEntityAfterChange( - callCtx, ms, new PolarisBaseEntity.Builder(entityWithPath.getEntity()).build(), false, @@ -1018,7 +961,7 @@ private void revokeGrantRecord( } try { - ms.writeEntities(callCtx, updatedEntities, originalEntities); + ms.writeEntities(updatedEntities, originalEntities); } catch (RetryOnConcurrencyException e) { return new EntitiesResult( BaseResult.ReturnStatus.TARGET_ENTITY_CONCURRENTLY_MODIFIED, e.getMessage()); @@ -1031,13 +974,11 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull EntityResult renameEntity( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entityToRename, @Nullable List newCatalogPath, @Nonnull PolarisEntity renamedEntity) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // entity and new name cannot be null getDiagnostics().checkNotNull(entityToRename, "unexpected_null_entityToRename"); @@ -1058,10 +999,7 @@ private void revokeGrantRecord( // find the entity to rename PolarisBaseEntity refreshEntityToRename = ms.lookupEntity( - callCtx, - entityToRename.getCatalogId(), - entityToRename.getId(), - entityToRename.getTypeCode()); + entityToRename.getCatalogId(), entityToRename.getId(), entityToRename.getTypeCode()); // if this entity was not found, return failure. Not expected here because it was // resolved successfully (see above) @@ -1082,18 +1020,14 @@ private void revokeGrantRecord( // ensure that nothing exists where we create that entity // if this entity already exists, this is an error long catalogId = - newCatalogPath == null || newCatalogPath.size() == 0 ? 0l : newCatalogPath.get(0).getId(); + newCatalogPath == null || newCatalogPath.isEmpty() ? 0L : newCatalogPath.get(0).getId(); long parentId = - newCatalogPath == null || newCatalogPath.size() == 0 - ? 0l + newCatalogPath == null || newCatalogPath.isEmpty() + ? 0L : newCatalogPath.get(newCatalogPath.size() - 1).getId(); EntityNameLookupRecord entityActiveRecord = ms.lookupEntityIdAndSubTypeByName( - callCtx, - catalogId, - parentId, - refreshEntityToRename.getTypeCode(), - renamedEntity.getName()); + catalogId, parentId, refreshEntityToRename.getTypeCode(), renamedEntity.getName()); if (entityActiveRecord != null) { return new EntityResult( BaseResult.ReturnStatus.ENTITY_ALREADY_EXISTS, entityActiveRecord.getSubTypeCode()); @@ -1119,7 +1053,7 @@ private void revokeGrantRecord( // lookups if applicable PolarisBaseEntity renamedEntityToReturn = this.persistEntityAfterChange( - callCtx, ms, refreshEntityToRenameBuilder.build(), true, refreshEntityToRename); + ms, refreshEntityToRenameBuilder.build(), true, refreshEntityToRename); // TODO: Use post-validation of source and destination parent paths and/or update the // BasePersistence interface to support conditions on entities *other* than the main @@ -1130,13 +1064,11 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull DropEntityResult dropEntityIfExists( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entityToDrop, @Nullable Map cleanupProperties, boolean cleanup) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // entity cannot be null getDiagnostics().checkNotNull(entityToDrop, "unexpected_null_entity"); @@ -1149,7 +1081,7 @@ private void revokeGrantRecord( // first find the entity to drop PolarisBaseEntity refreshEntityToDrop = ms.lookupEntity( - callCtx, entityToDrop.getCatalogId(), entityToDrop.getId(), entityToDrop.getTypeCode()); + entityToDrop.getCatalogId(), entityToDrop.getId(), entityToDrop.getTypeCode()); // if this entity was not found, return failure if (refreshEntityToDrop == null) { @@ -1173,8 +1105,7 @@ private void revokeGrantRecord( // TODO: Temporarily allow dropping a catalog with passthrough entities remaining, in the long // term we need to cleanup them up to avoid accumulation in the metastore if (!catalogEntityToDrop.isPassthroughFacade() - || !callCtx - .getRealmConfig() + || getRealmConfig() .getConfig( FeatureConfiguration.ALLOW_DROPPING_NON_EMPTY_PASSTHROUGH_FACADE_CATALOG, catalogEntityToDrop)) { @@ -1186,7 +1117,7 @@ private void revokeGrantRecord( // where dropping a namespace or container is effectively "recursive" in deleting its // children as well if those child entities were created within the short window of // the race condition. - if (ms.hasChildren(callCtx, PolarisEntityType.NAMESPACE, catalogId, catalogId)) { + if (ms.hasChildren(PolarisEntityType.NAMESPACE, catalogId, catalogId)) { return new DropEntityResult( BaseResult.ReturnStatus.NAMESPACE_NOT_EMPTY, catalogEntityToDrop.isPassthroughFacade() @@ -1201,7 +1132,6 @@ private void revokeGrantRecord( // get the list of catalog roles, at most 2 List catalogRoles = ms.loadEntities( - callCtx, catalogId, catalogId, PolarisEntityType.CATALOG_ROLE, @@ -1219,11 +1149,10 @@ private void revokeGrantRecord( // if 1, drop the last catalog role. Should be the catalog admin role but don't validate this if (!catalogRoles.isEmpty()) { // drop the last catalog role in that catalog, should be the admin catalog role - this.dropEntity(callCtx, ms, catalogRoles.get(0)); + this.dropEntity(ms, catalogRoles.get(0)); } } else if (refreshEntityToDrop.getType() == PolarisEntityType.NAMESPACE) { - if (ms.hasChildren( - callCtx, null, refreshEntityToDrop.getCatalogId(), refreshEntityToDrop.getId())) { + if (ms.hasChildren(null, refreshEntityToDrop.getCatalogId(), refreshEntityToDrop.getId())) { return new DropEntityResult(BaseResult.ReturnStatus.NAMESPACE_NOT_EMPTY, null); } } else if (refreshEntityToDrop.getType() == PolarisEntityType.POLICY && !cleanup) { @@ -1231,7 +1160,6 @@ private void revokeGrantRecord( // need to check if the policy is attached to any entity List records = ms.loadAllTargetsOnPolicy( - callCtx, refreshEntityToDrop.getCatalogId(), refreshEntityToDrop.getId(), PolicyEntity.of(refreshEntityToDrop).getPolicyTypeCode()); @@ -1245,7 +1173,7 @@ private void revokeGrantRecord( // simply delete that entity. Will be removed from entities_active, added to the // entities_dropped and its version will be changed. - this.dropEntity(callCtx, ms, refreshEntityToDrop); + this.dropEntity(ms, refreshEntityToDrop); // if cleanup, schedule a cleanup task for the entity. do this here, so that drop and scheduling // the cleanup task is transactional. Otherwise, we'll be unable to schedule the cleanup task @@ -1260,7 +1188,7 @@ private void revokeGrantRecord( PolarisBaseEntity.Builder taskEntityBuilder = new PolarisBaseEntity.Builder() .propertiesAsMap(properties) - .id(ms.generateNewId(callCtx)) + .id(ms.generateNewId()) .catalogId(0L) .name("entityCleanup_" + entityToDrop.getId()) .typeCode(PolarisEntityType.TASK.getCode()) @@ -1274,7 +1202,7 @@ private void revokeGrantRecord( // the entity is dropped but we don't have any persisted task records that will carry // out the cleanup. PolarisBaseEntity taskEntity = taskEntityBuilder.build(); - createEntityIfNotExists(callCtx, null, taskEntity); + createEntityIfNotExists(null, taskEntity); return new DropEntityResult(taskEntity.getId()); } @@ -1285,12 +1213,10 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull PrivilegeResult grantUsageOnRoleToGrantee( - @Nonnull PolarisCallContext callCtx, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @Nonnull PolarisEntityCore grantee) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // the usage privilege to grant PolarisPrivilege usagePriv = @@ -1300,20 +1226,17 @@ private void revokeGrantRecord( // grant usage on this role to this principal getDiagnostics().check(grantee.getType().isGrantee(), "not_a_grantee", "grantee={}", grantee); - PolarisGrantRecord grantRecord = - this.persistNewGrantRecord(callCtx, ms, role, grantee, usagePriv); + PolarisGrantRecord grantRecord = this.persistNewGrantRecord(ms, role, grantee, usagePriv); return new PrivilegeResult(grantRecord); } /** {@inheritDoc} */ @Override public @Nonnull PrivilegeResult revokeUsageOnRoleFromGrantee( - @Nonnull PolarisCallContext callCtx, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @Nonnull PolarisEntityCore grantee) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // the usage privilege to revoke PolarisPrivilege usagePriv = @@ -1324,7 +1247,6 @@ private void revokeGrantRecord( // first, ensure that this privilege has been granted PolarisGrantRecord grantRecord = ms.lookupGrantRecord( - callCtx, role.getCatalogId(), role.getId(), grantee.getCatalogId(), @@ -1337,7 +1259,7 @@ private void revokeGrantRecord( } // revoke usage on the role from the grantee - this.revokeGrantRecord(callCtx, ms, role, grantee, grantRecord); + this.revokeGrantRecord(ms, role, grantee, grantRecord); return new PrivilegeResult(grantRecord); } @@ -1345,35 +1267,29 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull PrivilegeResult grantPrivilegeOnSecurableToRole( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @Nonnull PolarisEntityCore securable, @Nonnull PolarisPrivilege privilege) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // grant specified privilege on this securable to this role and return the grant - PolarisGrantRecord grantRecord = - this.persistNewGrantRecord(callCtx, ms, securable, grantee, privilege); + PolarisGrantRecord grantRecord = this.persistNewGrantRecord(ms, securable, grantee, privilege); return new PrivilegeResult(grantRecord); } /** {@inheritDoc} */ @Override public @Nonnull PrivilegeResult revokePrivilegeOnSecurableFromRole( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @Nonnull PolarisEntityCore securable, @Nonnull PolarisPrivilege privilege) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // lookup the grants records to find this grant PolarisGrantRecord grantRecord = ms.lookupGrantRecord( - callCtx, securable.getCatalogId(), securable.getId(), grantee.getCatalogId(), @@ -1386,7 +1302,7 @@ private void revokeGrantRecord( } // revoke the specified privilege on this securable from this role - this.revokeGrantRecord(callCtx, ms, securable, grantee, grantRecord); + this.revokeGrantRecord(ms, securable, grantee, grantRecord); // success! return new PrivilegeResult(grantRecord); @@ -1394,22 +1310,19 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override - public @Nonnull LoadGrantsResult loadGrantsOnSecurable( - @Nonnull PolarisCallContext callCtx, PolarisEntityCore securable) { - return loadGrantsOnSecurable(callCtx, securable.getCatalogId(), securable.getId()); + public @Nonnull LoadGrantsResult loadGrantsOnSecurable(PolarisEntityCore securable) { + return loadGrantsOnSecurable(securable.getCatalogId(), securable.getId()); } public @Nonnull LoadGrantsResult loadGrantsOnSecurable( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + long securableCatalogId, long securableId) { + BasePersistence ms = getMetaStore(); // TODO: Consider whether it's necessary to look up both ends of the grant records atomically // or if it's actually safe as two independent lookups. // lookup grants version for this securable entity - int grantsVersion = - ms.lookupEntityGrantRecordsVersion(callCtx, securableCatalogId, securableId); + int grantsVersion = ms.lookupEntityGrantRecordsVersion(securableCatalogId, securableId); // return null if securable does not exists if (grantsVersion == 0) { @@ -1418,7 +1331,7 @@ private void revokeGrantRecord( // now fetch all grants for this securable final List returnGrantRecords = - ms.loadAllGrantRecordsOnSecurable(callCtx, securableCatalogId, securableId); + ms.loadAllGrantRecordsOnSecurable(securableCatalogId, securableId); // find all unique grantees List entityIds = @@ -1429,7 +1342,7 @@ private void revokeGrantRecord( grantRecord.getGranteeCatalogId(), grantRecord.getGranteeId())) .distinct() .collect(Collectors.toList()); - List entities = ms.lookupEntities(callCtx, entityIds); + List entities = ms.lookupEntities(entityIds); // done, return the list of grants and their version return new LoadGrantsResult( @@ -1440,21 +1353,18 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override - public @Nonnull LoadGrantsResult loadGrantsToGrantee( - @Nonnull PolarisCallContext callCtx, PolarisEntityCore grantee) { - return loadGrantsToGrantee(callCtx, grantee.getCatalogId(), grantee.getId()); + public @Nonnull LoadGrantsResult loadGrantsToGrantee(PolarisEntityCore grantee) { + return loadGrantsToGrantee(grantee.getCatalogId(), grantee.getId()); } - public @Nonnull LoadGrantsResult loadGrantsToGrantee( - @Nonnull PolarisCallContext callCtx, long granteeCatalogId, long granteeId) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + public @Nonnull LoadGrantsResult loadGrantsToGrantee(long granteeCatalogId, long granteeId) { + BasePersistence ms = getMetaStore(); // TODO: Consider whether it's necessary to look up both ends of the grant records atomically // or if it's actually safe as two independent lookups. // lookup grants version for this grantee entity - int grantsVersion = ms.lookupEntityGrantRecordsVersion(callCtx, granteeCatalogId, granteeId); + int grantsVersion = ms.lookupEntityGrantRecordsVersion(granteeCatalogId, granteeId); // return null if grantee does not exists if (grantsVersion == 0) { @@ -1463,7 +1373,7 @@ private void revokeGrantRecord( // now fetch all grants for this grantee final List returnGrantRecords = - ms.loadAllGrantRecordsOnGrantee(callCtx, granteeCatalogId, granteeId); + ms.loadAllGrantRecordsOnGrantee(granteeCatalogId, granteeId); // find all unique securables List entityIds = @@ -1474,7 +1384,7 @@ private void revokeGrantRecord( grantRecord.getSecurableCatalogId(), grantRecord.getSecurableId())) .distinct() .collect(Collectors.toList()); - List entities = ms.lookupEntities(callCtx, entityIds); + List entities = ms.lookupEntities(entityIds); // done, return the list of grants and their version return new LoadGrantsResult( @@ -1486,42 +1396,33 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull ChangeTrackingResult loadEntitiesChangeTracking( - @Nonnull PolarisCallContext callCtx, @Nonnull List entityIds) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + @Nonnull List entityIds) { + BasePersistence ms = getMetaStore(); - List changeTracking = - ms.lookupEntityVersions(callCtx, entityIds); + List changeTracking = ms.lookupEntityVersions(entityIds); return new ChangeTrackingResult(changeTracking); } /** {@inheritDoc} */ @Override public @Nonnull EntityResult loadEntity( - @Nonnull PolarisCallContext callCtx, - long entityCatalogId, - long entityId, - @Nonnull PolarisEntityType entityType) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + long entityCatalogId, long entityId, @Nonnull PolarisEntityType entityType) { + BasePersistence ms = getMetaStore(); // this is an easy one - PolarisBaseEntity entity = - ms.lookupEntity(callCtx, entityCatalogId, entityId, entityType.getCode()); + PolarisBaseEntity entity = ms.lookupEntity(entityCatalogId, entityId, entityType.getCode()); return (entity != null) ? new EntityResult(entity) : new EntityResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); } @Override - public @Nonnull EntitiesResult loadTasks( - @Nonnull PolarisCallContext callCtx, String executorId, PageToken pageToken) { - BasePersistence ms = callCtx.getMetaStore(); + public @Nonnull EntitiesResult loadTasks(String executorId, PageToken pageToken) { + BasePersistence ms = getMetaStore(); // find all available tasks Page availableTasks = ms.loadEntities( - callCtx, PolarisEntityConstants.getRootEntityId(), PolarisEntityConstants.getRootEntityId(), PolarisEntityType.TASK, @@ -1530,8 +1431,7 @@ private void revokeGrantRecord( PolarisObjectMapperUtil.TaskExecutionState taskState = PolarisObjectMapperUtil.parseTaskState(entity); long taskAgeTimeout = - callCtx - .getRealmConfig() + getRealmConfig() .getConfig( PolarisTaskConstants.TASK_TIMEOUT_MILLIS_CONFIG, PolarisTaskConstants.TASK_TIMEOUT_MILLIS); @@ -1561,7 +1461,7 @@ private void revokeGrantRecord( + 1)); updatedTaskBuilder.propertiesAsMap(properties); EntityResult result = - updateEntityPropertiesIfNotChanged(callCtx, null, updatedTaskBuilder.build()); + updateEntityPropertiesIfNotChanged(null, updatedTaskBuilder.build()); if (result.getReturnStatus() == BaseResult.ReturnStatus.SUCCESS) { return result.getEntity(); } else { @@ -1591,7 +1491,6 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull ScopedCredentialsResult getSubscopedCredsForEntity( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, PolarisEntityType entityType, @@ -1601,14 +1500,14 @@ private void revokeGrantRecord( Optional refreshCredentialsEndpoint) { // get meta store session we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); getDiagnostics() .check( !allowedReadLocations.isEmpty() || !allowedWriteLocations.isEmpty(), "allowed_locations_to_subscope_is_required"); // reload the entity, error out if not found - EntityResult reloadedEntity = loadEntity(callCtx, catalogId, entityId, entityType); + EntityResult reloadedEntity = loadEntity(catalogId, entityId, entityType); if (reloadedEntity.getReturnStatus() != BaseResult.ReturnStatus.SUCCESS) { return new ScopedCredentialsResult( reloadedEntity.getReturnStatus(), reloadedEntity.getExtraInformation()); @@ -1620,8 +1519,7 @@ private void revokeGrantRecord( // get storage integration PolarisStorageIntegration storageIntegration = - ((IntegrationPersistence) ms) - .loadPolarisStorageIntegration(callCtx, reloadedEntity.getEntity()); + ((IntegrationPersistence) ms).loadPolarisStorageIntegration(reloadedEntity.getEntity()); // cannot be null getDiagnostics() @@ -1635,7 +1533,7 @@ private void revokeGrantRecord( try { AccessConfig accessConfig = storageIntegration.getSubscopedCreds( - callCtx.getRealmConfig(), + getRealmConfig(), allowListOperation, allowedReadLocations, allowedWriteLocations, @@ -1650,16 +1548,11 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull ResolvedEntityResult loadResolvedEntityById( - @Nonnull PolarisCallContext callCtx, - long entityCatalogId, - long entityId, - PolarisEntityType entityType) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + long entityCatalogId, long entityId, PolarisEntityType entityType) { + BasePersistence ms = getMetaStore(); // load that entity - PolarisBaseEntity entity = - ms.lookupEntity(callCtx, entityCatalogId, entityId, entityType.getCode()); + PolarisBaseEntity entity = ms.lookupEntity(entityCatalogId, entityId, entityType.getCode()); // if entity not found, return null if (entity == null) { @@ -1672,11 +1565,10 @@ private void revokeGrantRecord( // load the grant records final List grantRecords; if (entity.getType().isGrantee()) { - grantRecords = - new ArrayList<>(ms.loadAllGrantRecordsOnGrantee(callCtx, entityCatalogId, entityId)); - grantRecords.addAll(ms.loadAllGrantRecordsOnSecurable(callCtx, entityCatalogId, entityId)); + grantRecords = new ArrayList<>(ms.loadAllGrantRecordsOnGrantee(entityCatalogId, entityId)); + grantRecords.addAll(ms.loadAllGrantRecordsOnSecurable(entityCatalogId, entityId)); } else { - grantRecords = ms.loadAllGrantRecordsOnSecurable(callCtx, entityCatalogId, entityId); + grantRecords = ms.loadAllGrantRecordsOnSecurable(entityCatalogId, entityId); } // return the result @@ -1686,17 +1578,15 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull ResolvedEntityResult loadResolvedEntityByName( - @Nonnull PolarisCallContext callCtx, long entityCatalogId, long parentId, @Nonnull PolarisEntityType entityType, @Nonnull String entityName) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // load that entity PolarisBaseEntity entity = - ms.lookupEntityByName(callCtx, entityCatalogId, parentId, entityType.getCode(), entityName); + ms.lookupEntityByName(entityCatalogId, parentId, entityType.getCode(), entityName); // null if entity not found if (entity == null) { @@ -1710,12 +1600,10 @@ private void revokeGrantRecord( final List grantRecords; if (entity.getType().isGrantee()) { grantRecords = - new ArrayList<>( - ms.loadAllGrantRecordsOnGrantee(callCtx, entityCatalogId, entity.getId())); - grantRecords.addAll( - ms.loadAllGrantRecordsOnSecurable(callCtx, entityCatalogId, entity.getId())); + new ArrayList<>(ms.loadAllGrantRecordsOnGrantee(entityCatalogId, entity.getId())); + grantRecords.addAll(ms.loadAllGrantRecordsOnSecurable(entityCatalogId, entity.getId())); } else { - grantRecords = ms.loadAllGrantRecordsOnSecurable(callCtx, entityCatalogId, entity.getId()); + grantRecords = ms.loadAllGrantRecordsOnSecurable(entityCatalogId, entity.getId()); } ResolvedEntityResult result = @@ -1732,11 +1620,10 @@ private void revokeGrantRecord( PolarisEntitySubType.NULL_SUBTYPE, PolarisEntityConstants.getRootEntityId(), PolarisEntityConstants.getRootContainerName()); - EntityResult backfillResult = this.createEntityIfNotExists(callCtx, null, rootContainer); + EntityResult backfillResult = this.createEntityIfNotExists(null, rootContainer); if (backfillResult.isSuccess()) { PolarisBaseEntity serviceAdminRole = ms.lookupEntityByName( - callCtx, 0L, 0L, PolarisEntityType.PRINCIPAL_ROLE.getCode(), @@ -1749,13 +1636,12 @@ private void revokeGrantRecord( // the root container, so consider removing this backfill entirely or else fix // the backfill of this serviceAdminRole grant. this.persistNewGrantRecord( - callCtx, ms, rootContainer, serviceAdminRole, PolarisPrivilege.SERVICE_MANAGE_ACCESS); + ms, rootContainer, serviceAdminRole, PolarisPrivilege.SERVICE_MANAGE_ACCESS); } } // Redo the lookup in a separate read transaction. - result = - this.loadResolvedEntityByName(callCtx, entityCatalogId, parentId, entityType, entityName); + result = this.loadResolvedEntityByName(entityCatalogId, parentId, entityType, entityName); } return result; } @@ -1763,19 +1649,16 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public @Nonnull ResolvedEntityResult refreshResolvedEntity( - @Nonnull PolarisCallContext callCtx, int entityVersion, int entityGrantRecordsVersion, @Nonnull PolarisEntityType entityType, long entityCatalogId, long entityId) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); // load version information PolarisChangeTrackingVersions entityVersions = - ms.lookupEntityVersions(callCtx, List.of(new PolarisEntityId(entityCatalogId, entityId))) - .get(0); + ms.lookupEntityVersions(List.of(new PolarisEntityId(entityCatalogId, entityId))).get(0); // if null, the entity has been purged if (entityVersions == null) { @@ -1785,7 +1668,7 @@ private void revokeGrantRecord( // load the entity if something changed final PolarisBaseEntity entity; if (entityVersion != entityVersions.getEntityVersion()) { - entity = ms.lookupEntity(callCtx, entityCatalogId, entityId, entityType.getCode()); + entity = ms.lookupEntity(entityCatalogId, entityId, entityType.getCode()); // if not found, return null if (entity == null) { @@ -1803,11 +1686,10 @@ private void revokeGrantRecord( final List grantRecords; if (entityVersions.getGrantRecordsVersion() != entityGrantRecordsVersion) { if (entityType.isGrantee()) { - grantRecords = - new ArrayList<>(ms.loadAllGrantRecordsOnGrantee(callCtx, entityCatalogId, entityId)); - grantRecords.addAll(ms.loadAllGrantRecordsOnSecurable(callCtx, entityCatalogId, entityId)); + grantRecords = new ArrayList<>(ms.loadAllGrantRecordsOnGrantee(entityCatalogId, entityId)); + grantRecords.addAll(ms.loadAllGrantRecordsOnSecurable(entityCatalogId, entityId)); } else { - grantRecords = ms.loadAllGrantRecordsOnSecurable(callCtx, entityCatalogId, entityId); + grantRecords = ms.loadAllGrantRecordsOnSecurable(entityCatalogId, entityId); } } else { grantRecords = null; @@ -1820,39 +1702,33 @@ private void revokeGrantRecord( /** {@inheritDoc} */ @Override public - Optional> hasOverlappingSiblings( - @Nonnull PolarisCallContext callContext, T entity) { - BasePersistence ms = callContext.getMetaStore(); - return ms.hasOverlappingSiblings(callContext, entity); + Optional> hasOverlappingSiblings(T entity) { + BasePersistence ms = getMetaStore(); + return ms.hasOverlappingSiblings(entity); } @Override public @Nonnull PolicyAttachmentResult attachPolicyToEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull List targetCatalogPath, @Nonnull PolarisEntityCore target, @Nonnull List policyCatalogPath, @Nonnull PolicyEntity policy, Map parameters) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); - return this.persistNewPolicyMappingRecord(callCtx, ms, target, policy, parameters); + return this.persistNewPolicyMappingRecord(ms, target, policy, parameters); } @Override public @Nonnull PolicyAttachmentResult detachPolicyFromEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull List catalogPath, @Nonnull PolarisEntityCore target, @Nonnull List policyCatalogPath, @Nonnull PolicyEntity policy) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + BasePersistence ms = getMetaStore(); PolarisPolicyMappingRecord mappingRecord = ms.lookupPolicyMappingRecord( - callCtx, target.getCatalogId(), target.getId(), policy.getPolicyTypeCode(), @@ -1862,60 +1738,53 @@ Optional> hasOverlappingSiblings( return new PolicyAttachmentResult(BaseResult.ReturnStatus.POLICY_MAPPING_NOT_FOUND, null); } - ms.deleteFromPolicyMappingRecords(callCtx, mappingRecord); + ms.deleteFromPolicyMappingRecords(mappingRecord); return new PolicyAttachmentResult(mappingRecord); } @Override - public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore target) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntity(@Nonnull PolarisEntityCore target) { + BasePersistence ms = getMetaStore(); PolarisBaseEntity entity = - ms.lookupEntity(callCtx, target.getCatalogId(), target.getId(), target.getTypeCode()); + ms.lookupEntity(target.getCatalogId(), target.getId(), target.getTypeCode()); if (entity == null) { // Target entity does not exist return new LoadPolicyMappingsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); } final List policyMappingRecords = - ms.loadAllPoliciesOnTarget(callCtx, target.getCatalogId(), target.getId()); + ms.loadAllPoliciesOnTarget(target.getCatalogId(), target.getId()); List policyEntities = - loadPoliciesFromMappingRecords(callCtx, ms, policyMappingRecords); + loadPoliciesFromMappingRecords(ms, policyMappingRecords); return new LoadPolicyMappingsResult(policyMappingRecords, policyEntities); } @Override public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntityByType( - @Nonnull PolarisCallContext callCtx, - @Nonnull PolarisEntityCore target, - @Nonnull PolicyType policyType) { - // get metastore we should be using - BasePersistence ms = callCtx.getMetaStore(); + @Nonnull PolarisEntityCore target, @Nonnull PolicyType policyType) { + BasePersistence ms = getMetaStore(); PolarisBaseEntity entity = - ms.lookupEntity(callCtx, target.getCatalogId(), target.getId(), target.getTypeCode()); + ms.lookupEntity(target.getCatalogId(), target.getId(), target.getTypeCode()); if (entity == null) { // Target entity does not exist return new LoadPolicyMappingsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); } final List policyMappingRecords = - ms.loadPoliciesOnTargetByType( - callCtx, target.getCatalogId(), target.getId(), policyType.getCode()); + ms.loadPoliciesOnTargetByType(target.getCatalogId(), target.getId(), policyType.getCode()); List policyEntities = - loadPoliciesFromMappingRecords(callCtx, ms, policyMappingRecords); + loadPoliciesFromMappingRecords(ms, policyMappingRecords); return new LoadPolicyMappingsResult(policyMappingRecords, policyEntities); } /** * Create and persist a new policy mapping record * - * @param callCtx call context * @param ms meta store in read/write mode * @param target target * @param policy policy @@ -1923,7 +1792,6 @@ Optional> hasOverlappingSiblings( * @return new policy mapping record which was created and persisted */ private @Nonnull PolicyAttachmentResult persistNewPolicyMappingRecord( - @Nonnull PolarisCallContext callCtx, @Nonnull BasePersistence ms, @Nonnull PolarisEntityCore target, @Nonnull PolicyEntity policy, @@ -1940,7 +1808,7 @@ Optional> hasOverlappingSiblings( policy.getPolicyTypeCode(), parameters); try { - ms.writeToPolicyMappingRecords(callCtx, mappingRecord); + ms.writeToPolicyMappingRecords(mappingRecord); } catch (IllegalArgumentException e) { return new PolicyAttachmentResult( BaseResult.ReturnStatus.UNEXPECTED_ERROR_SIGNALED, "Unknown policy type"); @@ -1956,15 +1824,12 @@ Optional> hasOverlappingSiblings( /** * Load policies from a list of policy mapping records * - * @param callCtx call context * @param ms meta store * @param policyMappingRecords a list of policy mapping records * @return a list of policy entities */ private List loadPoliciesFromMappingRecords( - @Nonnull PolarisCallContext callCtx, - @Nonnull BasePersistence ms, - @Nonnull List policyMappingRecords) { + @Nonnull BasePersistence ms, @Nonnull List policyMappingRecords) { List policyEntityIds = policyMappingRecords.stream() .map( @@ -1974,6 +1839,6 @@ private List loadPoliciesFromMappingRecords( policyMappingRecord.getPolicyId())) .distinct() .collect(Collectors.toList()); - return ms.lookupEntities(callCtx, policyEntityIds); + return ms.lookupEntities(policyEntityIds); } } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseMetaStoreManager.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseMetaStoreManager.java index 884883f275..e89fcd7ce2 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseMetaStoreManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/BaseMetaStoreManager.java @@ -19,18 +19,22 @@ package org.apache.polaris.core.persistence; import jakarta.annotation.Nonnull; +import java.util.List; import java.util.Map; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDiagnostics; +import org.apache.polaris.core.config.RealmConfig; +import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntityConstants; import org.apache.polaris.core.entity.PolarisEntitySubType; import org.apache.polaris.core.entity.PolarisEntityType; +import org.apache.polaris.core.entity.PolarisEvent; import org.apache.polaris.core.persistence.dao.entity.GenerateEntityIdResult; import org.apache.polaris.core.storage.PolarisStorageConfigurationInfo; /** Shared basic PolarisMetaStoreManager logic for transactional and non-transactional impls. */ -public abstract class BaseMetaStoreManager implements PolarisMetaStoreManager { +public abstract class BaseMetaStoreManager + implements PolarisMetaStoreManager { public static PolarisStorageConfigurationInfo extractStorageConfiguration( @Nonnull PolarisDiagnostics diagnostics, PolarisBaseEntity reloadedEntity) { @@ -48,27 +52,37 @@ public static PolarisStorageConfigurationInfo extractStorageConfiguration( } private final PolarisDiagnostics diagnostics; + private final RealmContext realmContext; + private final RealmConfig realmConfig; - protected BaseMetaStoreManager(PolarisDiagnostics diagnostics) { + protected BaseMetaStoreManager( + PolarisDiagnostics diagnostics, RealmContext realmContext, RealmConfig realmConfig) { this.diagnostics = diagnostics; + this.realmContext = realmContext; + this.realmConfig = realmConfig; } protected PolarisDiagnostics getDiagnostics() { return diagnostics; } + protected RealmContext getRealmContext() { + return realmContext; + } + + protected RealmConfig getRealmConfig() { + return realmConfig; + } + + protected abstract T getMetaStore(); + /** * Performs basic validation of expected invariants on a new entity, then returns the entity with * fields filled out for which the persistence layer is responsible. * - * @param callCtx call context - * @param ms meta store in read/write mode * @param entity entity we need a new persisted record for */ - protected PolarisBaseEntity prepareToPersistNewEntity( - @Nonnull PolarisCallContext callCtx, - @Nonnull BasePersistence ms, - @Nonnull PolarisBaseEntity entity) { + protected PolarisBaseEntity prepareToPersistNewEntity(@Nonnull PolarisBaseEntity entity) { // validate the entity type and subtype getDiagnostics().checkNotNull(entity, "unexpected_null_entity"); @@ -116,7 +130,6 @@ protected PolarisBaseEntity prepareToPersistNewEntity( * Performs basic validation of expected invariants on a changed entity, then returns the entity * with fields filled out for which the persistence layer is responsible. * - * @param callCtx call context * @param ms meta store * @param entity the entity which has been changed * @param nameOrParentChanged indicates if parent or name changed @@ -124,7 +137,6 @@ protected PolarisBaseEntity prepareToPersistNewEntity( * @return the entity with its version and lastUpdateTimestamp updated */ protected @Nonnull PolarisBaseEntity prepareToPersistEntityAfterChange( - @Nonnull PolarisCallContext callCtx, @Nonnull BasePersistence ms, @Nonnull PolarisBaseEntity entity, boolean nameOrParentChanged, @@ -166,10 +178,16 @@ protected PolarisBaseEntity prepareToPersistNewEntity( /** {@inheritDoc} */ @Override - public @Nonnull GenerateEntityIdResult generateNewEntityId(@Nonnull PolarisCallContext callCtx) { - // get meta store we should be using - BasePersistence ms = callCtx.getMetaStore(); + public @Nonnull GenerateEntityIdResult generateNewEntityId() { + BasePersistence ms = getMetaStore(); + + return new GenerateEntityIdResult(ms.generateNewId()); + } - return new GenerateEntityIdResult(ms.generateNewId(callCtx)); + /** {@inheritDoc} */ + @Override + public void writeEvents(@Nonnull List polarisEvents) { + BasePersistence ms = getMetaStore(); + ms.writeEvents(polarisEvents); } } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/BasePersistence.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/BasePersistence.java index 4fa60e8c5d..8965567f4c 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/BasePersistence.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/BasePersistence.java @@ -24,7 +24,6 @@ import java.util.Optional; import java.util.function.Function; import java.util.function.Predicate; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.EntityNameLookupRecord; import org.apache.polaris.core.entity.LocationBasedEntity; import org.apache.polaris.core.entity.PolarisBaseEntity; @@ -58,10 +57,9 @@ public interface BasePersistence extends PolicyMappingPersistence { * The returned id must be fully unique within a realm and never reused once generated, whether or * not anything ends up committing an entity with the generated id. * - * @param callCtx call context * @return new unique entity identifier */ - long generateNewId(@Nonnull PolarisCallContext callCtx); + long generateNewId(); /** * Write this entity to the persistence backend. If successful, the write must be durable and @@ -77,14 +75,12 @@ public interface BasePersistence extends PolicyMappingPersistence { * through correctly, in particular for values the PolarisMetaStoreManagerImpl doesn't have access * to such as the original name and parentId in renames. * - * @param callCtx call context * @param entity entity to persist * @param nameOrParentChanged if true, also write it to by-name lookups if applicable * @param originalEntity original state of the entity to use for compare-and-swap purposes, or * null if this is expected to be a brand-new entity */ void writeEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, boolean nameOrParentChanged, @Nullable PolarisBaseEntity originalEntity); @@ -113,7 +109,6 @@ void writeEntity( * through correctly, in particular for values the PolarisMetaStoreManagerImpl doesn't have access * to such as the original name and parentId in renames. * - * @param callCtx call context * @param entities entities to persist * @param originalEntities original states of the entity to use for compare-and-swap purposes, or * null if this is expected to be a brand-new entity; must contain exactly as many elements as @@ -122,7 +117,6 @@ void writeEntity( * there is no mix-and-match "create" and "update" in a single batch. */ void writeEntities( - @Nonnull PolarisCallContext callCtx, @Nonnull List entities, @Nullable List originalEntities); @@ -130,12 +124,10 @@ void writeEntities( * Write the specified grantRecord to the grant_records table. If there is a conflict (existing * record with the same PK), all attributes of the new record will replace the existing one. * - * @param callCtx call context * @param grantRec entity record to write, potentially replacing an existing entity record with * the same key */ - void writeToGrantRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec); + void writeToGrantRecords(@Nonnull PolarisGrantRecord grantRec); /** * Write all events to the events table. This is an append-only operation. @@ -147,33 +139,28 @@ void writeToGrantRecords( /** * Delete this entity from the meta store. * - * @param callCtx call context * @param entity entity to delete */ - void deleteEntity(@Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity); + void deleteEntity(@Nonnull PolarisBaseEntity entity); /** * Delete the specified grantRecord to the grant_records table. * - * @param callCtx call context * @param grantRec entity record to delete. */ - void deleteFromGrantRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec); + void deleteFromGrantRecords(@Nonnull PolarisGrantRecord grantRec); /** * Delete the all grant records in the grant_records table for the specified entity. This method * will delete all grant records on that securable entity and also all grants to that grantee * entity assuming that the entity is a grantee (catalog role, principal role or principal). * - * @param callCtx call context * @param entity entity whose grant records to and from should be deleted * @param grantsOnGrantee all grants to that grantee entity. Empty list if that entity is not a * grantee * @param grantsOnSecurable all grants on that securable entity */ void deleteAllEntityGrantRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity, @Nonnull List grantsOnGrantee, @Nonnull List grantsOnSecurable); @@ -181,10 +168,8 @@ void deleteAllEntityGrantRecords( /** * Delete Polaris entity and grant record metadata from all tables within the realm defined by the * contents of the {@code callCtx} - * - * @param callCtx call context */ - void deleteAll(@Nonnull PolarisCallContext callCtx); + void deleteAll(); /** * Lookup an entity given its catalog id (which can be {@link @@ -197,20 +182,17 @@ void deleteAllEntityGrantRecords( * specified {@code entityId}, implementations may still return the entity or may behave as if the * entity were not found. * - * @param callCtx call context * @param catalogId catalog id or NULL_ID * @param entityId entity id * @param typeCode the PolarisEntityType code of the entity to lookup * @return null if the entity was not found, else the retrieved entity. */ @Nullable - PolarisBaseEntity lookupEntity( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, int typeCode); + PolarisBaseEntity lookupEntity(long catalogId, long entityId, int typeCode); /** * Lookup an entity given its catalogId, parentId, typeCode, and name. * - * @param callCtx call context * @param catalogId catalog id or {@link * org.apache.polaris.core.entity.PolarisEntityConstants#NULL_ID} for top-level entities like * CATALOG, PRINCIPAL and PRINCIPAL_ROLE. Note that by convention, a catalog itself has @@ -223,16 +205,11 @@ PolarisBaseEntity lookupEntity( */ @Nullable PolarisBaseEntity lookupEntityByName( - @Nonnull PolarisCallContext callCtx, - long catalogId, - long parentId, - int typeCode, - @Nonnull String name); + long catalogId, long parentId, int typeCode, @Nonnull String name); /** * Looks up just the entity's subType and id given it catalogId, parentId, typeCode, and name. * - * @param callCtx call context * @param catalogId catalog id or NULL_ID * @param parentId id of the parent * @param typeCode the PolarisEntityType code of the entity to lookup @@ -241,12 +218,8 @@ PolarisBaseEntity lookupEntityByName( */ @Nullable default EntityNameLookupRecord lookupEntityIdAndSubTypeByName( - @Nonnull PolarisCallContext callCtx, - long catalogId, - long parentId, - int typeCode, - @Nonnull String name) { - PolarisBaseEntity baseEntity = lookupEntityByName(callCtx, catalogId, parentId, typeCode, name); + long catalogId, long parentId, int typeCode, @Nonnull String name) { + PolarisBaseEntity baseEntity = lookupEntityByName(catalogId, parentId, typeCode, name); if (baseEntity == null) { return null; } @@ -256,32 +229,27 @@ default EntityNameLookupRecord lookupEntityIdAndSubTypeByName( /** * Lookup a set of entities given their catalog id/entity id unique identifier * - * @param callCtx call context * @param entityIds list of entity ids * @return list of polaris base entities, parallel to the input list of ids. An entity in the list * will be null if the corresponding entity could not be found. */ @Nonnull - List lookupEntities( - @Nonnull PolarisCallContext callCtx, List entityIds); + List lookupEntities(List entityIds); /** * Get change tracking versions for all specified entity ids. * - * @param callCtx call context * @param entityIds list of entity id * @return list parallel to the input list of entity versions. If an entity cannot be found, the * corresponding element in the list will be null */ @Nonnull - List lookupEntityVersions( - @Nonnull PolarisCallContext callCtx, List entityIds); + List lookupEntityVersions(List entityIds); /** * List lightweight information of entities matching the given criteria with pagination. If all * properties of the entity are required,use {@link #loadEntities} instead. * - * @param callCtx call context * @param catalogId catalog id for that entity, NULL_ID if the entity is top-level * @param parentId id of the parent, can be the special 0 value representing the root entity * @param entityType type of entities to list @@ -291,7 +259,6 @@ List lookupEntityVersions( */ @Nonnull Page listEntities( - @Nonnull PolarisCallContext callCtx, long catalogId, long parentId, @Nonnull PolarisEntityType entityType, @@ -302,7 +269,6 @@ Page listEntities( * Load full entities matching the given criteria with pagination and transformation. If only the * entity name/id/type is required, use {@link #listEntities} instead. * - * @param callCtx call context * @param catalogId catalog id for that entity, NULL_ID if the entity is top-level * @param parentId id of the parent, can be the special 0 value representing the root entity * @param entityType type of entities to list @@ -315,7 +281,6 @@ Page listEntities( */ @Nonnull Page loadEntities( - @Nonnull PolarisCallContext callCtx, long catalogId, long parentId, @Nonnull PolarisEntityType entityType, @@ -328,18 +293,15 @@ Page loadEntities( * Lookup the current entityGrantRecordsVersion for the specified entity. That version is changed * everytime a grant record is added or removed on a base securable or added to a grantee. * - * @param callCtx call context * @param catalogId catalog id or NULL_ID * @param entityId unique entity id * @return current grant records version for that entity. */ - int lookupEntityGrantRecordsVersion( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId); + int lookupEntityGrantRecordsVersion(long catalogId, long entityId); /** * Lookup the specified grant record from the grant_records table. Return NULL if not found * - * @param callCtx call context * @param securableCatalogId catalog id of the securable entity, NULL_ID if the entity is * top-level * @param securableId id of the securable entity @@ -350,7 +312,6 @@ int lookupEntityGrantRecordsVersion( */ @Nullable PolarisGrantRecord lookupGrantRecord( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId, long granteeCatalogId, @@ -360,7 +321,6 @@ PolarisGrantRecord lookupGrantRecord( /** * Get all grant records on the specified securable entity. * - * @param callCtx call context * @param securableCatalogId catalog id of the securable entity, NULL_ID if the entity is * top-level * @param securableId id of the securable entity @@ -368,26 +328,23 @@ PolarisGrantRecord lookupGrantRecord( */ @Nonnull List loadAllGrantRecordsOnSecurable( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId); + long securableCatalogId, long securableId); /** * Get all grant records granted to the specified grantee entity. * - * @param callCtx call context * @param granteeCatalogId catalog id of the grantee entity, NULL_ID if the entity is top-level * @param granteeId id of the grantee entity * @return the list of grant records for the specified grantee */ @Nonnull - List loadAllGrantRecordsOnGrantee( - @Nonnull PolarisCallContext callCtx, long granteeCatalogId, long granteeId); + List loadAllGrantRecordsOnGrantee(long granteeCatalogId, long granteeId); /** * Check if the specified parent entity has children. * *

TODO: Figure out if this is needed vs listEntities with limit. * - * @param callContext the polaris call context * @param optionalEntityType if not null, only check for the specified type, else check for all * types of children entities * @param catalogId id of the catalog @@ -395,24 +352,19 @@ List loadAllGrantRecordsOnGrantee( * @return true if the parent entity has children */ boolean hasChildren( - @Nonnull PolarisCallContext callContext, - @Nullable PolarisEntityType optionalEntityType, - long catalogId, - long parentId); + @Nullable PolarisEntityType optionalEntityType, long catalogId, long parentId); /** * Check if the specified IcebergTableLikeEntity / NamespaceEntity has any sibling entities which * share a base location * - * @param callContext the polaris call context * @param entity the entity to check for overlapping siblings for * @return Optional.of(Optional.of(location)) if the parent entity has children, * Optional.of(Optional.empty()) if not, and Optional.empty() if the metastore doesn't support * this operation */ default - Optional> hasOverlappingSiblings( - @Nonnull PolarisCallContext callContext, T entity) { + Optional> hasOverlappingSiblings(T entity) { return Optional.empty(); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/IntegrationPersistence.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/IntegrationPersistence.java index 0d9eae6134..3c79e2692c 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/IntegrationPersistence.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/IntegrationPersistence.java @@ -20,7 +20,6 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.storage.PolarisStorageConfigurationInfo; @@ -43,30 +42,26 @@ public interface IntegrationPersistence { /** * Allows to retrieve to the secrets of a principal given its unique client id * - * @param callCtx call context * @param clientId principal client id * @return the secrets */ @Nullable - PolarisPrincipalSecrets loadPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId); + PolarisPrincipalSecrets loadPrincipalSecrets(@Nonnull String clientId); /** * generate and store a client id and associated secrets for a newly created principal entity * - * @param callCtx call context * @param principalName name of the principal * @param principalId principal id */ @Nonnull PolarisPrincipalSecrets generateNewPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String principalName, long principalId); + @Nonnull String principalName, long principalId); /** * Rotate the secrets of a principal entity, i.e. make the specified main secrets the secondary * and generate a new main secret * - * @param callCtx call context * @param clientId principal client id * @param principalId principal id * @param reset true if the principal secrets should be disabled and replaced with a one-time @@ -75,11 +70,7 @@ PolarisPrincipalSecrets generateNewPrincipalSecrets( */ @Nullable PolarisPrincipalSecrets rotatePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - @Nonnull String clientId, - long principalId, - boolean reset, - @Nonnull String oldSecretHash); + @Nonnull String clientId, long principalId, boolean reset, @Nonnull String oldSecretHash); /** * Store the secrets of a principal entity. @@ -87,7 +78,6 @@ PolarisPrincipalSecrets rotatePrincipalSecrets( *

This method creates and persists new credentials for the given client ID. The credentials * are expected not to already exist for the given client ID. * - * @param callCtx call context * @param principalId the principal id * @param resolvedClientId * @param customClientSecret the secret for the principal @@ -95,25 +85,19 @@ PolarisPrincipalSecrets rotatePrincipalSecrets( */ @Nullable PolarisPrincipalSecrets storePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - long principalId, - @Nonnull String resolvedClientId, - String customClientSecret); + long principalId, @Nonnull String resolvedClientId, String customClientSecret); /** * When dropping a principal, we also need to drop the secrets of that principal * - * @param callCtx the call context * @param clientId principal client id * @param principalId the id of the principal whose secrets are dropped */ - void deletePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId, long principalId); + void deletePrincipalSecrets(@Nonnull String clientId, long principalId); /** * Create an in-memory storage integration * - * @param callCtx the polaris calllctx * @param catalogId the catalog id * @param entityId the entity id * @param polarisStorageConfigurationInfo the storage configuration information @@ -121,7 +105,6 @@ void deletePrincipalSecrets( */ @Nullable PolarisStorageIntegration createStorageIntegration( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, PolarisStorageConfigurationInfo polarisStorageConfigurationInfo); @@ -129,24 +112,19 @@ PolarisStorageIntegration createS /** * Persist a storage integration in the metastore * - * @param callContext the polaris call context * @param entity the entity of the object * @param storageIntegration the storage integration to persist */ void persistStorageIntegrationIfNeeded( - @Nonnull PolarisCallContext callContext, - @Nonnull PolarisBaseEntity entity, - @Nullable PolarisStorageIntegration storageIntegration); + @Nonnull PolarisBaseEntity entity, @Nullable PolarisStorageIntegration storageIntegration); /** * Load the polaris storage integration for a polaris entity (Catalog,Namespace,Table,View) * - * @param callContext the polaris call context * @param entity the polaris entity * @return a polaris storage integration */ @Nullable - PolarisStorageIntegration loadPolarisStorageIntegration( - @Nonnull PolarisCallContext callContext, @Nonnull PolarisBaseEntity entity); + PolarisStorageIntegration loadPolarisStorageIntegration(@Nonnull PolarisBaseEntity entity); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java index fedc983016..37c94e53fb 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java @@ -25,9 +25,10 @@ import java.util.Map; import java.util.Optional; import java.util.function.Supplier; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDiagnostics; +import org.apache.polaris.core.config.PolarisConfigurationStore; import org.apache.polaris.core.config.RealmConfig; +import org.apache.polaris.core.config.RealmConfigImpl; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; @@ -48,7 +49,6 @@ public abstract class LocalPolarisMetaStoreManagerFactory implements MetaStoreManagerFactory { - final Map metaStoreManagerMap = new HashMap<>(); final Map entityCacheMap = new HashMap<>(); final Map backingStoreMap = new HashMap<>(); final Map> sessionSupplierMap = new HashMap<>(); @@ -58,11 +58,15 @@ public abstract class LocalPolarisMetaStoreManagerFactory private final Clock clock; private final PolarisDiagnostics diagnostics; + private final PolarisConfigurationStore configurationStore; protected LocalPolarisMetaStoreManagerFactory( - @Nonnull Clock clock, @Nonnull PolarisDiagnostics diagnostics) { + @Nonnull Clock clock, + @Nonnull PolarisDiagnostics diagnostics, + @Nonnull PolarisConfigurationStore configurationStore) { this.clock = clock; this.diagnostics = diagnostics; + this.configurationStore = configurationStore; } protected abstract StoreType createBackingStore(@Nonnull PolarisDiagnostics diagnostics); @@ -88,8 +92,16 @@ protected PrincipalSecretsGenerator secretsGenerator( * into the existing realm-based setup flow. */ protected PolarisMetaStoreManager createNewMetaStoreManager( - Clock clock, PolarisDiagnostics diagnostics) { - return new TransactionalMetaStoreManagerImpl(clock, diagnostics); + Clock clock, + PolarisDiagnostics diagnostics, + RealmContext realmContext, + RealmConfig realmConfig) { + return new TransactionalMetaStoreManagerImpl( + clock, + diagnostics, + realmContext, + realmConfig, + () -> createPersistenceSession(realmContext)); } private void initializeForRealm( @@ -98,9 +110,6 @@ private void initializeForRealm( sessionSupplierMap.put( realmContext.getRealmIdentifier(), () -> createMetaStoreSession(backingStore, realmContext, rootCredentialsSet, diagnostics)); - - PolarisMetaStoreManager metaStoreManager = createNewMetaStoreManager(clock, diagnostics); - metaStoreManagerMap.put(realmContext.getRealmIdentifier(), metaStoreManager); } @Override @@ -110,7 +119,7 @@ public synchronized Map bootstrapRealms( for (String realm : realms) { RealmContext realmContext = () -> realm; - if (!metaStoreManagerMap.containsKey(realm)) { + if (!sessionSupplierMap.containsKey(realm)) { initializeForRealm(realmContext, rootCredentialsSet); PrincipalSecretsResult secretsResult = bootstrapServiceAndCreatePolarisPrincipalForRealm(realmContext); @@ -127,51 +136,41 @@ public Map purgeRealms(Iterable realms) { for (String realm : realms) { RealmContext realmContext = () -> realm; - PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext); - TransactionalPersistence session = getOrCreateSession(realmContext); + PolarisMetaStoreManager metaStoreManager = createMetaStoreManager(realmContext); - PolarisCallContext callContext = new PolarisCallContext(realmContext, session); - BaseResult result = metaStoreManager.purge(callContext); + BaseResult result = metaStoreManager.purge(); results.put(realm, result); backingStoreMap.remove(realm); sessionSupplierMap.remove(realm); - metaStoreManagerMap.remove(realm); } return Map.copyOf(results); } @Override - public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager( - RealmContext realmContext) { - if (!metaStoreManagerMap.containsKey(realmContext.getRealmIdentifier())) { - initializeForRealm(realmContext, null); - checkPolarisServiceBootstrappedForRealm(realmContext); - } - return metaStoreManagerMap.get(realmContext.getRealmIdentifier()); + public PolarisMetaStoreManager createMetaStoreManager(RealmContext realmContext) { + RealmConfig realmConfig = new RealmConfigImpl(configurationStore, realmContext); + return createNewMetaStoreManager(clock, diagnostics, realmContext, realmConfig); } - @Override - public synchronized TransactionalPersistence getOrCreateSession(RealmContext realmContext) { + protected synchronized TransactionalPersistence createPersistenceSession( + RealmContext realmContext) { if (!sessionSupplierMap.containsKey(realmContext.getRealmIdentifier())) { initializeForRealm(realmContext, null); + checkPolarisServiceBootstrappedForRealm(realmContext); } - checkPolarisServiceBootstrappedForRealm(realmContext); return sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(); } @Override - public synchronized EntityCache getOrCreateEntityCache( - RealmContext realmContext, RealmConfig realmConfig) { - if (!entityCacheMap.containsKey(realmContext.getRealmIdentifier())) { - PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext); - entityCacheMap.put( - realmContext.getRealmIdentifier(), - new InMemoryEntityCache(diagnostics, realmConfig, metaStoreManager)); - } - - return entityCacheMap.get(realmContext.getRealmIdentifier()); + public synchronized EntityCache getOrCreateEntityCache(RealmContext realmContext) { + return entityCacheMap.computeIfAbsent( + realmContext.getRealmIdentifier(), + realmId -> { + RealmConfig realmConfig = new RealmConfigImpl(configurationStore, realmContext); + return new InMemoryEntityCache(diagnostics, realmConfig); + }); } /** @@ -180,15 +179,9 @@ public synchronized EntityCache getOrCreateEntityCache( */ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm( RealmContext realmContext) { - // While bootstrapping we need to act as a fake privileged context since the real - // 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); - - Optional preliminaryRootPrincipal = - metaStoreManager.findRootPrincipal(polarisContext); + PolarisMetaStoreManager metaStoreManager = createMetaStoreManager(realmContext); + + Optional preliminaryRootPrincipal = metaStoreManager.findRootPrincipal(); if (preliminaryRootPrincipal.isPresent()) { String overrideMessage = "It appears this metastore manager has already been bootstrapped. " @@ -197,11 +190,10 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm throw new IllegalArgumentException(overrideMessage); } - metaStoreManager.bootstrapPolarisService(polarisContext); + metaStoreManager.bootstrapPolarisService(); - PrincipalEntity rootPrincipal = - metaStoreManager.findRootPrincipal(polarisContext).orElseThrow(); - return metaStoreManager.loadPrincipalSecrets(polarisContext, rootPrincipal.getClientId()); + PrincipalEntity rootPrincipal = metaStoreManager.findRootPrincipal().orElseThrow(); + return metaStoreManager.loadPrincipalSecrets(rootPrincipal.getClientId()); } /** @@ -212,12 +204,9 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm * entities */ private void checkPolarisServiceBootstrappedForRealm(RealmContext realmContext) { - PolarisMetaStoreManager metaStoreManager = - metaStoreManagerMap.get(realmContext.getRealmIdentifier()); - BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(); - PolarisCallContext polarisContext = new PolarisCallContext(realmContext, metaStore); + PolarisMetaStoreManager metaStoreManager = createMetaStoreManager(realmContext); - Optional rootPrincipal = metaStoreManager.findRootPrincipal(polarisContext); + Optional rootPrincipal = metaStoreManager.findRootPrincipal(); if (rootPrincipal.isEmpty()) { LOGGER.error( "\n\n Realm {} is not bootstrapped, could not load root principal. Please run Bootstrap command. \n\n", diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java index 4a32a88591..df9df43108 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java @@ -19,7 +19,6 @@ package org.apache.polaris.core.persistence; import java.util.Map; -import org.apache.polaris.core.config.RealmConfig; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.persistence.bootstrap.BootstrapOptions; import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; @@ -30,11 +29,9 @@ /** Configuration interface for configuring the {@link PolarisMetaStoreManager}. */ public interface MetaStoreManagerFactory { - PolarisMetaStoreManager getOrCreateMetaStoreManager(RealmContext realmContext); + PolarisMetaStoreManager createMetaStoreManager(RealmContext realmContext); - BasePersistence getOrCreateSession(RealmContext realmContext); - - EntityCache getOrCreateEntityCache(RealmContext realmContext, RealmConfig realmConfig); + EntityCache getOrCreateEntityCache(RealmContext realmContext); Map bootstrapRealms( Iterable realms, RootCredentialsSet rootCredentialsSet); diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManager.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManager.java index cf3912fa95..f88674a760 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManager.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.auth.PolarisGrantManager; import org.apache.polaris.core.auth.PolarisSecretsManager; import org.apache.polaris.core.entity.LocationBasedEntity; @@ -68,11 +67,10 @@ public interface PolarisMetaStoreManager * Bootstrap the Polaris service, creating the root catalog, root principal, and associated * service admin role. Will fail if the service has already been bootstrapped. * - * @param callCtx call context * @return the result of the bootstrap attempt */ @Nonnull - BaseResult bootstrapPolarisService(@Nonnull PolarisCallContext callCtx); + BaseResult bootstrapPolarisService(); /** * Purge all metadata associated with the Polaris service, resetting the metastore to the state it @@ -82,18 +80,16 @@ public interface PolarisMetaStoreManager * *

This will destroy whatever Polaris metadata exists in the metastore * - * @param callCtx call context * @return always success or unexpected error */ @Nonnull - BaseResult purge(@Nonnull PolarisCallContext callCtx); + BaseResult purge(); /** * Resolve an entity by name. Can be a top-level entity like a catalog or an entity inside a * catalog like a namespace, a role, a table like entity, or a principal. If the entity is inside * a catalog, the parameter catalogPath must be specified * - * @param callCtx call context * @param catalogPath path inside a catalog to that entity, rooted by the catalog. If null, the * entity being resolved is a top-level account entity like a catalog. * @param entityType entity type @@ -106,7 +102,6 @@ public interface PolarisMetaStoreManager */ @Nonnull EntityResult readEntityByName( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @@ -116,7 +111,6 @@ EntityResult readEntityByName( * List lightweight information about entities matching the given criteria. If all properties of * the entity are required,use {@link #loadEntities} instead. * - * @param callCtx call context * @param catalogPath path inside a catalog. If null or empty, the entities to list are top-level, * like catalogs * @param entityType entity type @@ -126,7 +120,6 @@ EntityResult readEntityByName( */ @Nonnull ListEntitiesResult listEntities( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @@ -137,7 +130,6 @@ ListEntitiesResult listEntities( * is required, use {@link #listEntities} instead. If no pagination is required, use {@link * #loadEntitiesAll} instead. * - * @param callCtx call context * @param catalogPath path inside a catalog. If null or empty, the entities to list are top-level, * like catalogs * @param entityType type of entities to list @@ -146,7 +138,6 @@ ListEntitiesResult listEntities( */ @Nonnull Page loadEntities( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @@ -157,7 +148,6 @@ Page loadEntities( * use {@link #loadEntities} instead. If only the entity name/id/type is required, use {@link * #listEntities} instead. * - * @param callCtx call context * @param catalogPath path inside a catalog. If null or empty, the entities to list are top-level, * like catalogs * @param entityType type of entities to list @@ -165,43 +155,37 @@ Page loadEntities( * @return list of all matching entities */ default @Nonnull List loadEntitiesAll( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType) { - return loadEntities(callCtx, catalogPath, entityType, entitySubType, PageToken.readEverything()) - .items(); + return loadEntities(catalogPath, entityType, entitySubType, PageToken.readEverything()).items(); } /** * Generate a new unique id that can be used by the Polaris client when it needs to create a new * entity * - * @param callCtx call context * @return the newly created id, not expected to fail */ @Nonnull - GenerateEntityIdResult generateNewEntityId(@Nonnull PolarisCallContext callCtx); + GenerateEntityIdResult generateNewEntityId(); /** * Create a new principal. This not only creates the new principal entity but also generates a * client_id/secret pair for this new principal. * - * @param callCtx call context * @param principal the principal entity to create * @return the client_id/secret for the new principal which was created. Will return * ENTITY_ALREADY_EXISTS if the principal already exists */ @Nonnull - CreatePrincipalResult createPrincipal( - @Nonnull PolarisCallContext callCtx, @Nonnull PrincipalEntity principal); + CreatePrincipalResult createPrincipal(@Nonnull PrincipalEntity principal); /** * Create a new catalog. This not only creates the new catalog entity but also the initial admin * role required to admin this catalog. If inline storage integration property is provided, create * a storage integration. * - * @param callCtx call context * @param catalog the catalog entity to create * @param principalRoles once the catalog has been created, list of principal roles to grant its * catalog_admin role to. If no principal role is specified, we will grant the catalog_admin @@ -210,9 +194,7 @@ CreatePrincipalResult createPrincipal( */ @Nonnull CreateCatalogResult createCatalog( - @Nonnull PolarisCallContext callCtx, - @Nonnull PolarisBaseEntity catalog, - @Nonnull List principalRoles); + @Nonnull PolarisBaseEntity catalog, @Nonnull List principalRoles); /** * Persist a newly created entity under the specified catalog path if specified, else this is a @@ -222,7 +204,6 @@ CreateCatalogResult createCatalog( * cannot be resolved, we will return null. And of course if another entity exists with the same * name, we will fail and also return null. * - * @param callCtx call context * @param catalogPath path inside a catalog. If null, the entity to persist is assumed to be * top-level. * @param entity entity to write @@ -233,9 +214,7 @@ CreateCatalogResult createCatalog( */ @Nonnull EntityResult createEntityIfNotExists( - @Nonnull PolarisCallContext callCtx, - @Nullable List catalogPath, - @Nonnull PolarisBaseEntity entity); + @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity); /** * Persist a batch of newly created entities under the specified catalog path if specified, else @@ -246,7 +225,6 @@ EntityResult createEntityIfNotExists( * will be persisted. And of course if any entity conflicts with an existing entity with the same * name, we will fail all entities and also return null. * - * @param callCtx call context * @param catalogPath path inside a catalog. If null, the entity to persist is assumed to be * top-level. * @param entities batch of entities to write @@ -257,7 +235,6 @@ EntityResult createEntityIfNotExists( */ @Nonnull EntitiesResult createEntitiesIfNotExist( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull List entities); @@ -266,35 +243,29 @@ EntitiesResult createEntitiesIfNotExist( * has not changed. If this is not the case we will return false. Else we will update both the * internal and visible properties and return true * - * @param callCtx call context * @param catalogPath path to that entity. Could be null if this entity is top-level * @param entity entity to update, cannot be null * @return the entity we updated or null if the client should retry */ @Nonnull EntityResult updateEntityPropertiesIfNotChanged( - @Nonnull PolarisCallContext callCtx, - @Nullable List catalogPath, - @Nonnull PolarisBaseEntity entity); + @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity); /** - * This works exactly like {@link #updateEntityPropertiesIfNotChanged(PolarisCallContext, List, - * PolarisBaseEntity)} but allows to operate on multiple entities at once. Just loop through the - * list, calling each entity update and return null if any of those fail. + * This works exactly like {@link #updateEntityPropertiesIfNotChanged(List, PolarisBaseEntity)} + * but allows to operate on multiple entities at once. Just loop through the list, calling each + * entity update and return null if any of those fail. * - * @param callCtx call context * @param entities the set of entities to update * @return list of all entities we updated or null if the client should retry because one update * failed */ @Nonnull - EntitiesResult updateEntitiesPropertiesIfNotChanged( - @Nonnull PolarisCallContext callCtx, @Nonnull List entities); + EntitiesResult updateEntitiesPropertiesIfNotChanged(@Nonnull List entities); /** * Rename an entity, potentially re-parenting it. * - * @param callCtx call context * @param catalogPath path to that entity. Could be an empty list of the entity is a catalog. * @param entityToRename entity to rename. This entity should have been resolved by the client * @param newCatalogPath if not null, new catalog path @@ -305,7 +276,6 @@ EntitiesResult updateEntitiesPropertiesIfNotChanged( */ @Nonnull EntityResult renameEntity( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entityToRename, @Nullable List newCatalogPath, @@ -314,7 +284,6 @@ EntityResult renameEntity( /** * Drop the specified entity assuming it exists * - * @param callCtx call context * @param catalogPath path to that entity. Could be an empty list of the entity is a catalog. * @param entityToDrop entity to drop, must have been resolved by the client * @param cleanupProperties if not null, properties that will be persisted with the cleanup task @@ -325,7 +294,6 @@ EntityResult renameEntity( */ @Nonnull DropEntityResult dropEntityIfExists( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entityToDrop, @Nullable Map cleanupProperties, @@ -335,42 +303,34 @@ DropEntityResult dropEntityIfExists( * Load the entity from backend store. Will return NULL if the entity does not exist, i.e. has * been purged. The entity being loaded might have been dropped * - * @param callCtx call context * @param entityCatalogId id of the catalog for that entity * @param entityId the id of the entity to load */ @Nonnull EntityResult loadEntity( - @Nonnull PolarisCallContext callCtx, - long entityCatalogId, - long entityId, - @Nonnull PolarisEntityType entityType); + long entityCatalogId, long entityId, @Nonnull PolarisEntityType entityType); /** * Fetch a list of tasks to be completed. Tasks * - * @param callCtx call context * @param executorId executor id * @param pageToken page token to start after * @return list of tasks to be completed */ @Nonnull - EntitiesResult loadTasks( - @Nonnull PolarisCallContext callCtx, String executorId, PageToken pageToken); + EntitiesResult loadTasks(String executorId, PageToken pageToken); /** * Load change tracking information for a set of entities in one single shot and return for each * the version for the entity itself and the version associated to its grant records. * - * @param callCtx call context * @param entityIds list of catalog/entity pair ids for which we need to efficiently load the * version information, both entity version and grant records version. * @return a list of version tracking information. Order in that returned list is the same as the * input list. Some elements might be NULL if the entity has been purged. Not expected to fail */ @Nonnull - ChangeTrackingResult loadEntitiesChangeTracking( - @Nonnull PolarisCallContext callCtx, @Nonnull List entityIds); + ChangeTrackingResult loadEntitiesChangeTracking(@Nonnull List entityIds); /** * Load a resolved entity, i.e. an entity definition and associated grant records, from the @@ -379,7 +339,6 @@ ChangeTrackingResult loadEntitiesChangeTracking( *

For entities that can be grantees, the associated grant records will include both the grant * records for this entity as a grantee and for this entity as a securable. * - * @param callCtx call context * @param entityCatalogId id of the catalog for that entity * @param entityId id of the entity * @return result with entity and grants. Status will be ENTITY_NOT_FOUND if the entity was not @@ -387,10 +346,7 @@ ChangeTrackingResult loadEntitiesChangeTracking( */ @Nonnull ResolvedEntityResult loadResolvedEntityById( - @Nonnull PolarisCallContext callCtx, - long entityCatalogId, - long entityId, - PolarisEntityType entityType); + long entityCatalogId, long entityId, PolarisEntityType entityType); /** * Load a resolved entity, i.e. an entity definition and associated grant records, from the @@ -400,7 +356,6 @@ ResolvedEntityResult loadResolvedEntityById( *

For entities that can be grantees, the associated grant records will include both the grant * records for this entity as a grantee and for this entity as a securable. * - * @param callCtx call context * @param entityCatalogId id of the catalog for that entity * @param parentId the id of the parent of that entity * @param entityType the type of this entity @@ -410,7 +365,6 @@ ResolvedEntityResult loadResolvedEntityById( */ @Nonnull ResolvedEntityResult loadResolvedEntityByName( - @Nonnull PolarisCallContext callCtx, long entityCatalogId, long parentId, @Nonnull PolarisEntityType entityType, @@ -424,7 +378,6 @@ ResolvedEntityResult loadResolvedEntityByName( *

For entities that can be grantees, the associated grant records will include both the grant * records for this entity as a grantee and for this entity as a securable. * - * @param callCtx call context * @param entityType type of the entity whose entity and grants we are refreshing * @param entityCatalogId id of the catalog for that entity * @param entityId the id of the entity to load @@ -433,7 +386,6 @@ ResolvedEntityResult loadResolvedEntityByName( */ @Nonnull ResolvedEntityResult refreshResolvedEntity( - @Nonnull PolarisCallContext callCtx, int entityVersion, int entityGrantRecordsVersion, @Nonnull PolarisEntityType entityType, @@ -444,15 +396,13 @@ ResolvedEntityResult refreshResolvedEntity( * Check if the specified IcebergTableLikeEntity has any same-namespace siblings which share a * location * - * @param callContext the polaris call context * @param entity the entity to check for overlapping siblings for * @return Optional.of(Optional.of ( location)) if the parent entity has children, * Optional.of(Optional.empty()) if not, and Optional.empty() if the metastore doesn't support * this operation */ default - Optional> hasOverlappingSiblings( - @Nonnull PolarisCallContext callContext, T entity) { + Optional> hasOverlappingSiblings(T entity) { return Optional.empty(); } @@ -466,44 +416,32 @@ default boolean requiresEntityReload() { return true; } - default Optional findRootPrincipal(PolarisCallContext polarisCallContext) { - return findPrincipalByName(polarisCallContext, PolarisEntityConstants.getRootPrincipalName()); + default Optional findRootPrincipal() { + return findPrincipalByName(PolarisEntityConstants.getRootPrincipalName()); } - default Optional findPrincipalById( - PolarisCallContext polarisCallContext, long principalId) { + default Optional findPrincipalById(long principalId) { EntityResult loadResult = - loadEntity( - polarisCallContext, - PolarisEntityConstants.getNullId(), - principalId, - PolarisEntityType.PRINCIPAL); + loadEntity(PolarisEntityConstants.getNullId(), principalId, PolarisEntityType.PRINCIPAL); if (!loadResult.isSuccess()) { return Optional.empty(); } return Optional.of(loadResult.getEntity()).map(PrincipalEntity::of); } - default Optional findPrincipalByName( - PolarisCallContext polarisCallContext, String principalName) { + default Optional findPrincipalByName(String principalName) { EntityResult entityResult = readEntityByName( - polarisCallContext, - null, - PolarisEntityType.PRINCIPAL, - PolarisEntitySubType.NULL_SUBTYPE, - principalName); + null, PolarisEntityType.PRINCIPAL, PolarisEntitySubType.NULL_SUBTYPE, principalName); if (!entityResult.isSuccess()) { return Optional.empty(); } return Optional.of(entityResult.getEntity()).map(PrincipalEntity::of); } - default Optional findPrincipalRoleByName( - PolarisCallContext polarisCallContext, String principalRoleName) { + default Optional findPrincipalRoleByName(String principalRoleName) { EntityResult entityResult = readEntityByName( - polarisCallContext, null, PolarisEntityType.PRINCIPAL_ROLE, PolarisEntitySubType.NULL_SUBTYPE, diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java index 8729558935..2fdb9e9ce7 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java @@ -26,7 +26,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.entity.LocationBasedEntity; import org.apache.polaris.core.entity.PolarisBaseEntity; @@ -99,20 +98,19 @@ public List getPendingUpdates() { } @Override - public BaseResult bootstrapPolarisService(@Nonnull PolarisCallContext callCtx) { + public BaseResult bootstrapPolarisService() { diagnostics.fail("illegal_method_in_transaction_workspace", "bootstrapPolarisService"); return null; } @Override - public BaseResult purge(@Nonnull PolarisCallContext callCtx) { + public BaseResult purge() { diagnostics.fail("illegal_method_in_transaction_workspace", "purge"); return null; } @Override public EntityResult readEntityByName( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @@ -123,7 +121,6 @@ public EntityResult readEntityByName( @Override public @Nonnull ListEntitiesResult listEntities( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @@ -134,7 +131,6 @@ public EntityResult readEntityByName( @Override public @Nonnull Page loadEntities( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @@ -144,73 +140,58 @@ public EntityResult readEntityByName( } @Override - public GenerateEntityIdResult generateNewEntityId(@Nonnull PolarisCallContext callCtx) { + public GenerateEntityIdResult generateNewEntityId() { diagnostics.fail("illegal_method_in_transaction_workspace", "generateNewEntityId"); return null; } @Override - public CreatePrincipalResult createPrincipal( - @Nonnull PolarisCallContext callCtx, @Nonnull PrincipalEntity principal) { + public CreatePrincipalResult createPrincipal(@Nonnull PrincipalEntity principal) { diagnostics.fail("illegal_method_in_transaction_workspace", "createPrincipal"); return null; } @Override - public PrincipalSecretsResult loadPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId) { + public PrincipalSecretsResult loadPrincipalSecrets(@Nonnull String clientId) { diagnostics.fail("illegal_method_in_transaction_workspace", "loadPrincipalSecrets"); return null; } @Override - public void deletePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId, long principalId) { + public void deletePrincipalSecrets(@Nonnull String clientId, long principalId) { diagnostics.fail("illegal_method_in_transaction_workspace", "loadPrincipalSecrets"); } @Override public PrincipalSecretsResult rotatePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - @Nonnull String clientId, - long principalId, - boolean reset, - @Nonnull String oldSecretHash) { + @Nonnull String clientId, long principalId, boolean reset, @Nonnull String oldSecretHash) { diagnostics.fail("illegal_method_in_transaction_workspace", "rotatePrincipalSecrets"); return null; } @Override public PrincipalSecretsResult resetPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - long principalId, - @Nonnull String resolvedClientId, - String customClientSecret) { + long principalId, @Nonnull String resolvedClientId, String customClientSecret) { diagnostics.fail("illegal_method_in_transaction_workspace", "resetPrincipalSecrets"); return null; } @Override public CreateCatalogResult createCatalog( - @Nonnull PolarisCallContext callCtx, - @Nonnull PolarisBaseEntity catalog, - @Nonnull List principalRoles) { + @Nonnull PolarisBaseEntity catalog, @Nonnull List principalRoles) { diagnostics.fail("illegal_method_in_transaction_workspace", "createCatalog"); return null; } @Override public EntityResult createEntityIfNotExists( - @Nonnull PolarisCallContext callCtx, - @Nullable List catalogPath, - @Nonnull PolarisBaseEntity entity) { + @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity) { diagnostics.fail("illegal_method_in_transaction_workspace", "createEntityIfNotExists"); return null; } @Override public EntitiesResult createEntitiesIfNotExist( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull List entities) { diagnostics.fail("illegal_method_in_transaction_workspace", "createEntitiesIfNotExist"); @@ -219,16 +200,14 @@ public EntitiesResult createEntitiesIfNotExist( @Override public EntityResult updateEntityPropertiesIfNotChanged( - @Nonnull PolarisCallContext callCtx, - @Nullable List catalogPath, - @Nonnull PolarisBaseEntity entity) { + @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity) { pendingUpdates.add(new EntityWithPath(catalogPath, entity)); return new EntityResult(entity); } @Override public EntitiesResult updateEntitiesPropertiesIfNotChanged( - @Nonnull PolarisCallContext callCtx, @Nonnull List entities) { + @Nonnull List entities) { diagnostics.fail( "illegal_method_in_transaction_workspace", "updateEntitiesPropertiesIfNotChanged"); return null; @@ -236,7 +215,6 @@ public EntitiesResult updateEntitiesPropertiesIfNotChanged( @Override public EntityResult renameEntity( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entityToRename, @Nullable List newCatalogPath, @@ -247,7 +225,6 @@ public EntityResult renameEntity( @Override public DropEntityResult dropEntityIfExists( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entityToDrop, @Nullable Map cleanupProperties, @@ -258,7 +235,6 @@ public DropEntityResult dropEntityIfExists( @Override public PrivilegeResult grantUsageOnRoleToGrantee( - @Nonnull PolarisCallContext callCtx, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @Nonnull PolarisEntityCore grantee) { @@ -268,7 +244,6 @@ public PrivilegeResult grantUsageOnRoleToGrantee( @Override public PrivilegeResult revokeUsageOnRoleFromGrantee( - @Nonnull PolarisCallContext callCtx, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @Nonnull PolarisEntityCore grantee) { @@ -278,7 +253,6 @@ public PrivilegeResult revokeUsageOnRoleFromGrantee( @Override public PrivilegeResult grantPrivilegeOnSecurableToRole( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @Nonnull PolarisEntityCore securable, @@ -289,7 +263,6 @@ public PrivilegeResult grantPrivilegeOnSecurableToRole( @Override public PrivilegeResult revokePrivilegeOnSecurableFromRole( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @Nonnull PolarisEntityCore securable, @@ -300,46 +273,38 @@ public PrivilegeResult revokePrivilegeOnSecurableFromRole( } @Override - public @Nonnull LoadGrantsResult loadGrantsOnSecurable( - @Nonnull PolarisCallContext callCtx, PolarisEntityCore securable) { + public @Nonnull LoadGrantsResult loadGrantsOnSecurable(PolarisEntityCore securable) { diagnostics.fail("illegal_method_in_transaction_workspace", "loadGrantsOnSecurable"); return null; } @Override - public @Nonnull LoadGrantsResult loadGrantsToGrantee( - @Nonnull PolarisCallContext callCtx, PolarisEntityCore grantee) { + public @Nonnull LoadGrantsResult loadGrantsToGrantee(PolarisEntityCore grantee) { diagnostics.fail("illegal_method_in_transaction_workspace", "loadGrantsToGrantee"); return null; } @Override - public ChangeTrackingResult loadEntitiesChangeTracking( - @Nonnull PolarisCallContext callCtx, @Nonnull List entityIds) { + public ChangeTrackingResult loadEntitiesChangeTracking(@Nonnull List entityIds) { diagnostics.fail("illegal_method_in_transaction_workspace", "loadEntitiesChangeTracking"); return null; } @Override public EntityResult loadEntity( - @Nonnull PolarisCallContext callCtx, - long entityCatalogId, - long entityId, - PolarisEntityType entityType) { + long entityCatalogId, long entityId, PolarisEntityType entityType) { diagnostics.fail("illegal_method_in_transaction_workspace", "loadEntity"); return null; } @Override - public EntitiesResult loadTasks( - @Nonnull PolarisCallContext callCtx, String executorId, PageToken pageToken) { + public EntitiesResult loadTasks(String executorId, PageToken pageToken) { diagnostics.fail("illegal_method_in_transaction_workspace", "loadTasks"); return null; } @Override public ScopedCredentialsResult getSubscopedCredsForEntity( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, PolarisEntityType entityType, @@ -348,7 +313,6 @@ public ScopedCredentialsResult getSubscopedCredsForEntity( @Nonnull Set allowedWriteLocations, Optional refreshCredentialsEndpoint) { return delegate.getSubscopedCredsForEntity( - callCtx, catalogId, entityId, entityType, @@ -360,17 +324,13 @@ public ScopedCredentialsResult getSubscopedCredsForEntity( @Override public ResolvedEntityResult loadResolvedEntityById( - @Nonnull PolarisCallContext callCtx, - long entityCatalogId, - long entityId, - PolarisEntityType entityType) { + long entityCatalogId, long entityId, PolarisEntityType entityType) { diagnostics.fail("illegal_method_in_transaction_workspace", "loadResolvedEntityById"); return null; } @Override public ResolvedEntityResult loadResolvedEntityByName( - @Nonnull PolarisCallContext callCtx, long entityCatalogId, long parentId, @Nonnull PolarisEntityType entityType, @@ -381,7 +341,6 @@ public ResolvedEntityResult loadResolvedEntityByName( @Override public ResolvedEntityResult refreshResolvedEntity( - @Nonnull PolarisCallContext callCtx, int entityVersion, int entityGrantRecordsVersion, @Nonnull PolarisEntityType entityType, @@ -394,15 +353,13 @@ public ResolvedEntityResult refreshResolvedEntity( /** {@inheritDoc} */ @Override public - Optional> hasOverlappingSiblings( - @Nonnull PolarisCallContext callContext, T entity) { + Optional> hasOverlappingSiblings(T entity) { diagnostics.fail("illegal_method_in_transaction_workspace", "hasOverlappingSiblings"); return Optional.empty(); } @Override public @Nonnull PolicyAttachmentResult attachPolicyToEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull List targetCatalogPath, @Nonnull PolarisEntityCore target, @Nonnull List policyCatalogPath, @@ -414,7 +371,6 @@ Optional> hasOverlappingSiblings( @Override public @Nonnull PolicyAttachmentResult detachPolicyFromEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull List catalogPath, @Nonnull PolarisEntityCore target, @Nonnull List policyCatalogPath, @@ -424,25 +380,20 @@ Optional> hasOverlappingSiblings( } @Override - public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore target) { + public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntity(@Nonnull PolarisEntityCore target) { diagnostics.fail("illegal_method_in_transaction_workspace", "loadPoliciesOnEntity"); return null; } @Override public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntityByType( - @Nonnull PolarisCallContext callCtx, - @Nonnull PolarisEntityCore target, - @Nonnull PolicyType policyType) { + @Nonnull PolarisEntityCore target, @Nonnull PolicyType policyType) { diagnostics.fail("illegal_method_in_transaction_workspace", "loadPoliciesOnEntityByType"); return null; } - @Nonnull @Override - public void writeEvents( - @Nonnull PolarisCallContext callCtx, @Nonnull List polarisEvents) { + public void writeEvents(@Nonnull List polarisEvents) { diagnostics.fail("illegal_method_in_transaction_workspace", "writeEvents"); } } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCache.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCache.java index cd438c9950..647a8fc22b 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCache.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/EntityCache.java @@ -20,9 +20,9 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntityType; +import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.ResolvedPolarisEntity; /** Interface for a Polaris entity cache */ @@ -38,7 +38,6 @@ public interface EntityCache { * Refresh the cache if needs be with a version of the entity/grant records matching the minimum * specified version. * - * @param callContext the Polaris call context * @param entityToValidate copy of the entity held by the caller to validate * @param entityMinVersion minimum expected version. Should be reloaded if found in a cache with a * version less than this one @@ -48,7 +47,7 @@ public interface EntityCache { */ @Nullable ResolvedPolarisEntity getAndRefreshIfNeeded( - @Nonnull PolarisCallContext callContext, + @Nonnull PolarisMetaStoreManager metaStoreManager, @Nonnull PolarisBaseEntity entityToValidate, int entityMinVersion, int entityGrantRecordsMinVersion); @@ -56,7 +55,6 @@ ResolvedPolarisEntity getAndRefreshIfNeeded( /** * Get the specified entity by name and load it if it is not found. * - * @param callContext the Polaris call context * @param entityCatalogId id of the catalog where this entity resides or NULL_ID if top-level * @param entityId id of the entity to lookup * @return null if the entity does not exist or was dropped. Else return the entry for that @@ -64,7 +62,7 @@ ResolvedPolarisEntity getAndRefreshIfNeeded( */ @Nullable EntityCacheLookupResult getOrLoadEntityById( - @Nonnull PolarisCallContext callContext, + @Nonnull PolarisMetaStoreManager metaStoreManager, long entityCatalogId, long entityId, PolarisEntityType entityType); @@ -72,12 +70,12 @@ EntityCacheLookupResult getOrLoadEntityById( /** * Get the specified entity by name and load it if it is not found. * - * @param callContext the Polaris call context * @param entityNameKey name of the entity to load * @return null if the entity does not exist or was dropped. Else return the entry for that * entity, either as found in the cache or loaded from the backend */ @Nullable EntityCacheLookupResult getOrLoadEntityByName( - @Nonnull PolarisCallContext callContext, @Nonnull EntityCacheByNameKey entityNameKey); + @Nonnull PolarisMetaStoreManager metaStoreManager, + @Nonnull EntityCacheByNameKey entityNameKey); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java index c30b996f14..28d5b3958c 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java @@ -27,7 +27,6 @@ import java.util.List; 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; @@ -43,19 +42,12 @@ public class InMemoryEntityCache implements EntityCache { private final PolarisDiagnostics diagnostics; - private final PolarisMetaStoreManager polarisMetaStoreManager; private final Cache byId; private final AbstractMap byName; - /** - * Constructor. Cache can be private or shared - * - * @param polarisMetaStoreManager the meta store manager implementation - */ + /** Constructor. Cache can be private or shared */ public InMemoryEntityCache( - @Nonnull PolarisDiagnostics diagnostics, - @Nonnull RealmConfig realmConfig, - @Nonnull PolarisMetaStoreManager polarisMetaStoreManager) { + @Nonnull PolarisDiagnostics diagnostics, @Nonnull RealmConfig realmConfig) { this.diagnostics = diagnostics; // by name cache @@ -89,9 +81,6 @@ public InMemoryEntityCache( // use a Caffeine cache to purge entries when those have not been used for a long time. this.byId = byIdBuilder.build(); - - // remember the meta store manager - this.polarisMetaStoreManager = polarisMetaStoreManager; } /** @@ -231,7 +220,6 @@ private boolean entityNameKeyMismatch( * Refresh the cache if needs be with a version of the entity/grant records matching the minimum * specified version. * - * @param callContext the Polaris call context * @param entityToValidate copy of the entity held by the caller to validate * @param entityMinVersion minimum expected version. Should be reloaded if found in a cache with a * version less than this one @@ -241,7 +229,7 @@ private boolean entityNameKeyMismatch( */ @Override public @Nullable ResolvedPolarisEntity getAndRefreshIfNeeded( - @Nonnull PolarisCallContext callContext, + @Nonnull PolarisMetaStoreManager metaStoreManager, @Nonnull PolarisBaseEntity entityToValidate, int entityMinVersion, int entityGrantRecordsMinVersion) { @@ -281,8 +269,7 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) { if (existingCacheEntry == null) { // try to load it refreshedCacheEntry = - this.polarisMetaStoreManager.loadResolvedEntityById( - callContext, entityCatalogId, entityId, entityType); + metaStoreManager.loadResolvedEntityById(entityCatalogId, entityId, entityType); if (refreshedCacheEntry.isSuccess()) { entity = refreshedCacheEntry.getEntity(); grantRecords = refreshedCacheEntry.getEntityGrantRecords(); @@ -293,8 +280,7 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) { } else { // refresh it refreshedCacheEntry = - this.polarisMetaStoreManager.refreshResolvedEntity( - callContext, + metaStoreManager.refreshResolvedEntity( existingCacheEntry.getEntity().getEntityVersion(), existingCacheEntry.getEntity().getGrantRecordsVersion(), entityType, @@ -341,7 +327,6 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) { /** * Get the specified entity by name and load it if it is not found. * - * @param callContext the Polaris call context * @param entityCatalogId id of the catalog where this entity resides or NULL_ID if top-level * @param entityId id of the entity to lookup * @return null if the entity does not exist or was dropped. Else return the entry for that @@ -349,7 +334,7 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) { */ @Override public @Nullable EntityCacheLookupResult getOrLoadEntityById( - @Nonnull PolarisCallContext callContext, + @Nonnull PolarisMetaStoreManager metaStoreManager, long entityCatalogId, long entityId, PolarisEntityType entityType) { @@ -365,8 +350,7 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) { // load it ResolvedEntityResult result = - polarisMetaStoreManager.loadResolvedEntityById( - callContext, entityCatalogId, entityId, entityType); + metaStoreManager.loadResolvedEntityById(entityCatalogId, entityId, entityType); // not found, exit if (!result.isSuccess()) { @@ -397,14 +381,14 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) { /** * Get the specified entity by name and load it if it is not found. * - * @param callContext the Polaris call context * @param entityNameKey name of the entity to load * @return null if the entity does not exist or was dropped. Else return the entry for that * entity, either as found in the cache or loaded from the backend */ @Override public @Nullable EntityCacheLookupResult getOrLoadEntityByName( - @Nonnull PolarisCallContext callContext, @Nonnull EntityCacheByNameKey entityNameKey) { + @Nonnull PolarisMetaStoreManager metaStoreManager, + @Nonnull EntityCacheByNameKey entityNameKey) { // if it exists, we are set ResolvedPolarisEntity entry = this.getEntityByName(entityNameKey); @@ -417,8 +401,7 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) { // load it ResolvedEntityResult result = - polarisMetaStoreManager.loadResolvedEntityByName( - callContext, + metaStoreManager.loadResolvedEntityByName( entityNameKey.getCatalogId(), entityNameKey.getParentId(), entityNameKey.getType(), diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/Resolver.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/Resolver.java index a4eaf3dfe6..b1451e5f6a 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/Resolver.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/Resolver.java @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.auth.PolarisPrincipal; import org.apache.polaris.core.entity.CatalogEntity; @@ -55,9 +54,6 @@ */ public class Resolver { - // we stash the Polaris call context here - private final @Nonnull PolarisCallContext polarisCallContext; - // the diagnostic services private final @Nonnull PolarisDiagnostics diagnostics; @@ -114,7 +110,6 @@ public class Resolver { /** * Constructor, effectively starts an entity resolver session * - * @param polarisCallContext the polaris call context * @param polarisMetaStoreManager meta store manager * @param securityContext The {@link SecurityContext} for the current request * @param cache shared entity cache @@ -128,12 +123,10 @@ public class Resolver { */ public Resolver( @Nonnull PolarisDiagnostics diagnostics, - @Nonnull PolarisCallContext polarisCallContext, @Nonnull PolarisMetaStoreManager polarisMetaStoreManager, @Nonnull SecurityContext securityContext, @Nullable EntityCache cache, @Nullable String referenceCatalogName) { - this.polarisCallContext = polarisCallContext; this.diagnostics = diagnostics; this.polarisMetaStoreManager = polarisMetaStoreManager; this.cache = cache; @@ -141,7 +134,6 @@ public Resolver( this.referenceCatalogName = referenceCatalogName; // validate inputs - this.diagnostics.checkNotNull(polarisCallContext, "unexpected_null_polarisCallContext"); this.diagnostics.checkNotNull( polarisMetaStoreManager, "unexpected_null_polarisMetaStoreManager"); this.diagnostics.checkNotNull(securityContext, "security_context_must_be_specified"); @@ -551,8 +543,7 @@ private boolean bulkValidate(List toValidate) { // now get the current backend versions of all these entities ChangeTrackingResult changeTrackingResult = - this.polarisMetaStoreManager.loadEntitiesChangeTracking( - this.polarisCallContext, entityIds); + this.polarisMetaStoreManager.loadEntitiesChangeTracking(entityIds); // refresh any entity which is not fresh. If an entity is missing, reload it Iterator entityIterator = toValidate.iterator(); @@ -583,14 +574,13 @@ private boolean bulkValidate(List toValidate) { if (this.cache != null) { refreshedResolvedEntity = this.cache.getAndRefreshIfNeeded( - this.polarisCallContext, + polarisMetaStoreManager, entity, versions.getEntityVersion(), versions.getGrantRecordsVersion()); } else { ResolvedEntityResult result = this.polarisMetaStoreManager.refreshResolvedEntity( - this.polarisCallContext, entity.getEntityVersion(), entity.getGrantRecordsVersion(), entity.getType(), @@ -985,7 +975,7 @@ private ResolvedPolarisEntity resolveByName( if (this.cache != null) { EntityCacheLookupResult lookupResult = this.cache.getOrLoadEntityByName( - this.polarisCallContext, + polarisMetaStoreManager, new EntityCacheByNameKey(catalogId, parentId, entityType, entityName)); // if not found @@ -1008,7 +998,7 @@ private ResolvedPolarisEntity resolveByName( // If no cache, load directly from metastore manager. ResolvedEntityResult result = this.polarisMetaStoreManager.loadResolvedEntityByName( - this.polarisCallContext, catalogId, parentId, entityType, entityName); + catalogId, parentId, entityType, entityName); if (!result.isSuccess()) { // not found return null; @@ -1043,7 +1033,7 @@ private ResolvedPolarisEntity resolveById( if (this.cache != null) { // get or load by name EntityCacheLookupResult lookupResult = - this.cache.getOrLoadEntityById(this.polarisCallContext, catalogId, entityId, entityType); + this.cache.getOrLoadEntityById(polarisMetaStoreManager, catalogId, entityId, entityType); // if not found, return null if (lookupResult == null) { @@ -1064,8 +1054,7 @@ private ResolvedPolarisEntity resolveById( } else { // If no cache, load directly from metastore manager. ResolvedEntityResult result = - polarisMetaStoreManager.loadResolvedEntityById( - this.polarisCallContext, catalogId, entityId, entityType); + polarisMetaStoreManager.loadResolvedEntityById(catalogId, entityId, entityType); if (!result.isSuccess()) { // not found return null; diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/AbstractTransactionalPersistence.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/AbstractTransactionalPersistence.java index 848a8421e5..9fde25c809 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/AbstractTransactionalPersistence.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/AbstractTransactionalPersistence.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.function.Function; import java.util.function.Predicate; -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.PolarisBaseEntity; @@ -72,73 +71,62 @@ protected PolarisDiagnostics getDiagnostics() { /** * Lookup an entity by entityActiveKey * - * @param callCtx call context * @param entityActiveKey key by name * @return null if the specified entity does not exist or has been dropped. */ @Nullable protected abstract EntityNameLookupRecord lookupEntityActiveInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntitiesActiveKey entityActiveKey); + @Nonnull PolarisEntitiesActiveKey entityActiveKey); /** * Write the base entity to the entities table. If there is a conflict (existing record with the * same id), all attributes of the new record will replace the existing one. * - * @param callCtx call context * @param entity entity record to write, potentially replacing an existing entity record with the * same key */ - protected abstract void writeToEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity); + protected abstract void writeToEntitiesInCurrentTxn(@Nonnull PolarisBaseEntity entity); /** * Write the base entity to the entities_active table. If there is a conflict (existing record * with the same PK), all attributes of the new record will replace the existing one. * - * @param callCtx call context * @param entity entity record to write, potentially replacing an existing entity record with the * same key */ - protected abstract void writeToEntitiesActiveInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity); + protected abstract void writeToEntitiesActiveInCurrentTxn(@Nonnull PolarisBaseEntity entity); /** * Write the base entity to the entities change tracking table. If there is a conflict (existing * record with the same id), all attributes of the new record will replace the existing one. * - * @param callCtx call context * @param entity entity record to write, potentially replacing an existing entity record with the * same key */ protected abstract void writeToEntitiesChangeTrackingInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity); + @Nonnull PolarisBaseEntity entity); /** * Delete the base entity from the entities table. * - * @param callCtx call context * @param entity entity record to delete */ - protected abstract void deleteFromEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity); + protected abstract void deleteFromEntitiesInCurrentTxn(@Nonnull PolarisEntityCore entity); /** * Delete the base entity from the entities_active table. * - * @param callCtx call context * @param entity entity record to delete */ - protected abstract void deleteFromEntitiesActiveInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity); + protected abstract void deleteFromEntitiesActiveInCurrentTxn(@Nonnull PolarisEntityCore entity); /** * Delete the base entity from the entities change tracking table * - * @param callCtx call context * @param entity entity record to delete */ protected abstract void deleteFromEntitiesChangeTrackingInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity); + @Nonnull PolarisEntityCore entity); // // Implementations of the one-shot atomic BasePersistence methods which explicitly run @@ -147,18 +135,15 @@ protected abstract void deleteFromEntitiesChangeTrackingInCurrentTxn( /** {@inheritDoc} */ @Override - public long generateNewId(@Nonnull PolarisCallContext callCtx) { - return runInTransaction(callCtx, () -> this.generateNewIdInCurrentTxn(callCtx)); + public long generateNewId() { + return runInTransaction(this::generateNewIdInCurrentTxn); } /** Helper to perform the compare-and-swap semantics of a single writeEntity call. */ private void checkConditionsForWriteEntityInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - @Nonnull PolarisBaseEntity entity, - @Nullable PolarisBaseEntity originalEntity) { + @Nonnull PolarisBaseEntity entity, @Nullable PolarisBaseEntity originalEntity) { PolarisBaseEntity refreshedEntity = - this.lookupEntityInCurrentTxn( - callCtx, entity.getCatalogId(), entity.getId(), entity.getTypeCode()); + this.lookupEntityInCurrentTxn(entity.getCatalogId(), entity.getId(), entity.getTypeCode()); if (originalEntity == null) { if (refreshedEntity != null) { @@ -172,7 +157,6 @@ private void checkConditionsForWriteEntityInCurrentTxn( // we must also check for name-collection now. refreshedEntity = this.lookupEntityByNameInCurrentTxn( - callCtx, entity.getCatalogId(), entity.getParentId(), entity.getType().getCode(), @@ -204,22 +188,19 @@ private void checkConditionsForWriteEntityInCurrentTxn( /** {@inheritDoc} */ @Override public void writeEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, boolean nameOrParentChanged, @Nullable PolarisBaseEntity originalEntity) { runActionInTransaction( - callCtx, () -> { - this.checkConditionsForWriteEntityInCurrentTxn(callCtx, entity, originalEntity); - this.writeEntityInCurrentTxn(callCtx, entity, nameOrParentChanged, originalEntity); + this.checkConditionsForWriteEntityInCurrentTxn(entity, originalEntity); + this.writeEntityInCurrentTxn(entity, nameOrParentChanged, originalEntity); }); } /** {@inheritDoc} */ @Override public void writeEntities( - @Nonnull PolarisCallContext callCtx, @Nonnull List entities, @Nullable List originalEntities) { if (originalEntities != null) { @@ -232,7 +213,6 @@ public void writeEntities( originalEntities.size()); } runActionInTransaction( - callCtx, () -> { // Validate and write each one independently so that we can also detect conflicting // writes to the same entity id within a given batch (so that previously written @@ -252,7 +232,7 @@ public void writeEntities( || !entity.getName().equals(originalEntity.getName()) || entity.getParentId() != originalEntity.getParentId(); try { - this.checkConditionsForWriteEntityInCurrentTxn(callCtx, entity, originalEntity); + this.checkConditionsForWriteEntityInCurrentTxn(entity, originalEntity); } catch (EntityAlreadyExistsException e) { // If the ids are equal then it is an idempotent-create-retry error, which counts // as a "success" for multi-entity commit purposes; name-collisions on different @@ -262,16 +242,15 @@ public void writeEntities( } // Else silently swallow the apparent create-retry } - this.writeEntityInCurrentTxn(callCtx, entity, nameOrParentChanged, originalEntity); + this.writeEntityInCurrentTxn(entity, nameOrParentChanged, originalEntity); } }); } /** {@inheritDoc} */ @Override - public void writeToGrantRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec) { - runActionInTransaction(callCtx, () -> this.writeToGrantRecordsInCurrentTxn(callCtx, grantRec)); + public void writeToGrantRecords(@Nonnull PolarisGrantRecord grantRec) { + runActionInTransaction(() -> this.writeToGrantRecordsInCurrentTxn(grantRec)); } @Override @@ -281,116 +260,92 @@ public void writeEvents(@Nonnull List events) { /** {@inheritDoc} */ @Override - public void deleteEntity(@Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { - runActionInTransaction(callCtx, () -> this.deleteEntityInCurrentTxn(callCtx, entity)); + public void deleteEntity(@Nonnull PolarisBaseEntity entity) { + runActionInTransaction(() -> this.deleteEntityInCurrentTxn(entity)); } /** {@inheritDoc} */ @Override - public void deleteFromGrantRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec) { - runActionInTransaction( - callCtx, () -> this.deleteFromGrantRecordsInCurrentTxn(callCtx, grantRec)); + public void deleteFromGrantRecords(@Nonnull PolarisGrantRecord grantRec) { + runActionInTransaction(() -> this.deleteFromGrantRecordsInCurrentTxn(grantRec)); } /** {@inheritDoc} */ @Override public void deleteAllEntityGrantRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity, @Nonnull List grantsOnGrantee, @Nonnull List grantsOnSecurable) { runActionInTransaction( - callCtx, () -> this.deleteAllEntityGrantRecordsInCurrentTxn( - callCtx, entity, grantsOnGrantee, grantsOnSecurable)); + entity, grantsOnGrantee, grantsOnSecurable)); } /** {@inheritDoc} */ @Override - public void deleteAll(@Nonnull PolarisCallContext callCtx) { - runActionInTransaction(callCtx, () -> this.deleteAllInCurrentTxn(callCtx)); + public void deleteAll() { + runActionInTransaction(this::deleteAllInCurrentTxn); } /** {@inheritDoc} */ @Override @Nullable - public PolarisBaseEntity lookupEntity( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, int typeCode) { - return runInReadTransaction( - callCtx, () -> this.lookupEntityInCurrentTxn(callCtx, catalogId, entityId, typeCode)); + public PolarisBaseEntity lookupEntity(long catalogId, long entityId, int typeCode) { + return runInReadTransaction(() -> this.lookupEntityInCurrentTxn(catalogId, entityId, typeCode)); } /** {@inheritDoc} */ @Override @Nullable public PolarisBaseEntity lookupEntityByName( - @Nonnull PolarisCallContext callCtx, - long catalogId, - long parentId, - int typeCode, - @Nonnull String name) { + long catalogId, long parentId, int typeCode, @Nonnull String name) { return runInReadTransaction( - callCtx, - () -> this.lookupEntityByNameInCurrentTxn(callCtx, catalogId, parentId, typeCode, name)); + () -> this.lookupEntityByNameInCurrentTxn(catalogId, parentId, typeCode, name)); } /** {@inheritDoc} */ @Override @Nullable public EntityNameLookupRecord lookupEntityIdAndSubTypeByName( - @Nonnull PolarisCallContext callCtx, - long catalogId, - long parentId, - int typeCode, - @Nonnull String name) { + long catalogId, long parentId, int typeCode, @Nonnull String name) { return runInReadTransaction( - callCtx, - () -> - this.lookupEntityIdAndSubTypeByNameInCurrentTxn( - callCtx, catalogId, parentId, typeCode, name)); + () -> this.lookupEntityIdAndSubTypeByNameInCurrentTxn(catalogId, parentId, typeCode, name)); } /** {@inheritDoc} */ @Override @Nonnull - public List lookupEntities( - @Nonnull PolarisCallContext callCtx, List entityIds) { - return runInReadTransaction(callCtx, () -> this.lookupEntitiesInCurrentTxn(callCtx, entityIds)); + public List lookupEntities(List entityIds) { + return runInReadTransaction(() -> this.lookupEntitiesInCurrentTxn(entityIds)); } /** {@inheritDoc} */ @Override @Nonnull - public List lookupEntityVersions( - @Nonnull PolarisCallContext callCtx, List entityIds) { - return runInReadTransaction( - callCtx, () -> this.lookupEntityVersionsInCurrentTxn(callCtx, entityIds)); + public List lookupEntityVersions(List entityIds) { + return runInReadTransaction(() -> this.lookupEntityVersionsInCurrentTxn(entityIds)); } /** {@inheritDoc} */ @Override @Nonnull public Page listEntities( - @Nonnull PolarisCallContext callCtx, long catalogId, long parentId, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull PageToken pageToken) { return runInReadTransaction( - callCtx, () -> this.listEntitiesInCurrentTxn( - callCtx, catalogId, parentId, entityType, entitySubType, pageToken)); + catalogId, parentId, entityType, entitySubType, pageToken)); } /** {@inheritDoc} */ @Override @Nonnull public Page loadEntities( - @Nonnull PolarisCallContext callCtx, long catalogId, long parentId, @Nonnull PolarisEntityType entityType, @@ -399,10 +354,8 @@ public Page loadEntities( @Nonnull Function transformer, @Nonnull PageToken pageToken) { return runInReadTransaction( - callCtx, () -> this.loadEntitiesInCurrentTxn( - callCtx, catalogId, parentId, entityType, @@ -414,67 +367,50 @@ public Page loadEntities( /** {@inheritDoc} */ @Override - public int lookupEntityGrantRecordsVersion( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId) { + public int lookupEntityGrantRecordsVersion(long catalogId, long entityId) { return runInReadTransaction( - callCtx, - () -> this.lookupEntityGrantRecordsVersionInCurrentTxn(callCtx, catalogId, entityId)); + () -> this.lookupEntityGrantRecordsVersionInCurrentTxn(catalogId, entityId)); } /** {@inheritDoc} */ @Override @Nullable public PolarisGrantRecord lookupGrantRecord( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId, long granteeCatalogId, long granteeId, int privilegeCode) { return runInReadTransaction( - callCtx, () -> this.lookupGrantRecordInCurrentTxn( - callCtx, - securableCatalogId, - securableId, - granteeCatalogId, - granteeId, - privilegeCode)); + securableCatalogId, securableId, granteeCatalogId, granteeId, privilegeCode)); } /** {@inheritDoc} */ @Override @Nonnull public List loadAllGrantRecordsOnSecurable( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId) { + long securableCatalogId, long securableId) { return runInReadTransaction( - callCtx, - () -> - this.loadAllGrantRecordsOnSecurableInCurrentTxn( - callCtx, securableCatalogId, securableId)); + () -> this.loadAllGrantRecordsOnSecurableInCurrentTxn(securableCatalogId, securableId)); } /** {@inheritDoc} */ @Override @Nonnull public List loadAllGrantRecordsOnGrantee( - @Nonnull PolarisCallContext callCtx, long granteeCatalogId, long granteeId) { + long granteeCatalogId, long granteeId) { return runInReadTransaction( - callCtx, - () -> this.loadAllGrantRecordsOnGranteeInCurrentTxn(callCtx, granteeCatalogId, granteeId)); + () -> this.loadAllGrantRecordsOnGranteeInCurrentTxn(granteeCatalogId, granteeId)); } /** {@inheritDoc} */ @Override public boolean hasChildren( - @Nonnull PolarisCallContext callCtx, - @Nullable PolarisEntityType optionalEntityType, - long catalogId, - long parentId) { + @Nullable PolarisEntityType optionalEntityType, long catalogId, long parentId) { return runInReadTransaction( - callCtx, - () -> this.hasChildrenInCurrentTxn(callCtx, optionalEntityType, catalogId, parentId)); + () -> this.hasChildrenInCurrentTxn(optionalEntityType, catalogId, parentId)); } // @@ -485,44 +421,32 @@ public boolean hasChildren( /** {@inheritDoc} */ @Override @Nullable - public PolarisPrincipalSecrets loadPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId) { - return runInReadTransaction( - callCtx, () -> this.loadPrincipalSecretsInCurrentTxn(callCtx, clientId)); + public PolarisPrincipalSecrets loadPrincipalSecrets(@Nonnull String clientId) { + return runInReadTransaction(() -> this.loadPrincipalSecretsInCurrentTxn(clientId)); } /** {@inheritDoc} */ @Override @Nonnull public PolarisPrincipalSecrets generateNewPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String principalName, long principalId) { + @Nonnull String principalName, long principalId) { return runInTransaction( - callCtx, - () -> this.generateNewPrincipalSecretsInCurrentTxn(callCtx, principalName, principalId)); + () -> this.generateNewPrincipalSecretsInCurrentTxn(principalName, principalId)); } /** {@inheritDoc} */ @Override @Nullable public PolarisPrincipalSecrets rotatePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - @Nonnull String clientId, - long principalId, - boolean reset, - @Nonnull String oldSecretHash) { + @Nonnull String clientId, long principalId, boolean reset, @Nonnull String oldSecretHash) { return runInTransaction( - callCtx, - () -> - this.rotatePrincipalSecretsInCurrentTxn( - callCtx, clientId, principalId, reset, oldSecretHash)); + () -> this.rotatePrincipalSecretsInCurrentTxn(clientId, principalId, reset, oldSecretHash)); } /** {@inheritDoc} */ @Override - public void deletePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId, long principalId) { - runActionInTransaction( - callCtx, () -> this.deletePrincipalSecretsInCurrentTxn(callCtx, clientId, principalId)); + public void deletePrincipalSecrets(@Nonnull String clientId, long principalId) { + runActionInTransaction(() -> this.deletePrincipalSecretsInCurrentTxn(clientId, principalId)); } /** {@inheritDoc} */ @@ -530,28 +454,22 @@ public void deletePrincipalSecrets( @Nullable public PolarisStorageIntegration createStorageIntegration( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, PolarisStorageConfigurationInfo polarisStorageConfigurationInfo) { return runInTransaction( - callCtx, () -> this.createStorageIntegrationInCurrentTxn( - callCtx, catalogId, entityId, polarisStorageConfigurationInfo)); + catalogId, entityId, polarisStorageConfigurationInfo)); } /** {@inheritDoc} */ @Override public void persistStorageIntegrationIfNeeded( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, @Nullable PolarisStorageIntegration storageIntegration) { runActionInTransaction( - callCtx, - () -> - this.persistStorageIntegrationIfNeededInCurrentTxn( - callCtx, entity, storageIntegration)); + () -> this.persistStorageIntegrationIfNeededInCurrentTxn(entity, storageIntegration)); } /** {@inheritDoc} */ @@ -559,9 +477,8 @@ public void persistStorageIntegratio @Nullable public PolarisStorageIntegration loadPolarisStorageIntegration( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { - return runInReadTransaction( - callCtx, () -> this.loadPolarisStorageIntegrationInCurrentTxn(callCtx, entity)); + @Nonnull PolarisBaseEntity entity) { + return runInReadTransaction(() -> this.loadPolarisStorageIntegrationInCurrentTxn(entity)); } // @@ -572,28 +489,26 @@ PolarisStorageIntegration loadPolarisStorageIntegration( /** {@inheritDoc} */ @Override public void writeEntityInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, boolean nameOrParentChanged, @Nullable PolarisBaseEntity originalEntity) { - this.writeToEntitiesInCurrentTxn(callCtx, entity); - this.writeToEntitiesChangeTrackingInCurrentTxn(callCtx, entity); + this.writeToEntitiesInCurrentTxn(entity); + this.writeToEntitiesChangeTrackingInCurrentTxn(entity); if (nameOrParentChanged) { if (originalEntity != null) { // In our case, rename isn't automatically handled when the main "entities" slice // is updated; instead we must explicitly remove from the old entitiesActive // key as well. - this.deleteFromEntitiesActiveInCurrentTxn(callCtx, originalEntity); + this.deleteFromEntitiesActiveInCurrentTxn(originalEntity); } - this.writeToEntitiesActiveInCurrentTxn(callCtx, entity); + this.writeToEntitiesActiveInCurrentTxn(entity); } } /** {@inheritDoc} */ @Override public void writeEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull List entities, @Nullable List originalEntities) { if (originalEntities != null) { @@ -618,34 +533,29 @@ public void writeEntitiesInCurrentTxn( originalEntity == null || !entity.getName().equals(originalEntity.getName()) || entity.getParentId() != originalEntity.getParentId(); - this.writeEntityInCurrentTxn(callCtx, entity, nameOrParentChanged, originalEntity); + this.writeEntityInCurrentTxn(entity, nameOrParentChanged, originalEntity); } } /** {@inheritDoc} */ @Override - public void deleteEntityInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { - this.deleteFromEntitiesActiveInCurrentTxn(callCtx, entity); - this.deleteFromEntitiesInCurrentTxn(callCtx, entity); - this.deleteFromEntitiesChangeTrackingInCurrentTxn(callCtx, entity); + public void deleteEntityInCurrentTxn(@Nonnull PolarisBaseEntity entity) { + this.deleteFromEntitiesActiveInCurrentTxn(entity); + this.deleteFromEntitiesInCurrentTxn(entity); + this.deleteFromEntitiesChangeTrackingInCurrentTxn(entity); } /** {@inheritDoc} */ @Override @Nullable public PolarisBaseEntity lookupEntityByNameInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - long catalogId, - long parentId, - int typeCode, - @Nonnull String name) { + long catalogId, long parentId, int typeCode, @Nonnull String name) { PolarisEntitiesActiveKey entityActiveKey = new PolarisEntitiesActiveKey(catalogId, parentId, typeCode, name); // ensure that the entity exists EntityNameLookupRecord entityActiveRecord = - this.lookupEntityActiveInCurrentTxn(callCtx, entityActiveKey); + this.lookupEntityActiveInCurrentTxn(entityActiveKey); // if not found, return null if (entityActiveRecord == null) { @@ -655,7 +565,6 @@ public PolarisBaseEntity lookupEntityByNameInCurrentTxn( // lookup the entity, should be there PolarisBaseEntity entity = this.lookupEntityInCurrentTxn( - callCtx, entityActiveRecord.getCatalogId(), entityActiveRecord.getId(), entityActiveRecord.getTypeCode()); @@ -671,32 +580,26 @@ public PolarisBaseEntity lookupEntityByNameInCurrentTxn( @Override @Nullable public EntityNameLookupRecord lookupEntityIdAndSubTypeByNameInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - long catalogId, - long parentId, - int typeCode, - @Nonnull String name) { + long catalogId, long parentId, int typeCode, @Nonnull String name) { PolarisEntitiesActiveKey entityActiveKey = new PolarisEntitiesActiveKey(catalogId, parentId, typeCode, name); - return this.lookupEntityActiveInCurrentTxn(callCtx, entityActiveKey); + return this.lookupEntityActiveInCurrentTxn(entityActiveKey); } /** {@inheritDoc} */ @Override - public void writeToPolicyMappingRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + public void writeToPolicyMappingRecords(@Nonnull PolarisPolicyMappingRecord record) { this.runActionInTransaction( - callCtx, () -> { - this.checkConditionsForWriteToPolicyMappingRecordsInCurrentTxn(callCtx, record); - this.writeToPolicyMappingRecordsInCurrentTxn(callCtx, record); + this.checkConditionsForWriteToPolicyMappingRecordsInCurrentTxn(record); + this.writeToPolicyMappingRecordsInCurrentTxn(record); }); } /** {@inheritDoc} */ @Override public void checkConditionsForWriteToPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + @Nonnull PolarisPolicyMappingRecord record) { PolicyType policyType = PolicyType.fromCode(record.getPolicyTypeCode()); Preconditions.checkArgument( @@ -708,7 +611,7 @@ public void checkConditionsForWriteToPolicyMappingRecordsInCurrentTxn( List existingRecords = this.loadPoliciesOnTargetByTypeInCurrentTxn( - callCtx, record.getTargetCatalogId(), record.getTargetId(), record.getPolicyTypeCode()); + record.getTargetCatalogId(), record.getTargetId(), record.getPolicyTypeCode()); if (existingRecords.size() > 1) { throw new PolicyMappingAlreadyExistsException(existingRecords.get(0)); } else if (existingRecords.size() == 1) { @@ -722,80 +625,62 @@ public void checkConditionsForWriteToPolicyMappingRecordsInCurrentTxn( /** {@inheritDoc} */ @Override - public void deleteFromPolicyMappingRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { - this.runActionInTransaction( - callCtx, () -> this.deleteFromPolicyMappingRecordsInCurrentTxn(callCtx, record)); + public void deleteFromPolicyMappingRecords(@Nonnull PolarisPolicyMappingRecord record) { + this.runActionInTransaction(() -> this.deleteFromPolicyMappingRecordsInCurrentTxn(record)); } /** {@inheritDoc} */ @Override public void deleteAllEntityPolicyMappingRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, @Nonnull List mappingOnTarget, @Nonnull List mappingOnPolicy) { this.runActionInTransaction( - callCtx, () -> this.deleteAllEntityPolicyMappingRecordsInCurrentTxn( - callCtx, entity, mappingOnTarget, mappingOnPolicy)); + entity, mappingOnTarget, mappingOnPolicy)); } /** {@inheritDoc} */ @Override @Nullable public PolarisPolicyMappingRecord lookupPolicyMappingRecord( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId, int policyTypeCode, long policyCatalogId, long policyId) { return this.runInReadTransaction( - callCtx, () -> this.lookupPolicyMappingRecordInCurrentTxn( - callCtx, targetCatalogId, targetId, policyTypeCode, policyCatalogId, policyId)); + targetCatalogId, targetId, policyTypeCode, policyCatalogId, policyId)); } /** {@inheritDoc} */ @Override @Nonnull public List loadPoliciesOnTargetByType( - @Nonnull PolarisCallContext callCtx, - long targetCatalogId, - long targetId, - int policyTypeCode) { + long targetCatalogId, long targetId, int policyTypeCode) { return this.runInReadTransaction( - callCtx, () -> - this.loadPoliciesOnTargetByTypeInCurrentTxn( - callCtx, targetCatalogId, targetId, policyTypeCode)); + this.loadPoliciesOnTargetByTypeInCurrentTxn(targetCatalogId, targetId, policyTypeCode)); } /** {@inheritDoc} */ @Override @Nonnull public List loadAllPoliciesOnTarget( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId) { + long targetCatalogId, long targetId) { return this.runInReadTransaction( - callCtx, - () -> this.loadAllPoliciesOnTargetInCurrentTxn(callCtx, targetCatalogId, targetId)); + () -> this.loadAllPoliciesOnTargetInCurrentTxn(targetCatalogId, targetId)); } /** {@inheritDoc} */ @Override @Nonnull public List loadAllTargetsOnPolicy( - @Nonnull PolarisCallContext callCtx, - long policyCatalogId, - long policyId, - int policyTypeCode) { + long policyCatalogId, long policyId, int policyTypeCode) { return this.runInReadTransaction( - callCtx, - () -> - this.loadAllTargetsOnPolicyInCurrentTxn( - callCtx, policyCatalogId, policyId, policyTypeCode)); + () -> this.loadAllTargetsOnPolicyInCurrentTxn(policyCatalogId, policyId, policyTypeCode)); } } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/PolarisEntityResolver.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/PolarisEntityResolver.java index de37e2fe6b..df8cb9d7b7 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/PolarisEntityResolver.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/PolarisEntityResolver.java @@ -24,7 +24,6 @@ import java.util.Iterator; import java.util.List; 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.PolarisBaseEntity; @@ -67,7 +66,6 @@ public class PolarisEntityResolver { *

The resolver will ensure that none of the entities which are passed in have been dropped or * were renamed or moved. * - * @param callCtx call context * @param ms meta store in read mode * @param catalogPath path within the catalog. The first element MUST be a catalog entity. * @param resolvedEntity optional entity to resolve under that catalog path. If a non-null value @@ -78,7 +76,6 @@ public class PolarisEntityResolver { */ PolarisEntityResolver( @Nonnull PolarisDiagnostics diagnostics, - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, @Nullable PolarisEntityCore resolvedEntity, @@ -123,8 +120,7 @@ public class PolarisEntityResolver { // call the resolution logic this.isSuccess = - this.resolveEntitiesIfNeeded( - callCtx, ms, catalogPath, resolvedEntity, otherTopLevelEntities); + this.resolveEntitiesIfNeeded(ms, catalogPath, resolvedEntity, otherTopLevelEntities); // process result if (!this.isSuccess) { @@ -143,23 +139,20 @@ public class PolarisEntityResolver { /** * Constructor for the resolver, when we only need to resolve a path * - * @param callCtx call context * @param ms meta store in read mode * @param catalogPath input path, can be null or empty list if the entity is a top-level entity * like a catalog. */ PolarisEntityResolver( @Nonnull PolarisDiagnostics diagnostics, - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath) { - this(diagnostics, callCtx, ms, catalogPath, null, null); + this(diagnostics, ms, catalogPath, null, null); } /** * Constructor for the resolver, when we only need to resolve a path * - * @param callCtx call context * @param ms meta store in read mode * @param catalogPath input path, can be null or empty list if the entity is a top-level entity * like a catalog. @@ -167,17 +160,15 @@ public class PolarisEntityResolver { */ PolarisEntityResolver( @Nonnull PolarisDiagnostics diagnostics, - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, PolarisEntityCore resolvedEntityDto) { - this(diagnostics, callCtx, ms, catalogPath, resolvedEntityDto, null); + this(diagnostics, ms, catalogPath, resolvedEntityDto, null); } /** * Constructor for the resolver, when we only need to resolve a path * - * @param callCtx call context * @param ms meta store in read mode * @param catalogPath input path, can be null or empty list if the entity is a top-level entity * like a catalog. @@ -185,17 +176,10 @@ public class PolarisEntityResolver { */ PolarisEntityResolver( @Nonnull PolarisDiagnostics diagnostics, - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity) { - this( - diagnostics, - callCtx, - ms, - catalogPath, - new PolarisEntityCore.Builder<>(entity).build(), - null); + this(diagnostics, ms, catalogPath, new PolarisEntityCore.Builder<>(entity).build(), null); } /** @@ -227,7 +211,6 @@ long getCatalogIdOrNull() { /** * Ensure all specified entities are still active, have not been renamed or re-parented. * - * @param callCtx call context * @param ms meta store in read mode * @param catalogPath path within the catalog. The first element MUST be a catalog. Null or empty * for top-level entities like catalog @@ -240,7 +223,6 @@ long getCatalogIdOrNull() { * @return true if all entities have been resolved successfully */ private boolean resolveEntitiesIfNeeded( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, @Nullable PolarisEntityCore resolvedEntity, @@ -285,7 +267,7 @@ private boolean resolveEntitiesIfNeeded( // now lookup all these entities by name Iterator activeRecordIt = - ms.lookupEntityActiveBatchInCurrentTxn(callCtx, entityActiveKeys).iterator(); + ms.lookupEntityActiveBatchInCurrentTxn(entityActiveKeys).iterator(); // now validate if there was a change and if yes, re-resolve again for (PolarisEntityCore resolveEntity : toResolve) { diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java index 402cdc280e..b0d7477f9b 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalMetaStoreManagerImpl.java @@ -18,6 +18,7 @@ */ package org.apache.polaris.core.persistence.transactional; +import com.google.common.base.Suppliers; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import java.time.Clock; @@ -30,10 +31,12 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Collectors; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.config.FeatureConfiguration; +import org.apache.polaris.core.config.RealmConfig; +import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.EntityNameLookupRecord; @@ -89,15 +92,28 @@ * Default implementation of the Polaris Meta Store Manager. Uses the underlying meta store to store * and retrieve all Polaris metadata */ -public class TransactionalMetaStoreManagerImpl extends BaseMetaStoreManager { +public class TransactionalMetaStoreManagerImpl + extends BaseMetaStoreManager { private static final Logger LOGGER = LoggerFactory.getLogger(TransactionalMetaStoreManagerImpl.class); private final Clock clock; - - public TransactionalMetaStoreManagerImpl(Clock clock, PolarisDiagnostics diagnostics) { - super(diagnostics); + private final Supplier metaStoreSupplier; + + public TransactionalMetaStoreManagerImpl( + Clock clock, + PolarisDiagnostics diagnostics, + RealmContext realmContext, + RealmConfig realmConfig, + Supplier metaStoreSupplier) { + super(diagnostics, realmContext, realmConfig); this.clock = clock; + this.metaStoreSupplier = Suppliers.memoize(metaStoreSupplier::get); + } + + @Override + protected TransactionalPersistence getMetaStore() { + return metaStoreSupplier.get(); } /** @@ -106,19 +122,16 @@ public TransactionalMetaStoreManagerImpl(Clock clock, PolarisDiagnostics diagnos * runInTransaction, and calls through to analogous versions of * methods of * TransactionalPersistence. * - * @param callCtx call context * @param ms meta store in read/write mode * @param entity entity we need a new persisted record for */ protected void persistNewEntity( - @Nonnull PolarisCallContext callCtx, - @Nonnull TransactionalPersistence ms, - @Nonnull PolarisBaseEntity entity) { + @Nonnull TransactionalPersistence ms, @Nonnull PolarisBaseEntity entity) { // Invoke shared logic for validation and filling out remaining fields. - entity = prepareToPersistNewEntity(callCtx, ms, entity); + entity = prepareToPersistNewEntity(entity); // write it - ms.writeEntityInCurrentTxn(callCtx, entity, true, null); + ms.writeEntityInCurrentTxn(entity, true, null); } /** @@ -127,7 +140,6 @@ protected void persistNewEntity( * runInTransaction, and calls through to analogous versions of * methods of * TransactionalPersistence. * - * @param callCtx call context * @param ms meta store * @param entity the entity which has been changed * @param nameOrParentChanged indicates if parent or name changed @@ -135,18 +147,16 @@ protected void persistNewEntity( * @return the entity with its version and lastUpdateTimestamp updated */ private @Nonnull PolarisBaseEntity persistEntityAfterChange( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull PolarisBaseEntity entity, boolean nameOrParentChanged, @Nonnull PolarisBaseEntity originalEntity) { // Invoke shared logic for validation and updating expected fields. - entity = - prepareToPersistEntityAfterChange(callCtx, ms, entity, nameOrParentChanged, originalEntity); + entity = prepareToPersistEntityAfterChange(ms, entity, nameOrParentChanged, originalEntity); // Use the write method defined in TransactionalPersistence which expects an // existing runInTransaction to already be in-place. - ms.writeEntityInCurrentTxn(callCtx, entity, nameOrParentChanged, originalEntity); + ms.writeEntityInCurrentTxn(entity, nameOrParentChanged, originalEntity); // return it return entity; @@ -162,14 +172,10 @@ protected void persistNewEntity( * - we will fully delete the entity from persistence store * * - * @param callCtx call context * @param ms meta store * @param entity the entity being dropped */ - private void dropEntity( - @Nonnull PolarisCallContext callCtx, - @Nonnull TransactionalPersistence ms, - @Nonnull PolarisBaseEntity entity) { + private void dropEntity(@Nonnull TransactionalPersistence ms, @Nonnull PolarisBaseEntity entity) { // validate the entity type and subtype getDiagnostics().checkNotNull(entity, "unexpected_null_dpo"); @@ -182,13 +188,11 @@ private void dropEntity( // delete ALL grant records to (if the entity is a grantee) and from that entity final List grantsOnGrantee = (entity.getType().isGrantee()) - ? ms.loadAllGrantRecordsOnGranteeInCurrentTxn( - callCtx, entity.getCatalogId(), entity.getId()) + ? ms.loadAllGrantRecordsOnGranteeInCurrentTxn(entity.getCatalogId(), entity.getId()) : List.of(); final List grantsOnSecurable = - ms.loadAllGrantRecordsOnSecurableInCurrentTxn( - callCtx, entity.getCatalogId(), entity.getId()); - ms.deleteAllEntityGrantRecordsInCurrentTxn(callCtx, entity, grantsOnGrantee, grantsOnSecurable); + ms.loadAllGrantRecordsOnSecurableInCurrentTxn(entity.getCatalogId(), entity.getId()); + ms.deleteAllEntityGrantRecordsInCurrentTxn(entity, grantsOnGrantee, grantsOnSecurable); // Now determine the set of entities on the other side of the grants we just removed. Grants // from/to these entities has been removed, hence we need to update the grant version of @@ -205,11 +209,11 @@ private void dropEntity( // Bump up the grant version of these entities List entities = - ms.lookupEntitiesInCurrentTxn(callCtx, new ArrayList<>(entityIdsGrantChanged)); + ms.lookupEntitiesInCurrentTxn(new ArrayList<>(entityIdsGrantChanged)); for (PolarisBaseEntity originalEntity : entities) { PolarisBaseEntity entityGrantChanged = originalEntity.withGrantRecordsVersion(originalEntity.getGrantRecordsVersion() + 1); - ms.writeEntityInCurrentTxn(callCtx, entityGrantChanged, false, originalEntity); + ms.writeEntityInCurrentTxn(entityGrantChanged, false, originalEntity); } if (entity.getType() == PolarisEntityType.POLICY @@ -220,7 +224,6 @@ private void dropEntity( final List mappingOnPolicy = (entity.getType() == PolarisEntityType.POLICY) ? ms.loadAllTargetsOnPolicyInCurrentTxn( - callCtx, entity.getCatalogId(), entity.getId(), PolicyEntity.of(entity).getPolicyTypeCode()) @@ -228,24 +231,23 @@ private void dropEntity( final List mappingOnTarget = (entity.getType() == PolarisEntityType.POLICY) ? List.of() - : ms.loadAllPoliciesOnTargetInCurrentTxn( - callCtx, entity.getCatalogId(), entity.getId()); + : ms.loadAllPoliciesOnTargetInCurrentTxn(entity.getCatalogId(), entity.getId()); ms.deleteAllEntityPolicyMappingRecordsInCurrentTxn( - callCtx, entity, mappingOnTarget, mappingOnPolicy); + entity, mappingOnTarget, mappingOnPolicy); } catch (UnsupportedOperationException e) { // Policy mapping persistence not implemented, but we should not block dropping entities } } // remove the entity being dropped now - ms.deleteEntityInCurrentTxn(callCtx, entity); + ms.deleteEntityInCurrentTxn(entity); // if it is a principal, we also need to drop the secrets if (entity.getType() == PolarisEntityType.PRINCIPAL) { PrincipalEntity principalEntity = PrincipalEntity.of(entity); String clientId = principalEntity.getClientId(); // delete it from the secret slice - ms.deletePrincipalSecretsInCurrentTxn(callCtx, clientId, entity.getId()); + ms.deletePrincipalSecretsInCurrentTxn(clientId, entity.getId()); } // TODO: Also, if an entity contains a storage integration, delete the storage integration // and other things of that nature. @@ -255,7 +257,6 @@ private void dropEntity( * Create and persist a new grant record. This will at the same time invalidate the grant records * of the grantee and the securable if the grantee is a catalog role * - * @param callCtx call context * @param ms meta store in read/write mode * @param securable securable * @param grantee grantee, either a catalog role, a principal role or a principal @@ -263,7 +264,6 @@ private void dropEntity( * @return new grant record which was created and persisted */ private @Nonnull PolarisGrantRecord persistNewGrantRecord( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull PolarisEntityCore securable, @Nonnull PolarisEntityCore grantee, @@ -288,24 +288,23 @@ private void dropEntity( priv.getCode()); // persist the new grant - ms.writeToGrantRecordsInCurrentTxn(callCtx, grantRecord); + ms.writeToGrantRecordsInCurrentTxn(grantRecord); // load the grantee (either a catalog/principal role or a principal) and increment its grants // version PolarisBaseEntity granteeEntity = - ms.lookupEntityInCurrentTxn( - callCtx, grantee.getCatalogId(), grantee.getId(), grantee.getTypeCode()); + ms.lookupEntityInCurrentTxn(grantee.getCatalogId(), grantee.getId(), grantee.getTypeCode()); getDiagnostics().checkNotNull(granteeEntity, "grantee_not_found", "grantee={}", grantee); // grants have changed, we need to bump-up the grants version PolarisBaseEntity updatedGranteeEntity = granteeEntity.withGrantRecordsVersion(granteeEntity.getGrantRecordsVersion() + 1); - ms.writeEntityInCurrentTxn(callCtx, updatedGranteeEntity, false, granteeEntity); + ms.writeEntityInCurrentTxn(updatedGranteeEntity, false, granteeEntity); // we also need to invalidate the grants on that securable so that we can reload them. // load the securable and increment its grants version PolarisBaseEntity securableEntity = ms.lookupEntityInCurrentTxn( - callCtx, securable.getCatalogId(), securable.getId(), securable.getTypeCode()); + securable.getCatalogId(), securable.getId(), securable.getTypeCode()); getDiagnostics() .checkNotNull(securableEntity, "securable_not_found", "securable={}", securable); // grants have changed, we need to bump-up the grants version @@ -313,7 +312,7 @@ private void dropEntity( new PolarisBaseEntity.Builder(securableEntity) .grantRecordsVersion(securableEntity.getGrantRecordsVersion() + 1) .build(); - ms.writeEntityInCurrentTxn(callCtx, updatedSecurableEntity, false, securableEntity); + ms.writeEntityInCurrentTxn(updatedSecurableEntity, false, securableEntity); // TODO: Update this to be an atomic bulk-update of the grantee/securable, ideally along // with adding the grant record in the same bulk-update. @@ -326,14 +325,12 @@ private void dropEntity( * Delete the specified grant record from the GRANT_RECORDS table. This will at the same time * invalidate the grant records of the grantee and the securable if the grantee is a role * - * @param callCtx call context * @param ms meta store * @param securable the securable entity * @param grantee the grantee entity * @param grantRecord the grant record to remove, which was read in the same transaction */ private void revokeGrantRecord( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull PolarisEntityCore securable, @Nonnull PolarisEntityCore grantee, @@ -363,25 +360,24 @@ private void revokeGrantRecord( getDiagnostics().check(grantee.getType().isGrantee(), "not_a_grantee", "grantee={}", grantee); // remove that grant - ms.deleteFromGrantRecordsInCurrentTxn(callCtx, grantRecord); + ms.deleteFromGrantRecordsInCurrentTxn(grantRecord); // load the grantee and increment its grants version PolarisBaseEntity refreshGrantee = - ms.lookupEntityInCurrentTxn( - callCtx, grantee.getCatalogId(), grantee.getId(), grantee.getTypeCode()); + ms.lookupEntityInCurrentTxn(grantee.getCatalogId(), grantee.getId(), grantee.getTypeCode()); getDiagnostics() .checkNotNull( refreshGrantee, "missing_grantee", "grantRecord={} grantee={}", grantRecord, grantee); // grants have changed, we need to bump-up the grants version PolarisBaseEntity updatedRefreshGrantee = refreshGrantee.withGrantRecordsVersion(refreshGrantee.getGrantRecordsVersion() + 1); - ms.writeEntityInCurrentTxn(callCtx, updatedRefreshGrantee, false, refreshGrantee); + ms.writeEntityInCurrentTxn(updatedRefreshGrantee, false, refreshGrantee); // we also need to invalidate the grants on that securable so that we can reload them. // load the securable and increment its grants version PolarisBaseEntity refreshSecurable = ms.lookupEntityInCurrentTxn( - callCtx, securable.getCatalogId(), securable.getId(), securable.getTypeCode()); + securable.getCatalogId(), securable.getId(), securable.getTypeCode()); getDiagnostics() .checkNotNull( refreshSecurable, @@ -392,7 +388,7 @@ private void revokeGrantRecord( // grants have changed, we need to bump-up the grants version PolarisBaseEntity updatedRefreshSecurable = refreshSecurable.withGrantRecordsVersion(refreshSecurable.getGrantRecordsVersion() + 1); - ms.writeEntityInCurrentTxn(callCtx, updatedRefreshSecurable, false, refreshSecurable); + ms.writeEntityInCurrentTxn(updatedRefreshSecurable, false, refreshSecurable); // TODO: Update this to be an atomic bulk-update of the grantee/securable, ideally along // with removing the grant record in the same bulk-update. @@ -402,7 +398,6 @@ private void revokeGrantRecord( * Create a new catalog. This not only creates the new catalog entity but also the initial admin * role required to admin this catalog. * - * @param callCtx call context * @param ms meta store in read/write mode * @param catalog the catalog entity to create * @param integration the storage integration that should be attached to the catalog. If null, do @@ -414,7 +409,6 @@ private void revokeGrantRecord( * to */ private @Nonnull CreateCatalogResult createCatalog( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull PolarisBaseEntity catalog, @Nullable PolarisStorageIntegration integration, @@ -424,8 +418,7 @@ private void revokeGrantRecord( // check if that catalog has already been created PolarisBaseEntity refreshCatalog = - ms.lookupEntityInCurrentTxn( - callCtx, catalog.getCatalogId(), catalog.getId(), catalog.getTypeCode()); + ms.lookupEntityInCurrentTxn(catalog.getCatalogId(), catalog.getId(), catalog.getTypeCode()); // if found, probably a retry, simply return the previously created catalog if (refreshCatalog != null) { @@ -440,7 +433,6 @@ private void revokeGrantRecord( // lookup catalog admin role, should exist PolarisBaseEntity catalogAdminRole = ms.lookupEntityByNameInCurrentTxn( - callCtx, refreshCatalog.getId(), refreshCatalog.getId(), PolarisEntityType.CATALOG_ROLE.getCode(), @@ -458,7 +450,6 @@ private void revokeGrantRecord( // check that a catalog with the same name does not exist already // if it exists, this is an error, the client should retry if (ms.lookupEntityIdAndSubTypeByNameInCurrentTxn( - callCtx, PolarisEntityConstants.getNullId(), PolarisEntityConstants.getRootEntityId(), PolarisEntityType.CATALOG.getCode(), @@ -467,13 +458,13 @@ private void revokeGrantRecord( return new CreateCatalogResult(BaseResult.ReturnStatus.ENTITY_ALREADY_EXISTS, null); } - ms.persistStorageIntegrationIfNeededInCurrentTxn(callCtx, catalog, integration); + ms.persistStorageIntegrationIfNeededInCurrentTxn(catalog, integration); // now create and persist new catalog entity - this.persistNewEntity(callCtx, ms, catalog); + this.persistNewEntity(ms, catalog); // create the catalog admin role for this new catalog - long adminRoleId = ms.generateNewIdInCurrentTxn(callCtx); + long adminRoleId = ms.generateNewIdInCurrentTxn(); PolarisBaseEntity adminRole = new PolarisBaseEntity( catalog.getId(), @@ -482,30 +473,27 @@ private void revokeGrantRecord( PolarisEntitySubType.NULL_SUBTYPE, catalog.getId(), PolarisEntityConstants.getNameOfCatalogAdminRole()); - this.persistNewEntity(callCtx, ms, adminRole); + this.persistNewEntity(ms, adminRole); // grant the catalog admin role access-management on the catalog - this.persistNewGrantRecord( - callCtx, ms, catalog, adminRole, PolarisPrivilege.CATALOG_MANAGE_ACCESS); + this.persistNewGrantRecord(ms, catalog, adminRole, PolarisPrivilege.CATALOG_MANAGE_ACCESS); // grant the catalog admin role metadata-management on the catalog; this one // is revocable - this.persistNewGrantRecord( - callCtx, ms, catalog, adminRole, PolarisPrivilege.CATALOG_MANAGE_METADATA); + this.persistNewGrantRecord(ms, catalog, adminRole, PolarisPrivilege.CATALOG_MANAGE_METADATA); // immediately assign its catalog_admin role if (principalRoles.isEmpty()) { // lookup service admin role, should exist PolarisBaseEntity serviceAdminRole = ms.lookupEntityByNameInCurrentTxn( - callCtx, PolarisEntityConstants.getNullId(), PolarisEntityConstants.getRootEntityId(), PolarisEntityType.PRINCIPAL_ROLE.getCode(), PolarisEntityConstants.getNameOfPrincipalServiceAdminRole()); getDiagnostics().checkNotNull(serviceAdminRole, "missing_service_admin_role"); this.persistNewGrantRecord( - callCtx, ms, adminRole, serviceAdminRole, PolarisPrivilege.CATALOG_ROLE_USAGE); + ms, adminRole, serviceAdminRole, PolarisPrivilege.CATALOG_ROLE_USAGE); } else { // grant to each principal role usage on its catalog_admin role for (PolarisEntityCore principalRole : principalRoles) { @@ -520,7 +508,7 @@ private void revokeGrantRecord( // grant usage on that catalog admin role to this principal this.persistNewGrantRecord( - callCtx, ms, adminRole, principalRole, PolarisPrivilege.CATALOG_ROLE_USAGE); + ms, adminRole, principalRole, PolarisPrivilege.CATALOG_ROLE_USAGE); } } @@ -531,11 +519,9 @@ private void revokeGrantRecord( /** * Bootstrap Polaris catalog service * - * @param callCtx call context * @param ms meta store in read/write mode */ - private void bootstrapPolarisService( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms) { + private void bootstrapPolarisService(@Nonnull TransactionalPersistence ms) { // Create a root container entity that can represent the securable for any top-level grants. PolarisBaseEntity rootContainer = @@ -546,68 +532,58 @@ private void bootstrapPolarisService( PolarisEntitySubType.NULL_SUBTYPE, PolarisEntityConstants.getRootEntityId(), PolarisEntityConstants.getRootContainerName()); - this.persistNewEntity(callCtx, ms, rootContainer); + this.persistNewEntity(ms, rootContainer); // Now bootstrap the service by creating the root principal and the service_admin principal // role. The principal role will be granted to that root principal and the root catalog admin // of the root catalog will be granted to that principal role. - long rootPrincipalId = ms.generateNewIdInCurrentTxn(callCtx); + long rootPrincipalId = ms.generateNewIdInCurrentTxn(); PrincipalEntity rootPrincipal = new PrincipalEntity.Builder() .setId(rootPrincipalId) .setName(PolarisEntityConstants.getRootPrincipalName()) .setCreateTimestamp(System.currentTimeMillis()) .build(); - this.createPrincipal(callCtx, ms, rootPrincipal); + this.createPrincipal(ms, rootPrincipal); // now create the account admin principal role - long serviceAdminPrincipalRoleId = ms.generateNewIdInCurrentTxn(callCtx); + long serviceAdminPrincipalRoleId = ms.generateNewIdInCurrentTxn(); PrincipalRoleEntity serviceAdminPrincipalRole = new PrincipalRoleEntity.Builder() .setId(serviceAdminPrincipalRoleId) .setName(PolarisEntityConstants.getNameOfPrincipalServiceAdminRole()) .setCreateTimestamp(System.currentTimeMillis()) .build(); - this.persistNewEntity(callCtx, ms, serviceAdminPrincipalRole); + this.persistNewEntity(ms, serviceAdminPrincipalRole); // we also need to grant usage on the account-admin principal to the principal this.persistNewGrantRecord( - callCtx, - ms, - serviceAdminPrincipalRole, - rootPrincipal, - PolarisPrivilege.PRINCIPAL_ROLE_USAGE); + ms, serviceAdminPrincipalRole, rootPrincipal, PolarisPrivilege.PRINCIPAL_ROLE_USAGE); // grant SERVICE_MANAGE_ACCESS on the rootContainer to the serviceAdminPrincipalRole this.persistNewGrantRecord( - callCtx, - ms, - rootContainer, - serviceAdminPrincipalRole, - PolarisPrivilege.SERVICE_MANAGE_ACCESS); + ms, rootContainer, serviceAdminPrincipalRole, PolarisPrivilege.SERVICE_MANAGE_ACCESS); } /** {@inheritDoc} */ @Override - public @Nonnull BaseResult bootstrapPolarisService(@Nonnull PolarisCallContext callCtx) { - // get meta store we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + public @Nonnull BaseResult bootstrapPolarisService() { + TransactionalPersistence ms = getMetaStore(); // run operation in a read/write transaction - ms.runActionInTransaction(callCtx, () -> this.bootstrapPolarisService(callCtx, ms)); + ms.runActionInTransaction(() -> this.bootstrapPolarisService(ms)); // all good return new BaseResult(BaseResult.ReturnStatus.SUCCESS); } @Override - public @Nonnull BaseResult purge(@Nonnull PolarisCallContext callCtx) { - // get meta store we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + public @Nonnull BaseResult purge() { + TransactionalPersistence ms = getMetaStore(); // run operation in a read/write transaction LOGGER.warn("Deleting all metadata in the metastore..."); - ms.runActionInTransaction(callCtx, () -> ms.deleteAllInCurrentTxn(callCtx)); + ms.runActionInTransaction(ms::deleteAllInCurrentTxn); LOGGER.warn("Finished deleting all metadata in the metastore"); // all good @@ -615,19 +591,17 @@ private void bootstrapPolarisService( } /** - * See {@link #readEntityByName(PolarisCallContext, List, PolarisEntityType, PolarisEntitySubType, - * String)} + * See {@link PolarisMetaStoreManager#readEntityByName(List, PolarisEntityType, + * PolarisEntitySubType, String)} */ private @Nonnull EntityResult readEntityByName( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull String name) { // first resolve again the catalogPath to that entity - PolarisEntityResolver resolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, catalogPath); + PolarisEntityResolver resolver = new PolarisEntityResolver(getDiagnostics(), ms, catalogPath); // return if we failed to resolve if (resolver.isFailure()) { @@ -637,11 +611,7 @@ private void bootstrapPolarisService( // now looking the entity by name PolarisBaseEntity entity = ms.lookupEntityByNameInCurrentTxn( - callCtx, - resolver.getCatalogIdOrNull(), - resolver.getParentId(), - entityType.getCode(), - name); + resolver.getCatalogIdOrNull(), resolver.getParentId(), entityType.getCode(), name); // if found, check if subType really matches if (entity != null @@ -659,33 +629,29 @@ private void bootstrapPolarisService( /** {@inheritDoc} */ @Override public @Nonnull EntityResult readEntityByName( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull String name) { - // get meta store we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // run operation in a read/write transaction return ms.runInReadTransaction( - callCtx, () -> readEntityByName(callCtx, ms, catalogPath, entityType, entitySubType, name)); + () -> readEntityByName(ms, catalogPath, entityType, entitySubType, name)); } /** - * See {@link PolarisMetaStoreManager#listEntities(PolarisCallContext, List, PolarisEntityType, - * PolarisEntitySubType, PageToken)} + * See {@link PolarisMetaStoreManager#listEntities(List, PolarisEntityType, PolarisEntitySubType, + * PageToken)} */ private @Nonnull ListEntitiesResult listEntities( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull PageToken pageToken) { // first resolve again the catalogPath to that entity - PolarisEntityResolver resolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, catalogPath); + PolarisEntityResolver resolver = new PolarisEntityResolver(getDiagnostics(), ms, catalogPath); // return if we failed to resolve if (resolver.isFailure()) { @@ -695,7 +661,6 @@ private void bootstrapPolarisService( // return list of active entities Page resultPage = ms.listEntitiesInCurrentTxn( - callCtx, resolver.getCatalogIdOrNull(), resolver.getParentId(), entityType, @@ -708,34 +673,29 @@ private void bootstrapPolarisService( /** {@inheritDoc} */ @Override public @Nonnull ListEntitiesResult listEntities( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull PageToken pageToken) { - // get meta store we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // run operation in a read transaction return ms.runInReadTransaction( - callCtx, - () -> listEntities(callCtx, ms, catalogPath, entityType, entitySubType, pageToken)); + () -> listEntities(ms, catalogPath, entityType, entitySubType, pageToken)); } /** - * See {@link PolarisMetaStoreManager#loadEntities(PolarisCallContext, List, PolarisEntityType, - * PolarisEntitySubType, PageToken)} + * See {@link PolarisMetaStoreManager#loadEntities(List, PolarisEntityType, PolarisEntitySubType, + * PageToken)} */ private @Nonnull Page loadEntities( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull PageToken pageToken) { // first resolve again the catalogPath to that entity - PolarisEntityResolver resolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, catalogPath); + PolarisEntityResolver resolver = new PolarisEntityResolver(getDiagnostics(), ms, catalogPath); // throw if we failed to resolve if (resolver.isFailure()) { @@ -744,7 +704,6 @@ private void bootstrapPolarisService( // return list of active entities return ms.loadEntitiesInCurrentTxn( - callCtx, resolver.getCatalogIdOrNull(), resolver.getParentId(), entityType, @@ -757,25 +716,20 @@ private void bootstrapPolarisService( /** {@inheritDoc} */ @Override public @Nonnull Page loadEntities( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull PageToken pageToken) { - // get meta store we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // run operation in a read transaction return ms.runInReadTransaction( - callCtx, - () -> loadEntities(callCtx, ms, catalogPath, entityType, entitySubType, pageToken)); + () -> loadEntities(ms, catalogPath, entityType, entitySubType, pageToken)); } - /** {@link #createPrincipal(PolarisCallContext, PrincipalEntity)} */ + /** {@link #createPrincipal(PrincipalEntity)} */ private @Nonnull CreatePrincipalResult createPrincipal( - @Nonnull PolarisCallContext callCtx, - @Nonnull TransactionalPersistence ms, - @Nonnull PrincipalEntity principal) { + @Nonnull TransactionalPersistence ms, @Nonnull PrincipalEntity principal) { // validate input getDiagnostics().checkNotNull(principal, "unexpected_null_principal"); @@ -783,7 +737,7 @@ private void bootstrapPolarisService( PrincipalEntity refreshPrincipal = PrincipalEntity.of( ms.lookupEntityInCurrentTxn( - callCtx, principal.getCatalogId(), principal.getId(), principal.getTypeCode())); + principal.getCatalogId(), principal.getId(), principal.getTypeCode())); // if found, probably a retry, simply return the previously created principal if (refreshPrincipal != null) { @@ -793,8 +747,7 @@ private void bootstrapPolarisService( .check(!clientId.isEmpty(), "empty_client_id", "principal={}", refreshPrincipal); // get the main and secondary secrets for that client - PolarisPrincipalSecrets principalSecrets = - ms.loadPrincipalSecretsInCurrentTxn(callCtx, clientId); + PolarisPrincipalSecrets principalSecrets = ms.loadPrincipalSecretsInCurrentTxn(clientId); // should not be null getDiagnostics() @@ -812,7 +765,6 @@ private void bootstrapPolarisService( // check that a principal with the same name does not exist already // if it exists, this is an error, the client should retry if (ms.lookupEntityIdAndSubTypeByNameInCurrentTxn( - callCtx, PolarisEntityConstants.getNullId(), PolarisEntityConstants.getRootEntityId(), PolarisEntityType.PRINCIPAL.getCode(), @@ -823,7 +775,7 @@ private void bootstrapPolarisService( // generate new secrets for this principal PolarisPrincipalSecrets principalSecrets = - ms.generateNewPrincipalSecretsInCurrentTxn(callCtx, principal.getName(), principal.getId()); + ms.generateNewPrincipalSecretsInCurrentTxn(principal.getName(), principal.getId()); // remember client id PrincipalEntity updatedPrincipal = @@ -832,7 +784,7 @@ private void bootstrapPolarisService( .build(); // now create and persist new catalog entity - this.persistNewEntity(callCtx, ms, updatedPrincipal); + this.persistNewEntity(ms, updatedPrincipal); // success, return the two entities return new CreatePrincipalResult(updatedPrincipal, principalSecrets); @@ -840,31 +792,27 @@ private void bootstrapPolarisService( /** {@inheritDoc} */ @Override - public @Nonnull CreatePrincipalResult createPrincipal( - @Nonnull PolarisCallContext callCtx, @Nonnull PrincipalEntity principal) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + public @Nonnull CreatePrincipalResult createPrincipal(@Nonnull PrincipalEntity principal) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction - return ms.runInTransaction(callCtx, () -> this.createPrincipal(callCtx, ms, principal)); + return ms.runInTransaction(() -> this.createPrincipal(ms, principal)); } - /** See {@link #loadPrincipalSecrets(PolarisCallContext, String)} */ + /** See {@link org.apache.polaris.core.auth.PolarisSecretsManager#loadPrincipalSecrets(String)} */ private @Nullable PolarisPrincipalSecrets loadPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, TransactionalPersistence ms, @Nonnull String clientId) { - return ms.loadPrincipalSecretsInCurrentTxn(callCtx, clientId); + TransactionalPersistence ms, @Nonnull String clientId) { + return ms.loadPrincipalSecretsInCurrentTxn(clientId); } /** {@inheritDoc} */ @Override - public @Nonnull PrincipalSecretsResult loadPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + public @Nonnull PrincipalSecretsResult loadPrincipalSecrets(@Nonnull String clientId) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction PolarisPrincipalSecrets secrets = - ms.runInTransaction(callCtx, () -> this.loadPrincipalSecrets(callCtx, ms, clientId)); + ms.runInTransaction(() -> this.loadPrincipalSecrets(ms, clientId)); return (secrets == null) ? new PrincipalSecretsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null) @@ -873,18 +821,15 @@ private void bootstrapPolarisService( /** {@inheritDoc} */ @Override - public @Nonnull void deletePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId, long principalId) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + public @Nonnull void deletePrincipalSecrets(@Nonnull String clientId, long principalId) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction - ms.deletePrincipalSecrets(callCtx, clientId, principalId); + ms.deletePrincipalSecrets(clientId, principalId); } /** See {@link #} */ private @Nullable PolarisPrincipalSecrets rotatePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull String clientId, long principalId, @@ -893,7 +838,6 @@ private void bootstrapPolarisService( // if not found, the principal must have been dropped EntityResult loadEntityResult = loadEntity( - callCtx, ms, PolarisEntityConstants.getNullId(), principalId, @@ -912,8 +856,7 @@ private void bootstrapPolarisService( PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE) != null; PolarisPrincipalSecrets secrets = - ms.rotatePrincipalSecretsInCurrentTxn( - callCtx, clientId, principalId, doReset, oldSecretHash); + ms.rotatePrincipalSecretsInCurrentTxn(clientId, principalId, doReset, oldSecretHash); if (reset && !internalProps.containsKey( @@ -922,13 +865,13 @@ private void bootstrapPolarisService( PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE, "true"); principalBuilder.internalPropertiesAsMap(internalProps); principalBuilder.entityVersion(principal.getEntityVersion() + 1); - ms.writeEntityInCurrentTxn(callCtx, principalBuilder.build(), true, principal); + ms.writeEntityInCurrentTxn(principalBuilder.build(), true, principal); } else if (internalProps.containsKey( PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE)) { internalProps.remove(PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE); principalBuilder.internalPropertiesAsMap(internalProps); principalBuilder.entityVersion(principal.getEntityVersion() + 1); - ms.writeEntityInCurrentTxn(callCtx, principalBuilder.build(), true, principal); + ms.writeEntityInCurrentTxn(principalBuilder.build(), true, principal); } return secrets; } @@ -936,21 +879,13 @@ private void bootstrapPolarisService( /** {@inheritDoc} */ @Override public @Nonnull PrincipalSecretsResult rotatePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - @Nonnull String clientId, - long principalId, - boolean reset, - @Nonnull String oldSecretHash) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + @Nonnull String clientId, long principalId, boolean reset, @Nonnull String oldSecretHash) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction PolarisPrincipalSecrets secrets = ms.runInTransaction( - callCtx, - () -> - this.rotatePrincipalSecrets( - callCtx, ms, clientId, principalId, reset, oldSecretHash)); + () -> this.rotatePrincipalSecrets(ms, clientId, principalId, reset, oldSecretHash)); return (secrets == null) ? new PrincipalSecretsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null) @@ -958,29 +893,23 @@ private void bootstrapPolarisService( } private @Nullable PolarisPrincipalSecrets resetPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull String clientId, long principalId, String customClientId, String customClientSecret) { PolarisPrincipalSecrets secrets = - ms.storePrincipalSecrets(callCtx, principalId, customClientId, customClientSecret); + ms.storePrincipalSecrets(principalId, customClientId, customClientSecret); return secrets; } @Override public @Nonnull PrincipalSecretsResult resetPrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - long principalId, - @Nonnull String resolvedClientId, - String customClientSecret) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + long principalId, @Nonnull String resolvedClientId, String customClientSecret) { + TransactionalPersistence ms = getMetaStore(); // if not found, the principal must have been dropped EntityResult loadEntityResult = - loadEntity( - callCtx, PolarisEntityConstants.getNullId(), principalId, PolarisEntityType.PRINCIPAL); + loadEntity(PolarisEntityConstants.getNullId(), principalId, PolarisEntityType.PRINCIPAL); if (loadEntityResult.getReturnStatus() != BaseResult.ReturnStatus.SUCCESS) { return new PrincipalSecretsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); } @@ -988,15 +917,9 @@ private void bootstrapPolarisService( // need to run inside a read/write transaction PolarisPrincipalSecrets secrets = ms.runInTransaction( - callCtx, () -> this.resetPrincipalSecrets( - callCtx, - ms, - resolvedClientId, - principalId, - resolvedClientId, - customClientSecret)); + ms, resolvedClientId, principalId, resolvedClientId, customClientSecret)); return (secrets == null) ? new PrincipalSecretsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null) @@ -1006,11 +929,8 @@ private void bootstrapPolarisService( /** {@inheritDoc} */ @Override public @Nonnull CreateCatalogResult createCatalog( - @Nonnull PolarisCallContext callCtx, - @Nonnull PolarisBaseEntity catalog, - @Nonnull List principalRoles) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + @Nonnull PolarisBaseEntity catalog, @Nonnull List principalRoles) { + TransactionalPersistence ms = getMetaStore(); Map internalProp = catalog.getInternalPropertiesAsMap(); String integrationIdentifierOrId = @@ -1023,7 +943,6 @@ private void bootstrapPolarisService( if (storageConfigInfoStr != null && integrationIdentifierOrId == null) { integration = ms.createStorageIntegrationInCurrentTxn( - callCtx, catalog.getCatalogId(), catalog.getId(), PolarisStorageConfigurationInfo.deserialize(storageConfigInfoStr)); @@ -1031,13 +950,11 @@ private void bootstrapPolarisService( integration = null; } // need to run inside a read/write transaction - return ms.runInTransaction( - callCtx, () -> this.createCatalog(callCtx, ms, catalog, integration, principalRoles)); + return ms.runInTransaction(() -> this.createCatalog(ms, catalog, integration, principalRoles)); } - /** {@link #createEntityIfNotExists(PolarisCallContext, List, PolarisBaseEntity)} */ + /** {@link PolarisMetaStoreManager#createEntityIfNotExists(List, PolarisBaseEntity)} */ private @Nonnull EntityResult createEntityIfNotExists( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity) { @@ -1050,8 +967,7 @@ private void bootstrapPolarisService( // first, check if the entity has already been created, in which case we will simply return it PolarisBaseEntity entityFound = - ms.lookupEntityInCurrentTxn( - callCtx, entity.getCatalogId(), entity.getId(), entity.getTypeCode()); + ms.lookupEntityInCurrentTxn(entity.getCatalogId(), entity.getId(), entity.getTypeCode()); if (entityFound != null) { // probably the client retried, simply return it // TODO: Check correctness of returning entityFound vs entity here. It may have already @@ -1060,8 +976,7 @@ private void bootstrapPolarisService( } // first resolve again the catalogPath - PolarisEntityResolver resolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, catalogPath); + PolarisEntityResolver resolver = new PolarisEntityResolver(getDiagnostics(), ms, catalogPath); // return if we failed to resolve if (resolver.isFailure()) { @@ -1071,7 +986,6 @@ private void bootstrapPolarisService( // check if an entity does not already exist with the same name. If true, this is an error EntityNameLookupRecord entityActiveRecord = ms.lookupEntityIdAndSubTypeByNameInCurrentTxn( - callCtx, entity.getCatalogId(), entity.getParentId(), entity.getType().getCode(), @@ -1082,7 +996,7 @@ private void bootstrapPolarisService( } // persist that new entity - this.persistNewEntity(callCtx, ms, entity); + this.persistNewEntity(ms, entity); // done, return that newly created entity return new EntityResult(entity); @@ -1091,33 +1005,25 @@ private void bootstrapPolarisService( /** {@inheritDoc} */ @Override public @Nonnull EntityResult createEntityIfNotExists( - @Nonnull PolarisCallContext callCtx, - @Nullable List catalogPath, - @Nonnull PolarisBaseEntity entity) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction - return ms.runInTransaction( - callCtx, () -> this.createEntityIfNotExists(callCtx, ms, catalogPath, entity)); + return ms.runInTransaction(() -> this.createEntityIfNotExists(ms, catalogPath, entity)); } @Override public @Nonnull EntitiesResult createEntitiesIfNotExist( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull List entities) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction return ms.runInTransaction( - callCtx, () -> { List createdEntities = new ArrayList<>(entities.size()); for (PolarisBaseEntity entity : entities) { - EntityResult entityCreateResult = - createEntityIfNotExists(callCtx, ms, catalogPath, entity); + EntityResult entityCreateResult = createEntityIfNotExists(ms, catalogPath, entity); // abort everything if error if (entityCreateResult.getReturnStatus() != BaseResult.ReturnStatus.SUCCESS) { ms.rollback(); @@ -1131,10 +1037,9 @@ private void bootstrapPolarisService( } /** - * See {@link #updateEntityPropertiesIfNotChanged(PolarisCallContext, List, PolarisBaseEntity)} + * See {@link PolarisMetaStoreManager#updateEntityPropertiesIfNotChanged(List, PolarisBaseEntity)} */ private @Nonnull EntityResult updateEntityPropertiesIfNotChanged( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity) { @@ -1143,7 +1048,7 @@ private void bootstrapPolarisService( // re-resolve everything including that entity PolarisEntityResolver resolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, catalogPath, entity); + new PolarisEntityResolver(getDiagnostics(), ms, catalogPath, entity); // if resolution failed, return false if (resolver.isFailure()) { @@ -1152,8 +1057,7 @@ private void bootstrapPolarisService( // lookup the entity, cannot be null PolarisBaseEntity entityRefreshed = - ms.lookupEntityInCurrentTxn( - callCtx, entity.getCatalogId(), entity.getId(), entity.getTypeCode()); + ms.lookupEntityInCurrentTxn(entity.getCatalogId(), entity.getId(), entity.getTypeCode()); getDiagnostics() .checkNotNull(entityRefreshed, "unexpected_entity_not_found", "entity={}", entity); @@ -1182,29 +1086,24 @@ private void bootstrapPolarisService( // persist this entity after changing it. This will update the version and update the last // updated time. Because the entity version is changed, we will update the change tracking table PolarisBaseEntity persistedEntity = - this.persistEntityAfterChange(callCtx, ms, updatedEntity, false, entityRefreshed); + this.persistEntityAfterChange(ms, updatedEntity, false, entityRefreshed); return new EntityResult(persistedEntity); } /** {@inheritDoc} */ @Override public @Nonnull EntityResult updateEntityPropertiesIfNotChanged( - @Nonnull PolarisCallContext callCtx, - @Nullable List catalogPath, - @Nonnull PolarisBaseEntity entity) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + @Nullable List catalogPath, @Nonnull PolarisBaseEntity entity) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction return ms.runInTransaction( - callCtx, () -> this.updateEntityPropertiesIfNotChanged(callCtx, ms, catalogPath, entity)); + () -> this.updateEntityPropertiesIfNotChanged(ms, catalogPath, entity)); } - /** See {@link #updateEntitiesPropertiesIfNotChanged(PolarisCallContext, List)} */ + /** See {@link PolarisMetaStoreManager#updateEntitiesPropertiesIfNotChanged(List)} */ private @Nonnull EntitiesResult updateEntitiesPropertiesIfNotChanged( - @Nonnull PolarisCallContext callCtx, - @Nonnull TransactionalPersistence ms, - @Nonnull List entities) { + @Nonnull TransactionalPersistence ms, @Nonnull List entities) { // ensure that the entities list is not null getDiagnostics().checkNotNull(entities, "unexpected_null_entities"); @@ -1216,7 +1115,7 @@ private void bootstrapPolarisService( // update that entity, abort if it fails EntityResult updatedEntityResult = this.updateEntityPropertiesIfNotChanged( - callCtx, ms, entityWithPath.getCatalogPath(), entityWithPath.getEntity()); + ms, entityWithPath.getCatalogPath(), entityWithPath.getEntity()); // if failed, rollback and return the last error if (updatedEntityResult.getReturnStatus() != BaseResult.ReturnStatus.SUCCESS) { @@ -1236,21 +1135,17 @@ private void bootstrapPolarisService( /** {@inheritDoc} */ @Override public @Nonnull EntitiesResult updateEntitiesPropertiesIfNotChanged( - @Nonnull PolarisCallContext callCtx, @Nonnull List entities) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + @Nonnull List entities) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction - return ms.runInTransaction( - callCtx, () -> this.updateEntitiesPropertiesIfNotChanged(callCtx, ms, entities)); + return ms.runInTransaction(() -> this.updateEntitiesPropertiesIfNotChanged(ms, entities)); } /** - * See {@link PolarisMetaStoreManager#renameEntity(PolarisCallContext, List, PolarisBaseEntity, - * List, PolarisEntity)} + * See {@link PolarisMetaStoreManager#renameEntity(List, PolarisBaseEntity, List, PolarisEntity)} */ private @Nonnull EntityResult renameEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, @Nonnull PolarisEntityCore entityToRename, @@ -1275,7 +1170,7 @@ private void bootstrapPolarisService( // re-resolve everything including that entity PolarisEntityResolver resolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, catalogPath, entityToRename); + new PolarisEntityResolver(getDiagnostics(), ms, catalogPath, entityToRename); // if resolution failed, return false if (resolver.isFailure()) { @@ -1285,10 +1180,7 @@ private void bootstrapPolarisService( // find the entity to rename PolarisBaseEntity refreshEntityToRename = ms.lookupEntityInCurrentTxn( - callCtx, - entityToRename.getCatalogId(), - entityToRename.getId(), - entityToRename.getTypeCode()); + entityToRename.getCatalogId(), entityToRename.getId(), entityToRename.getTypeCode()); // if this entity was not found, return failure. Not expected here because it was // resolved successfully (see above) @@ -1308,7 +1200,7 @@ private void bootstrapPolarisService( // re-resolve the new catalog path if this entity is going to be moved if (newCatalogPath != null) { - resolver = new PolarisEntityResolver(getDiagnostics(), callCtx, ms, newCatalogPath); + resolver = new PolarisEntityResolver(getDiagnostics(), ms, newCatalogPath); // if resolution failed, return false if (resolver.isFailure()) { @@ -1320,7 +1212,6 @@ private void bootstrapPolarisService( // if this entity already exists, this is an error EntityNameLookupRecord entityActiveRecord = ms.lookupEntityIdAndSubTypeByNameInCurrentTxn( - callCtx, resolver.getCatalogIdOrNull(), resolver.getParentId(), refreshEntityToRename.getTypeCode(), @@ -1350,37 +1241,30 @@ private void bootstrapPolarisService( // lookups if applicable PolarisBaseEntity renamedEntityToReturn = this.persistEntityAfterChange( - callCtx, ms, updatedEntityBuilder.build(), true, refreshEntityToRename); + ms, updatedEntityBuilder.build(), true, refreshEntityToRename); return new EntityResult(renamedEntityToReturn); } /** {@inheritDoc} */ @Override public @Nonnull EntityResult renameEntity( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entityToRename, @Nullable List newCatalogPath, @Nonnull PolarisEntity renamedEntity) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction return ms.runInTransaction( - callCtx, - () -> - this.renameEntity( - callCtx, ms, catalogPath, entityToRename, newCatalogPath, renamedEntity)); + () -> this.renameEntity(ms, catalogPath, entityToRename, newCatalogPath, renamedEntity)); } /** * See * - *

{@link #dropEntityIfExists(PolarisCallContext, TransactionalPersistence, List, - * PolarisBaseEntity, Map, boolean)} + *

{@link #dropEntityIfExists(TransactionalPersistence, List, PolarisBaseEntity, Map, boolean)} */ private @Nonnull DropEntityResult dropEntityIfExists( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entityToDrop, @@ -1391,7 +1275,7 @@ private void bootstrapPolarisService( // re-resolve everything including that entity PolarisEntityResolver resolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, catalogPath, entityToDrop); + new PolarisEntityResolver(getDiagnostics(), ms, catalogPath, entityToDrop); // if resolution failed, return false if (resolver.isFailure()) { @@ -1401,7 +1285,7 @@ private void bootstrapPolarisService( // first find the entity to drop PolarisBaseEntity refreshEntityToDrop = ms.lookupEntityInCurrentTxn( - callCtx, entityToDrop.getCatalogId(), entityToDrop.getId(), entityToDrop.getTypeCode()); + entityToDrop.getCatalogId(), entityToDrop.getId(), entityToDrop.getTypeCode()); // if this entity was not found, return failure if (refreshEntityToDrop == null) { @@ -1425,14 +1309,12 @@ private void bootstrapPolarisService( // TODO: Temporarily allow dropping a catalog with passthrough entities remaining, in the long // term we need to cleanup them up to avoid accumulation in the metastore if (!catalogEntityToDrop.isPassthroughFacade() - || !callCtx - .getRealmConfig() + || !getRealmConfig() .getConfig( FeatureConfiguration.ALLOW_DROPPING_NON_EMPTY_PASSTHROUGH_FACADE_CATALOG, catalogEntityToDrop)) { // if not all namespaces are dropped, we cannot drop this catalog - if (ms.hasChildrenInCurrentTxn( - callCtx, PolarisEntityType.NAMESPACE, catalogId, catalogId)) { + if (ms.hasChildrenInCurrentTxn(PolarisEntityType.NAMESPACE, catalogId, catalogId)) { return new DropEntityResult( BaseResult.ReturnStatus.NAMESPACE_NOT_EMPTY, catalogEntityToDrop.isPassthroughFacade() @@ -1447,7 +1329,6 @@ private void bootstrapPolarisService( // get the list of catalog roles, at most 2 List catalogRoles = ms.loadEntitiesInCurrentTxn( - callCtx, catalogId, catalogId, PolarisEntityType.CATALOG_ROLE, @@ -1465,11 +1346,11 @@ private void bootstrapPolarisService( // if 1, drop the last catalog role. Should be the catalog admin role but don't validate this if (!catalogRoles.isEmpty()) { // drop the last catalog role in that catalog, should be the admin catalog role - this.dropEntity(callCtx, ms, catalogRoles.get(0)); + this.dropEntity(ms, catalogRoles.get(0)); } } else if (refreshEntityToDrop.getType() == PolarisEntityType.NAMESPACE) { if (ms.hasChildrenInCurrentTxn( - callCtx, null, refreshEntityToDrop.getCatalogId(), refreshEntityToDrop.getId())) { + null, refreshEntityToDrop.getCatalogId(), refreshEntityToDrop.getId())) { return new DropEntityResult(BaseResult.ReturnStatus.NAMESPACE_NOT_EMPTY, null); } } else if (refreshEntityToDrop.getType() == PolarisEntityType.POLICY && !cleanup) { @@ -1477,7 +1358,6 @@ private void bootstrapPolarisService( try { List records = ms.loadAllTargetsOnPolicyInCurrentTxn( - callCtx, refreshEntityToDrop.getCatalogId(), refreshEntityToDrop.getId(), PolicyEntity.of(refreshEntityToDrop).getPolicyTypeCode()); @@ -1491,7 +1371,7 @@ private void bootstrapPolarisService( // simply delete that entity. Will be removed from entities_active, added to the // entities_dropped and its version will be changed. - this.dropEntity(callCtx, ms, refreshEntityToDrop); + this.dropEntity(ms, refreshEntityToDrop); // if cleanup, schedule a cleanup task for the entity. do this here, so that drop and scheduling // the cleanup task is transactional. Otherwise, we'll be unable to schedule the cleanup task @@ -1505,7 +1385,7 @@ private void bootstrapPolarisService( PolarisTaskConstants.TASK_DATA, PolarisObjectMapperUtil.serialize(refreshEntityToDrop)); PolarisBaseEntity.Builder taskEntityBuilder = new PolarisBaseEntity.Builder() - .id(ms.generateNewIdInCurrentTxn(callCtx)) + .id(ms.generateNewIdInCurrentTxn()) .catalogId(0L) .name("entityCleanup_" + entityToDrop.getId()) .typeCode(PolarisEntityType.TASK.getCode()) @@ -1516,7 +1396,7 @@ private void bootstrapPolarisService( taskEntityBuilder.internalPropertiesAsMap(cleanupProperties); } PolarisBaseEntity taskEntity = taskEntityBuilder.build(); - createEntityIfNotExists(callCtx, ms, null, taskEntity); + createEntityIfNotExists(ms, null, taskEntity); return new DropEntityResult(taskEntity.getId()); } @@ -1527,27 +1407,21 @@ private void bootstrapPolarisService( /** {@inheritDoc} */ @Override public @Nonnull DropEntityResult dropEntityIfExists( - @Nonnull PolarisCallContext callCtx, @Nullable List catalogPath, @Nonnull PolarisBaseEntity entityToDrop, @Nullable Map cleanupProperties, boolean cleanup) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction return ms.runInTransaction( - callCtx, - () -> - this.dropEntityIfExists( - callCtx, ms, catalogPath, entityToDrop, cleanupProperties, cleanup)); + () -> this.dropEntityIfExists(ms, catalogPath, entityToDrop, cleanupProperties, cleanup)); } /** * Resolve the arguments of granting/revoking a usage grant between a role (catalog or principal * role) and a grantee (either a principal role or a principal) * - * @param callCtx call context * @param ms meta store in read/write mode * @param catalog if the role is a catalog role, the caller needs to pass-in the catalog entity * which was used to resolve that role. Else null. @@ -1556,7 +1430,6 @@ private void bootstrapPolarisService( * @return resolver for the specified entities */ private @Nonnull PolarisEntityResolver resolveRoleToGranteeUsageGrant( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @@ -1592,7 +1465,6 @@ private void bootstrapPolarisService( // ensure these entities have not changed return new PolarisEntityResolver( getDiagnostics(), - callCtx, ms, catalog != null ? List.of(catalog) : null, null, @@ -1608,7 +1480,6 @@ private void bootstrapPolarisService( * @return a resolver for the role, the catalog path and the securable */ private PolarisEntityResolver resolveSecurableToRoleGrant( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @@ -1627,15 +1498,15 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // re-resolve now all these entities return new PolarisEntityResolver( - getDiagnostics(), callCtx, ms, catalogPath, securable, List.of(grantee)); + getDiagnostics(), ms, catalogPath, securable, List.of(grantee)); } /** - * See {@link #grantUsageOnRoleToGrantee(PolarisCallContext, PolarisEntityCore, PolarisEntityCore, - * PolarisEntityCore)} + * See {@link + * org.apache.polaris.core.auth.PolarisGrantManager#grantUsageOnRoleToGrantee(PolarisEntityCore, + * PolarisEntityCore, PolarisEntityCore)} */ private @Nonnull PrivilegeResult grantUsageOnRoleToGrantee( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @@ -1643,7 +1514,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // ensure these entities have not changed PolarisEntityResolver resolver = - this.resolveRoleToGranteeUsageGrant(callCtx, ms, catalog, role, grantee); + this.resolveRoleToGranteeUsageGrant(ms, catalog, role, grantee); // if failure to resolve, let the caller know if (resolver.isFailure()) { @@ -1658,32 +1529,28 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // grant usage on this role to this principal getDiagnostics().check(grantee.getType().isGrantee(), "not_a_grantee", "grantee={}", grantee); - PolarisGrantRecord grantRecord = - this.persistNewGrantRecord(callCtx, ms, role, grantee, usagePriv); + PolarisGrantRecord grantRecord = this.persistNewGrantRecord(ms, role, grantee, usagePriv); return new PrivilegeResult(grantRecord); } /** {@inheritDoc} */ @Override public @Nonnull PrivilegeResult grantUsageOnRoleToGrantee( - @Nonnull PolarisCallContext callCtx, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @Nonnull PolarisEntityCore grantee) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction - return ms.runInTransaction( - callCtx, () -> this.grantUsageOnRoleToGrantee(callCtx, ms, catalog, role, grantee)); + return ms.runInTransaction(() -> this.grantUsageOnRoleToGrantee(ms, catalog, role, grantee)); } /** - * See {@link #revokeUsageOnRoleFromGrantee(PolarisCallContext, PolarisEntityCore, + * See {@link + * org.apache.polaris.core.auth.PolarisGrantManager#revokeUsageOnRoleFromGrantee(PolarisEntityCore, * PolarisEntityCore, PolarisEntityCore)} */ private @Nonnull PrivilegeResult revokeUsageOnRoleFromGrantee( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @@ -1691,7 +1558,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // ensure these entities have not changed PolarisEntityResolver resolver = - this.resolveRoleToGranteeUsageGrant(callCtx, ms, catalog, role, grantee); + this.resolveRoleToGranteeUsageGrant(ms, catalog, role, grantee); // if failure to resolve, let the caller know if (resolver.isFailure()) { @@ -1707,7 +1574,6 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // first, ensure that this privilege has been granted PolarisGrantRecord grantRecord = ms.lookupGrantRecordInCurrentTxn( - callCtx, role.getCatalogId(), role.getId(), grantee.getCatalogId(), @@ -1720,7 +1586,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( } // revoke usage on the role from the grantee - this.revokeGrantRecord(callCtx, ms, role, grantee, grantRecord); + this.revokeGrantRecord(ms, role, grantee, grantRecord); return new PrivilegeResult(grantRecord); } @@ -1728,24 +1594,21 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( /** {@inheritDoc} */ @Override public @Nonnull PrivilegeResult revokeUsageOnRoleFromGrantee( - @Nonnull PolarisCallContext callCtx, @Nullable PolarisEntityCore catalog, @Nonnull PolarisEntityCore role, @Nonnull PolarisEntityCore grantee) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction - return ms.runInTransaction( - callCtx, () -> this.revokeUsageOnRoleFromGrantee(callCtx, ms, catalog, role, grantee)); + return ms.runInTransaction(() -> this.revokeUsageOnRoleFromGrantee(ms, catalog, role, grantee)); } /** - * See {@link #grantPrivilegeOnSecurableToRole(PolarisCallContext, PolarisEntityCore, List, - * PolarisEntityCore, PolarisPrivilege)} + * See {@link + * org.apache.polaris.core.auth.PolarisGrantManager#grantPrivilegeOnSecurableToRole(PolarisEntityCore, + * List, PolarisEntityCore, PolarisPrivilege)} */ private @Nonnull PrivilegeResult grantPrivilegeOnSecurableToRole( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @@ -1754,7 +1617,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // re-resolve now all these entities PolarisEntityResolver resolver = - this.resolveSecurableToRoleGrant(callCtx, ms, grantee, catalogPath, securable); + this.resolveSecurableToRoleGrant(ms, grantee, catalogPath, securable); // if failure to resolve, let the caller know if (resolver.isFailure()) { @@ -1762,36 +1625,30 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( } // grant specified privilege on this securable to this role and return the grant - PolarisGrantRecord grantRecord = - this.persistNewGrantRecord(callCtx, ms, securable, grantee, priv); + PolarisGrantRecord grantRecord = this.persistNewGrantRecord(ms, securable, grantee, priv); return new PrivilegeResult(grantRecord); } /** {@inheritDoc} */ @Override public @Nonnull PrivilegeResult grantPrivilegeOnSecurableToRole( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @Nonnull PolarisEntityCore securable, @Nonnull PolarisPrivilege privilege) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction return ms.runInTransaction( - callCtx, - () -> - this.grantPrivilegeOnSecurableToRole( - callCtx, ms, grantee, catalogPath, securable, privilege)); + () -> this.grantPrivilegeOnSecurableToRole(ms, grantee, catalogPath, securable, privilege)); } /** - * See {@link #revokePrivilegeOnSecurableFromRole(PolarisCallContext, PolarisEntityCore, List, - * PolarisEntityCore, PolarisPrivilege)} + * See {@link + * org.apache.polaris.core.auth.PolarisGrantManager#revokePrivilegeOnSecurableFromRole(PolarisEntityCore, + * List, PolarisEntityCore, PolarisPrivilege)} */ private @Nonnull PrivilegeResult revokePrivilegeOnSecurableFromRole( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @@ -1800,7 +1657,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // re-resolve now all these entities PolarisEntityResolver resolver = - this.resolveSecurableToRoleGrant(callCtx, ms, grantee, catalogPath, securable); + this.resolveSecurableToRoleGrant(ms, grantee, catalogPath, securable); // if failure to resolve, let the caller know if (resolver.isFailure()) { @@ -1810,7 +1667,6 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // lookup the grants records to find this grant PolarisGrantRecord grantRecord = ms.lookupGrantRecordInCurrentTxn( - callCtx, securable.getCatalogId(), securable.getId(), grantee.getCatalogId(), @@ -1823,7 +1679,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( } // revoke the specified privilege on this securable from this role - this.revokeGrantRecord(callCtx, ms, securable, grantee, grantRecord); + this.revokeGrantRecord(ms, securable, grantee, grantRecord); // success! return new PrivilegeResult(grantRecord); @@ -1832,32 +1688,26 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( /** {@inheritDoc} */ @Override public @Nonnull PrivilegeResult revokePrivilegeOnSecurableFromRole( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore grantee, @Nullable List catalogPath, @Nonnull PolarisEntityCore securable, @Nonnull PolarisPrivilege privilege) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // need to run inside a read/write transaction return ms.runInTransaction( - callCtx, () -> this.revokePrivilegeOnSecurableFromRole( - callCtx, ms, grantee, catalogPath, securable, privilege)); + ms, grantee, catalogPath, securable, privilege)); } - /** {@link #loadGrantsOnSecurable(PolarisCallContext, long, long)} */ + /** {@link #loadGrantsOnSecurable(long, long)} */ private @Nonnull LoadGrantsResult loadGrantsOnSecurable( - @Nonnull PolarisCallContext callCtx, - @Nonnull TransactionalPersistence ms, - long securableCatalogId, - long securableId) { + @Nonnull TransactionalPersistence ms, long securableCatalogId, long securableId) { // lookup grants version for this securable entity int grantsVersion = - ms.lookupEntityGrantRecordsVersionInCurrentTxn(callCtx, securableCatalogId, securableId); + ms.lookupEntityGrantRecordsVersionInCurrentTxn(securableCatalogId, securableId); // return null if securable does not exists if (grantsVersion == 0) { @@ -1866,7 +1716,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // now fetch all grants for this securable final List returnGrantRecords = - ms.loadAllGrantRecordsOnSecurableInCurrentTxn(callCtx, securableCatalogId, securableId); + ms.loadAllGrantRecordsOnSecurableInCurrentTxn(securableCatalogId, securableId); // find all unique grantees List entityIds = @@ -1877,7 +1727,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( grantRecord.getGranteeCatalogId(), grantRecord.getGranteeId())) .distinct() .collect(Collectors.toList()); - List entities = ms.lookupEntitiesInCurrentTxn(callCtx, entityIds); + List entities = ms.lookupEntitiesInCurrentTxn(entityIds); // done, return the list of grants and their version return new LoadGrantsResult( @@ -1888,31 +1738,25 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( /** {@inheritDoc} */ @Override - public @Nonnull LoadGrantsResult loadGrantsOnSecurable( - @Nonnull PolarisCallContext callCtx, PolarisEntityCore securable) { - return loadGrantsOnSecurable(callCtx, securable.getCatalogId(), securable.getId()); + public @Nonnull LoadGrantsResult loadGrantsOnSecurable(PolarisEntityCore securable) { + return loadGrantsOnSecurable(securable.getCatalogId(), securable.getId()); } public @Nonnull LoadGrantsResult loadGrantsOnSecurable( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + long securableCatalogId, long securableId) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read transaction return ms.runInReadTransaction( - callCtx, () -> this.loadGrantsOnSecurable(callCtx, ms, securableCatalogId, securableId)); + () -> this.loadGrantsOnSecurable(ms, securableCatalogId, securableId)); } - /** {@link #loadGrantsToGrantee(PolarisCallContext, long, long)} */ + /** {@link #loadGrantsToGrantee(long, long)} */ public @Nonnull LoadGrantsResult loadGrantsToGrantee( - @Nonnull PolarisCallContext callCtx, - @Nonnull TransactionalPersistence ms, - long granteeCatalogId, - long granteeId) { + @Nonnull TransactionalPersistence ms, long granteeCatalogId, long granteeId) { // lookup grants version for this grantee entity - int grantsVersion = - ms.lookupEntityGrantRecordsVersionInCurrentTxn(callCtx, granteeCatalogId, granteeId); + int grantsVersion = ms.lookupEntityGrantRecordsVersionInCurrentTxn(granteeCatalogId, granteeId); // return null if grantee does not exists if (grantsVersion == 0) { @@ -1921,7 +1765,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // now fetch all grants for this grantee final List returnGrantRecords = - ms.loadAllGrantRecordsOnGranteeInCurrentTxn(callCtx, granteeCatalogId, granteeId); + ms.loadAllGrantRecordsOnGranteeInCurrentTxn(granteeCatalogId, granteeId); // find all unique securables List entityIds = @@ -1932,7 +1776,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( grantRecord.getSecurableCatalogId(), grantRecord.getSecurableId())) .distinct() .collect(Collectors.toList()); - List entities = ms.lookupEntitiesInCurrentTxn(callCtx, entityIds); + List entities = ms.lookupEntitiesInCurrentTxn(entityIds); // done, return the list of grants and their version return new LoadGrantsResult( @@ -1943,53 +1787,44 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( /** {@inheritDoc} */ @Override - public @Nonnull LoadGrantsResult loadGrantsToGrantee( - @Nonnull PolarisCallContext callCtx, PolarisEntityCore grantee) { - return loadGrantsToGrantee(callCtx, grantee.getCatalogId(), grantee.getId()); + public @Nonnull LoadGrantsResult loadGrantsToGrantee(PolarisEntityCore grantee) { + return loadGrantsToGrantee(grantee.getCatalogId(), grantee.getId()); } - public @Nonnull LoadGrantsResult loadGrantsToGrantee( - @Nonnull PolarisCallContext callCtx, long granteeCatalogId, long granteeId) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + public @Nonnull LoadGrantsResult loadGrantsToGrantee(long granteeCatalogId, long granteeId) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read transaction - return ms.runInReadTransaction( - callCtx, () -> this.loadGrantsToGrantee(callCtx, ms, granteeCatalogId, granteeId)); + return ms.runInReadTransaction(() -> this.loadGrantsToGrantee(ms, granteeCatalogId, granteeId)); } - /** {@link PolarisMetaStoreManager#loadEntitiesChangeTracking(PolarisCallContext, List)} */ + /** {@link PolarisMetaStoreManager#loadEntitiesChangeTracking(List)} */ private @Nonnull ChangeTrackingResult loadEntitiesChangeTracking( - @Nonnull PolarisCallContext callCtx, - @Nonnull TransactionalPersistence ms, - @Nonnull List entityIds) { + @Nonnull TransactionalPersistence ms, @Nonnull List entityIds) { List changeTracking = - ms.lookupEntityVersionsInCurrentTxn(callCtx, entityIds); + ms.lookupEntityVersionsInCurrentTxn(entityIds); return new ChangeTrackingResult(changeTracking); } /** {@inheritDoc} */ @Override public @Nonnull ChangeTrackingResult loadEntitiesChangeTracking( - @Nonnull PolarisCallContext callCtx, @Nonnull List entityIds) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + @Nonnull List entityIds) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read transaction - return ms.runInReadTransaction( - callCtx, () -> this.loadEntitiesChangeTracking(callCtx, ms, entityIds)); + return ms.runInReadTransaction(() -> this.loadEntitiesChangeTracking(ms, entityIds)); } - /** Refer to {@link #loadEntity(PolarisCallContext, long, long, PolarisEntityType)} */ + /** Refer to {@link PolarisMetaStoreManager#loadEntity(long, long, PolarisEntityType)} */ private @Nonnull EntityResult loadEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, long entityCatalogId, long entityId, int entityTypeCode) { // this is an easy one PolarisBaseEntity entity = - ms.lookupEntityInCurrentTxn(callCtx, entityCatalogId, entityId, entityTypeCode); + ms.lookupEntityInCurrentTxn(entityCatalogId, entityId, entityTypeCode); return (entity != null) ? new EntityResult(entity) : new EntityResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); @@ -1998,30 +1833,21 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( /** {@inheritDoc} */ @Override public @Nonnull EntityResult loadEntity( - @Nonnull PolarisCallContext callCtx, - long entityCatalogId, - long entityId, - @Nonnull PolarisEntityType entityType) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + long entityCatalogId, long entityId, @Nonnull PolarisEntityType entityType) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read transaction return ms.runInReadTransaction( - callCtx, - () -> this.loadEntity(callCtx, ms, entityCatalogId, entityId, entityType.getCode())); + () -> this.loadEntity(ms, entityCatalogId, entityId, entityType.getCode())); } - /** Refer to {@link #loadTasks(PolarisCallContext, String, PageToken)} */ + /** Refer to {@link PolarisMetaStoreManager#loadTasks(String, PageToken)} */ private @Nonnull EntitiesResult loadTasks( - @Nonnull PolarisCallContext callCtx, - @Nonnull TransactionalPersistence ms, - String executorId, - PageToken pageToken) { + @Nonnull TransactionalPersistence ms, String executorId, PageToken pageToken) { // find all available tasks Page availableTasks = ms.loadEntitiesInCurrentTxn( - callCtx, PolarisEntityConstants.getRootEntityId(), PolarisEntityConstants.getRootEntityId(), PolarisEntityType.TASK, @@ -2030,8 +1856,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( PolarisObjectMapperUtil.TaskExecutionState taskState = PolarisObjectMapperUtil.parseTaskState(entity); long taskAgeTimeout = - callCtx - .getRealmConfig() + getRealmConfig() .getConfig( PolarisTaskConstants.TASK_TIMEOUT_MILLIS_CONFIG, PolarisTaskConstants.TASK_TIMEOUT_MILLIS); @@ -2059,7 +1884,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( + 1)); updatedTask.propertiesAsMap(properties); EntityResult result = - updateEntityPropertiesIfNotChanged(callCtx, ms, null, updatedTask.build()); + updateEntityPropertiesIfNotChanged(ms, null, updatedTask.build()); if (result.getReturnStatus() == BaseResult.ReturnStatus.SUCCESS) { return result.getEntity(); } else { @@ -2079,16 +1904,14 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( } @Override - public @Nonnull EntitiesResult loadTasks( - @Nonnull PolarisCallContext callCtx, String executorId, PageToken pageToken) { - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); - return ms.runInTransaction(callCtx, () -> this.loadTasks(callCtx, ms, executorId, pageToken)); + public @Nonnull EntitiesResult loadTasks(String executorId, PageToken pageToken) { + TransactionalPersistence ms = getMetaStore(); + return ms.runInTransaction(() -> this.loadTasks(ms, executorId, pageToken)); } /** {@inheritDoc} */ @Override public @Nonnull ScopedCredentialsResult getSubscopedCredsForEntity( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, PolarisEntityType entityType, @@ -2098,14 +1921,14 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( Optional refreshCredentialsEndpoint) { // get meta store session we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); getDiagnostics() .check( !allowedReadLocations.isEmpty() || !allowedWriteLocations.isEmpty(), "allowed_locations_to_subscope_is_required"); // reload the entity, error out if not found - EntityResult reloadedEntity = loadEntity(callCtx, catalogId, entityId, entityType); + EntityResult reloadedEntity = loadEntity(catalogId, entityId, entityType); if (reloadedEntity.getReturnStatus() != BaseResult.ReturnStatus.SUCCESS) { return new ScopedCredentialsResult( reloadedEntity.getReturnStatus(), reloadedEntity.getExtraInformation()); @@ -2113,7 +1936,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // get storage integration PolarisStorageIntegration storageIntegration = - ms.loadPolarisStorageIntegrationInCurrentTxn(callCtx, reloadedEntity.getEntity()); + ms.loadPolarisStorageIntegrationInCurrentTxn(reloadedEntity.getEntity()); // cannot be null getDiagnostics() @@ -2127,7 +1950,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( try { AccessConfig accessConfig = storageIntegration.getSubscopedCreds( - callCtx.getRealmConfig(), + getRealmConfig(), allowListOperation, allowedReadLocations, allowedWriteLocations, @@ -2139,17 +1962,12 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( } } - /** {@link #loadResolvedEntityById(PolarisCallContext, long, long, PolarisEntityType)} */ + /** {@link PolarisMetaStoreManager#loadResolvedEntityById(long, long, PolarisEntityType)} */ private @Nonnull ResolvedEntityResult loadResolvedEntityById( - @Nonnull PolarisCallContext callCtx, - @Nonnull TransactionalPersistence ms, - long entityCatalogId, - long entityId, - int typeCode) { + @Nonnull TransactionalPersistence ms, long entityCatalogId, long entityId, int typeCode) { // load that entity - PolarisBaseEntity entity = - ms.lookupEntityInCurrentTxn(callCtx, entityCatalogId, entityId, typeCode); + PolarisBaseEntity entity = ms.lookupEntityInCurrentTxn(entityCatalogId, entityId, typeCode); // if entity not found, return null if (entity == null) { @@ -2160,13 +1978,10 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( final List grantRecords; if (entity.getType().isGrantee()) { grantRecords = - new ArrayList<>( - ms.loadAllGrantRecordsOnGranteeInCurrentTxn(callCtx, entityCatalogId, entityId)); - grantRecords.addAll( - ms.loadAllGrantRecordsOnSecurableInCurrentTxn(callCtx, entityCatalogId, entityId)); + new ArrayList<>(ms.loadAllGrantRecordsOnGranteeInCurrentTxn(entityCatalogId, entityId)); + grantRecords.addAll(ms.loadAllGrantRecordsOnSecurableInCurrentTxn(entityCatalogId, entityId)); } else { - grantRecords = - ms.loadAllGrantRecordsOnSecurableInCurrentTxn(callCtx, entityCatalogId, entityId); + grantRecords = ms.loadAllGrantRecordsOnSecurableInCurrentTxn(entityCatalogId, entityId); } // return the result @@ -2176,24 +1991,16 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( /** {@inheritDoc} */ @Override public @Nonnull ResolvedEntityResult loadResolvedEntityById( - @Nonnull PolarisCallContext callCtx, - long entityCatalogId, - long entityId, - PolarisEntityType entityType) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + long entityCatalogId, long entityId, PolarisEntityType entityType) { + TransactionalPersistence ms = getMetaStore(); // need to run inside a read transaction return ms.runInReadTransaction( - callCtx, - () -> - this.loadResolvedEntityById( - callCtx, ms, entityCatalogId, entityId, entityType.getCode())); + () -> this.loadResolvedEntityById(ms, entityCatalogId, entityId, entityType.getCode())); } - /** {@link #loadResolvedEntityById(PolarisCallContext, long, long, PolarisEntityType)} */ + /** {@link PolarisMetaStoreManager#loadResolvedEntityById(long, long, PolarisEntityType)} */ private @Nonnull ResolvedEntityResult loadResolvedEntityByName( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, long entityCatalogId, long parentId, @@ -2203,7 +2010,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // load that entity PolarisBaseEntity entity = ms.lookupEntityByNameInCurrentTxn( - callCtx, entityCatalogId, parentId, entityType.getCode(), entityName); + entityCatalogId, parentId, entityType.getCode(), entityName); // null if entity not found if (entity == null) { @@ -2215,13 +2022,11 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( if (entity.getType().isGrantee()) { grantRecords = new ArrayList<>( - ms.loadAllGrantRecordsOnGranteeInCurrentTxn( - callCtx, entityCatalogId, entity.getId())); + ms.loadAllGrantRecordsOnGranteeInCurrentTxn(entityCatalogId, entity.getId())); grantRecords.addAll( - ms.loadAllGrantRecordsOnSecurableInCurrentTxn(callCtx, entityCatalogId, entity.getId())); + ms.loadAllGrantRecordsOnSecurableInCurrentTxn(entityCatalogId, entity.getId())); } else { - grantRecords = - ms.loadAllGrantRecordsOnSecurableInCurrentTxn(callCtx, entityCatalogId, entity.getId()); + grantRecords = ms.loadAllGrantRecordsOnSecurableInCurrentTxn(entityCatalogId, entity.getId()); } // return the result @@ -2231,27 +2036,23 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( /** {@inheritDoc} */ @Override public @Nonnull ResolvedEntityResult loadResolvedEntityByName( - @Nonnull PolarisCallContext callCtx, long entityCatalogId, long parentId, @Nonnull PolarisEntityType entityType, @Nonnull String entityName) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // need to run inside a read transaction ResolvedEntityResult result = ms.runInReadTransaction( - callCtx, () -> this.loadResolvedEntityByName( - callCtx, ms, entityCatalogId, parentId, entityType, entityName)); + ms, entityCatalogId, parentId, entityType, entityName)); if (PolarisEntityConstants.getRootContainerName().equals(entityName) && entityType == PolarisEntityType.ROOT && !result.isSuccess()) { // Backfill rootContainer if needed. ms.runActionInTransaction( - callCtx, () -> { PolarisBaseEntity rootContainer = new PolarisBaseEntity( @@ -2261,23 +2062,17 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( PolarisEntitySubType.NULL_SUBTYPE, PolarisEntityConstants.getRootEntityId(), PolarisEntityConstants.getRootContainerName()); - EntityResult backfillResult = - this.createEntityIfNotExists(callCtx, ms, null, rootContainer); + EntityResult backfillResult = this.createEntityIfNotExists(ms, null, rootContainer); if (backfillResult.isSuccess()) { PolarisBaseEntity serviceAdminRole = ms.lookupEntityByNameInCurrentTxn( - callCtx, 0L, 0L, PolarisEntityType.PRINCIPAL_ROLE.getCode(), PolarisEntityConstants.getNameOfPrincipalServiceAdminRole()); if (serviceAdminRole != null) { this.persistNewGrantRecord( - callCtx, - ms, - rootContainer, - serviceAdminRole, - PolarisPrivilege.SERVICE_MANAGE_ACCESS); + ms, rootContainer, serviceAdminRole, PolarisPrivilege.SERVICE_MANAGE_ACCESS); } } }); @@ -2285,17 +2080,15 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // Redo the lookup in a separate read transaction. result = ms.runInReadTransaction( - callCtx, () -> this.loadResolvedEntityByName( - callCtx, ms, entityCatalogId, parentId, entityType, entityName)); + ms, entityCatalogId, parentId, entityType, entityName)); } return result; } /** {@inheritDoc} */ private @Nonnull ResolvedEntityResult refreshResolvedEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, int entityVersion, int entityGrantRecordsVersion, @@ -2305,8 +2098,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // load version information PolarisChangeTrackingVersions entityVersions = - ms.lookupEntityVersionsInCurrentTxn( - callCtx, List.of(new PolarisEntityId(entityCatalogId, entityId))) + ms.lookupEntityVersionsInCurrentTxn(List.of(new PolarisEntityId(entityCatalogId, entityId))) .get(0); // if null, the entity has been purged @@ -2317,8 +2109,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( // load the entity if something changed final PolarisBaseEntity entity; if (entityVersion != entityVersions.getEntityVersion()) { - entity = - ms.lookupEntityInCurrentTxn(callCtx, entityCatalogId, entityId, entityType.getCode()); + entity = ms.lookupEntityInCurrentTxn(entityCatalogId, entityId, entityType.getCode()); // if not found, return null if (entity == null) { @@ -2334,13 +2125,11 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( if (entityVersions.getGrantRecordsVersion() != entityGrantRecordsVersion) { if (entityType.isGrantee()) { grantRecords = - new ArrayList<>( - ms.loadAllGrantRecordsOnGranteeInCurrentTxn(callCtx, entityCatalogId, entityId)); + new ArrayList<>(ms.loadAllGrantRecordsOnGranteeInCurrentTxn(entityCatalogId, entityId)); grantRecords.addAll( - ms.loadAllGrantRecordsOnSecurableInCurrentTxn(callCtx, entityCatalogId, entityId)); + ms.loadAllGrantRecordsOnSecurableInCurrentTxn(entityCatalogId, entityId)); } else { - grantRecords = - ms.loadAllGrantRecordsOnSecurableInCurrentTxn(callCtx, entityCatalogId, entityId); + grantRecords = ms.loadAllGrantRecordsOnSecurableInCurrentTxn(entityCatalogId, entityId); } } else { grantRecords = null; @@ -2353,21 +2142,17 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( /** {@inheritDoc} */ @Override public @Nonnull ResolvedEntityResult refreshResolvedEntity( - @Nonnull PolarisCallContext callCtx, int entityVersion, int entityGrantRecordsVersion, @Nonnull PolarisEntityType entityType, long entityCatalogId, long entityId) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); // need to run inside a read transaction return ms.runInReadTransaction( - callCtx, () -> this.refreshResolvedEntity( - callCtx, ms, entityVersion, entityGrantRecordsVersion, @@ -2379,41 +2164,33 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( /** {@inheritDoc} */ @Override public - Optional> hasOverlappingSiblings( - @Nonnull PolarisCallContext callContext, T entity) { - TransactionalPersistence ms = ((TransactionalPersistence) callContext.getMetaStore()); - return ms.runInTransaction( - callContext, - () -> { - return callContext.getMetaStore().hasOverlappingSiblings(callContext, entity); - }); + Optional> hasOverlappingSiblings(T entity) { + TransactionalPersistence ms = getMetaStore(); + return ms.runInTransaction(() -> ms.hasOverlappingSiblings(entity)); } /** {@inheritDoc} */ @Override public @Nonnull PolicyAttachmentResult attachPolicyToEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull List targetCatalogPath, @Nonnull PolarisEntityCore target, @Nonnull List policyCatalogPath, @Nonnull PolicyEntity policy, Map parameters) { - // get metastore we should be using - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); return ms.runInTransaction( - callCtx, () -> this.doAttachPolicyToEntity( - callCtx, ms, targetCatalogPath, target, policyCatalogPath, policy, parameters)); + ms, targetCatalogPath, target, policyCatalogPath, policy, parameters)); } /** - * See {@link #attachPolicyToEntity(PolarisCallContext, List, PolarisEntityCore, List, - * PolicyEntity, Map)} + * See {@link + * org.apache.polaris.core.policy.PolarisPolicyMappingManager#attachPolicyToEntity(List, + * PolarisEntityCore, List, PolicyEntity, Map)} */ private @Nonnull PolicyAttachmentResult doAttachPolicyToEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull List targetCatalogPath, @Nonnull PolarisEntityCore target, @@ -2421,54 +2198,51 @@ Optional> hasOverlappingSiblings( @Nonnull PolicyEntity policy, Map parameters) { PolarisEntityResolver targetResolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, targetCatalogPath, target); + new PolarisEntityResolver(getDiagnostics(), ms, targetCatalogPath, target); PolarisEntityResolver policyResolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, policyCatalogPath, policy); + new PolarisEntityResolver(getDiagnostics(), ms, policyCatalogPath, policy); if (targetResolver.isFailure() || policyResolver.isFailure()) { return new PolicyAttachmentResult(BaseResult.ReturnStatus.ENTITY_CANNOT_BE_RESOLVED, null); } - return this.persistNewPolicyMappingRecord(callCtx, ms, target, policy, parameters); + return this.persistNewPolicyMappingRecord(ms, target, policy, parameters); } /** {@inheritDoc} */ @Override public @Nonnull PolicyAttachmentResult detachPolicyFromEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull List targetCatalogPath, @Nonnull PolarisEntityCore target, @Nonnull List policyCatalogPath, @Nonnull PolicyEntity policy) { - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); + TransactionalPersistence ms = getMetaStore(); return ms.runInTransaction( - callCtx, () -> this.doDetachPolicyFromEntity( - callCtx, ms, targetCatalogPath, target, policyCatalogPath, policy)); + ms, targetCatalogPath, target, policyCatalogPath, policy)); } /** - * See {@link #detachPolicyFromEntity(PolarisCallContext, List, PolarisEntityCore, - * List,PolicyEntity)} + * See {@link + * org.apache.polaris.core.policy.PolarisPolicyMappingManager#detachPolicyFromEntity(List, + * PolarisEntityCore, List, PolicyEntity)} */ private PolicyAttachmentResult doDetachPolicyFromEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull List targetCatalogPath, @Nonnull PolarisEntityCore target, @Nonnull List policyCatalogPath, @Nonnull PolicyEntity policy) { PolarisEntityResolver targetResolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, targetCatalogPath, target); + new PolarisEntityResolver(getDiagnostics(), ms, targetCatalogPath, target); PolarisEntityResolver policyResolver = - new PolarisEntityResolver(getDiagnostics(), callCtx, ms, policyCatalogPath, policy); + new PolarisEntityResolver(getDiagnostics(), ms, policyCatalogPath, policy); if (targetResolver.isFailure() || policyResolver.isFailure()) { return new PolicyAttachmentResult(BaseResult.ReturnStatus.ENTITY_CANNOT_BE_RESOLVED, null); } PolarisPolicyMappingRecord mappingRecord = ms.lookupPolicyMappingRecordInCurrentTxn( - callCtx, target.getCatalogId(), target.getId(), policy.getPolicyTypeCode(), @@ -2478,60 +2252,58 @@ private PolicyAttachmentResult doDetachPolicyFromEntity( return new PolicyAttachmentResult(BaseResult.ReturnStatus.POLICY_MAPPING_NOT_FOUND, null); } - ms.deleteFromPolicyMappingRecordsInCurrentTxn(callCtx, mappingRecord); + ms.deleteFromPolicyMappingRecordsInCurrentTxn(mappingRecord); return new PolicyAttachmentResult(mappingRecord); } /** {@inheritDoc} */ @Override - public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore target) { - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); - return ms.runInReadTransaction(callCtx, () -> this.doLoadPoliciesOnEntity(callCtx, ms, target)); + public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntity(@Nonnull PolarisEntityCore target) { + TransactionalPersistence ms = getMetaStore(); + return ms.runInReadTransaction(() -> this.doLoadPoliciesOnEntity(ms, target)); } - /** See {@link #loadPoliciesOnEntity(PolarisCallContext, PolarisEntityCore)} */ + /** + * See {@link + * org.apache.polaris.core.policy.PolarisPolicyMappingManager#loadPoliciesOnEntity(PolarisEntityCore)} + */ private LoadPolicyMappingsResult doLoadPoliciesOnEntity( - @Nonnull PolarisCallContext callCtx, - @Nonnull TransactionalPersistence ms, - @Nonnull PolarisEntityCore target) { + @Nonnull TransactionalPersistence ms, @Nonnull PolarisEntityCore target) { PolarisBaseEntity entity = - ms.lookupEntityInCurrentTxn( - callCtx, target.getCatalogId(), target.getId(), target.getTypeCode()); + ms.lookupEntityInCurrentTxn(target.getCatalogId(), target.getId(), target.getTypeCode()); if (entity == null) { // Target entity does not exists return new LoadPolicyMappingsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); } final List policyMappingRecords = - ms.loadAllPoliciesOnTargetInCurrentTxn(callCtx, target.getCatalogId(), target.getId()); + ms.loadAllPoliciesOnTargetInCurrentTxn(target.getCatalogId(), target.getId()); List policyEntities = - loadPoliciesFromMappingRecords(callCtx, ms, policyMappingRecords); + loadPoliciesFromMappingRecords(ms, policyMappingRecords); return new LoadPolicyMappingsResult(policyMappingRecords, policyEntities); } /** {@inheritDoc} */ @Override public @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntityByType( - @Nonnull PolarisCallContext callCtx, - @Nonnull PolarisEntityCore target, - @Nonnull PolicyType policyType) { - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); - return ms.runInReadTransaction( - callCtx, () -> this.doLoadPoliciesOnEntityByType(callCtx, ms, target, policyType)); + @Nonnull PolarisEntityCore target, @Nonnull PolicyType policyType) { + TransactionalPersistence ms = getMetaStore(); + return ms.runInReadTransaction(() -> this.doLoadPoliciesOnEntityByType(ms, target, policyType)); } - /** See {@link #loadPoliciesOnEntityByType(PolarisCallContext, PolarisEntityCore, PolicyType)} */ + /** + * See {@link + * org.apache.polaris.core.policy.PolarisPolicyMappingManager#loadPoliciesOnEntityByType(PolarisEntityCore, + * PolicyType)} + */ private LoadPolicyMappingsResult doLoadPoliciesOnEntityByType( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull PolarisEntityCore target, @Nonnull PolicyType policyType) { PolarisBaseEntity entity = - ms.lookupEntityInCurrentTxn( - callCtx, target.getCatalogId(), target.getId(), target.getTypeCode()); + ms.lookupEntityInCurrentTxn(target.getCatalogId(), target.getId(), target.getTypeCode()); if (entity == null) { // Target entity does not exists return new LoadPolicyMappingsResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null); @@ -2539,16 +2311,15 @@ private LoadPolicyMappingsResult doLoadPoliciesOnEntityByType( final List policyMappingRecords = ms.loadPoliciesOnTargetByTypeInCurrentTxn( - callCtx, target.getCatalogId(), target.getId(), policyType.getCode()); + target.getCatalogId(), target.getId(), policyType.getCode()); List policyEntities = - loadPoliciesFromMappingRecords(callCtx, ms, policyMappingRecords); + loadPoliciesFromMappingRecords(ms, policyMappingRecords); return new LoadPolicyMappingsResult(policyMappingRecords, policyEntities); } /** * Create and persist a new policy mapping record * - * @param callCtx call context * @param ms meta store in read/write mode * @param target target * @param policy policy @@ -2556,7 +2327,6 @@ private LoadPolicyMappingsResult doLoadPoliciesOnEntityByType( * @return new policy mapping record which was created and persisted */ private @Nonnull PolicyAttachmentResult persistNewPolicyMappingRecord( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull PolarisEntityCore target, @Nonnull PolicyEntity policy, @@ -2574,8 +2344,8 @@ private LoadPolicyMappingsResult doLoadPoliciesOnEntityByType( parameters); try { - ms.checkConditionsForWriteToPolicyMappingRecordsInCurrentTxn(callCtx, mappingRecord); - ms.writeToPolicyMappingRecordsInCurrentTxn(callCtx, mappingRecord); + ms.checkConditionsForWriteToPolicyMappingRecordsInCurrentTxn(mappingRecord); + ms.writeToPolicyMappingRecordsInCurrentTxn(mappingRecord); } catch (IllegalArgumentException e) { return new PolicyAttachmentResult( BaseResult.ReturnStatus.UNEXPECTED_ERROR_SIGNALED, "Unknown policy type"); @@ -2591,13 +2361,11 @@ private LoadPolicyMappingsResult doLoadPoliciesOnEntityByType( /** * Load policies from a list of policy mapping records * - * @param callCtx call context * @param ms meta store * @param policyMappingRecords a list of policy mapping records * @return a list of policy entities */ private List loadPoliciesFromMappingRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull TransactionalPersistence ms, @Nonnull List policyMappingRecords) { List policyEntityIds = @@ -2609,6 +2377,6 @@ private List loadPoliciesFromMappingRecords( policyMappingRecord.getPolicyId())) .distinct() .collect(Collectors.toList()); - return ms.lookupEntitiesInCurrentTxn(callCtx, policyEntityIds); + return ms.lookupEntitiesInCurrentTxn(policyEntityIds); } } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalPersistence.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalPersistence.java index 3802908b82..ed8902804c 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalPersistence.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TransactionalPersistence.java @@ -24,7 +24,6 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.EntityNameLookupRecord; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisChangeTrackingVersions; @@ -58,10 +57,9 @@ public interface TransactionalPersistence * error. The result of the supplier lambda is returned if success, else the error will be * re-thrown. * - * @param callCtx call context * @param transactionCode code of the transaction being executed, a supplier lambda */ - T runInTransaction(@Nonnull PolarisCallContext callCtx, @Nonnull Supplier transactionCode); + T runInTransaction(@Nonnull Supplier transactionCode); /** * Run the specified transaction code (a runnable lambda type) in a database read/write @@ -69,11 +67,9 @@ public interface TransactionalPersistence * the transaction will be committed, else the transaction will be automatically rolled-back on * error. * - * @param callCtx call context * @param transactionCode code of the transaction being executed, a runnable lambda */ - void runActionInTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode); + void runActionInTransaction(@Nonnull Runnable transactionCode); /** * Run the specified transaction code (a Supplier lambda type) in a database read transaction. If @@ -81,22 +77,18 @@ void runActionInTransaction( * will be committed, else the transaction will be automatically rolled-back on error. The result * of the supplier lambda is returned if success, else the error will be re-thrown. * - * @param callCtx call context * @param transactionCode code of the transaction being executed, a supplier lambda */ - T runInReadTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Supplier transactionCode); + T runInReadTransaction(@Nonnull Supplier transactionCode); /** * Run the specified transaction code (a runnable lambda type) in a database read transaction. If * the code of the transaction does not throw any exception and returns normally, the transaction * will be committed, else the transaction will be automatically rolled-back on error. * - * @param callCtx call context * @param transactionCode code of the transaction being executed, a runnable lambda */ - void runActionInReadTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode); + void runActionInReadTransaction(@Nonnull Runnable transactionCode); /** * Lookup the specified set of entities by entityActiveKeys Return the result, a parallel list of @@ -106,7 +98,7 @@ void runActionInReadTransaction( */ @Nonnull List lookupEntityActiveBatchInCurrentTxn( - @Nonnull PolarisCallContext callCtx, List entityActiveKeys); + List entityActiveKeys); /** Rollback the current transaction */ void rollback(); @@ -121,7 +113,7 @@ List lookupEntityActiveBatchInCurrentTxn( // /** See {@link org.apache.polaris.core.persistence.BasePersistence#generateNewId} */ - long generateNewIdInCurrentTxn(@Nonnull PolarisCallContext callCtx); + long generateNewIdInCurrentTxn(); /** * See {@link org.apache.polaris.core.persistence.BasePersistence#writeEntity} @@ -134,73 +126,57 @@ List lookupEntityActiveBatchInCurrentTxn( * entity, but TransactionalPersistence::writeEntityInCurrentTxn is *not* expected to do the same. */ void writeEntityInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, boolean nameOrParentChanged, @Nullable PolarisBaseEntity originalEntity); /** See {@link org.apache.polaris.core.persistence.BasePersistence#writeEntities} */ void writeEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull List entities, @Nullable List originalEntities); /** See {@link org.apache.polaris.core.persistence.BasePersistence#writeToGrantRecords} */ - void writeToGrantRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec); + void writeToGrantRecordsInCurrentTxn(@Nonnull PolarisGrantRecord grantRec); /** See {@link org.apache.polaris.core.persistence.BasePersistence#deleteEntity} */ - void deleteEntityInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity); + void deleteEntityInCurrentTxn(@Nonnull PolarisBaseEntity entity); /** See {@link org.apache.polaris.core.persistence.BasePersistence#deleteFromGrantRecords} */ - void deleteFromGrantRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec); + void deleteFromGrantRecordsInCurrentTxn(@Nonnull PolarisGrantRecord grantRec); /** See {@link org.apache.polaris.core.persistence.BasePersistence#deleteAllEntityGrantRecords} */ void deleteAllEntityGrantRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity, @Nonnull List grantsOnGrantee, @Nonnull List grantsOnSecurable); /** See {@link org.apache.polaris.core.persistence.BasePersistence#deleteAll} */ - void deleteAllInCurrentTxn(@Nonnull PolarisCallContext callCtx); + void deleteAllInCurrentTxn(); /** See {@link org.apache.polaris.core.persistence.BasePersistence#lookupEntity} */ @Nullable - PolarisBaseEntity lookupEntityInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, int typeCode); + PolarisBaseEntity lookupEntityInCurrentTxn(long catalogId, long entityId, int typeCode); /** See {@link org.apache.polaris.core.persistence.BasePersistence#lookupEntityByName} */ @Nullable PolarisBaseEntity lookupEntityByNameInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - long catalogId, - long parentId, - int typeCode, - @Nonnull String name); + long catalogId, long parentId, int typeCode, @Nonnull String name); /** * See {@link org.apache.polaris.core.persistence.BasePersistence#lookupEntityIdAndSubTypeByName} */ @Nullable EntityNameLookupRecord lookupEntityIdAndSubTypeByNameInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - long catalogId, - long parentId, - int typeCode, - @Nonnull String name); + long catalogId, long parentId, int typeCode, @Nonnull String name); /** See {@link org.apache.polaris.core.persistence.BasePersistence#lookupEntities} */ @Nonnull - List lookupEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, List entityIds); + List lookupEntitiesInCurrentTxn(List entityIds); /** See {@link org.apache.polaris.core.persistence.BasePersistence#lookupEntityVersions} */ @Nonnull List lookupEntityVersionsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, List entityIds); + List entityIds); /** * See {@link org.apache.polaris.core.persistence.BasePersistence#listEntities}. Implementations @@ -208,14 +184,12 @@ List lookupEntityVersionsInCurrentTxn( * the entity properties to build the EntityNameLookupRecord). */ default @Nonnull Page listEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long parentId, @Nonnull PolarisEntityType entityType, @Nonnull PolarisEntitySubType entitySubType, @Nonnull PageToken pageToken) { return loadEntitiesInCurrentTxn( - callCtx, catalogId, parentId, entityType, @@ -228,7 +202,6 @@ List lookupEntityVersionsInCurrentTxn( /** See {@link org.apache.polaris.core.persistence.BasePersistence#loadEntities} */ @Nonnull Page loadEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long parentId, @Nonnull PolarisEntityType entityType, @@ -240,13 +213,11 @@ Page loadEntitiesInCurrentTxn( /** * See {@link org.apache.polaris.core.persistence.BasePersistence#lookupEntityGrantRecordsVersion} */ - int lookupEntityGrantRecordsVersionInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId); + int lookupEntityGrantRecordsVersionInCurrentTxn(long catalogId, long entityId); /** See {@link org.apache.polaris.core.persistence.BasePersistence#lookupGrantRecord} */ @Nullable PolarisGrantRecord lookupGrantRecordInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId, long granteeCatalogId, @@ -258,26 +229,22 @@ PolarisGrantRecord lookupGrantRecordInCurrentTxn( */ @Nonnull List loadAllGrantRecordsOnSecurableInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId); + long securableCatalogId, long securableId); /** * See {@link org.apache.polaris.core.persistence.BasePersistence#loadAllGrantRecordsOnGrantee} */ @Nonnull List loadAllGrantRecordsOnGranteeInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long granteeCatalogId, long granteeId); + long granteeCatalogId, long granteeId); /** See {@link org.apache.polaris.core.persistence.BasePersistence#hasChildren} */ boolean hasChildrenInCurrentTxn( - @Nonnull PolarisCallContext callContext, - @Nullable PolarisEntityType optionalEntityType, - long catalogId, - long parentId); + @Nullable PolarisEntityType optionalEntityType, long catalogId, long parentId); /** See {@link org.apache.polaris.core.persistence.IntegrationPersistence#loadPrincipalSecrets} */ @Nullable - PolarisPrincipalSecrets loadPrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId); + PolarisPrincipalSecrets loadPrincipalSecretsInCurrentTxn(@Nonnull String clientId); /** * See {@link @@ -285,24 +252,19 @@ PolarisPrincipalSecrets loadPrincipalSecretsInCurrentTxn( */ @Nonnull PolarisPrincipalSecrets generateNewPrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull String principalName, long principalId); + @Nonnull String principalName, long principalId); /** * See {@link org.apache.polaris.core.persistence.IntegrationPersistence#rotatePrincipalSecrets} */ @Nullable PolarisPrincipalSecrets rotatePrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - @Nonnull String clientId, - long principalId, - boolean reset, - @Nonnull String oldSecretHash); + @Nonnull String clientId, long principalId, boolean reset, @Nonnull String oldSecretHash); /** * See {@link org.apache.polaris.core.persistence.IntegrationPersistence#deletePrincipalSecrets} */ - void deletePrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId, long principalId); + void deletePrincipalSecretsInCurrentTxn(@Nonnull String clientId, long principalId); /** * See {@link org.apache.polaris.core.persistence.IntegrationPersistence#createStorageIntegration} @@ -310,7 +272,6 @@ void deletePrincipalSecretsInCurrentTxn( @Nullable PolarisStorageIntegration createStorageIntegrationInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, PolarisStorageConfigurationInfo polarisStorageConfigurationInfo); @@ -320,9 +281,7 @@ PolarisStorageIntegration createStorageIntegrationInCurrentTxn( * org.apache.polaris.core.persistence.IntegrationPersistence#persistStorageIntegrationIfNeeded} */ void persistStorageIntegrationIfNeededInCurrentTxn( - @Nonnull PolarisCallContext callContext, - @Nonnull PolarisBaseEntity entity, - @Nullable PolarisStorageIntegration storageIntegration); + @Nonnull PolarisBaseEntity entity, @Nullable PolarisStorageIntegration storageIntegration); /** * See {@link @@ -331,5 +290,5 @@ void persistStorageIntegrationIfNeed @Nullable PolarisStorageIntegration loadPolarisStorageIntegrationInCurrentTxn( - @Nonnull PolarisCallContext callContext, @Nonnull PolarisBaseEntity entity); + @Nonnull PolarisBaseEntity entity); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java index a4bf1d9461..85b01be3e2 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java @@ -28,7 +28,6 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; -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; @@ -75,8 +74,7 @@ public TreeMapTransactionalPersistenceImpl( /** {@inheritDoc} */ @Override - public T runInTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Supplier transactionCode) { + public T runInTransaction(@Nonnull Supplier transactionCode) { // run transaction on our underlying store return store.runInTransaction(getDiagnostics(), transactionCode); @@ -84,8 +82,7 @@ public T runInTransaction( /** {@inheritDoc} */ @Override - public void runActionInTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) { + public void runActionInTransaction(@Nonnull Runnable transactionCode) { // run transaction on our underlying store store.runActionInTransaction(getDiagnostics(), transactionCode); @@ -93,16 +90,14 @@ public void runActionInTransaction( /** {@inheritDoc} */ @Override - public T runInReadTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Supplier transactionCode) { + public T runInReadTransaction(@Nonnull Supplier transactionCode) { // run transaction on our underlying store return store.runInReadTransaction(getDiagnostics(), transactionCode); } /** {@inheritDoc} */ @Override - public void runActionInReadTransaction( - @Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) { + public void runActionInReadTransaction(@Nonnull Runnable transactionCode) { // run transaction on our underlying store store.runActionInReadTransaction(getDiagnostics(), transactionCode); @@ -112,14 +107,13 @@ public void runActionInReadTransaction( * @return new unique entity identifier */ @Override - public long generateNewIdInCurrentTxn(@Nonnull PolarisCallContext callCtx) { + public long generateNewIdInCurrentTxn() { return this.store.getNextSequence(); } /** {@inheritDoc} */ @Override - public void writeToEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { + public void writeToEntitiesInCurrentTxn(@Nonnull PolarisBaseEntity entity) { // write it this.store.getSliceEntities().write(entity); } @@ -128,7 +122,6 @@ public void writeToEntitiesInCurrentTxn( @Override public void persistStorageIntegrationIfNeededInCurrentTxn( - @Nonnull PolarisCallContext callContext, @Nonnull PolarisBaseEntity entity, @Nullable PolarisStorageIntegration storageIntegration) { // not implemented for in-memory store @@ -136,24 +129,21 @@ void persistStorageIntegrationIfNeededInCurrentTxn( /** {@inheritDoc} */ @Override - public void writeToEntitiesActiveInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { + public void writeToEntitiesActiveInCurrentTxn(@Nonnull PolarisBaseEntity entity) { // write it this.store.getSliceEntitiesActive().write(entity); } /** {@inheritDoc} */ @Override - public void writeToEntitiesChangeTrackingInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { + public void writeToEntitiesChangeTrackingInCurrentTxn(@Nonnull PolarisBaseEntity entity) { // write it this.store.getSliceEntitiesChangeTracking().write(entity); } /** {@inheritDoc} */ @Override - public void writeToGrantRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec) { + public void writeToGrantRecordsInCurrentTxn(@Nonnull PolarisGrantRecord grantRec) { // write it this.store.getSliceGrantRecords().write(grantRec); this.store.getSliceGrantRecordsByGrantee().write(grantRec); @@ -161,8 +151,7 @@ public void writeToGrantRecordsInCurrentTxn( /** {@inheritDoc} */ @Override - public void deleteFromEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity) { + public void deleteFromEntitiesInCurrentTxn(@Nonnull PolarisEntityCore entity) { // delete it this.store.getSliceEntities().delete(this.store.buildEntitiesKey(entity)); @@ -170,8 +159,7 @@ public void deleteFromEntitiesInCurrentTxn( /** {@inheritDoc} */ @Override - public void deleteFromEntitiesActiveInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity) { + public void deleteFromEntitiesActiveInCurrentTxn(@Nonnull PolarisEntityCore entity) { // delete it this.store.getSliceEntitiesActive().delete(this.store.buildEntitiesActiveKey(entity)); } @@ -179,20 +167,17 @@ public void deleteFromEntitiesActiveInCurrentTxn( /** * {@inheritDoc} * - * @param callCtx * @param entity entity record to delete */ @Override - public void deleteFromEntitiesChangeTrackingInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity) { + public void deleteFromEntitiesChangeTrackingInCurrentTxn(@Nonnull PolarisEntityCore entity) { // delete it this.store.getSliceEntitiesChangeTracking().delete(this.store.buildEntitiesKey(entity)); } /** {@inheritDoc} */ @Override - public void deleteFromGrantRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisGrantRecord grantRec) { + public void deleteFromGrantRecordsInCurrentTxn(@Nonnull PolarisGrantRecord grantRec) { // delete it this.store.getSliceGrantRecords().delete(grantRec); @@ -202,7 +187,6 @@ public void deleteFromGrantRecordsInCurrentTxn( /** {@inheritDoc} */ @Override public void deleteAllEntityGrantRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore entity, @Nonnull List grantsOnGrantee, @Nonnull List grantsOnSecurable) { @@ -220,7 +204,7 @@ public void deleteAllEntityGrantRecordsInCurrentTxn( /** {@inheritDoc} */ @Override - public void deleteAllInCurrentTxn(@Nonnull PolarisCallContext callCtx) { + public void deleteAllInCurrentTxn() { // clear all slices this.store.deleteAll(); } @@ -228,7 +212,7 @@ public void deleteAllInCurrentTxn(@Nonnull PolarisCallContext callCtx) { /** {@inheritDoc} */ @Override public @Nullable PolarisBaseEntity lookupEntityInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, int typeCode) { + long catalogId, long entityId, int typeCode) { PolarisBaseEntity entity = this.store.getSliceEntities().read(this.store.buildKeyComposite(catalogId, entityId)); if (entity != null && entity.getTypeCode() != typeCode) { @@ -240,7 +224,7 @@ public void deleteAllInCurrentTxn(@Nonnull PolarisCallContext callCtx) { /** {@inheritDoc} */ @Override public @Nonnull List lookupEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, List entityIds) { + List entityIds) { // allocate return list return entityIds.stream() .map( @@ -254,7 +238,7 @@ public void deleteAllInCurrentTxn(@Nonnull PolarisCallContext callCtx) { /** {@inheritDoc} */ @Override public @Nonnull List lookupEntityVersionsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, List entityIds) { + List entityIds) { // allocate return list return entityIds.stream() .map( @@ -275,7 +259,7 @@ public void deleteAllInCurrentTxn(@Nonnull PolarisCallContext callCtx) { @Override @Nullable public EntityNameLookupRecord lookupEntityActiveInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntitiesActiveKey entityActiveKey) { + @Nonnull PolarisEntitiesActiveKey entityActiveKey) { // lookup the active entity slice PolarisBaseEntity entity = this.store @@ -295,17 +279,15 @@ public EntityNameLookupRecord lookupEntityActiveInCurrentTxn( @Override @Nonnull public List lookupEntityActiveBatchInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull List entityActiveKeys) { // now build a list to quickly verify that nothing has changed return entityActiveKeys.stream() - .map(entityActiveKey -> this.lookupEntityActiveInCurrentTxn(callCtx, entityActiveKey)) + .map(entityActiveKey -> this.lookupEntityActiveInCurrentTxn(entityActiveKey)) .collect(Collectors.toList()); } @Override public @Nonnull Page loadEntitiesInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long parentId, @Nonnull PolarisEntityType entityType, @@ -323,7 +305,7 @@ public List lookupEntityActiveBatchInCurrentTxn( .map( nameRecord -> this.lookupEntityInCurrentTxn( - callCtx, catalogId, nameRecord.getId(), entityType.getCode())); + catalogId, nameRecord.getId(), entityType.getCode())); Predicate tokenFilter = pageToken @@ -349,10 +331,7 @@ public List lookupEntityActiveBatchInCurrentTxn( /** {@inheritDoc} */ @Override public boolean hasChildrenInCurrentTxn( - @Nonnull PolarisCallContext callContext, - @Nullable PolarisEntityType entityType, - long catalogId, - long parentId) { + @Nullable PolarisEntityType entityType, long catalogId, long parentId) { // determine key prefix, add type if one is passed-in String prefixKey = entityType == null @@ -364,8 +343,7 @@ public boolean hasChildrenInCurrentTxn( /** {@inheritDoc} */ @Override - public int lookupEntityGrantRecordsVersionInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId) { + public int lookupEntityGrantRecordsVersionInCurrentTxn(long catalogId, long entityId) { PolarisBaseEntity entity = this.store .getSliceEntitiesChangeTracking() @@ -378,7 +356,6 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nullable PolarisGrantRecord lookupGrantRecordInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId, long granteeCatalogId, @@ -395,7 +372,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nonnull List loadAllGrantRecordsOnSecurableInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long securableCatalogId, long securableId) { + long securableCatalogId, long securableId) { // now fetch all grants for this securable return this.store .getSliceGrantRecords() @@ -405,7 +382,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nonnull List loadAllGrantRecordsOnGranteeInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long granteeCatalogId, long granteeId) { + long granteeCatalogId, long granteeId) { // now fetch all grants assigned to this grantee return this.store .getSliceGrantRecordsByGrantee() @@ -415,14 +392,14 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nullable PolarisPrincipalSecrets loadPrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId) { + @Nonnull String clientId) { return this.store.getSlicePrincipalSecrets().read(clientId); } /** {@inheritDoc} */ @Override public @Nonnull PolarisPrincipalSecrets generateNewPrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull String principalName, long principalId) { + @Nonnull String principalName, long principalId) { // ensure principal client id is unique PolarisPrincipalSecrets principalSecrets; PolarisPrincipalSecrets lookupPrincipalSecrets; @@ -445,11 +422,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override public @Nonnull PolarisPrincipalSecrets rotatePrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - @Nonnull String clientId, - long principalId, - boolean reset, - @Nonnull String oldSecretHash) { + @Nonnull String clientId, long principalId, boolean reset, @Nonnull String oldSecretHash) { // load the existing secrets PolarisPrincipalSecrets principalSecrets = this.store.getSlicePrincipalSecrets().read(clientId); @@ -487,10 +460,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( @Override public @Nonnull PolarisPrincipalSecrets storePrincipalSecrets( - @Nonnull PolarisCallContext callCtx, - long principalId, - @Nonnull String resolvedClientId, - String customClientSecret) { + long principalId, @Nonnull String resolvedClientId, String customClientSecret) { PolarisPrincipalSecrets principalSecrets = new PolarisPrincipalSecrets(principalId, resolvedClientId, customClientSecret); @@ -503,8 +473,7 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn( /** {@inheritDoc} */ @Override - public void deletePrincipalSecretsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull String clientId, long principalId) { + public void deletePrincipalSecretsInCurrentTxn(@Nonnull String clientId, long principalId) { // load the existing secrets PolarisPrincipalSecrets principalSecrets = this.store.getSlicePrincipalSecrets().read(clientId); @@ -534,7 +503,6 @@ public void deletePrincipalSecretsInCurrentTxn( @Override public @Nullable PolarisStorageIntegration createStorageIntegrationInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, PolarisStorageConfigurationInfo polarisStorageConfigurationInfo) { @@ -546,7 +514,7 @@ PolarisStorageIntegration createStorageIntegrationInCurrentTxn( @Override public @Nullable PolarisStorageIntegration loadPolarisStorageIntegrationInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) { + @Nonnull PolarisBaseEntity entity) { PolarisStorageConfigurationInfo storageConfig = BaseMetaStoreManager.extractStorageConfiguration(getDiagnostics(), entity); return storageIntegrationProvider.getStorageIntegrationForConfig(storageConfig); @@ -559,8 +527,7 @@ public void rollback() { /** {@inheritDoc} */ @Override - public void writeToPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + public void writeToPolicyMappingRecordsInCurrentTxn(@Nonnull PolarisPolicyMappingRecord record) { this.store.getSlicePolicyMappingRecords().write(record); this.store.getSlicePolicyMappingRecordsByPolicy().write(record); } @@ -568,7 +535,7 @@ public void writeToPolicyMappingRecordsInCurrentTxn( /** {@inheritDoc} */ @Override public void deleteFromPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + @Nonnull PolarisPolicyMappingRecord record) { this.store.getSlicePolicyMappingRecords().delete(record); this.store.getSlicePolicyMappingRecordsByPolicy().delete(record); } @@ -576,7 +543,6 @@ public void deleteFromPolicyMappingRecordsInCurrentTxn( /** {@inheritDoc} */ @Override public void deleteAllEntityPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, @Nonnull List mappingOnTarget, @Nonnull List mappingOnPolicy) { @@ -606,7 +572,6 @@ record -> this.store.getSlicePolicyMappingRecordsByPolicy().delete(record)); /** {@inheritDoc} */ @Override public @Nullable PolarisPolicyMappingRecord lookupPolicyMappingRecordInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId, int policyTypeCode, @@ -622,10 +587,7 @@ record -> this.store.getSlicePolicyMappingRecordsByPolicy().delete(record)); /** {@inheritDoc} */ @Override public @Nonnull List loadPoliciesOnTargetByTypeInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - long targetCatalogId, - long targetId, - int policyTypeCode) { + long targetCatalogId, long targetId, int policyTypeCode) { return this.store .getSlicePolicyMappingRecords() .readRange(this.store.buildPrefixKeyComposite(targetCatalogId, targetId, policyTypeCode)); @@ -634,7 +596,7 @@ record -> this.store.getSlicePolicyMappingRecordsByPolicy().delete(record)); /** {@inheritDoc} */ @Override public @Nonnull List loadAllPoliciesOnTargetInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId) { + long targetCatalogId, long targetId) { return this.store .getSlicePolicyMappingRecords() .readRange(this.store.buildPrefixKeyComposite(targetCatalogId, targetId)); @@ -643,10 +605,7 @@ record -> this.store.getSlicePolicyMappingRecordsByPolicy().delete(record)); /** {@inheritDoc} */ @Override public @Nonnull List loadAllTargetsOnPolicyInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - long policyCatalogId, - long policyId, - int policyTypeCode) { + long policyCatalogId, long policyId, int policyTypeCode) { return this.store .getSlicePolicyMappingRecordsByPolicy() .readRange(this.store.buildPrefixKeyComposite(policyTypeCode, policyCatalogId, policyId)); @@ -674,8 +633,7 @@ private Optional getEntityLocationWithoutScheme(PolarisBaseEntity entity /** {@inheritDoc} */ @Override public - Optional> hasOverlappingSiblings( - @Nonnull PolarisCallContext callContext, T entity) { + Optional> hasOverlappingSiblings(T entity) { // TODO we could optimize this full scan StorageLocation entityLocationWithoutScheme = StorageLocation.of(StorageLocation.of(entity.getBaseLocation()).withoutScheme()); diff --git a/polaris-core/src/main/java/org/apache/polaris/core/policy/PolarisPolicyMappingManager.java b/polaris-core/src/main/java/org/apache/polaris/core/policy/PolarisPolicyMappingManager.java index 266d5477ea..a895fbb27b 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/policy/PolarisPolicyMappingManager.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/policy/PolarisPolicyMappingManager.java @@ -21,7 +21,6 @@ import jakarta.annotation.Nonnull; import java.util.List; import java.util.Map; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.PolarisEntityCore; import org.apache.polaris.core.persistence.dao.entity.LoadPolicyMappingsResult; import org.apache.polaris.core.persistence.dao.entity.PolicyAttachmentResult; @@ -34,7 +33,6 @@ public interface PolarisPolicyMappingManager { *

For inheritable policy, only one policy of the same type can be attached to the target. For * non-inheritable policy, multiple policies of the same type can be attached to the target. * - * @param callCtx call context * @param targetCatalogPath path to the target entity * @param target target entity * @param policyCatalogPath path to the policy entity @@ -47,7 +45,6 @@ public interface PolarisPolicyMappingManager { */ @Nonnull PolicyAttachmentResult attachPolicyToEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull List targetCatalogPath, @Nonnull PolarisEntityCore target, @Nonnull List policyCatalogPath, @@ -57,7 +54,6 @@ PolicyAttachmentResult attachPolicyToEntity( /** * Detach a policy from a target entity * - * @param callCtx call context * @param catalogPath path to the target entity * @param target target entity * @param policyCatalogPath path to the policy entity @@ -68,7 +64,6 @@ PolicyAttachmentResult attachPolicyToEntity( */ @Nonnull PolicyAttachmentResult detachPolicyFromEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull List catalogPath, @Nonnull PolarisEntityCore target, @Nonnull List policyCatalogPath, @@ -77,19 +72,16 @@ PolicyAttachmentResult detachPolicyFromEntity( /** * Load all policies attached to a target entity * - * @param callCtx call context * @param target target entity * @return the list of policy mapping records on the target entity. Will return ENTITY_NOT_FOUND * if the specified target does not exist. */ @Nonnull - LoadPolicyMappingsResult loadPoliciesOnEntity( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityCore target); + LoadPolicyMappingsResult loadPoliciesOnEntity(@Nonnull PolarisEntityCore target); /** * Load all policies of a specific type attached to a target entity * - * @param callCtx call context * @param target target entity * @param policyType the type of policy * @return the list of policy mapping records on the target entity. Will return ENTITY_NOT_FOUND @@ -97,7 +89,5 @@ LoadPolicyMappingsResult loadPoliciesOnEntity( */ @Nonnull LoadPolicyMappingsResult loadPoliciesOnEntityByType( - @Nonnull PolarisCallContext callCtx, - @Nonnull PolarisEntityCore target, - @Nonnull PolicyType policyType); + @Nonnull PolarisEntityCore target, @Nonnull PolicyType policyType); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/policy/PolicyMappingPersistence.java b/polaris-core/src/main/java/org/apache/polaris/core/policy/PolicyMappingPersistence.java index 0456f7b32f..8fda6647fc 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/policy/PolicyMappingPersistence.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/policy/PolicyMappingPersistence.java @@ -21,7 +21,6 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import java.util.List; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.PolarisBaseEntity; /** @@ -40,23 +39,19 @@ public interface PolicyMappingPersistence { * conflict (existing record with the same PK), all attributes of the new record will replace the * existing one. * - * @param callCtx call context * @param record policy mapping record to write, potentially replacing an existing policy mapping * with the same key */ - default void writeToPolicyMappingRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + default void writeToPolicyMappingRecords(@Nonnull PolarisPolicyMappingRecord record) { throw new UnsupportedOperationException("Not Implemented"); } /** * Delete the specified policyMappingRecord to the policy_mapping_records table. * - * @param callCtx call context * @param record policy mapping record to delete. */ - default void deleteFromPolicyMappingRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + default void deleteFromPolicyMappingRecords(@Nonnull PolarisPolicyMappingRecord record) { throw new UnsupportedOperationException("Not Implemented"); } @@ -64,7 +59,6 @@ default void deleteFromPolicyMappingRecords( * Delete the all policy mapping records in the policy_mapping_records table for the specified * entity. This method will delete all policy mapping records on the entity * - * @param callCtx call context * @param entity entity whose policy mapping records should be deleted * @param mappingOnTarget all mappings on that target entity. Empty list if that entity is not a * target @@ -72,7 +66,6 @@ default void deleteFromPolicyMappingRecords( * policy */ default void deleteAllEntityPolicyMappingRecords( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, @Nonnull List mappingOnTarget, @Nonnull List mappingOnPolicy) { @@ -83,7 +76,6 @@ default void deleteAllEntityPolicyMappingRecords( * Look up the specified policy mapping record from the policy_mapping_records table. Return NULL * if not found * - * @param callCtx call context * @param targetCatalogId catalog id of the target entity, NULL_ID if the entity is top-level * @param targetId id of the target entity * @param policyTypeCode type code of the policy entity @@ -93,7 +85,6 @@ default void deleteAllEntityPolicyMappingRecords( */ @Nullable default PolarisPolicyMappingRecord lookupPolicyMappingRecord( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId, int policyTypeCode, @@ -105,7 +96,6 @@ default PolarisPolicyMappingRecord lookupPolicyMappingRecord( /** * Get all policies on the specified target entity with specified policy type. * - * @param callCtx call context * @param targetCatalogId catalog id of the target entity, NULL_ID if the entity is top-level * @param targetId id of the target entity * @param policyTypeCode type code of the policy entity @@ -114,31 +104,26 @@ default PolarisPolicyMappingRecord lookupPolicyMappingRecord( */ @Nonnull default List loadPoliciesOnTargetByType( - @Nonnull PolarisCallContext callCtx, - long targetCatalogId, - long targetId, - int policyTypeCode) { + long targetCatalogId, long targetId, int policyTypeCode) { throw new UnsupportedOperationException("Not Implemented"); } /** * Get all policies on the specified target entity. * - * @param callCtx call context * @param targetCatalogId catalog id of the target entity, NULL_ID if the entity is top-level * @param targetId id of the target entity * @return the list of policy mapping records for the specified target entity */ @Nonnull default List loadAllPoliciesOnTarget( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId) { + long targetCatalogId, long targetId) { throw new UnsupportedOperationException("Not Implemented"); } /** * Get all targets of the specified policy entity * - * @param callCtx call context * @param policyCatalogId catalog id of the policy entity, NULL_ID if the entity is top-level * @param policyId id of the policy entity * @param policyTypeCode type code of the policy entity @@ -146,10 +131,7 @@ default List loadAllPoliciesOnTarget( */ @Nonnull default List loadAllTargetsOnPolicy( - @Nonnull PolarisCallContext callCtx, - long policyCatalogId, - long policyId, - int policyTypeCode) { + long policyCatalogId, long policyId, int policyTypeCode) { throw new UnsupportedOperationException("Not Implemented"); } } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/policy/TransactionalPolicyMappingPersistence.java b/polaris-core/src/main/java/org/apache/polaris/core/policy/TransactionalPolicyMappingPersistence.java index 398ddb1a16..782bdf68df 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/policy/TransactionalPolicyMappingPersistence.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/policy/TransactionalPolicyMappingPersistence.java @@ -21,13 +21,11 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import java.util.List; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.PolarisBaseEntity; public interface TransactionalPolicyMappingPersistence { /** See {@link PolicyMappingPersistence#writeToPolicyMappingRecords} */ - default void writeToPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + default void writeToPolicyMappingRecordsInCurrentTxn(@Nonnull PolarisPolicyMappingRecord record) { throw new UnsupportedOperationException("Not Implemented"); } @@ -37,23 +35,21 @@ default void writeToPolicyMappingRecordsInCurrentTxn( *

It should throw a PolicyMappingAlreadyExistsException if the new record conflicts with an * exising record with same policy type but different policy. * - * @param callCtx call context * @param record policy mapping record to write. */ default void checkConditionsForWriteToPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + @Nonnull PolarisPolicyMappingRecord record) { throw new UnsupportedOperationException("Not Implemented"); } /** See {@link PolicyMappingPersistence#deleteFromPolicyMappingRecords} */ default void deleteFromPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisPolicyMappingRecord record) { + @Nonnull PolarisPolicyMappingRecord record) { throw new UnsupportedOperationException("Not Implemented"); } /** See {@link PolicyMappingPersistence#deleteAllEntityPolicyMappingRecords} */ default void deleteAllEntityPolicyMappingRecordsInCurrentTxn( - @Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity, @Nonnull List mappingOnTarget, @Nonnull List mappingOnPolicy) { @@ -63,7 +59,6 @@ default void deleteAllEntityPolicyMappingRecordsInCurrentTxn( /** See {@link PolicyMappingPersistence#lookupPolicyMappingRecord} */ @Nullable default PolarisPolicyMappingRecord lookupPolicyMappingRecordInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId, int policyTypeCode, @@ -75,27 +70,21 @@ default PolarisPolicyMappingRecord lookupPolicyMappingRecordInCurrentTxn( /** See {@link PolicyMappingPersistence#loadPoliciesOnTargetByType} */ @Nonnull default List loadPoliciesOnTargetByTypeInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - long targetCatalogId, - long targetId, - int policyTypeCode) { + long targetCatalogId, long targetId, int policyTypeCode) { throw new UnsupportedOperationException("Not Implemented"); } /** See {@link PolicyMappingPersistence#loadAllPoliciesOnTarget} */ @Nonnull default List loadAllPoliciesOnTargetInCurrentTxn( - @Nonnull PolarisCallContext callCtx, long targetCatalogId, long targetId) { + long targetCatalogId, long targetId) { throw new UnsupportedOperationException("Not Implemented"); } /** See {@link PolicyMappingPersistence#loadAllTargetsOnPolicy} */ @Nonnull default List loadAllTargetsOnPolicyInCurrentTxn( - @Nonnull PolarisCallContext callCtx, - long policyCatalogId, - long policyId, - int policyTypeCode) { + long policyCatalogId, long policyId, int policyTypeCode) { throw new UnsupportedOperationException("Not Implemented"); } } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisCredentialVendor.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisCredentialVendor.java index d64e9ad88c..a6965cada3 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisCredentialVendor.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisCredentialVendor.java @@ -21,7 +21,6 @@ import jakarta.annotation.Nonnull; import java.util.Optional; import java.util.Set; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.persistence.dao.entity.ScopedCredentialsResult; @@ -31,7 +30,6 @@ public interface PolarisCredentialVendor { * Get a sub-scoped credentials for an entity against the provided allowed read and write * locations. * - * @param callCtx the polaris call context * @param catalogId the catalog id * @param entityId the entity id * @param allowListOperation whether to allow LIST operation on the allowedReadLocations and @@ -46,7 +44,6 @@ public interface PolarisCredentialVendor { */ @Nonnull ScopedCredentialsResult getSubscopedCredsForEntity( - @Nonnull PolarisCallContext callCtx, long catalogId, long entityId, PolarisEntityType entityType, diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java index 82de799152..361ea1bd89 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java @@ -129,7 +129,6 @@ public AccessConfig getOrGenerateSubScopeCreds( LOGGER.atDebug().log("StorageCredentialCache::load"); ScopedCredentialsResult scopedCredentialsResult = credentialVendor.getSubscopedCredsForEntity( - callCtx, k.catalogId(), polarisEntity.getId(), polarisEntity.getType(), diff --git a/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapAtomicOperationMetaStoreManagerTest.java b/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapAtomicOperationMetaStoreManagerTest.java index f1fa909e8c..6c721e4e35 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapAtomicOperationMetaStoreManagerTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapAtomicOperationMetaStoreManagerTest.java @@ -20,7 +20,6 @@ import static org.apache.polaris.core.persistence.PrincipalSecretsGenerator.RANDOM_SECRETS; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.persistence.transactional.TreeMapMetaStore; @@ -37,8 +36,8 @@ public PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() { new TreeMapTransactionalPersistenceImpl( diagServices, store, Mockito.mock(), RANDOM_SECRETS); AtomicOperationMetaStoreManager metaStoreManager = - new AtomicOperationMetaStoreManager(clock, diagServices); - PolarisCallContext callCtx = new PolarisCallContext(() -> "testRealm", metaStore); - return new PolarisTestMetaStoreManager(metaStoreManager, callCtx); + new AtomicOperationMetaStoreManager( + clock, diagServices, realmContext, realmConfig, () -> metaStore); + return new PolarisTestMetaStoreManager(metaStoreManager); } } diff --git a/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapMetaStoreManagerTest.java b/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapMetaStoreManagerTest.java index 4ecfa027f5..e3c6445c50 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapMetaStoreManagerTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapMetaStoreManagerTest.java @@ -20,7 +20,6 @@ import static org.apache.polaris.core.persistence.PrincipalSecretsGenerator.RANDOM_SECRETS; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.persistence.transactional.TransactionalMetaStoreManagerImpl; @@ -37,8 +36,8 @@ public PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() { new TreeMapTransactionalPersistenceImpl( diagServices, store, Mockito.mock(), RANDOM_SECRETS); TransactionalMetaStoreManagerImpl metaStoreManager = - new TransactionalMetaStoreManagerImpl(clock, diagServices); - PolarisCallContext callCtx = new PolarisCallContext(() -> "testRealm", metaStore); - return new PolarisTestMetaStoreManager(metaStoreManager, callCtx); + new TransactionalMetaStoreManagerImpl( + clock, diagServices, realmContext, realmConfig, () -> metaStore); + return new PolarisTestMetaStoreManager(metaStoreManager); } } diff --git a/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java b/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java index 3c8633a827..a37be2e457 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java @@ -21,7 +21,6 @@ import static org.apache.polaris.core.persistence.PrincipalSecretsGenerator.RANDOM_SECRETS; import java.time.Clock; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.persistence.transactional.TransactionalMetaStoreManagerImpl; import org.apache.polaris.core.persistence.transactional.TreeMapMetaStore; import org.apache.polaris.core.persistence.transactional.TreeMapTransactionalPersistenceImpl; @@ -30,26 +29,19 @@ public class ResolverTest extends BaseResolverTest { private final Clock clock = Clock.systemUTC(); - private PolarisCallContext callCtx; private PolarisTestMetaStoreManager tm; private TransactionalMetaStoreManagerImpl metaStoreManager; @Override - protected PolarisCallContext callCtx() { - if (callCtx == null) { + protected PolarisMetaStoreManager metaStoreManager() { + if (metaStoreManager == null) { TreeMapMetaStore store = new TreeMapMetaStore(diagServices); TreeMapTransactionalPersistenceImpl metaStore = new TreeMapTransactionalPersistenceImpl( diagServices, store, Mockito.mock(), RANDOM_SECRETS); - callCtx = new PolarisCallContext(() -> "testRealm", metaStore); - } - return callCtx; - } - - @Override - protected PolarisMetaStoreManager metaStoreManager() { - if (metaStoreManager == null) { - metaStoreManager = new TransactionalMetaStoreManagerImpl(clock, diagServices); + metaStoreManager = + new TransactionalMetaStoreManagerImpl( + clock, diagServices, realmContext, realmConfig, () -> metaStore); } return metaStoreManager; } @@ -58,7 +50,7 @@ protected PolarisMetaStoreManager metaStoreManager() { protected PolarisTestMetaStoreManager tm() { if (tm == null) { // bootstrap the meta store with our test schema - tm = new PolarisTestMetaStoreManager(metaStoreManager(), callCtx()); + tm = new PolarisTestMetaStoreManager(metaStoreManager()); } return tm; } diff --git a/polaris-core/src/test/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCacheTest.java b/polaris-core/src/test/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCacheTest.java index ce34320504..fe7511dceb 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCacheTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCacheTest.java @@ -24,9 +24,12 @@ import java.util.List; import java.util.stream.Collectors; import org.apache.iceberg.catalog.TableIdentifier; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; import org.apache.polaris.core.PolarisDiagnostics; +import org.apache.polaris.core.config.PolarisConfigurationStore; +import org.apache.polaris.core.config.RealmConfig; +import org.apache.polaris.core.config.RealmConfigImpl; +import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.entity.PolarisEntitySubType; @@ -49,7 +52,9 @@ public class InMemoryEntityCacheTest { private final PolarisDiagnostics diagServices; - private final PolarisCallContext callCtx; + private final RealmContext realmContext = () -> "testRealm"; + private final RealmConfig realmConfig = + new RealmConfigImpl(new PolarisConfigurationStore() {}, realmContext); private final PolarisTestMetaStoreManager tm; private final PolarisMetaStoreManager metaStoreManager; @@ -81,11 +86,12 @@ public InMemoryEntityCacheTest() { TransactionalPersistence metaStore = new TreeMapTransactionalPersistenceImpl( diagServices, store, Mockito.mock(), RANDOM_SECRETS); - metaStoreManager = new TransactionalMetaStoreManagerImpl(Clock.systemUTC(), diagServices); - callCtx = new PolarisCallContext(() -> "testRealm", metaStore); + metaStoreManager = + new TransactionalMetaStoreManagerImpl( + Clock.systemUTC(), diagServices, realmContext, realmConfig, () -> metaStore); // bootstrap the meta store with our test schema - tm = new PolarisTestMetaStoreManager(metaStoreManager, callCtx); + tm = new PolarisTestMetaStoreManager(metaStoreManager); tm.testCreateTestCatalog(); } @@ -93,7 +99,7 @@ public InMemoryEntityCacheTest() { * @return new cache for the entity store */ InMemoryEntityCache allocateNewCache() { - return new InMemoryEntityCache(diagServices, callCtx.getRealmConfig(), this.metaStoreManager); + return new InMemoryEntityCache(diagServices, realmConfig); } @Test @@ -104,7 +110,7 @@ void testGetOrLoadEntityByName() { // should exist and no cache hit EntityCacheLookupResult lookup = cache.getOrLoadEntityByName( - this.callCtx, new EntityCacheByNameKey(PolarisEntityType.CATALOG, "test")); + metaStoreManager, new EntityCacheByNameKey(PolarisEntityType.CATALOG, "test")); Assertions.assertThat(lookup).isNotNull(); Assertions.assertThat(lookup.isCacheHit()).isFalse(); Assertions.assertThat(lookup.getCacheEntry()).isNotNull(); @@ -117,14 +123,14 @@ void testGetOrLoadEntityByName() { // do it again, should be found in the cache lookup = cache.getOrLoadEntityByName( - this.callCtx, new EntityCacheByNameKey(PolarisEntityType.CATALOG, "test")); + metaStoreManager, new EntityCacheByNameKey(PolarisEntityType.CATALOG, "test")); Assertions.assertThat(lookup).isNotNull(); Assertions.assertThat(lookup.isCacheHit()).isTrue(); // do it again by id, should be found in the cache lookup = cache.getOrLoadEntityById( - this.callCtx, catalog.getCatalogId(), catalog.getId(), catalog.getType()); + metaStoreManager, catalog.getCatalogId(), catalog.getId(), catalog.getType()); Assertions.assertThat(lookup).isNotNull(); Assertions.assertThat(lookup.isCacheHit()).isTrue(); Assertions.assertThat(lookup.getCacheEntry()).isNotNull(); @@ -143,7 +149,8 @@ void testGetOrLoadEntityByName() { Assertions.assertThat(cacheEntry).isNull(); // try to find it in the cache by id. Should not be there, i.e. no cache hit - lookup = cache.getOrLoadEntityById(this.callCtx, N1.getCatalogId(), N1.getId(), N1.getType()); + lookup = + cache.getOrLoadEntityById(metaStoreManager, N1.getCatalogId(), N1.getId(), N1.getType()); Assertions.assertThat(lookup).isNotNull(); Assertions.assertThat(lookup.isCacheHit()).isFalse(); @@ -166,18 +173,18 @@ void testGetOrLoadEntityByName() { Assertions.assertThat(N1_entry.getGrantRecordsAsSecurable()).isNotNull(); // negative tests, load an entity which does not exist - lookup = cache.getOrLoadEntityById(this.callCtx, N1.getCatalogId(), 10000, N1.getType()); + lookup = cache.getOrLoadEntityById(metaStoreManager, N1.getCatalogId(), 10000, N1.getType()); Assertions.assertThat(lookup).isNull(); lookup = cache.getOrLoadEntityByName( - this.callCtx, + metaStoreManager, new EntityCacheByNameKey(PolarisEntityType.CATALOG, "non_existant_catalog")); Assertions.assertThat(lookup).isNull(); // lookup N2 to validate grants EntityCacheByNameKey N2_name = new EntityCacheByNameKey(catalog.getId(), N1.getId(), PolarisEntityType.NAMESPACE, "N2"); - lookup = cache.getOrLoadEntityByName(callCtx, N2_name); + lookup = cache.getOrLoadEntityByName(metaStoreManager, N2_name); Assertions.assertThat(lookup).isNotNull(); ResolvedPolarisEntity cacheEntry_N1 = lookup.getCacheEntry(); Assertions.assertThat(cacheEntry_N1).isNotNull(); @@ -188,7 +195,7 @@ void testGetOrLoadEntityByName() { EntityCacheByNameKey R1_name = new EntityCacheByNameKey( catalog.getId(), catalog.getId(), PolarisEntityType.CATALOG_ROLE, "R1"); - lookup = cache.getOrLoadEntityByName(callCtx, R1_name); + lookup = cache.getOrLoadEntityByName(metaStoreManager, R1_name); Assertions.assertThat(lookup).isNotNull(); ResolvedPolarisEntity cacheEntry_R1 = lookup.getCacheEntry(); Assertions.assertThat(cacheEntry_R1).isNotNull(); @@ -232,7 +239,7 @@ void testGetOrLoadEntityByName() { // lookup principal role PR1 EntityCacheByNameKey PR1_name = new EntityCacheByNameKey(PolarisEntityType.PRINCIPAL_ROLE, "PR1"); - lookup = cache.getOrLoadEntityByName(callCtx, PR1_name); + lookup = cache.getOrLoadEntityByName(metaStoreManager, PR1_name); Assertions.assertThat(lookup).isNotNull(); ResolvedPolarisEntity cacheEntry_PR1 = lookup.getCacheEntry(); Assertions.assertThat(cacheEntry_PR1).isNotNull(); @@ -273,7 +280,7 @@ void testRefresh() { // should exist and no cache hit EntityCacheLookupResult lookup = cache.getOrLoadEntityByName( - this.callCtx, new EntityCacheByNameKey(PolarisEntityType.CATALOG, "test")); + metaStoreManager, new EntityCacheByNameKey(PolarisEntityType.CATALOG, "test")); Assertions.assertThat(lookup).isNotNull(); Assertions.assertThat(lookup.isCacheHit()).isFalse(); @@ -303,7 +310,7 @@ void testRefresh() { // now load that table in the cache cacheEntry = cache.getAndRefreshIfNeeded( - this.callCtx, T6v1, T6v1.getEntityVersion(), T6v1.getGrantRecordsVersion()); + metaStoreManager, T6v1, T6v1.getEntityVersion(), T6v1.getGrantRecordsVersion()); Assertions.assertThat(cacheEntry).isNotNull(); Assertions.assertThat(cacheEntry.getEntity()).isNotNull(); Assertions.assertThat(cacheEntry.getGrantRecordsAsSecurable()).isNotNull(); @@ -324,7 +331,7 @@ void testRefresh() { // now refresh that entity. But because we don't change the versions, nothing should be reloaded cacheEntry = cache.getAndRefreshIfNeeded( - this.callCtx, T6v1, T6v1.getEntityVersion(), T6v1.getGrantRecordsVersion()); + metaStoreManager, T6v1, T6v1.getEntityVersion(), T6v1.getGrantRecordsVersion()); Assertions.assertThat(cacheEntry).isNotNull(); Assertions.assertThat(cacheEntry.getEntity()).isNotNull(); Assertions.assertThat(cacheEntry.getGrantRecordsAsSecurable()).isNotNull(); @@ -336,7 +343,7 @@ void testRefresh() { // now refresh again, this time with the new versions. Should be reloaded cacheEntry = cache.getAndRefreshIfNeeded( - this.callCtx, T6v2, T6v2.getEntityVersion(), T6v2.getGrantRecordsVersion()); + metaStoreManager, T6v2, T6v2.getEntityVersion(), T6v2.getGrantRecordsVersion()); Assertions.assertThat(cacheEntry).isNotNull(); Assertions.assertThat(cacheEntry.getEntity()).isNotNull(); Assertions.assertThat(cacheEntry.getGrantRecordsAsSecurable()).isNotNull(); @@ -365,7 +372,7 @@ void testRefresh() { // load that namespace cacheEntry = cache.getAndRefreshIfNeeded( - this.callCtx, N2, N2.getEntityVersion(), N2.getGrantRecordsVersion()); + metaStoreManager, N2, N2.getEntityVersion(), N2.getGrantRecordsVersion()); // should have one single grant Assertions.assertThat(cacheEntry).isNotNull(); @@ -386,7 +393,7 @@ void testRefresh() { // the cache is outdated now lookup = cache.getOrLoadEntityByName( - this.callCtx, + metaStoreManager, new EntityCacheByNameKey( catalog.getId(), N1.getId(), PolarisEntityType.NAMESPACE, "N2")); Assertions.assertThat(lookup).isNotNull(); @@ -401,7 +408,7 @@ void testRefresh() { // now refresh cacheEntry = cache.getAndRefreshIfNeeded( - this.callCtx, N2, N2v2.getEntityVersion(), N2v2.getGrantRecordsVersion()); + metaStoreManager, N2, N2v2.getEntityVersion(), N2v2.getGrantRecordsVersion()); Assertions.assertThat(cacheEntry).isNotNull(); Assertions.assertThat(cacheEntry.getEntity()).isNotNull(); Assertions.assertThat(cacheEntry.getGrantRecordsAsSecurable()).isNotNull(); @@ -417,19 +424,20 @@ void testRenameAndCacheDestinationBeforeLoadingSource() { EntityCacheLookupResult lookup = cache.getOrLoadEntityByName( - this.callCtx, new EntityCacheByNameKey(PolarisEntityType.CATALOG, "test")); + metaStoreManager, new EntityCacheByNameKey(PolarisEntityType.CATALOG, "test")); Assertions.assertThat(lookup).isNotNull(); Assertions.assertThat(lookup.getCacheEntry()).isNotNull(); PolarisBaseEntity catalog = lookup.getCacheEntry().getEntity(); PolarisBaseEntity N1 = this.tm.ensureExistsByName(List.of(catalog), PolarisEntityType.NAMESPACE, "N1"); - lookup = cache.getOrLoadEntityById(this.callCtx, N1.getCatalogId(), N1.getId(), N1.getType()); + lookup = + cache.getOrLoadEntityById(metaStoreManager, N1.getCatalogId(), N1.getId(), N1.getType()); Assertions.assertThat(lookup).isNotNull(); EntityCacheByNameKey T4_name = new EntityCacheByNameKey(N1.getCatalogId(), N1.getId(), PolarisEntityType.TABLE_LIKE, "T4"); - lookup = cache.getOrLoadEntityByName(callCtx, T4_name); + lookup = cache.getOrLoadEntityByName(metaStoreManager, T4_name); Assertions.assertThat(lookup).isNotNull(); ResolvedPolarisEntity cacheEntry_T4 = lookup.getCacheEntry(); Assertions.assertThat(cacheEntry_T4).isNotNull(); @@ -444,7 +452,7 @@ void testRenameAndCacheDestinationBeforeLoadingSource() { EntityCacheByNameKey T4_renamed = new EntityCacheByNameKey( N1.getCatalogId(), N1.getId(), PolarisEntityType.TABLE_LIKE, "T4_renamed"); - lookup = cache.getOrLoadEntityByName(callCtx, T4_renamed); + lookup = cache.getOrLoadEntityByName(metaStoreManager, T4_renamed); Assertions.assertThat(lookup).isNotNull(); ResolvedPolarisEntity cacheEntry_T4_renamed = lookup.getCacheEntry(); Assertions.assertThat(cacheEntry_T4_renamed).isNotNull(); @@ -452,7 +460,7 @@ void testRenameAndCacheDestinationBeforeLoadingSource() { // new entry if lookup by id EntityCacheLookupResult lookupResult = - cache.getOrLoadEntityById(callCtx, T4.getCatalogId(), T4.getId(), T4.getType()); + cache.getOrLoadEntityById(metaStoreManager, T4.getCatalogId(), T4.getId(), T4.getType()); Assertions.assertThat(lookupResult).isNotNull(); Assertions.assertThat(lookupResult.getCacheEntry()).isNotNull(); Assertions.assertThat(lookupResult.getCacheEntry().getEntity().getName()) @@ -463,13 +471,13 @@ void testRenameAndCacheDestinationBeforeLoadingSource() { // refreshing should return null since our current held T4 is outdated cache.getAndRefreshIfNeeded( - callCtx, + metaStoreManager, T4, T4_renamed_entity.getEntityVersion(), T4_renamed_entity.getGrantRecordsVersion()); // now the loading by the old name should return null - Assertions.assertThat(cache.getOrLoadEntityByName(callCtx, T4_name)).isNull(); + Assertions.assertThat(cache.getOrLoadEntityByName(metaStoreManager, T4_name)).isNull(); } /* Helper for `testEntityWeigher` */ diff --git a/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java b/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java index a51badf4b8..84b5c570c9 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java @@ -18,8 +18,6 @@ */ package org.apache.polaris.core.storage.cache; -import static org.apache.polaris.core.persistence.PrincipalSecretsGenerator.RANDOM_SECRETS; - import jakarta.annotation.Nonnull; import java.util.ArrayList; import java.util.Arrays; @@ -39,9 +37,6 @@ import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.dao.entity.BaseResult; import org.apache.polaris.core.persistence.dao.entity.ScopedCredentialsResult; -import org.apache.polaris.core.persistence.transactional.TransactionalPersistence; -import org.apache.polaris.core.persistence.transactional.TreeMapMetaStore; -import org.apache.polaris.core.persistence.transactional.TreeMapTransactionalPersistenceImpl; import org.apache.polaris.core.storage.AccessConfig; import org.apache.polaris.core.storage.StorageAccessProperty; import org.assertj.core.api.Assertions; @@ -58,13 +53,7 @@ public class StorageCredentialCacheTest { private StorageCredentialCache storageCredentialCache; public StorageCredentialCacheTest() { - // the entity store, use treemap implementation - TreeMapMetaStore store = new TreeMapMetaStore(diagServices); - // to interact with the metastore - TransactionalPersistence metaStore = - new TreeMapTransactionalPersistenceImpl( - diagServices, store, Mockito.mock(), RANDOM_SECRETS); - callCtx = new PolarisCallContext(() -> "testRealm", metaStore); + callCtx = new PolarisCallContext(() -> "testRealm"); storageCredentialCacheConfig = () -> 10_000; metaStoreManager = Mockito.mock(PolarisMetaStoreManager.class); storageCredentialCache = newStorageCredentialCache(); @@ -82,7 +71,6 @@ public void testBadResult() { BaseResult.ReturnStatus.SUBSCOPE_CREDS_ERROR, "extra_error_info"); Mockito.when( metaStoreManager.getSubscopedCredsForEntity( - Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), @@ -116,7 +104,6 @@ public void testCacheHit() { getFakeScopedCreds(3, /* expireSoon= */ false); Mockito.when( metaStoreManager.getSubscopedCredsForEntity( - Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), @@ -162,7 +149,6 @@ public void testCacheEvict() throws InterruptedException { Mockito.when( metaStoreManager.getSubscopedCredsForEntity( - Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), @@ -225,7 +211,6 @@ public void testCacheGenerateNewEntries() { getFakeScopedCreds(3, /* expireSoon= */ false); Mockito.when( metaStoreManager.getSubscopedCredsForEntity( - Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), @@ -319,7 +304,6 @@ public void testCacheNotAffectedBy() { Mockito.when( metaStoreManager.getSubscopedCredsForEntity( - Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), @@ -466,7 +450,6 @@ public void testExtraProperties() { .build()); Mockito.when( metaStoreManager.getSubscopedCredsForEntity( - Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.any(), diff --git a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BasePolarisMetaStoreManagerTest.java b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BasePolarisMetaStoreManagerTest.java index 43a0c55815..a02a91e361 100644 --- a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BasePolarisMetaStoreManagerTest.java +++ b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BasePolarisMetaStoreManagerTest.java @@ -34,7 +34,10 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.polaris.core.PolarisCallContext; +import org.apache.polaris.core.config.PolarisConfigurationStore; +import org.apache.polaris.core.config.RealmConfig; +import org.apache.polaris.core.config.RealmConfigImpl; +import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntity; @@ -64,6 +67,9 @@ public abstract class BasePolarisMetaStoreManagerTest { protected final MutableClock clock = MutableClock.of(Instant.now(), ZoneOffset.UTC); + protected final RealmContext realmContext = () -> "testRealm"; + protected final RealmConfig realmConfig = + new RealmConfigImpl(new PolarisConfigurationStore() {}, realmContext); private PolarisTestMetaStoreManager polarisTestMetaStoreManager; @@ -106,10 +112,7 @@ protected void testCreateEntities() { TaskEntity task1 = createTask("task1", 100L); TaskEntity task2 = createTask("task2", 101L); List createdEntities = - metaStoreManager - .createEntitiesIfNotExist( - polarisTestMetaStoreManager.polarisCallContext, null, List.of(task1, task2)) - .getEntities(); + metaStoreManager.createEntitiesIfNotExist(null, List.of(task1, task2)).getEntities(); Assertions.assertThat(createdEntities) .isNotNull() @@ -119,10 +122,7 @@ protected void testCreateEntities() { List listedEntities = metaStoreManager.loadEntitiesAll( - polarisTestMetaStoreManager.polarisCallContext, - null, - PolarisEntityType.TASK, - PolarisEntitySubType.NULL_SUBTYPE); + null, PolarisEntityType.TASK, PolarisEntitySubType.NULL_SUBTYPE); Assertions.assertThat(listedEntities) .isNotNull() .hasSize(2) @@ -136,10 +136,7 @@ protected void testCreateEntitiesAlreadyExisting() { TaskEntity task1 = createTask("task1", 100L); TaskEntity task2 = createTask("task2", 101L); List createdEntities = - metaStoreManager - .createEntitiesIfNotExist( - polarisTestMetaStoreManager.polarisCallContext, null, List.of(task1, task2)) - .getEntities(); + metaStoreManager.createEntitiesIfNotExist(null, List.of(task1, task2)).getEntities(); Assertions.assertThat(createdEntities) .isNotNull() @@ -152,10 +149,7 @@ protected void testCreateEntitiesAlreadyExisting() { // entities task1 and task2 already exist with the same identifier, so the full list is // returned createdEntities = - metaStoreManager - .createEntitiesIfNotExist( - polarisTestMetaStoreManager.polarisCallContext, null, List.of(task1, task2, task3)) - .getEntities(); + metaStoreManager.createEntitiesIfNotExist(null, List.of(task1, task2, task3)).getEntities(); Assertions.assertThat(createdEntities) .isNotNull() .hasSize(3) @@ -171,10 +165,7 @@ protected void testCreateEntitiesWithConflict() { TaskEntity task2 = createTask("task2", 101L); TaskEntity task3 = createTask("task3", 103L); List createdEntities = - metaStoreManager - .createEntitiesIfNotExist( - polarisTestMetaStoreManager.polarisCallContext, null, List.of(task1, task2, task3)) - .getEntities(); + metaStoreManager.createEntitiesIfNotExist(null, List.of(task1, task2, task3)).getEntities(); Assertions.assertThat(createdEntities) .isNotNull() @@ -187,10 +178,7 @@ protected void testCreateEntitiesWithConflict() { TaskEntity task4 = createTask("task4", 105L); createdEntities = - metaStoreManager - .createEntitiesIfNotExist( - polarisTestMetaStoreManager.polarisCallContext, null, List.of(secondTask3, task4)) - .getEntities(); + metaStoreManager.createEntitiesIfNotExist(null, List.of(secondTask3, task4)).getEntities(); Assertions.assertThat(createdEntities).isNull(); } @@ -264,9 +252,8 @@ protected void testLoadTasks() { } String executorId = "testExecutor_abc"; PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager; - PolarisCallContext callCtx = polarisTestMetaStoreManager.polarisCallContext; List taskList = - metaStoreManager.loadTasks(callCtx, executorId, PageToken.fromLimit(5)).getEntities(); + metaStoreManager.loadTasks(executorId, PageToken.fromLimit(5)).getEntities(); Assertions.assertThat(taskList) .isNotNull() .isNotEmpty() @@ -284,7 +271,7 @@ protected void testLoadTasks() { // grab a second round of tasks. Assert that none of the original 5 are in the list List newTaskList = - metaStoreManager.loadTasks(callCtx, executorId, PageToken.fromLimit(5)).getEntities(); + metaStoreManager.loadTasks(executorId, PageToken.fromLimit(5)).getEntities(); Assertions.assertThat(newTaskList) .isNotNull() .isNotEmpty() @@ -298,7 +285,7 @@ protected void testLoadTasks() { // only 10 tasks are unassigned. Requesting 20, we should only receive those 10 List lastTen = - metaStoreManager.loadTasks(callCtx, executorId, PageToken.fromLimit(20)).getEntities(); + metaStoreManager.loadTasks(executorId, PageToken.fromLimit(20)).getEntities(); Assertions.assertThat(lastTen) .isNotNull() @@ -312,7 +299,7 @@ protected void testLoadTasks() { .collect(Collectors.toSet()); List emtpyList = - metaStoreManager.loadTasks(callCtx, executorId, PageToken.fromLimit(20)).getEntities(); + metaStoreManager.loadTasks(executorId, PageToken.fromLimit(20)).getEntities(); Assertions.assertThat(emtpyList).isNotNull().isEmpty(); @@ -320,7 +307,7 @@ protected void testLoadTasks() { // all the tasks are unassigned. Fetch them all List allTasks = - metaStoreManager.loadTasks(callCtx, executorId, PageToken.fromLimit(20)).getEntities(); + metaStoreManager.loadTasks(executorId, PageToken.fromLimit(20)).getEntities(); Assertions.assertThat(allTasks) .isNotNull() @@ -330,12 +317,11 @@ protected void testLoadTasks() { .allMatch(allTaskNames::contains); // drop all the tasks. Skip the clock forward and fetch. empty list expected - allTasks.forEach( - entity -> metaStoreManager.dropEntityIfExists(callCtx, null, entity, Map.of(), false)); + allTasks.forEach(entity -> metaStoreManager.dropEntityIfExists(null, entity, Map.of(), false)); clock.add(Duration.ofMinutes(10)); List finalList = - metaStoreManager.loadTasks(callCtx, executorId, PageToken.fromLimit(20)).getEntities(); + metaStoreManager.loadTasks(executorId, PageToken.fromLimit(20)).getEntities(); Assertions.assertThat(finalList).isNotNull().isEmpty(); } @@ -347,7 +333,6 @@ protected void testLoadTasksInParallel() throws Exception { null, PolarisEntityType.TASK, PolarisEntitySubType.NULL_SUBTYPE, "task_" + i); } PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager; - PolarisCallContext callCtx = polarisTestMetaStoreManager.polarisCallContext; List>> futureList = new ArrayList<>(); ExecutorService executorService = Executors.newCachedThreadPool(); try { @@ -365,7 +350,7 @@ protected void testLoadTasksInParallel() throws Exception { try { taskList = metaStoreManager - .loadTasks(callCtx, executorId, PageToken.fromLimit(5)) + .loadTasks(executorId, PageToken.fromLimit(5)) .getEntities(); taskList.stream().map(PolarisBaseEntity::getName).forEach(taskNames::add); } catch (RetryOnConcurrencyException e) { diff --git a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BaseResolverTest.java b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BaseResolverTest.java index 585006f56b..28e35e75d2 100644 --- a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BaseResolverTest.java +++ b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BaseResolverTest.java @@ -30,9 +30,12 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; import org.apache.polaris.core.auth.PolarisPrincipal; +import org.apache.polaris.core.config.PolarisConfigurationStore; +import org.apache.polaris.core.config.RealmConfig; +import org.apache.polaris.core.config.RealmConfigImpl; +import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntityCore; import org.apache.polaris.core.entity.PolarisEntitySubType; @@ -53,6 +56,9 @@ public abstract class BaseResolverTest { protected final PolarisDefaultDiagServiceImpl diagServices = new PolarisDefaultDiagServiceImpl(); + protected final RealmContext realmContext = () -> "testRealm"; + protected final RealmConfig realmConfig = + new RealmConfigImpl(new PolarisConfigurationStore() {}, realmContext); // Principal P1 protected PolarisBaseEntity P1; @@ -99,9 +105,6 @@ public void setupTest() { this.P1 = tm().ensureExistsByName(null, PolarisEntityType.PRINCIPAL, "P1"); } - // polaris call context - protected abstract PolarisCallContext callCtx(); - // utility to bootstrap the mata store protected abstract PolarisTestMetaStoreManager tm(); @@ -420,8 +423,7 @@ private Resolver allocateResolver( // create a new cache if needs be if (cache == null) { - this.cache = - new InMemoryEntityCache(diagServices, callCtx().getRealmConfig(), metaStoreManager()); + this.cache = new InMemoryEntityCache(diagServices, realmConfig); } boolean allRoles = principalRolesScope == null; Optional> roleEntities = @@ -429,9 +431,7 @@ private Resolver allocateResolver( .map( scopes -> scopes.stream() - .map( - roleName -> - metaStoreManager().findPrincipalRoleByName(callCtx(), roleName)) + .map(roleName -> metaStoreManager().findPrincipalRoleByName(roleName)) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList())); @@ -440,7 +440,6 @@ private Resolver allocateResolver( PrincipalEntity.of(P1), Optional.ofNullable(principalRolesScope).orElse(Set.of())); return new Resolver( diagServices, - callCtx(), metaStoreManager(), new SecurityContext() { @Override @@ -655,8 +654,7 @@ private Resolver resolveDriver( // the principal does not exist, check that this is the case if (principalName != null) { // see if the principal exists - Optional principal = - metaStoreManager().findPrincipalByName(callCtx(), principalName); + Optional principal = metaStoreManager().findPrincipalByName(principalName); // if found, ensure properly resolved if (principal.isPresent()) { // the principal exist, check that this is the case @@ -857,7 +855,7 @@ private void ensureResolved( ResolvedEntityResult refResolvedEntity = metaStoreManager() .loadResolvedEntityById( - callCtx(), refEntity.getCatalogId(), refEntity.getId(), refEntity.getType()); + refEntity.getCatalogId(), refEntity.getId(), refEntity.getType()); // should exist Assertions.assertThat(refResolvedEntity).isNotNull(); diff --git a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java index c8e486ee6e..65b20dca81 100644 --- a/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java +++ b/polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/PolarisTestMetaStoreManager.java @@ -25,7 +25,6 @@ import java.util.Map; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.EntityNameLookupRecord; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisChangeTrackingVersions; @@ -59,9 +58,6 @@ /** Test the Polaris persistence layer */ public class PolarisTestMetaStoreManager { - // call context - final PolarisCallContext polarisCallContext; - // call metastore manager final PolarisMetaStoreManager polarisMetaStoreManager; @@ -74,22 +70,19 @@ public class PolarisTestMetaStoreManager { private boolean doRetry; // initialize the test - public PolarisTestMetaStoreManager( - PolarisMetaStoreManager polarisMetaStoreManager, PolarisCallContext polarisCallContext) { - this(polarisMetaStoreManager, polarisCallContext, System.currentTimeMillis(), true); + public PolarisTestMetaStoreManager(PolarisMetaStoreManager polarisMetaStoreManager) { + this(polarisMetaStoreManager, System.currentTimeMillis(), true); // bootstrap the Polaris service - polarisMetaStoreManager.purge(polarisCallContext); - polarisMetaStoreManager.bootstrapPolarisService(polarisCallContext); + polarisMetaStoreManager.purge(); + polarisMetaStoreManager.bootstrapPolarisService(); } public PolarisTestMetaStoreManager( PolarisMetaStoreManager polarisMetaStoreManager, - PolarisCallContext polarisCallContext, long testStartTime, boolean supportsChangeTracking) { this.testStartTime = testStartTime; - this.polarisCallContext = polarisCallContext; this.polarisMetaStoreManager = polarisMetaStoreManager; this.supportsChangeTracking = supportsChangeTracking; this.doRetry = false; @@ -133,9 +126,7 @@ private PolarisBaseEntity ensureExistsById( // make sure this entity was persisted PolarisBaseEntity entity = - polarisMetaStoreManager - .loadEntity(this.polarisCallContext, catalogId, entityId, expectedType) - .getEntity(); + polarisMetaStoreManager.loadEntity(catalogId, entityId, expectedType).getEntity(); // assert all expected values Assertions.assertThat(entity).isNotNull(); @@ -158,7 +149,7 @@ private PolarisBaseEntity ensureExistsById( // we should find it EntityResult result = polarisMetaStoreManager.readEntityByName( - this.polarisCallContext, catalogPath, expectedType, expectedSubType, expectedName); + catalogPath, expectedType, expectedSubType, expectedName); // should be success, nothing changed Assertions.assertThat(result).isNotNull(); @@ -175,7 +166,7 @@ private PolarisBaseEntity ensureExistsById( // we should not find it EntityResult result = polarisMetaStoreManager.readEntityByName( - this.polarisCallContext, catalogPath, expectedType, expectedSubType, expectedName); + catalogPath, expectedType, expectedSubType, expectedName); // lookup must be success, nothing changed Assertions.assertThat(result).isNotNull(); @@ -200,9 +191,7 @@ private PolarisBaseEntity ensureExistsById( private void ensureNotExistsById(long catalogId, long entityId, PolarisEntityType expectedType) { PolarisBaseEntity entity = - polarisMetaStoreManager - .loadEntity(this.polarisCallContext, catalogId, entityId, expectedType) - .getEntity(); + polarisMetaStoreManager.loadEntity(catalogId, entityId, expectedType).getEntity(); // assert entity was not found Assertions.assertThat(entity).isNull(); @@ -283,17 +272,12 @@ void ensureGrantRecordExists( // re-load both entities, ensure not null securable = polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, - securable.getCatalogId(), - securable.getId(), - securable.getType()) + .loadEntity(securable.getCatalogId(), securable.getId(), securable.getType()) .getEntity(); Assertions.assertThat(securable).isNotNull(); grantee = polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, grantee.getCatalogId(), grantee.getId(), grantee.getType()) + .loadEntity(grantee.getCatalogId(), grantee.getId(), grantee.getType()) .getEntity(); Assertions.assertThat(grantee).isNotNull(); @@ -302,7 +286,7 @@ void ensureGrantRecordExists( // load all grant records on that securable, should not fail LoadGrantsResult loadGrantsOnSecurable = - polarisMetaStoreManager.loadGrantsOnSecurable(this.polarisCallContext, securable); + polarisMetaStoreManager.loadGrantsOnSecurable(securable); // ensure entities for these grant records have been properly loaded this.validateLoadedGrants(loadGrantsOnSecurable, false); @@ -310,8 +294,7 @@ void ensureGrantRecordExists( this.checkGrantRecordExists(loadGrantsOnSecurable.getGrantRecords(), securable, grantee, priv); // load all grant records on that grantee, should not fail - LoadGrantsResult loadGrantsOnGrantee = - polarisMetaStoreManager.loadGrantsToGrantee(this.polarisCallContext, grantee); + LoadGrantsResult loadGrantsOnGrantee = polarisMetaStoreManager.loadGrantsToGrantee(grantee); // ensure entities for these grant records have been properly loaded this.validateLoadedGrants(loadGrantsOnGrantee, true); @@ -344,8 +327,7 @@ private void validateLoadedGrants(LoadGrantsResult loadGrantRecords, boolean isG // load that entity PolarisBaseEntity entity = null; for (PolarisEntityType type : PolarisEntityType.values()) { - EntityResult entityResult = - polarisMetaStoreManager.loadEntity(this.polarisCallContext, catalogId, entityId, type); + EntityResult entityResult = polarisMetaStoreManager.loadEntity(catalogId, entityId, type); if (entityResult.isSuccess()) { entity = entityResult.getEntity(); break; @@ -368,17 +350,12 @@ void ensureGrantRecordRemoved( // re-load both entities, ensure not null securable = polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, - securable.getCatalogId(), - securable.getId(), - securable.getType()) + .loadEntity(securable.getCatalogId(), securable.getId(), securable.getType()) .getEntity(); Assertions.assertThat(securable).isNotNull(); grantee = polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, grantee.getCatalogId(), grantee.getId(), grantee.getType()) + .loadEntity(grantee.getCatalogId(), grantee.getId(), grantee.getType()) .getEntity(); Assertions.assertThat(grantee).isNotNull(); @@ -387,7 +364,7 @@ void ensureGrantRecordRemoved( // load all grant records on that securable, should not fail LoadGrantsResult loadGrantsOnSecurable = - polarisMetaStoreManager.loadGrantsOnSecurable(this.polarisCallContext, securable); + polarisMetaStoreManager.loadGrantsOnSecurable(securable); // ensure entities for these grant records have been properly loaded this.validateLoadedGrants(loadGrantsOnSecurable, false); @@ -395,8 +372,7 @@ void ensureGrantRecordRemoved( this.checkGrantRecordRemoved(loadGrantsOnSecurable.getGrantRecords(), securable, grantee, priv); // load all grant records on that grantee, should not fail - LoadGrantsResult loadGrantsOnGrantee = - polarisMetaStoreManager.loadGrantsToGrantee(this.polarisCallContext, grantee); + LoadGrantsResult loadGrantsOnGrantee = polarisMetaStoreManager.loadGrantsToGrantee(grantee); this.validateLoadedGrants(loadGrantsOnGrantee, true); // check that the grant record has been removed @@ -408,7 +384,7 @@ PrincipalEntity createPrincipal(String name) { // create new principal identity PrincipalEntity principalEntity = new PrincipalEntity.Builder() - .setId(polarisMetaStoreManager.generateNewEntityId(this.polarisCallContext).getId()) + .setId(polarisMetaStoreManager.generateNewEntityId().getId()) .setName(name) .setInternalProperties( Map.of(PolarisEntityConstants.PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_STATE, "true")) @@ -416,7 +392,7 @@ PrincipalEntity createPrincipal(String name) { .build(); CreatePrincipalResult createPrincipalResult = - polarisMetaStoreManager.createPrincipal(this.polarisCallContext, principalEntity); + polarisMetaStoreManager.createPrincipal(principalEntity); Assertions.assertThat(createPrincipalResult).isNotNull(); // ensure well created @@ -443,9 +419,7 @@ PrincipalEntity createPrincipal(String name) { // ensure that the secrets have been properly saved and match PolarisPrincipalSecrets reloadSecrets = - polarisMetaStoreManager - .loadPrincipalSecrets(this.polarisCallContext, clientId) - .getPrincipalSecrets(); + polarisMetaStoreManager.loadPrincipalSecrets(clientId).getPrincipalSecrets(); Assertions.assertThat(reloadSecrets).isNotNull(); Assertions.assertThat(reloadSecrets.getPrincipalId()).isEqualTo(secrets.getPrincipalId()); Assertions.assertThat(reloadSecrets.getPrincipalClientId()) @@ -465,7 +439,7 @@ PrincipalEntity createPrincipal(String name) { if (this.doRetry) { // simulate that we retried CreatePrincipalResult newCreatePrincipalResult = - polarisMetaStoreManager.createPrincipal(this.polarisCallContext, principalEntity); + polarisMetaStoreManager.createPrincipal(principalEntity); Assertions.assertThat(newCreatePrincipalResult).isNotNull(); // ensure same @@ -482,18 +456,13 @@ PrincipalEntity createPrincipal(String name) { secrets = polarisMetaStoreManager .rotatePrincipalSecrets( - this.polarisCallContext, - clientId, - principalEntity.getId(), - false, - secrets.getMainSecretHash()) + clientId, principalEntity.getId(), false, secrets.getMainSecretHash()) .getPrincipalSecrets(); Assertions.assertThat(secrets.getMainSecret()).isNotEqualTo(reloadSecrets.getMainSecret()); PrincipalEntity reloadPrincipal = polarisMetaStoreManager - .findPrincipalById( - this.polarisCallContext, createPrincipalResult.getPrincipal().getId()) + .findPrincipalById(createPrincipalResult.getPrincipal().getId()) .orElseThrow(); internalProperties = reloadPrincipal.getInternalPropertiesAsMap(); Assertions.assertThat( @@ -503,23 +472,12 @@ PrincipalEntity createPrincipal(String name) { // rotate the secrets, twice! polarisMetaStoreManager.rotatePrincipalSecrets( - this.polarisCallContext, - clientId, - principalEntity.getId(), - false, - secrets.getMainSecretHash()); + clientId, principalEntity.getId(), false, secrets.getMainSecretHash()); polarisMetaStoreManager.rotatePrincipalSecrets( - this.polarisCallContext, - clientId, - principalEntity.getId(), - false, - secrets.getMainSecretHash()); + clientId, principalEntity.getId(), false, secrets.getMainSecretHash()); // reload and check that now the main should be secondary - reloadSecrets = - polarisMetaStoreManager - .loadPrincipalSecrets(this.polarisCallContext, clientId) - .getPrincipalSecrets(); + reloadSecrets = polarisMetaStoreManager.loadPrincipalSecrets(clientId).getPrincipalSecrets(); Assertions.assertThat(reloadSecrets).isNotNull(); Assertions.assertThat(reloadSecrets.getPrincipalId()).isEqualTo(secrets.getPrincipalId()); Assertions.assertThat(reloadSecrets.getPrincipalClientId()) @@ -530,15 +488,8 @@ PrincipalEntity createPrincipal(String name) { // reset - the previous main secret is no longer one of the secrets polarisMetaStoreManager.rotatePrincipalSecrets( - this.polarisCallContext, - clientId, - principalEntity.getId(), - true, - reloadSecrets.getMainSecretHash()); - reloadSecrets = - polarisMetaStoreManager - .loadPrincipalSecrets(this.polarisCallContext, clientId) - .getPrincipalSecrets(); + clientId, principalEntity.getId(), true, reloadSecrets.getMainSecretHash()); + reloadSecrets = polarisMetaStoreManager.loadPrincipalSecrets(clientId).getPrincipalSecrets(); Assertions.assertThat(reloadSecrets).isNotNull(); Assertions.assertThat(reloadSecrets.getPrincipalId()).isEqualTo(secrets.getPrincipalId()); Assertions.assertThat(reloadSecrets.getPrincipalClientId()) @@ -547,9 +498,7 @@ PrincipalEntity createPrincipal(String name) { Assertions.assertThat(reloadSecrets.getSecondarySecretHash()).isNotEqualTo(newMainSecretHash); PrincipalEntity newPrincipal = - polarisMetaStoreManager - .findPrincipalById(this.polarisCallContext, principalEntity.getId()) - .orElseThrow(); + polarisMetaStoreManager.findPrincipalById(principalEntity.getId()).orElseThrow(); internalProperties = newPrincipal.getInternalPropertiesAsMap(); Assertions.assertThat( internalProperties.get( @@ -559,15 +508,9 @@ PrincipalEntity createPrincipal(String name) { // reset again. we should get new secrets and the CREDENTIAL_ROTATION_REQUIRED flag should be // gone polarisMetaStoreManager.rotatePrincipalSecrets( - this.polarisCallContext, - clientId, - principalEntity.getId(), - true, - reloadSecrets.getMainSecretHash()); + clientId, principalEntity.getId(), true, reloadSecrets.getMainSecretHash()); PolarisPrincipalSecrets postResetCredentials = - polarisMetaStoreManager - .loadPrincipalSecrets(this.polarisCallContext, clientId) - .getPrincipalSecrets(); + polarisMetaStoreManager.loadPrincipalSecrets(clientId).getPrincipalSecrets(); Assertions.assertThat(reloadSecrets).isNotNull(); Assertions.assertThat(postResetCredentials.getPrincipalId()) .isEqualTo(reloadSecrets.getPrincipalId()); @@ -579,9 +522,7 @@ PrincipalEntity createPrincipal(String name) { .isNotEqualTo(reloadSecrets.getSecondarySecretHash()); PrincipalEntity finalPrincipal = - polarisMetaStoreManager - .findPrincipalById(this.polarisCallContext, principalEntity.getId()) - .orElseThrow(); + polarisMetaStoreManager.findPrincipalById(principalEntity.getId()).orElseThrow(); internalProperties = finalPrincipal.getInternalPropertiesAsMap(); Assertions.assertThat( internalProperties.get( @@ -612,7 +553,7 @@ public PolarisBaseEntity createEntity( entityType, entitySubType, name, - polarisMetaStoreManager.generateNewEntityId(this.polarisCallContext).getId(), + polarisMetaStoreManager.generateNewEntityId().getId(), properties); } @@ -652,9 +593,7 @@ PolarisBaseEntity createEntity( .propertiesAsMap(properties) .build(); PolarisBaseEntity entity = - polarisMetaStoreManager - .createEntityIfNotExists(this.polarisCallContext, catalogPath, newEntity) - .getEntity(); + polarisMetaStoreManager.createEntityIfNotExists(catalogPath, newEntity).getEntity(); Assertions.assertThat(entity).isNotNull(); // same id @@ -666,9 +605,7 @@ PolarisBaseEntity createEntity( // retry if we are asked to if (this.doRetry) { PolarisBaseEntity retryEntity = - polarisMetaStoreManager - .createEntityIfNotExists(this.polarisCallContext, catalogPath, newEntity) - .getEntity(); + polarisMetaStoreManager.createEntityIfNotExists(catalogPath, newEntity).getEntity(); Assertions.assertThat(retryEntity).isNotNull(); // same id @@ -722,20 +659,12 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD // check if it exists PolarisBaseEntity entity = polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, - entityToDrop.getCatalogId(), - entityToDrop.getId(), - entityToDrop.getType()) + .loadEntity(entityToDrop.getCatalogId(), entityToDrop.getId(), entityToDrop.getType()) .getEntity(); if (entity != null) { EntityResult entityFound = polarisMetaStoreManager.readEntityByName( - this.polarisCallContext, - catalogPath, - entity.getType(), - entity.getSubType(), - entity.getName()); + catalogPath, entity.getType(), entity.getSubType(), entity.getName()); exists = entityFound.isSuccess(); // if exists, see if empty @@ -753,7 +682,6 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD List children = polarisMetaStoreManager .listEntities( - this.polarisCallContext, path, PolarisEntityType.NAMESPACE, PolarisEntitySubType.NULL_SUBTYPE, @@ -764,7 +692,6 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD children = polarisMetaStoreManager .listEntities( - this.polarisCallContext, path, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ANY_SUBTYPE, @@ -775,7 +702,6 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD children = polarisMetaStoreManager .listEntities( - this.polarisCallContext, path, PolarisEntityType.CATALOG_ROLE, PolarisEntitySubType.ANY_SUBTYPE, @@ -798,15 +724,9 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD final List securableEntities; if (exists) { granteeEntities = - new ArrayList<>( - polarisMetaStoreManager - .loadGrantsOnSecurable(this.polarisCallContext, entity) - .getEntities()); + new ArrayList<>(polarisMetaStoreManager.loadGrantsOnSecurable(entity).getEntities()); securableEntities = - new ArrayList<>( - polarisMetaStoreManager - .loadGrantsToGrantee(this.polarisCallContext, entity) - .getEntities()); + new ArrayList<>(polarisMetaStoreManager.loadGrantsToGrantee(entity).getEntities()); } else { granteeEntities = List.of(); securableEntities = List.of(); @@ -817,7 +737,7 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD Map.of("taskId", String.valueOf(entity.getId()), "cleanupProperty", "cleanupValue"); DropEntityResult dropResult = polarisMetaStoreManager.dropEntityIfExists( - this.polarisCallContext, catalogPath, entityToDrop, cleanupProperties, true); + catalogPath, entityToDrop, cleanupProperties, true); // should have been dropped if exists if (entityToDrop.cannotBeDroppedOrRenamed()) { @@ -841,11 +761,7 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD Assertions.assertThat(dropResult.getCleanupTaskId()).isNotNull(); PolarisBaseEntity cleanupTask = polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, - 0L, - dropResult.getCleanupTaskId(), - PolarisEntityType.TASK) + .loadEntity(0L, dropResult.getCleanupTaskId(), PolarisEntityType.TASK) .getEntity(); Assertions.assertThat(cleanupTask).isNotNull(); Assertions.assertThat(cleanupTask.getType()).isEqualTo(PolarisEntityType.TASK); @@ -867,11 +783,7 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD // should be found but deleted PolarisBaseEntity entityAfterDrop = polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, - entityToDrop.getCatalogId(), - entityToDrop.getId(), - entityToDrop.getType()) + .loadEntity(entityToDrop.getCatalogId(), entityToDrop.getId(), entityToDrop.getType()) .getEntity(); // ensure dropped @@ -881,11 +793,7 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD Assertions.assertThat(entity).isNotNull(); EntityResult entityFound = polarisMetaStoreManager.readEntityByName( - this.polarisCallContext, - catalogPath, - entity.getType(), - entity.getSubType(), - entity.getName()); + catalogPath, entity.getType(), entity.getSubType(), entity.getName()); // should not be found Assertions.assertThat(entityFound.getReturnStatus()) @@ -894,8 +802,7 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD // make sure that the entity which was dropped is no longer referenced by a grant with any // of the entity it was connected with before being dropped for (PolarisBaseEntity connectedEntity : granteeEntities) { - LoadGrantsResult grantResult = - polarisMetaStoreManager.loadGrantsToGrantee(this.polarisCallContext, connectedEntity); + LoadGrantsResult grantResult = polarisMetaStoreManager.loadGrantsToGrantee(connectedEntity); if (grantResult.isSuccess()) { long cnt = grantResult.getGrantRecords().stream() @@ -916,7 +823,7 @@ void dropEntity(List catalogPath, PolarisBaseEntity entityToD } for (PolarisBaseEntity connectedEntity : securableEntities) { LoadGrantsResult grantResult = - polarisMetaStoreManager.loadGrantsOnSecurable(this.polarisCallContext, connectedEntity); + polarisMetaStoreManager.loadGrantsOnSecurable(connectedEntity); long cnt = grantResult.getGrantRecords().stream() .filter(gr -> gr.getGranteeId() == entityToDrop.getId()) @@ -933,8 +840,7 @@ public void grantPrivilege( PolarisBaseEntity securable, PolarisPrivilege priv) { // grant the privilege - polarisMetaStoreManager.grantPrivilegeOnSecurableToRole( - this.polarisCallContext, role, catalogPath, securable, priv); + polarisMetaStoreManager.grantPrivilegeOnSecurableToRole(role, catalogPath, securable, priv); // now validate the privilege this.ensureGrantRecordExists(securable, role, priv); @@ -947,8 +853,7 @@ void revokePrivilege( PolarisBaseEntity securable, PolarisPrivilege priv) { // grant the privilege - polarisMetaStoreManager.revokePrivilegeOnSecurableFromRole( - this.polarisCallContext, role, catalogPath, securable, priv); + polarisMetaStoreManager.revokePrivilegeOnSecurableFromRole(role, catalogPath, securable, priv); // now validate the privilege this.ensureGrantRecordRemoved(securable, role, priv); @@ -961,8 +866,7 @@ void grantToGrantee( PolarisBaseEntity grantee, PolarisPrivilege priv) { // grant the privilege - polarisMetaStoreManager.grantUsageOnRoleToGrantee( - this.polarisCallContext, catalog, granted, grantee); + polarisMetaStoreManager.grantUsageOnRoleToGrantee(catalog, granted, grantee); // now validate the privilege this.ensureGrantRecordExists(granted, grantee, priv); @@ -975,8 +879,7 @@ void revokeToGrantee( PolarisBaseEntity grantee, PolarisPrivilege priv) { // revoked the privilege - polarisMetaStoreManager.revokeUsageOnRoleFromGrantee( - this.polarisCallContext, catalog, granted, grantee); + polarisMetaStoreManager.revokeUsageOnRoleFromGrantee(catalog, granted, grantee); // now validate that the privilege is gone this.ensureGrantRecordRemoved(granted, grantee, priv); @@ -998,7 +901,7 @@ void attachPolicyToTarget( PolicyEntity policy, Map parameters) { polarisMetaStoreManager.attachPolicyToEntity( - polarisCallContext, targetCatalogPath, target, policyCatalogPath, policy, parameters); + targetCatalogPath, target, policyCatalogPath, policy, parameters); ensurePolicyMappingRecordExists(target, policy, parameters); } @@ -1010,7 +913,7 @@ void detachPolicyFromTarget( List policyCatalogPath, PolicyEntity policy) { polarisMetaStoreManager.detachPolicyFromEntity( - polarisCallContext, targetCatalogPath, target, policyCatalogPath, policy); + targetCatalogPath, target, policyCatalogPath, policy); ensurePolicyMappingRecordRemoved(target, policy); } @@ -1025,24 +928,19 @@ void ensurePolicyMappingRecordExists( PolarisBaseEntity target, PolicyEntity policy, Map parameters) { target = polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, target.getCatalogId(), target.getId(), target.getType()) + .loadEntity(target.getCatalogId(), target.getId(), target.getType()) .getEntity(); Assertions.assertThat(target).isNotNull(); policy = PolicyEntity.of( polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, - policy.getCatalogId(), - policy.getId(), - PolarisEntityType.POLICY) + .loadEntity(policy.getCatalogId(), policy.getId(), PolarisEntityType.POLICY) .getEntity()); Assertions.assertThat(policy).isNotNull(); LoadPolicyMappingsResult loadPolicyMappingsResult = - polarisMetaStoreManager.loadPoliciesOnEntity(this.polarisCallContext, target); + polarisMetaStoreManager.loadPoliciesOnEntity(target); validateLoadedPolicyMappings(loadPolicyMappingsResult); @@ -1051,8 +949,7 @@ void ensurePolicyMappingRecordExists( // also try load by specific type LoadPolicyMappingsResult loadPolicyMappingsResultByType = - polarisMetaStoreManager.loadPoliciesOnEntityByType( - this.polarisCallContext, target, policy.getPolicyType()); + polarisMetaStoreManager.loadPoliciesOnEntityByType(target, policy.getPolicyType()); validateLoadedPolicyMappings(loadPolicyMappingsResultByType); checkPolicyMappingRecordExists( loadPolicyMappingsResultByType.getPolicyMappingRecords(), target, policy, parameters); @@ -1067,24 +964,19 @@ void ensurePolicyMappingRecordExists( void ensurePolicyMappingRecordRemoved(PolarisBaseEntity target, PolicyEntity policy) { target = polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, target.getCatalogId(), target.getId(), target.getType()) + .loadEntity(target.getCatalogId(), target.getId(), target.getType()) .getEntity(); Assertions.assertThat(target).isNotNull(); policy = PolicyEntity.of( polarisMetaStoreManager - .loadEntity( - this.polarisCallContext, - policy.getCatalogId(), - policy.getId(), - PolarisEntityType.POLICY) + .loadEntity(policy.getCatalogId(), policy.getId(), PolarisEntityType.POLICY) .getEntity()); Assertions.assertThat(policy).isNotNull(); LoadPolicyMappingsResult loadPolicyMappingsResult = - polarisMetaStoreManager.loadPoliciesOnEntity(this.polarisCallContext, target); + polarisMetaStoreManager.loadPoliciesOnEntity(target); validateLoadedPolicyMappings(loadPolicyMappingsResult); @@ -1093,8 +985,7 @@ void ensurePolicyMappingRecordRemoved(PolarisBaseEntity target, PolicyEntity pol // also try load by specific type LoadPolicyMappingsResult loadPolicyMappingsResultByType = - polarisMetaStoreManager.loadPoliciesOnEntityByType( - this.polarisCallContext, target, policy.getPolicyType()); + polarisMetaStoreManager.loadPoliciesOnEntityByType(target, policy.getPolicyType()); validateLoadedPolicyMappings(loadPolicyMappingsResultByType); checkPolicyMappingRecordRemoved( loadPolicyMappingsResultByType.getPolicyMappingRecords(), target, policy); @@ -1118,7 +1009,6 @@ void validateLoadedPolicyMappings(LoadPolicyMappingsResult loadPolicyMappingReco PolicyEntity.of( polarisMetaStoreManager .loadEntity( - this.polarisCallContext, policyMappingRecord.getPolicyCatalogId(), policyMappingRecord.getPolicyId(), PolarisEntityType.POLICY) @@ -1241,13 +1131,12 @@ PolarisBaseEntity createTestCatalog(String catalogName) { PolarisBaseEntity catalog = new PolarisBaseEntity( PolarisEntityConstants.getNullId(), - polarisMetaStoreManager.generateNewEntityId(this.polarisCallContext).getId(), + polarisMetaStoreManager.generateNewEntityId().getId(), PolarisEntityType.CATALOG, PolarisEntitySubType.NULL_SUBTYPE, PolarisEntityConstants.getRootEntityId(), catalogName); - CreateCatalogResult catalogCreated = - polarisMetaStoreManager.createCatalog(this.polarisCallContext, catalog, List.of()); + CreateCatalogResult catalogCreated = polarisMetaStoreManager.createCatalog(catalog, List.of()); Assertions.assertThat(catalogCreated).isNotNull(); catalog = catalogCreated.getCatalog(); @@ -1360,8 +1249,7 @@ public PolarisBaseEntity ensureExistsByName( String name) { // find by name, ensure we found it EntityResult entityFound = - polarisMetaStoreManager.readEntityByName( - this.polarisCallContext, catalogPath, entityType, entitySubType, name); + polarisMetaStoreManager.readEntityByName(catalogPath, entityType, entitySubType, name); Assertions.assertThat(entityFound).isNotNull(); Assertions.assertThat(entityFound.isSuccess()).isTrue(); @@ -1438,7 +1326,6 @@ public PolarisBaseEntity updateEntity( PolarisBaseEntity beforeUpdateEntity = polarisMetaStoreManager .loadEntity( - this.polarisCallContext, updatedPropEntity.getCatalogId(), updatedPropEntity.getId(), updatedPropEntity.getType()) @@ -1447,8 +1334,7 @@ public PolarisBaseEntity updateEntity( // update that property PolarisBaseEntity updatedEntity = polarisMetaStoreManager - .updateEntityPropertiesIfNotChanged( - this.polarisCallContext, catalogPath, updatedPropEntity) + .updateEntityPropertiesIfNotChanged(catalogPath, updatedPropEntity) .getEntity(); // if version mismatch, nothing should be updated @@ -1460,7 +1346,6 @@ public PolarisBaseEntity updateEntity( entity = polarisMetaStoreManager .loadEntity( - this.polarisCallContext, updatedPropEntity.getCatalogId(), updatedPropEntity.getId(), updatedPropEntity.getType()) @@ -1518,7 +1403,6 @@ public PolarisBaseEntity updateEntity( List versions = polarisMetaStoreManager .loadEntitiesChangeTracking( - this.polarisCallContext, List.of(new PolarisEntityId(catalogId, updatedPropEntity.getId()))) .getChangeTrackingVersions(); Assertions.assertThat(versions).hasSize(1); @@ -1541,12 +1425,7 @@ private void validateListReturn( // list the entities under the specified path List result = polarisMetaStoreManager - .listEntities( - this.polarisCallContext, - path, - entityType, - entitySubType, - PageToken.readEverything()) + .listEntities(path, entityType, entitySubType, PageToken.readEverything()) .getEntities(); Assertions.assertThat(result).isNotNull(); @@ -1598,7 +1477,7 @@ private void validateCacheEntryLoad(ResolvedEntityResult cacheEntry) { PolarisEntity refEntity = PolarisEntity.of( this.polarisMetaStoreManager.loadEntity( - this.polarisCallContext, entity.getCatalogId(), entity.getId(), entity.getType())); + entity.getCatalogId(), entity.getId(), entity.getType())); Assertions.assertThat(refEntity).isNotNull(); // same entity @@ -1610,7 +1489,7 @@ private void validateCacheEntryLoad(ResolvedEntityResult cacheEntry) { List refGrantRecords = new ArrayList<>(); if (refEntity.getType().isGrantee()) { LoadGrantsResult loadGrantResult = - this.polarisMetaStoreManager.loadGrantsToGrantee(this.polarisCallContext, refEntity); + this.polarisMetaStoreManager.loadGrantsToGrantee(refEntity); this.validateLoadedGrants(loadGrantResult, true); // same version @@ -1621,7 +1500,7 @@ private void validateCacheEntryLoad(ResolvedEntityResult cacheEntry) { } LoadGrantsResult loadGrantResult = - this.polarisMetaStoreManager.loadGrantsOnSecurable(this.polarisCallContext, refEntity); + this.polarisMetaStoreManager.loadGrantsOnSecurable(refEntity); this.validateLoadedGrants(loadGrantResult, false); // same version @@ -1653,17 +1532,14 @@ private void validateCacheEntryRefresh( // reload the entity PolarisBaseEntity refEntity = - this.polarisMetaStoreManager - .loadEntity(this.polarisCallContext, catalogId, entityId, entityType) - .getEntity(); + this.polarisMetaStoreManager.loadEntity(catalogId, entityId, entityType).getEntity(); Assertions.assertThat(refEntity).isNotNull(); // reload the grants LoadGrantsResult loadGrantResult = refEntity.getType().isGrantee() - ? this.polarisMetaStoreManager.loadGrantsToGrantee(this.polarisCallContext, refEntity) - : this.polarisMetaStoreManager.loadGrantsOnSecurable( - this.polarisCallContext, refEntity); + ? this.polarisMetaStoreManager.loadGrantsToGrantee(refEntity) + : this.polarisMetaStoreManager.loadGrantsOnSecurable(refEntity); this.validateLoadedGrants(loadGrantResult, refEntity.getType().isGrantee()); Assertions.assertThat(cacheEntry.getGrantRecordsVersion()) .isEqualTo(loadGrantResult.getGrantsVersion()); @@ -1717,7 +1593,7 @@ private PolarisBaseEntity loadCacheEntryByName( // load cached entry ResolvedEntityResult cacheEntry = this.polarisMetaStoreManager.loadResolvedEntityByName( - this.polarisCallContext, entityCatalogId, parentId, entityType, entityName); + entityCatalogId, parentId, entityType, entityName); // if null, validate that indeed the entry does not exist Assertions.assertThat(cacheEntry.isSuccess()).isEqualTo(expectExists); @@ -1762,8 +1638,7 @@ private PolarisBaseEntity loadCacheEntryById( long entityCatalogId, long entityId, PolarisEntityType entityType, boolean expectExists) { // load cached entry ResolvedEntityResult cacheEntry = - this.polarisMetaStoreManager.loadResolvedEntityById( - this.polarisCallContext, entityCatalogId, entityId, entityType); + this.polarisMetaStoreManager.loadResolvedEntityById(entityCatalogId, entityId, entityType); // if null, validate that indeed the entry does not exist Assertions.assertThat(cacheEntry.isSuccess()).isEqualTo(expectExists); @@ -1811,12 +1686,7 @@ private void refreshCacheEntry( // load cached entry ResolvedEntityResult cacheEntry = this.polarisMetaStoreManager.refreshResolvedEntity( - this.polarisCallContext, - entityVersion, - entityGrantRecordsVersion, - entityType, - entityCatalogId, - entityId); + entityVersion, entityGrantRecordsVersion, entityType, entityCatalogId, entityId); // if null, validate that indeed the entry does not exist Assertions.assertThat(cacheEntry.isSuccess()).isEqualTo(expectExists); @@ -1860,7 +1730,6 @@ void validateBootstrap() { List principals = polarisMetaStoreManager .listEntities( - this.polarisCallContext, null, PolarisEntityType.PRINCIPAL, PolarisEntitySubType.NULL_SUBTYPE, @@ -1887,7 +1756,6 @@ void validateBootstrap() { List principalRoles = polarisMetaStoreManager .listEntities( - this.polarisCallContext, null, PolarisEntityType.PRINCIPAL_ROLE, PolarisEntitySubType.NULL_SUBTYPE, @@ -2346,11 +2214,7 @@ void testDropEntities() { // catalog exists EntityResult catalogFound = polarisMetaStoreManager.readEntityByName( - this.polarisCallContext, - null, - PolarisEntityType.CATALOG, - PolarisEntitySubType.NULL_SUBTYPE, - "test"); + null, PolarisEntityType.CATALOG, PolarisEntitySubType.NULL_SUBTYPE, "test"); // success and found Assertions.assertThat(catalogFound.isSuccess()).isTrue(); Assertions.assertThat(catalogFound.getEntity()).isNotNull(); @@ -2379,11 +2243,7 @@ void testDropEntities() { // catalog exists? catalogFound = polarisMetaStoreManager.readEntityByName( - this.polarisCallContext, - null, - PolarisEntityType.CATALOG, - PolarisEntitySubType.NULL_SUBTYPE, - "test"); + null, PolarisEntityType.CATALOG, PolarisEntitySubType.NULL_SUBTYPE, "test"); // success and not found Assertions.assertThat(catalogFound.getReturnStatus()) .isEqualTo(BaseResult.ReturnStatus.ENTITY_NOT_FOUND); @@ -2466,8 +2326,7 @@ public void testPrivileges() { // assign catalog role to PR9000 grantToGrantee(catalog, R1, PR9000, PolarisPrivilege.CATALOG_ROLE_USAGE); - LoadGrantsResult loadGrantsResult = - polarisMetaStoreManager.loadGrantsToGrantee(this.polarisCallContext, PR9000); + LoadGrantsResult loadGrantsResult = polarisMetaStoreManager.loadGrantsToGrantee(PR9000); this.validateLoadedGrants(loadGrantsResult, true); Assertions.assertThat(loadGrantsResult.getGrantRecords()).hasSize(1); Assertions.assertThat(loadGrantsResult.getGrantRecords().get(0).getSecurableCatalogId()) @@ -2475,7 +2334,7 @@ public void testPrivileges() { Assertions.assertThat(loadGrantsResult.getGrantRecords().get(0).getSecurableId()) .isEqualTo(R1.getId()); - loadGrantsResult = polarisMetaStoreManager.loadGrantsToGrantee(this.polarisCallContext, PR900); + loadGrantsResult = polarisMetaStoreManager.loadGrantsToGrantee(PR900); Assertions.assertThat(loadGrantsResult).isNotNull(); Assertions.assertThat(loadGrantsResult.getGrantRecords()).hasSize(0); } @@ -2512,7 +2371,6 @@ public void renameEntity( // check to see if we would have a name conflict EntityResult newNameLookup = polarisMetaStoreManager.readEntityByName( - polarisCallContext, newCatPath == null ? catPath : newCatPath, entity.getType(), PolarisEntitySubType.ANY_SUBTYPE, @@ -2521,7 +2379,7 @@ public void renameEntity( // rename it PolarisBaseEntity renamedEntity = polarisMetaStoreManager - .renameEntity(polarisCallContext, catPath, entity, newCatPath, renamedEntityInput) + .renameEntity(catPath, entity, newCatPath, renamedEntityInput) .getEntity(); // ensure success @@ -2548,7 +2406,7 @@ public void renameEntity( // ensure the old one is gone EntityResult res = polarisMetaStoreManager.readEntityByName( - polarisCallContext, catPath, entity.getType(), entity.getSubType(), oldName); + catPath, entity.getType(), entity.getSubType(), oldName); // not found Assertions.assertThat(res.getReturnStatus()) @@ -2628,7 +2486,6 @@ public void testLookup() { List principals = polarisMetaStoreManager .listEntities( - this.polarisCallContext, null, PolarisEntityType.PRINCIPAL, PolarisEntitySubType.NULL_SUBTYPE, @@ -2661,13 +2518,12 @@ public void testLookup() { PolarisBaseEntity catalog = new PolarisBaseEntity( PolarisEntityConstants.getNullId(), - polarisMetaStoreManager.generateNewEntityId(this.polarisCallContext).getId(), + polarisMetaStoreManager.generateNewEntityId().getId(), PolarisEntityType.CATALOG, PolarisEntitySubType.NULL_SUBTYPE, PolarisEntityConstants.getRootEntityId(), "test"); - CreateCatalogResult catalogCreated = - polarisMetaStoreManager.createCatalog(this.polarisCallContext, catalog, List.of()); + CreateCatalogResult catalogCreated = polarisMetaStoreManager.createCatalog(catalog, List.of()); Assertions.assertThat(catalogCreated).isNotNull(); catalog = catalogCreated.getCatalog(); @@ -2805,12 +2661,7 @@ void testPolicyMapping() { // attach a different policy of same inheritable type to the same target, should fail PolicyAttachmentResult policyAttachmentResult = polarisMetaStoreManager.attachPolicyToEntity( - polarisCallContext, - List.of(catalog, N1, N1_N2), - N1_N2_T1, - List.of(catalog, N1), - N1_P2, - null); + List.of(catalog, N1, N1_N2), N1_N2_T1, List.of(catalog, N1), N1_P2, null); Assertions.assertThat(policyAttachmentResult.isSuccess()).isFalse(); Assertions.assertThat(policyAttachmentResult.getReturnStatus()) @@ -2822,7 +2673,7 @@ void testPolicyMapping() { LoadPolicyMappingsResult loadPolicyMappingsResult = polarisMetaStoreManager.loadPoliciesOnEntityByType( - polarisCallContext, N1_N2_T1, PredefinedPolicyTypes.DATA_COMPACTION); + N1_N2_T1, PredefinedPolicyTypes.DATA_COMPACTION); Assertions.assertThat(loadPolicyMappingsResult.isSuccess()).isTrue(); Assertions.assertThat(loadPolicyMappingsResult.getEntities()).hasSize(1); PolicyEntity policyEntity = PolicyEntity.of(loadPolicyMappingsResult.getEntities().get(0)); @@ -2863,26 +2714,28 @@ void testPolicyMappingCleanup() { attachPolicyToTarget(List.of(catalog, N1, N1_N2), N1_N2_T3, List.of(catalog, N1), N1_P1); LoadPolicyMappingsResult loadPolicyMappingsResult = - polarisMetaStoreManager.loadPoliciesOnEntity(polarisCallContext, N1_N2_T3); + polarisMetaStoreManager.loadPoliciesOnEntity(N1_N2_T3); Assertions.assertThat(loadPolicyMappingsResult.isSuccess()).isTrue(); Assertions.assertThat(loadPolicyMappingsResult.getEntities()).hasSize(1); // Drop N1_N2_T1, the corresponding policy mapping should be cleaned-up this.dropEntity(List.of(catalog, N1, N1_N2), N1_N2_T3); + // FIXME: how to express this assertion without access to BasePersistence? + /* BasePersistence ms = polarisCallContext.getMetaStore(); Assertions.assertThat( ms.loadAllTargetsOnPolicy( polarisCallContext, N1_P1.getCatalogId(), N1_P1.getId(), N1_P1.getPolicyTypeCode())) .isEmpty(); + */ attachPolicyToTarget(List.of(catalog, N1, N1_N2), N1_N2_T1, List.of(catalog, N1), N1_P2); // Drop N1_P2, the dropEntity helper will have cleanup enabled to detach the policy from all // targets this.dropEntity(List.of(catalog, N1), N1_P2); - loadPolicyMappingsResult = - polarisMetaStoreManager.loadPoliciesOnEntity(polarisCallContext, N1_N2_T1); + loadPolicyMappingsResult = polarisMetaStoreManager.loadPoliciesOnEntity(N1_N2_T1); Assertions.assertThat(loadPolicyMappingsResult.isSuccess()).isTrue(); Assertions.assertThat(loadPolicyMappingsResult.getEntities()).isEmpty(); } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java b/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java index 67ae7ad6e5..fe023f3e86 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java @@ -46,7 +46,6 @@ import org.apache.iceberg.exceptions.NoSuchNamespaceException; import org.apache.iceberg.exceptions.NotFoundException; import org.apache.iceberg.exceptions.ValidationException; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.admin.model.AuthenticationParameters; import org.apache.polaris.core.admin.model.BearerAuthenticationParameters; @@ -184,10 +183,6 @@ public PolarisAdminService( this.reservedProperties = reservedProperties; } - private PolarisCallContext getCurrentPolarisContext() { - return callContext.getPolarisCallContext(); - } - private UserSecretsManager getUserSecretsManager() { return userSecretsManager; } @@ -530,10 +525,8 @@ private PolarisResolutionManifest authorizeGrantOnTableLikeOperationOrThrow( resolutionManifest.getResolvedPath( identifier, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ANY_SUBTYPE, true); boolean rbacForFederatedCatalogsEnabled = - getCurrentPolarisContext() - .getRealmConfig() - .getConfig( - FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS, catalogEntity); + realmConfig.getConfig( + FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS, catalogEntity); if (!(resolutionManifest.getIsPassthroughFacade() && rbacForFederatedCatalogsEnabled) && !subTypes.contains(tableLikeWrapper.getRawLeafEntity().getSubType())) { CatalogHandler.throwNotFoundExceptionForTableLikeEntity(identifier, subTypes); @@ -739,7 +732,7 @@ public PolarisEntity createCatalog(CreateCatalogRequest catalogRequest) { // After basic validations, now populate id and creation timestamp. entity = new CatalogEntity.Builder(entity) - .setId(metaStoreManager.generateNewEntityId(getCurrentPolarisContext()).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setCreateTimestamp(System.currentTimeMillis()) .setProperties(reservedProperties.removeReservedProperties(entity.getPropertiesAsMap())) .build(); @@ -799,8 +792,7 @@ public PolarisEntity createCatalog(CreateCatalogRequest catalogRequest) { } } - CreateCatalogResult catalogResult = - metaStoreManager.createCatalog(getCurrentPolarisContext(), entity, List.of()); + CreateCatalogResult catalogResult = metaStoreManager.createCatalog(entity, List.of()); if (catalogResult.alreadyExists()) { // TODO: Proactive garbage-collection of any inline secrets that were written to the // secrets manager, here and on any other unexpected exception as well. @@ -827,8 +819,7 @@ public void deleteCatalog(String name) { // TODO: Handle return value in case of concurrent modification boolean cleanup = realmConfig.getConfig(FeatureConfiguration.CLEANUP_ON_CATALOG_DROP); DropEntityResult dropEntityResult = - metaStoreManager.dropEntityIfExists( - getCurrentPolarisContext(), null, entity, Map.of(), cleanup); + metaStoreManager.dropEntityIfExists(null, entity, Map.of(), cleanup); // at least some handling of error if (!dropEntityResult.isSuccess()) { @@ -959,8 +950,7 @@ private void validateUpdateCatalogDiffOrThrow( Optional.ofNullable( CatalogEntity.of( PolarisEntity.of( - metaStoreManager.updateEntityPropertiesIfNotChanged( - getCurrentPolarisContext(), null, updatedEntity)))) + metaStoreManager.updateEntityPropertiesIfNotChanged(null, updatedEntity)))) .orElseThrow( () -> new CommitConflictException( @@ -979,11 +969,7 @@ public List listCatalogs() { /** List all catalogs without checking for permission. */ private Stream listCatalogsUnsafe() { return metaStoreManager - .loadEntitiesAll( - getCurrentPolarisContext(), - null, - PolarisEntityType.CATALOG, - PolarisEntitySubType.ANY_SUBTYPE) + .loadEntitiesAll(null, PolarisEntityType.CATALOG, PolarisEntitySubType.ANY_SUBTYPE) .stream() .map(CatalogEntity::of); } @@ -1000,9 +986,8 @@ public PrincipalWithCredentials createPrincipal(PrincipalEntity entity) { CreatePrincipalResult principalResult = metaStoreManager.createPrincipal( - getCurrentPolarisContext(), new PrincipalEntity.Builder(entity) - .setId(metaStoreManager.generateNewEntityId(getCurrentPolarisContext()).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setCreateTimestamp(System.currentTimeMillis()) .build()); if (principalResult.alreadyExists()) { @@ -1025,8 +1010,7 @@ public void deletePrincipal(String name) { PrincipalEntity entity = getPrincipalByName(resolutionManifest, name); // TODO: Handle return value in case of concurrent modification DropEntityResult dropEntityResult = - metaStoreManager.dropEntityIfExists( - getCurrentPolarisContext(), null, entity, Map.of(), false); + metaStoreManager.dropEntityIfExists(null, entity, Map.of(), false); // at least some handling of error if (!dropEntityResult.isSuccess()) { @@ -1078,8 +1062,7 @@ public void deletePrincipal(String name) { Optional.ofNullable( PrincipalEntity.of( PolarisEntity.of( - metaStoreManager.updateEntityPropertiesIfNotChanged( - getCurrentPolarisContext(), null, updatedEntity)))) + metaStoreManager.updateEntityPropertiesIfNotChanged(null, updatedEntity)))) .orElseThrow( () -> new CommitConflictException( @@ -1100,14 +1083,12 @@ public void deletePrincipal(String name) { } PolarisPrincipalSecrets currentSecrets = metaStoreManager - .loadPrincipalSecrets(getCurrentPolarisContext(), currentPrincipalEntity.getClientId()) + .loadPrincipalSecrets(currentPrincipalEntity.getClientId()) .getPrincipalSecrets(); // delete the existing creds if present if (currentSecrets != null) { metaStoreManager.deletePrincipalSecrets( - getCurrentPolarisContext(), - currentPrincipalEntity.getClientId(), - currentPrincipalEntity.getId()); + currentPrincipalEntity.getClientId(), currentPrincipalEntity.getId()); } PrincipalEntity newPrincipalEntity = currentPrincipalEntity; // update the clientId tied to the principal entity @@ -1120,7 +1101,7 @@ public void deletePrincipal(String name) { PrincipalEntity.of( PolarisEntity.of( metaStoreManager.updateEntityPropertiesIfNotChanged( - getCurrentPolarisContext(), null, updatedNewPrincipalEntity)))) + null, updatedNewPrincipalEntity)))) .orElseThrow( () -> new CommitConflictException( @@ -1134,10 +1115,7 @@ public void deletePrincipal(String name) { PolarisPrincipalSecrets newSecrets = metaStoreManager .resetPrincipalSecrets( - getCurrentPolarisContext(), - currentPrincipalEntity.getId(), - resolvedClientId, - customClientSecret) + currentPrincipalEntity.getId(), resolvedClientId, customClientSecret) .getPrincipalSecrets(); if (newSecrets == null) { @@ -1161,7 +1139,7 @@ public void deletePrincipal(String name) { } PolarisPrincipalSecrets currentSecrets = metaStoreManager - .loadPrincipalSecrets(getCurrentPolarisContext(), currentPrincipalEntity.getClientId()) + .loadPrincipalSecrets(currentPrincipalEntity.getClientId()) .getPrincipalSecrets(); if (currentSecrets == null) { throw new IllegalArgumentException( @@ -1170,7 +1148,6 @@ public void deletePrincipal(String name) { PolarisPrincipalSecrets newSecrets = metaStoreManager .rotatePrincipalSecrets( - getCurrentPolarisContext(), currentPrincipalEntity.getClientId(), currentPrincipalEntity.getId(), shouldReset, @@ -1183,8 +1160,7 @@ public void deletePrincipal(String name) { shouldReset ? "reset" : "rotate", principalName)); } Optional updatedPrincipalEntity = - metaStoreManager.findPrincipalById( - getCurrentPolarisContext(), currentPrincipalEntity.getId()); + metaStoreManager.findPrincipalById(currentPrincipalEntity.getId()); if (updatedPrincipalEntity.isEmpty()) { throw new IllegalStateException( String.format( @@ -1226,11 +1202,7 @@ public List listPrincipals() { authorizeBasicRootOperationOrThrow(op); return metaStoreManager - .loadEntitiesAll( - getCurrentPolarisContext(), - null, - PolarisEntityType.PRINCIPAL, - PolarisEntitySubType.NULL_SUBTYPE) + .loadEntitiesAll(null, PolarisEntityType.PRINCIPAL, PolarisEntitySubType.NULL_SUBTYPE) .stream() .map(PrincipalEntity::of) .map(PrincipalEntity::asPrincipal) @@ -1246,10 +1218,9 @@ public PolarisEntity createPrincipalRole(PolarisEntity entity) { PolarisEntity returnedEntity = PolarisEntity.of( metaStoreManager.createEntityIfNotExists( - getCurrentPolarisContext(), null, new PolarisEntity.Builder(entity) - .setId(metaStoreManager.generateNewEntityId(getCurrentPolarisContext()).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setCreateTimestamp(System.currentTimeMillis()) .build())); if (returnedEntity == null) { @@ -1268,8 +1239,7 @@ public void deletePrincipalRole(String name) { PrincipalRoleEntity entity = getPrincipalRoleByName(resolutionManifest, name); // TODO: Handle return value in case of concurrent modification DropEntityResult dropEntityResult = - metaStoreManager.dropEntityIfExists( - getCurrentPolarisContext(), null, entity, Map.of(), true); // cleanup grants + metaStoreManager.dropEntityIfExists(null, entity, Map.of(), true); // cleanup grants // at least some handling of error if (!dropEntityResult.isSuccess()) { @@ -1319,8 +1289,7 @@ public void deletePrincipalRole(String name) { Optional.ofNullable( PrincipalRoleEntity.of( PolarisEntity.of( - metaStoreManager.updateEntityPropertiesIfNotChanged( - getCurrentPolarisContext(), null, updatedEntity)))) + metaStoreManager.updateEntityPropertiesIfNotChanged(null, updatedEntity)))) .orElseThrow( () -> new CommitConflictException( @@ -1333,11 +1302,7 @@ public List listPrincipalRoles() { authorizeBasicRootOperationOrThrow(op); return metaStoreManager - .loadEntitiesAll( - getCurrentPolarisContext(), - null, - PolarisEntityType.PRINCIPAL_ROLE, - PolarisEntitySubType.NULL_SUBTYPE) + .loadEntitiesAll(null, PolarisEntityType.PRINCIPAL_ROLE, PolarisEntitySubType.NULL_SUBTYPE) .stream() .map(PrincipalRoleEntity::of) .map(PrincipalRoleEntity::asPrincipalRole) @@ -1356,10 +1321,9 @@ public PolarisEntity createCatalogRole(String catalogName, PolarisEntity entity) PolarisEntity returnedEntity = PolarisEntity.of( metaStoreManager.createEntityIfNotExists( - getCurrentPolarisContext(), PolarisEntity.toCoreList(List.of(catalogEntity)), new PolarisEntity.Builder(entity) - .setId(metaStoreManager.generateNewEntityId(getCurrentPolarisContext()).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setCatalogId(catalogEntity.getId()) .setParentId(catalogEntity.getId()) .setCreateTimestamp(System.currentTimeMillis()) @@ -1384,7 +1348,6 @@ public void deleteCatalogRole(String catalogName, String name) { // TODO: Handle return value in case of concurrent modification DropEntityResult dropEntityResult = metaStoreManager.dropEntityIfExists( - getCurrentPolarisContext(), PolarisEntity.toCoreList(resolvedCatalogRoleEntity.getRawParentPath()), resolvedCatalogRoleEntity.getRawLeafEntity(), Map.of(), @@ -1439,9 +1402,7 @@ public void deleteCatalogRole(String catalogName, String name) { CatalogRoleEntity.of( PolarisEntity.of( metaStoreManager.updateEntityPropertiesIfNotChanged( - getCurrentPolarisContext(), - PolarisEntity.toCoreList(List.of(catalogEntity)), - updatedEntity)))) + PolarisEntity.toCoreList(List.of(catalogEntity)), updatedEntity)))) .orElseThrow( () -> new CommitConflictException( @@ -1458,10 +1419,7 @@ public List listCatalogRoles(String catalogName) { List catalogPath = PolarisEntity.toCoreList(List.of(catalogEntity)); return metaStoreManager .loadEntitiesAll( - getCurrentPolarisContext(), - catalogPath, - PolarisEntityType.CATALOG_ROLE, - PolarisEntitySubType.NULL_SUBTYPE) + catalogPath, PolarisEntityType.CATALOG_ROLE, PolarisEntitySubType.NULL_SUBTYPE) .stream() .map(CatalogRoleEntity::of) .map(CatalogRoleEntity::asCatalogRole) @@ -1483,8 +1441,7 @@ public PrivilegeResult assignPrincipalRole(String principalName, String principa if (FederatedEntities.isFederated(principalRoleEntity)) { throw new ValidationException("Cannot assign a federated role to a principal"); } - return metaStoreManager.grantUsageOnRoleToGrantee( - getCurrentPolarisContext(), null, principalRoleEntity, principalEntity); + return metaStoreManager.grantUsageOnRoleToGrantee(null, principalRoleEntity, principalEntity); } public PrivilegeResult revokePrincipalRole(String principalName, String principalRoleName) { @@ -1503,7 +1460,7 @@ public PrivilegeResult revokePrincipalRole(String principalName, String principa throw new ValidationException("Cannot revoke a federated role from a principal"); } return metaStoreManager.revokeUsageOnRoleFromGrantee( - getCurrentPolarisContext(), null, principalRoleEntity, principalEntity); + null, principalRoleEntity, principalEntity); } public List listPrincipalRolesAssigned(String principalName) { @@ -1514,8 +1471,7 @@ public List listPrincipalRolesAssigned(String principalName) { op, principalName, PolarisEntityType.PRINCIPAL); PrincipalEntity principalEntity = getPrincipalByName(resolutionManifest, principalName); - LoadGrantsResult grantList = - metaStoreManager.loadGrantsToGrantee(getCurrentPolarisContext(), principalEntity); + LoadGrantsResult grantList = metaStoreManager.loadGrantsToGrantee(principalEntity); return buildEntitiesFromGrantResults(grantList, false, PolarisEntityType.PRINCIPAL_ROLE, null); } @@ -1533,7 +1489,7 @@ public PrivilegeResult assignCatalogRoleToPrincipalRole( CatalogRoleEntity catalogRoleEntity = getCatalogRoleByName(resolutionManifest, catalogRoleName); return metaStoreManager.grantUsageOnRoleToGrantee( - getCurrentPolarisContext(), catalogEntity, catalogRoleEntity, principalRoleEntity); + catalogEntity, catalogRoleEntity, principalRoleEntity); } public PrivilegeResult revokeCatalogRoleFromPrincipalRole( @@ -1549,7 +1505,7 @@ public PrivilegeResult revokeCatalogRoleFromPrincipalRole( CatalogEntity catalogEntity = getCatalogByName(resolutionManifest, catalogName); CatalogRoleEntity catalogRoleEntity = getCatalogRoleByName(resolutionManifest, catalogRoleName); return metaStoreManager.revokeUsageOnRoleFromGrantee( - getCurrentPolarisContext(), catalogEntity, catalogRoleEntity, principalRoleEntity); + catalogEntity, catalogRoleEntity, principalRoleEntity); } public List listAssigneePrincipalsForPrincipalRole(String principalRoleName) { @@ -1562,8 +1518,7 @@ public List listAssigneePrincipalsForPrincipalRole(String princip PrincipalRoleEntity principalRoleEntity = getPrincipalRoleByName(resolutionManifest, principalRoleName); - LoadGrantsResult grantList = - metaStoreManager.loadGrantsOnSecurable(getCurrentPolarisContext(), principalRoleEntity); + LoadGrantsResult grantList = metaStoreManager.loadGrantsOnSecurable(principalRoleEntity); return buildEntitiesFromGrantResults(grantList, true, PolarisEntityType.PRINCIPAL, null); } @@ -1611,8 +1566,7 @@ public List listCatalogRolesForPrincipalRole( CatalogEntity catalogEntity = getCatalogByName(resolutionManifest, catalogName); PrincipalRoleEntity principalRoleEntity = getPrincipalRoleByName(resolutionManifest, principalRoleName); - LoadGrantsResult grantList = - metaStoreManager.loadGrantsToGrantee(getCurrentPolarisContext(), principalRoleEntity); + LoadGrantsResult grantList = metaStoreManager.loadGrantsToGrantee(principalRoleEntity); return buildEntitiesFromGrantResults( grantList, false, @@ -1633,7 +1587,7 @@ public PrivilegeResult grantPrivilegeOnRootContainerToPrincipalRole( getPrincipalRoleByName(resolutionManifest, principalRoleName); return metaStoreManager.grantPrivilegeOnSecurableToRole( - getCurrentPolarisContext(), principalRoleEntity, null, rootContainerEntity, privilege); + principalRoleEntity, null, rootContainerEntity, privilege); } /** Revokes a grant on the root container of this realm from {@code principalRoleName}. */ @@ -1650,7 +1604,7 @@ public PrivilegeResult revokePrivilegeOnRootContainerFromPrincipalRole( getPrincipalRoleByName(resolutionManifest, principalRoleName); return metaStoreManager.revokePrivilegeOnSecurableFromRole( - getCurrentPolarisContext(), principalRoleEntity, null, rootContainerEntity, privilege); + principalRoleEntity, null, rootContainerEntity, privilege); } /** @@ -1669,7 +1623,6 @@ public PrivilegeResult grantPrivilegeOnCatalogToRole( CatalogRoleEntity catalogRoleEntity = getCatalogRoleByName(resolutionManifest, catalogRoleName); return metaStoreManager.grantPrivilegeOnSecurableToRole( - getCurrentPolarisContext(), catalogRoleEntity, PolarisEntity.toCoreList(List.of(catalogEntity)), catalogEntity, @@ -1688,7 +1641,6 @@ public PrivilegeResult revokePrivilegeOnCatalogFromRole( CatalogRoleEntity catalogRoleEntity = getCatalogRoleByName(resolutionManifest, catalogRoleName); return metaStoreManager.revokePrivilegeOnSecurableFromRole( - getCurrentPolarisContext(), catalogRoleEntity, PolarisEntity.toCoreList(List.of(catalogEntity)), catalogEntity, @@ -1710,11 +1662,8 @@ public PrivilegeResult grantPrivilegeOnNamespaceToRole( if (resolvedPathWrapper == null || !resolvedPathWrapper.isFullyResolvedNamespace(catalogName, namespace)) { boolean rbacForFederatedCatalogsEnabled = - getCurrentPolarisContext() - .getRealmConfig() - .getConfig( - FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS, - catalogEntity); + realmConfig.getConfig( + FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS, catalogEntity); if (resolutionManifest.getIsPassthroughFacade() && rbacForFederatedCatalogsEnabled) { resolvedPathWrapper = createSyntheticNamespaceEntities( @@ -1735,11 +1684,7 @@ public PrivilegeResult grantPrivilegeOnNamespaceToRole( PolarisEntity namespaceEntity = resolvedPathWrapper.getRawLeafEntity(); return metaStoreManager.grantPrivilegeOnSecurableToRole( - getCurrentPolarisContext(), - catalogRoleEntity, - PolarisEntity.toCoreList(catalogPath), - namespaceEntity, - privilege); + catalogRoleEntity, PolarisEntity.toCoreList(catalogPath), namespaceEntity, privilege); } /** Removes a namespace-level grant on {@code namespace} from {@code catalogRoleName}. */ @@ -1761,11 +1706,7 @@ public PrivilegeResult revokePrivilegeOnNamespaceFromRole( PolarisEntity namespaceEntity = resolvedPathWrapper.getRawLeafEntity(); return metaStoreManager.revokePrivilegeOnSecurableFromRole( - getCurrentPolarisContext(), - catalogRoleEntity, - PolarisEntity.toCoreList(catalogPath), - namespaceEntity, - privilege); + catalogRoleEntity, PolarisEntity.toCoreList(catalogPath), namespaceEntity, privilege); } /** @@ -1809,7 +1750,7 @@ private PolarisResolvedPathWrapper createSyntheticNamespaceEntities( // TODO: Instead of creating synthetic entitties, rely on external catalog mediated backfill. PolarisEntity syntheticNamespace = new NamespaceEntity.Builder(currentNamespace) - .setId(metaStoreManager.generateNewEntityId(getCurrentPolarisContext()).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setCatalogId(catalogEntity.getId()) .setParentId(currentParent.getId()) .setCreateTimestamp(System.currentTimeMillis()) @@ -1817,9 +1758,7 @@ private PolarisResolvedPathWrapper createSyntheticNamespaceEntities( EntityResult result = metaStoreManager.createEntityIfNotExists( - getCurrentPolarisContext(), - PolarisEntity.toCoreList(completePath), - syntheticNamespace); + PolarisEntity.toCoreList(completePath), syntheticNamespace); if (result.isSuccess()) { syntheticNamespace = PolarisEntity.of(result.getEntity()); @@ -1986,8 +1925,7 @@ public List listAssigneePrincipalRolesForCatalogRole( authorizeBasicCatalogRoleOperationOrThrow(op, catalogName, catalogRoleName); CatalogRoleEntity catalogRoleEntity = getCatalogRoleByName(resolutionManifest, catalogRoleName); - LoadGrantsResult grantList = - metaStoreManager.loadGrantsOnSecurable(getCurrentPolarisContext(), catalogRoleEntity); + LoadGrantsResult grantList = metaStoreManager.loadGrantsOnSecurable(catalogRoleEntity); return buildEntitiesFromGrantResults(grantList, true, PolarisEntityType.PRINCIPAL_ROLE, null); } @@ -2001,8 +1939,7 @@ public List listGrantsForCatalogRole(String catalogName, String c authorizeBasicCatalogRoleOperationOrThrow(op, catalogName, catalogRoleName); CatalogRoleEntity catalogRoleEntity = getCatalogRoleByName(resolutionManifest, catalogRoleName); - LoadGrantsResult grantList = - metaStoreManager.loadGrantsToGrantee(getCurrentPolarisContext(), catalogRoleEntity); + LoadGrantsResult grantList = metaStoreManager.loadGrantsToGrantee(catalogRoleEntity); List catalogGrants = new ArrayList<>(); List namespaceGrants = new ArrayList<>(); List tableGrants = new ArrayList<>(); @@ -2108,9 +2045,7 @@ public List listGrantsForCatalogRole(String catalogName, String c long id, PolarisEntityType entityType) { return (entitiesMap == null) - ? metaStoreManager - .loadEntity(getCurrentPolarisContext(), catalogId, id, entityType) - .getEntity() + ? metaStoreManager.loadEntity(catalogId, id, entityType).getEntity() : entitiesMap.get(id); } @@ -2123,10 +2058,7 @@ public List listGrantsForCatalogRole(String catalogName, String c for (PolarisEntityType type : PolarisEntityType.values()) { EntityResult entityResult = metaStoreManager.loadEntity( - getCurrentPolarisContext(), - record.getSecurableCatalogId(), - record.getSecurableId(), - type); + record.getSecurableCatalogId(), record.getSecurableId(), type); if (entityResult.isSuccess()) { return entityResult.getEntity(); } @@ -2152,11 +2084,8 @@ private PrivilegeResult grantPrivilegeOnTableLikeToRole( if (resolvedPathWrapper == null || !subTypes.contains(resolvedPathWrapper.getRawLeafEntity().getSubType())) { boolean rbacForFederatedCatalogsEnabled = - getCurrentPolarisContext() - .getRealmConfig() - .getConfig( - FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS, - catalogEntity); + realmConfig.getConfig( + FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS, catalogEntity); if (resolutionManifest.getIsPassthroughFacade() && rbacForFederatedCatalogsEnabled) { resolvedPathWrapper = createSyntheticTableLikeEntities( @@ -2177,11 +2106,7 @@ private PrivilegeResult grantPrivilegeOnTableLikeToRole( PolarisEntity tableLikeEntity = resolvedPathWrapper.getRawLeafEntity(); return metaStoreManager.grantPrivilegeOnSecurableToRole( - getCurrentPolarisContext(), - catalogRoleEntity, - PolarisEntity.toCoreList(catalogPath), - tableLikeEntity, - privilege); + catalogRoleEntity, PolarisEntity.toCoreList(catalogPath), tableLikeEntity, privilege); } /** @@ -2230,13 +2155,12 @@ private PolarisResolvedPathWrapper createSyntheticTableLikeEntities( PolarisEntity syntheticTableEntity = new IcebergTableLikeEntity.Builder(syntheticEntitySubType, identifier, "") .setParentId(parentNamespaceEntity.getId()) - .setId(metaStoreManager.generateNewEntityId(getCurrentPolarisContext()).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setCatalogId(parentNamespaceEntity.getCatalogId()) .setCreateTimestamp(System.currentTimeMillis()) .build(); // We will re-resolve later anyway, so metaStoreManager.createEntityIfNotExists( - getCurrentPolarisContext(), PolarisEntity.toCoreList(resolvedNamespacePathWrapper.getRawFullPath()), syntheticTableEntity); @@ -2280,7 +2204,6 @@ private PrivilegeResult revokePrivilegeOnTableLikeFromRole( PolarisEntity tableLikeEntity = resolvedPathWrapper.getRawLeafEntity(); return metaStoreManager.revokePrivilegeOnSecurableFromRole( - getCurrentPolarisContext(), catalogRoleEntity, PolarisEntity.toCoreList(List.of(catalogEntity)), tableLikeEntity, @@ -2304,7 +2227,6 @@ private PrivilegeResult grantPrivilegeOnPolicyEntityToRole( PolarisEntity policyEntity = resolvedPathWrapper.getRawLeafEntity(); return metaStoreManager.grantPrivilegeOnSecurableToRole( - getCurrentPolarisContext(), catalogRoleEntity, PolarisEntity.toCoreList(List.of(catalogEntity)), policyEntity, @@ -2328,7 +2250,6 @@ private PrivilegeResult revokePrivilegeOnPolicyEntityFromRole( PolarisEntity policyEntity = resolvedPathWrapper.getRawLeafEntity(); return metaStoreManager.revokePrivilegeOnSecurableFromRole( - getCurrentPolarisContext(), catalogRoleEntity, PolarisEntity.toCoreList(List.of(catalogEntity)), policyEntity, diff --git a/runtime/service/src/main/java/org/apache/polaris/service/auth/DefaultAuthenticator.java b/runtime/service/src/main/java/org/apache/polaris/service/auth/DefaultAuthenticator.java index 83a3a419d7..3d666df35c 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/auth/DefaultAuthenticator.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/auth/DefaultAuthenticator.java @@ -27,10 +27,8 @@ import java.util.stream.Collectors; import org.apache.iceberg.exceptions.NotAuthorizedException; import org.apache.iceberg.exceptions.ServiceFailureException; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.auth.PolarisPrincipal; -import org.apache.polaris.core.context.CallContext; import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.entity.PrincipalRoleEntity; @@ -84,7 +82,6 @@ public class DefaultAuthenticator implements Authenticator { private static final Set ALL_ROLES_REQUESTED = Set.of(); @Inject PolarisMetaStoreManager metaStoreManager; - @Inject CallContext callContext; @Inject PolarisDiagnostics diagnostics; @Override @@ -114,17 +111,10 @@ protected PrincipalEntity resolvePrincipalEntity(PolarisCredential credentials) // If the principal id is present, prefer to use it to load the principal entity, // otherwise, use the principal name to load the entity. if (credentials.getPrincipalId() != null && credentials.getPrincipalId() > 0) { - principal = - metaStoreManager - .findPrincipalById( - callContext.getPolarisCallContext(), credentials.getPrincipalId()) - .orElse(null); + principal = metaStoreManager.findPrincipalById(credentials.getPrincipalId()).orElse(null); } else if (credentials.getPrincipalName() != null) { principal = - metaStoreManager - .findPrincipalByName( - callContext.getPolarisCallContext(), credentials.getPrincipalName()) - .orElse(null); + metaStoreManager.findPrincipalByName(credentials.getPrincipalName()).orElse(null); } } catch (Exception e) { LOGGER @@ -169,7 +159,6 @@ protected Set resolvePrincipalRoles( .map( gr -> metaStoreManager.loadEntity( - callContext.getPolarisCallContext(), gr.getSecurableCatalogId(), gr.getSecurableId(), PolarisEntityType.PRINCIPAL_ROLE)) @@ -229,9 +218,7 @@ protected Set extractRequestedRoles(PolarisCredential credentials) { * will be used to determine the active roles for the principal. */ protected LoadGrantsResult loadPrincipalGrants(PrincipalEntity principal) { - PolarisCallContext polarisContext = callContext.getPolarisCallContext(); - LoadGrantsResult principalGrantResults = - metaStoreManager.loadGrantsToGrantee(polarisContext, principal); + LoadGrantsResult principalGrantResults = metaStoreManager.loadGrantsToGrantee(principal); diagnostics.check( principalGrantResults.isSuccess(), "Failed to resolve principal roles for principal name={} id={}", diff --git a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/JWTBroker.java b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/JWTBroker.java index 71ea0d0548..a4680b0f43 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/JWTBroker.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/JWTBroker.java @@ -27,7 +27,6 @@ import java.util.Optional; import java.util.UUID; import org.apache.iceberg.exceptions.NotAuthorizedException; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult; @@ -48,11 +47,9 @@ public abstract class JWTBroker implements TokenBroker { private static final String CLAIM_KEY_PRINCIPAL_ID = "principalId"; private static final String CLAIM_KEY_SCOPE = "scope"; - private final PolarisMetaStoreManager metaStoreManager; private final int maxTokenGenerationInSeconds; - JWTBroker(PolarisMetaStoreManager metaStoreManager, int maxTokenGenerationInSeconds) { - this.metaStoreManager = metaStoreManager; + JWTBroker(int maxTokenGenerationInSeconds) { this.maxTokenGenerationInSeconds = maxTokenGenerationInSeconds; } @@ -86,7 +83,7 @@ public TokenResponse generateFromToken( String subjectToken, String grantType, String scope, - PolarisCallContext polarisCallContext, + PolarisMetaStoreManager metaStoreManager, TokenType requestedTokenType) { if (requestedTokenType != null && !TokenType.ACCESS_TOKEN.equals(requestedTokenType)) { return TokenResponse.of(OAuthError.invalid_request); @@ -105,7 +102,7 @@ public TokenResponse generateFromToken( return TokenResponse.of(OAuthError.invalid_client); } Optional principalLookup = - metaStoreManager.findPrincipalById(polarisCallContext, decodedToken.getPrincipalId()); + metaStoreManager.findPrincipalById(decodedToken.getPrincipalId()); if (principalLookup.isEmpty()) { return TokenResponse.of(OAuthError.unauthorized_client); } @@ -125,7 +122,7 @@ public TokenResponse generateFromClientSecrets( String clientSecret, String grantType, String scope, - PolarisCallContext polarisCallContext, + PolarisMetaStoreManager metaStoreManager, TokenType requestedTokenType) { // Initial sanity checks TokenRequestValidator validator = new TokenRequestValidator(); @@ -136,7 +133,7 @@ public TokenResponse generateFromClientSecrets( } Optional principal = - findPrincipalEntity(clientId, clientSecret, polarisCallContext); + findPrincipalEntity(metaStoreManager, clientId, clientSecret); if (principal.isEmpty()) { return TokenResponse.of(OAuthError.unauthorized_client); } @@ -177,10 +174,9 @@ private String scopes(String scope) { } private Optional findPrincipalEntity( - String clientId, String clientSecret, PolarisCallContext polarisCallContext) { + PolarisMetaStoreManager metaStoreManager, String clientId, String clientSecret) { // Validate the principal is present and secrets match - PrincipalSecretsResult principalSecrets = - metaStoreManager.loadPrincipalSecrets(polarisCallContext, clientId); + PrincipalSecretsResult principalSecrets = metaStoreManager.loadPrincipalSecrets(clientId); if (!principalSecrets.isSuccess()) { return Optional.empty(); } @@ -188,6 +184,6 @@ private Optional findPrincipalEntity( return Optional.empty(); } return metaStoreManager.findPrincipalById( - polarisCallContext, principalSecrets.getPrincipalSecrets().getPrincipalId()); + principalSecrets.getPrincipalSecrets().getPrincipalId()); } } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBroker.java b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBroker.java index a2d903f6e7..13f1d7259c 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBroker.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBroker.java @@ -21,18 +21,14 @@ import com.auth0.jwt.algorithms.Algorithm; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager; /** Generates a JWT using a Public/Private RSA Key */ public class RSAKeyPairJWTBroker extends JWTBroker { private final KeyProvider keyProvider; - RSAKeyPairJWTBroker( - PolarisMetaStoreManager metaStoreManager, - int maxTokenGenerationInSeconds, - KeyProvider keyProvider) { - super(metaStoreManager, maxTokenGenerationInSeconds); + RSAKeyPairJWTBroker(int maxTokenGenerationInSeconds, KeyProvider keyProvider) { + super(maxTokenGenerationInSeconds); this.keyProvider = keyProvider; } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBrokerFactory.java b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBrokerFactory.java index 74b4f90ef8..2feea2dd7f 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBrokerFactory.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBrokerFactory.java @@ -26,8 +26,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.apache.polaris.core.context.RealmContext; -import org.apache.polaris.core.persistence.MetaStoreManagerFactory; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.service.auth.AuthenticationConfiguration; import org.apache.polaris.service.auth.AuthenticationRealmConfiguration; import org.apache.polaris.service.auth.AuthenticationRealmConfiguration.TokenBrokerConfiguration.RSAKeyPairConfiguration; @@ -36,21 +34,17 @@ @Identifier("rsa-key-pair") public class RSAKeyPairJWTBrokerFactory implements TokenBrokerFactory { - private final MetaStoreManagerFactory metaStoreManagerFactory; private final AuthenticationConfiguration authenticationConfiguration; private final ConcurrentMap tokenBrokers = new ConcurrentHashMap<>(); @Inject - public RSAKeyPairJWTBrokerFactory( - MetaStoreManagerFactory metaStoreManagerFactory, - AuthenticationConfiguration authenticationConfiguration) { - this.metaStoreManagerFactory = metaStoreManagerFactory; + public RSAKeyPairJWTBrokerFactory(AuthenticationConfiguration authenticationConfiguration) { this.authenticationConfiguration = authenticationConfiguration; } @Override - public TokenBroker apply(RealmContext realmContext) { + public TokenBroker newTokenBroker(RealmContext realmContext) { return tokenBrokers.computeIfAbsent( realmContext.getRealmIdentifier(), k -> createTokenBroker(realmContext)); } @@ -64,10 +58,7 @@ private RSAKeyPairJWTBroker createTokenBroker(RealmContext realmContext) { .rsaKeyPair() .map(this::fileSystemKeyPair) .orElseGet(this::generateEphemeralKeyPair); - PolarisMetaStoreManager metaStoreManager = - metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); - return new RSAKeyPairJWTBroker( - metaStoreManager, (int) maxTokenGeneration.toSeconds(), keyProvider); + return new RSAKeyPairJWTBroker((int) maxTokenGeneration.toSeconds(), keyProvider); } private KeyProvider fileSystemKeyPair(RSAKeyPairConfiguration config) { diff --git a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/SymmetricKeyJWTBroker.java b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/SymmetricKeyJWTBroker.java index 0ca456f264..c3a9ecdaac 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/SymmetricKeyJWTBroker.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/SymmetricKeyJWTBroker.java @@ -20,17 +20,13 @@ import com.auth0.jwt.algorithms.Algorithm; import java.util.function.Supplier; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager; /** Generates a JWT using a Symmetric Key. */ public class SymmetricKeyJWTBroker extends JWTBroker { private final Supplier secretSupplier; - public SymmetricKeyJWTBroker( - PolarisMetaStoreManager metaStoreManager, - int maxTokenGenerationInSeconds, - Supplier secretSupplier) { - super(metaStoreManager, maxTokenGenerationInSeconds); + public SymmetricKeyJWTBroker(int maxTokenGenerationInSeconds, Supplier secretSupplier) { + super(maxTokenGenerationInSeconds); this.secretSupplier = secretSupplier; } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/SymmetricKeyJWTBrokerFactory.java b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/SymmetricKeyJWTBrokerFactory.java index 302b32393f..6c80c4d424 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/SymmetricKeyJWTBrokerFactory.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/SymmetricKeyJWTBrokerFactory.java @@ -31,7 +31,6 @@ import java.util.concurrent.ConcurrentMap; import java.util.function.Supplier; import org.apache.polaris.core.context.RealmContext; -import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.service.auth.AuthenticationConfiguration; import org.apache.polaris.service.auth.AuthenticationRealmConfiguration; import org.apache.polaris.service.auth.AuthenticationRealmConfiguration.TokenBrokerConfiguration.SymmetricKeyConfiguration; @@ -40,22 +39,18 @@ @Identifier("symmetric-key") public class SymmetricKeyJWTBrokerFactory implements TokenBrokerFactory { - private final MetaStoreManagerFactory metaStoreManagerFactory; private final AuthenticationConfiguration authenticationConfiguration; private final ConcurrentMap tokenBrokers = new ConcurrentHashMap<>(); @Inject - public SymmetricKeyJWTBrokerFactory( - MetaStoreManagerFactory metaStoreManagerFactory, - AuthenticationConfiguration authenticationConfiguration) { - this.metaStoreManagerFactory = metaStoreManagerFactory; + public SymmetricKeyJWTBrokerFactory(AuthenticationConfiguration authenticationConfiguration) { this.authenticationConfiguration = authenticationConfiguration; } @Override - public TokenBroker apply(RealmContext realmContext) { + public TokenBroker newTokenBroker(RealmContext realmContext) { return tokenBrokers.computeIfAbsent( realmContext.getRealmIdentifier(), k -> createTokenBroker(realmContext)); } @@ -72,10 +67,7 @@ private SymmetricKeyJWTBroker createTokenBroker(RealmContext realmContext) { Path file = symmetricKeyConfiguration.file().orElse(null); checkState(secret != null || file != null, "Either file or secret must be set"); Supplier secretSupplier = secret != null ? () -> secret : readSecretFromDisk(file); - return new SymmetricKeyJWTBroker( - metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext), - (int) maxTokenGeneration.toSeconds(), - secretSupplier); + return new SymmetricKeyJWTBroker((int) maxTokenGeneration.toSeconds(), secretSupplier); } private static Supplier readSecretFromDisk(Path file) { diff --git a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/TokenBroker.java b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/TokenBroker.java index e35561b073..9831c0c08c 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/TokenBroker.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/TokenBroker.java @@ -18,7 +18,7 @@ */ package org.apache.polaris.service.auth.internal.broker; -import org.apache.polaris.core.PolarisCallContext; +import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.service.auth.PolarisCredential; import org.apache.polaris.service.types.TokenType; @@ -39,7 +39,7 @@ TokenResponse generateFromClientSecrets( final String clientSecret, final String grantType, final String scope, - PolarisCallContext polarisCallContext, + PolarisMetaStoreManager metaStoreManager, TokenType requestedTokenType); /** @@ -52,7 +52,7 @@ TokenResponse generateFromToken( String subjectToken, final String grantType, final String scope, - PolarisCallContext polarisCallContext, + PolarisMetaStoreManager metaStoreManager, TokenType requestedTokenType); /** Decodes and verifies the token, then returns the associated {@link PolarisCredential}. */ diff --git a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/TokenBrokerFactory.java b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/TokenBrokerFactory.java index 52d8aa1b72..fda3801bce 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/TokenBrokerFactory.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/broker/TokenBrokerFactory.java @@ -18,11 +18,13 @@ */ package org.apache.polaris.service.auth.internal.broker; -import java.util.function.Function; import org.apache.polaris.core.context.RealmContext; /** * Factory that creates a {@link TokenBroker} for generating and parsing. The {@link TokenBroker} is * created based on the realm context. */ -public interface TokenBrokerFactory extends Function {} +public interface TokenBrokerFactory { + + TokenBroker newTokenBroker(RealmContext realmContext); +} diff --git a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/service/DefaultOAuth2ApiService.java b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/service/DefaultOAuth2ApiService.java index e02f938882..d8a4ce1bef 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/service/DefaultOAuth2ApiService.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/auth/internal/service/DefaultOAuth2ApiService.java @@ -27,8 +27,8 @@ import jakarta.ws.rs.core.SecurityContext; import java.util.Base64; import org.apache.iceberg.rest.responses.OAuthTokenResponse; -import org.apache.polaris.core.context.CallContext; import org.apache.polaris.core.context.RealmContext; +import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.service.auth.internal.broker.TokenBroker; import org.apache.polaris.service.auth.internal.broker.TokenResponse; import org.apache.polaris.service.catalog.api.IcebergRestOAuth2ApiService; @@ -49,12 +49,13 @@ public class DefaultOAuth2ApiService implements IcebergRestOAuth2ApiService { private static final String BEARER = "bearer"; private final TokenBroker tokenBroker; - private final CallContext callContext; + private final PolarisMetaStoreManager metaStoreManager; @Inject - public DefaultOAuth2ApiService(TokenBroker tokenBroker, CallContext callContext) { + public DefaultOAuth2ApiService( + TokenBroker tokenBroker, PolarisMetaStoreManager metaStoreManager) { this.tokenBroker = tokenBroker; - this.callContext = callContext; + this.metaStoreManager = metaStoreManager; } @Override @@ -104,12 +105,7 @@ public Response getToken( if (clientSecret != null) { tokenResponse = tokenBroker.generateFromClientSecrets( - clientId, - clientSecret, - grantType, - scope, - callContext.getPolarisCallContext(), - requestedTokenType); + clientId, clientSecret, grantType, scope, metaStoreManager, requestedTokenType); } else if (subjectToken != null) { tokenResponse = tokenBroker.generateFromToken( @@ -117,7 +113,7 @@ public Response getToken( subjectToken, grantType, scope, - callContext.getPolarisCallContext(), + metaStoreManager, requestedTokenType); } else { return OAuthUtils.getResponseFromError(OAuthError.invalid_request); diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/generic/GenericTableCatalogHandler.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/generic/GenericTableCatalogHandler.java index 55d52070f5..74eb7c3b07 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/generic/GenericTableCatalogHandler.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/generic/GenericTableCatalogHandler.java @@ -110,7 +110,7 @@ protected void initializeCatalog() { } else { LOGGER.atInfo().log("Initializing non-federated catalog"); this.genericTableCatalog = - new PolarisGenericTableCatalog(metaStoreManager, callContext, this.resolutionManifest); + new PolarisGenericTableCatalog(metaStoreManager, this.resolutionManifest); this.genericTableCatalog.initialize(catalogName, Map.of()); } } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/generic/PolarisGenericTableCatalog.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/generic/PolarisGenericTableCatalog.java index 3332608c1f..6b78394338 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/generic/PolarisGenericTableCatalog.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/generic/PolarisGenericTableCatalog.java @@ -27,7 +27,6 @@ import org.apache.iceberg.exceptions.NoSuchTableException; import org.apache.polaris.core.catalog.GenericTableCatalog; import org.apache.polaris.core.catalog.PolarisCatalogHelpers; -import org.apache.polaris.core.context.CallContext; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.entity.PolarisEntitySubType; @@ -48,17 +47,14 @@ public class PolarisGenericTableCatalog implements GenericTableCatalog { private String name; - private final CallContext callContext; private final PolarisResolutionManifestCatalogView resolvedEntityView; private final CatalogEntity catalogEntity; - private long catalogId = -1; - private PolarisMetaStoreManager metaStoreManager; + private final long catalogId; + private final PolarisMetaStoreManager metaStoreManager; public PolarisGenericTableCatalog( PolarisMetaStoreManager metaStoreManager, - CallContext callContext, PolarisResolutionManifestCatalogView resolvedEntityView) { - this.callContext = callContext; this.resolvedEntityView = resolvedEntityView; this.catalogEntity = resolvedEntityView.getResolvedCatalogEntity(); this.catalogId = catalogEntity.getId(); @@ -101,10 +97,7 @@ public GenericTableEntity createGenericTable( .setCatalogId(this.catalogId) .setParentNamespace(tableIdentifier.namespace()) .setParentId(resolvedParent.getRawLeafEntity().getId()) - .setId( - this.metaStoreManager - .generateNewEntityId(this.callContext.getPolarisCallContext()) - .getId()) + .setId(this.metaStoreManager.generateNewEntityId().getId()) .setProperties(properties) .setDoc(doc) .setBaseLocation(baseLocation) @@ -117,9 +110,7 @@ public GenericTableEntity createGenericTable( EntityResult res = this.metaStoreManager.createEntityIfNotExists( - this.callContext.getPolarisCallContext(), - PolarisEntity.toCoreList(catalogPath), - entity); + PolarisEntity.toCoreList(catalogPath), entity); if (!res.isSuccess()) { switch (res.getReturnStatus()) { case BaseResult.ReturnStatus.ENTITY_ALREADY_EXISTS: @@ -169,11 +160,7 @@ public boolean dropGenericTable(TableIdentifier tableIdentifier) { DropEntityResult dropEntityResult = this.metaStoreManager.dropEntityIfExists( - this.callContext.getPolarisCallContext(), - PolarisEntity.toCoreList(catalogPath), - leafEntity, - Map.of(), - false); + PolarisEntity.toCoreList(catalogPath), leafEntity, Map.of(), false); return dropEntityResult.isSuccess(); } @@ -190,7 +177,6 @@ public List listGenericTables(Namespace namespace) { PolarisEntity.toNameAndIdList( this.metaStoreManager .listEntities( - this.callContext.getPolarisCallContext(), PolarisEntity.toCoreList(catalogPath), PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.GENERIC_TABLE, diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java index c3e248b52b..7af579fe91 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java @@ -88,7 +88,6 @@ import org.apache.iceberg.view.ViewOperations; import org.apache.iceberg.view.ViewProperties; import org.apache.iceberg.view.ViewUtil; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.catalog.PolarisCatalogHelpers; import org.apache.polaris.core.config.BehaviorChangeConfiguration; @@ -487,7 +486,7 @@ private void createNamespaceInternal( NamespaceEntity entity = new NamespaceEntity.Builder(namespace) .setCatalogId(getCatalogId()) - .setId(getMetaStoreManager().generateNewEntityId(getCurrentPolarisContext()).getId()) + .setId(getMetaStoreManager().generateNewEntityId().getId()) .setParentId(resolvedParent.getRawLeafEntity().getId()) .setProperties(metadata) .setCreateTimestamp(System.currentTimeMillis()) @@ -506,9 +505,7 @@ private void createNamespaceInternal( EntityResult result = getMetaStoreManager() .createEntityIfNotExists( - getCurrentPolarisContext(), - PolarisEntity.toCoreList(resolvedParent.getRawFullPath()), - entity); + PolarisEntity.toCoreList(resolvedParent.getRawFullPath()), entity); if (!result.isSuccess()) { if (result.alreadyExists()) { throw new AlreadyExistsException( @@ -629,7 +626,6 @@ public boolean dropNamespace(Namespace namespace) throws NamespaceNotEmptyExcept DropEntityResult dropEntityResult = getMetaStoreManager() .dropEntityIfExists( - getCurrentPolarisContext(), PolarisEntity.toCoreList(catalogPath), leafEntity, Map.of(), @@ -677,9 +673,7 @@ public boolean setProperties(Namespace namespace, Map properties Optional.ofNullable( getMetaStoreManager() .updateEntityPropertiesIfNotChanged( - getCurrentPolarisContext(), - PolarisEntity.toCoreList(parentPath), - updatedEntity) + PolarisEntity.toCoreList(parentPath), updatedEntity) .getEntity()) .map(PolarisEntity::new) .orElse(null); @@ -709,9 +703,7 @@ public boolean removeProperties(Namespace namespace, Set properties) Optional.ofNullable( getMetaStoreManager() .updateEntityPropertiesIfNotChanged( - getCurrentPolarisContext(), - PolarisEntity.toCoreList(parentPath), - updatedEntity) + PolarisEntity.toCoreList(parentPath), updatedEntity) .getEntity()) .map(PolarisEntity::new) .orElse(null); @@ -759,7 +751,6 @@ public Page listNamespaces(Namespace namespace, PageToken pageToken) ListEntitiesResult listResult = getMetaStoreManager() .listEntities( - getCurrentPolarisContext(), PolarisEntity.toCoreList(catalogPath), PolarisEntityType.NAMESPACE, PolarisEntitySubType.NULL_SUBTYPE, @@ -802,9 +793,7 @@ protected ViewOperations newViewOps(TableIdentifier identifier) { @Override public boolean dropView(TableIdentifier identifier) { boolean purge = - callContext - .getRealmConfig() - .getConfig(FeatureConfiguration.PURGE_VIEW_METADATA_ON_DROP, catalogEntity); + realmConfig.getConfig(FeatureConfiguration.PURGE_VIEW_METADATA_ON_DROP, catalogEntity); return dropTableLike(PolarisEntitySubType.ICEBERG_VIEW, identifier, Map.of(), purge) .isSuccess(); @@ -1083,7 +1072,7 @@ private void validateNoLocationO realmConfig.getConfig(FeatureConfiguration.OPTIMIZED_SIBLING_CHECK); if (useOptimizedSiblingCheck) { Optional> directSiblingCheckResult = - getMetaStoreManager().hasOverlappingSiblings(callContext.getPolarisCallContext(), entity); + getMetaStoreManager().hasOverlappingSiblings(entity); if (directSiblingCheckResult.isPresent()) { if (directSiblingCheckResult.get().isPresent()) { throw new org.apache.iceberg.exceptions.ForbiddenException( @@ -1106,7 +1095,6 @@ private void validateNoLocationO ListEntitiesResult siblingNamespacesResult = getMetaStoreManager() .listEntities( - getCurrentPolarisContext(), PolarisEntity.toCoreList(parentPath), PolarisEntityType.NAMESPACE, PolarisEntitySubType.ANY_SUBTYPE, @@ -1123,7 +1111,6 @@ private void validateNoLocationO ListEntitiesResult siblingTablesResult = getMetaStoreManager() .listEntities( - getCurrentPolarisContext(), PolarisEntity.toCoreList(parentPath), PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ANY_SUBTYPE, @@ -1503,8 +1490,7 @@ public void doCommit(TableMetadata base, TableMetadata metadata) { PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier, newLocation) .setCatalogId(getCatalogId()) .setBaseLocation(metadata.location()) - .setId( - getMetaStoreManager().generateNewEntityId(getCurrentPolarisContext()).getId()) + .setId(getMetaStoreManager().generateNewEntityId().getId()) .build(); } else { existingLocation = entity.getMetadataLocation(); @@ -1841,8 +1827,7 @@ public void doCommit(ViewMetadata base, ViewMetadata metadata) { new IcebergTableLikeEntity.Builder( PolarisEntitySubType.ICEBERG_VIEW, identifier, newLocation) .setCatalogId(getCatalogId()) - .setId( - getMetaStoreManager().generateNewEntityId(getCurrentPolarisContext()).getId()) + .setId(getMetaStoreManager().generateNewEntityId().getId()) .build(); } else { existingLocation = entity.getMetadataLocation(); @@ -2050,10 +2035,6 @@ private FileIO loadFileIOForTableLike( return fileIO; } - private PolarisCallContext getCurrentPolarisContext() { - return callContext.getPolarisCallContext(); - } - private PolarisMetaStoreManager getMetaStoreManager() { return metaStoreManager; } @@ -2116,7 +2097,6 @@ private void renameTableLike( EntityResult returnedEntityResult = getMetaStoreManager() .renameEntity( - getCurrentPolarisContext(), PolarisEntity.toCoreList(catalogPath), leafEntity, PolarisEntity.toCoreList(newCatalogPath), @@ -2180,7 +2160,6 @@ private void renameTableLike( .log("Returned entity identifier doesn't match toEntity identifier"); getMetaStoreManager() .updateEntityPropertiesIfNotChanged( - getCurrentPolarisContext(), PolarisEntity.toCoreList(newCatalogPath), new IcebergTableLikeEntity.Builder(returnedEntity).setTableIdentifier(to).build()); } @@ -2239,10 +2218,7 @@ private void createTableLike( EntityResult res = getMetaStoreManager() - .createEntityIfNotExists( - getCurrentPolarisContext(), - PolarisEntity.toCoreList(catalogPath), - icebergTableLikeEntity); + .createEntityIfNotExists(PolarisEntity.toCoreList(catalogPath), icebergTableLikeEntity); if (!res.isSuccess()) { switch (res.getReturnStatus()) { case BaseResult.ReturnStatus.CATALOG_PATH_CANNOT_BE_RESOLVED: @@ -2292,9 +2268,7 @@ private void updateTableLike(TableIdentifier identifier, PolarisEntity entity) { EntityResult res = getMetaStoreManager() .updateEntityPropertiesIfNotChanged( - getCurrentPolarisContext(), - PolarisEntity.toCoreList(catalogPath), - icebergTableLikeEntity); + PolarisEntity.toCoreList(catalogPath), icebergTableLikeEntity); if (!res.isSuccess()) { switch (res.getReturnStatus()) { case BaseResult.ReturnStatus.CATALOG_PATH_CANNOT_BE_RESOLVED: @@ -2348,11 +2322,7 @@ private void updateTableLike(TableIdentifier identifier, PolarisEntity entity) { return getMetaStoreManager() .dropEntityIfExists( - getCurrentPolarisContext(), - PolarisEntity.toCoreList(catalogPath), - leafEntity, - storageProperties, - purge); + PolarisEntity.toCoreList(catalogPath), leafEntity, storageProperties, purge); } private boolean sendNotificationForTableLike( @@ -2437,8 +2407,7 @@ private boolean sendNotificationForTableLike( new IcebergTableLikeEntity.Builder( PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier, newLocation) .setCatalogId(getCatalogId()) - .setId( - getMetaStoreManager().generateNewEntityId(getCurrentPolarisContext()).getId()) + .setId(getMetaStoreManager().generateNewEntityId().getId()) .setLastNotificationTimestamp(request.getPayload().getTimestamp()) .build(); } else { @@ -2542,7 +2511,6 @@ private Page listTableLike( ListEntitiesResult listResult = getMetaStoreManager() .listEntities( - getCurrentPolarisContext(), PolarisEntity.toCoreList(catalogPath), PolarisEntityType.TABLE_LIKE, subType, diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java index c3b92971aa..16f12e67b8 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java @@ -1054,9 +1054,7 @@ public void commitTransaction(CommitTransactionRequest commitTransactionRequest) // Commit the collected updates in a single atomic operation List pendingUpdates = transactionMetaStoreManager.getPendingUpdates(); - EntitiesResult result = - metaStoreManager.updateEntitiesPropertiesIfNotChanged( - callContext.getPolarisCallContext(), pendingUpdates); + EntitiesResult result = metaStoreManager.updateEntitiesPropertiesIfNotChanged(pendingUpdates); if (!result.isSuccess()) { // TODO: Retries and server-side cleanup on failure, review possible exceptions throw new CommitFailedException( diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/io/AccessConfigProvider.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/io/AccessConfigProvider.java index d336040273..59255a88d6 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/io/AccessConfigProvider.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/io/AccessConfigProvider.java @@ -26,10 +26,12 @@ import java.util.Set; import org.apache.iceberg.catalog.TableIdentifier; import org.apache.polaris.core.context.CallContext; +import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper; import org.apache.polaris.core.storage.AccessConfig; +import org.apache.polaris.core.storage.PolarisCredentialVendor; import org.apache.polaris.core.storage.PolarisStorageActions; import org.apache.polaris.core.storage.cache.StorageCredentialCache; import org.slf4j.Logger; @@ -91,10 +93,14 @@ public AccessConfig getAccessConfig( .log("Table entity has no storage configuration in its hierarchy"); return AccessConfig.builder().supportsCredentialVending(false).build(); } + RealmContext realmContext = callContext.getRealmContext(); + PolarisCredentialVendor credentialVendor = + metaStoreManagerFactory.createMetaStoreManager(realmContext); + return FileIOUtil.refreshAccessConfig( callContext, storageCredentialCache, - metaStoreManagerFactory.getOrCreateMetaStoreManager(callContext.getRealmContext()), + credentialVendor, tableIdentifier, tableLocations, storageActions, diff --git a/runtime/service/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalog.java b/runtime/service/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalog.java index 8e4063b87b..c0f09ad3c9 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalog.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/catalog/policy/PolicyCatalog.java @@ -125,16 +125,14 @@ public Policy createPolicy( .setParentId(resolvedParent.getRawLeafEntity().getId()) .setDescription(description) .setContent(content) - .setId( - metaStoreManager.generateNewEntityId(callContext.getPolarisCallContext()).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setCreateTimestamp(System.currentTimeMillis()) .build(); PolicyValidators.validate(entity); EntityResult res = - metaStoreManager.createEntityIfNotExists( - callContext.getPolarisCallContext(), PolarisEntity.toCoreList(catalogPath), entity); + metaStoreManager.createEntityIfNotExists(PolarisEntity.toCoreList(catalogPath), entity); if (!res.isSuccess()) { @@ -169,7 +167,6 @@ public List listPolicies(Namespace namespace, @Nullable Policy // without a policyType filter we can call listEntities to acquire the entity names ListEntitiesResult listEntitiesResult = metaStoreManager.listEntities( - callContext.getPolarisCallContext(), catalogPath, PolarisEntityType.POLICY, PolarisEntitySubType.NULL_SUBTYPE, @@ -188,11 +185,7 @@ public List listPolicies(Namespace namespace, @Nullable Policy } // with a policyType filter we need to load the full PolicyEntity to apply the filter return metaStoreManager - .loadEntitiesAll( - callContext.getPolarisCallContext(), - catalogPath, - PolarisEntityType.POLICY, - PolarisEntitySubType.NULL_SUBTYPE) + .loadEntitiesAll(catalogPath, PolarisEntityType.POLICY, PolarisEntitySubType.NULL_SUBTYPE) .stream() .map(PolicyEntity::of) .filter(policyEntity -> policyEntity.getPolicyType() == policyType) @@ -248,9 +241,7 @@ public Policy updatePolicy( Optional.ofNullable( metaStoreManager .updateEntityPropertiesIfNotChanged( - callContext.getPolarisCallContext(), - PolarisEntity.toCoreList(catalogPath), - newPolicyEntity) + PolarisEntity.toCoreList(catalogPath), newPolicyEntity) .getEntity()) .map(PolicyEntity::of) .orElse(null); @@ -270,11 +261,7 @@ public boolean dropPolicy(PolicyIdentifier policyIdentifier, boolean detachAll) var result = metaStoreManager.dropEntityIfExists( - callContext.getPolarisCallContext(), - PolarisEntity.toCoreList(catalogPath), - policyEntity, - Map.of(), - detachAll); + PolarisEntity.toCoreList(catalogPath), policyEntity, Map.of(), detachAll); if (!result.isSuccess()) { if (result.getReturnStatus() == POLICY_HAS_MAPPINGS) { @@ -307,12 +294,7 @@ public boolean attachPolicy( var result = metaStoreManager.attachPolicyToEntity( - callContext.getPolarisCallContext(), - targetCatalogPath, - targetEntity, - policyCatalogPath, - policyEntity, - parameters); + targetCatalogPath, targetEntity, policyCatalogPath, policyEntity, parameters); if (!result.isSuccess()) { var targetId = getIdentifier(target); @@ -341,11 +323,7 @@ public boolean detachPolicy(PolicyIdentifier policyIdentifier, PolicyAttachmentT var result = metaStoreManager.detachPolicyFromEntity( - callContext.getPolarisCallContext(), - targetCatalogPath, - targetEntity, - policyCatalogPath, - policyEntity); + targetCatalogPath, targetEntity, policyCatalogPath, policyEntity); if (!result.isSuccess()) { throw new IllegalStateException( @@ -438,11 +416,9 @@ private List getEffectivePolicies( private List getPolicies(PolarisEntity target, PolicyType policyType) { LoadPolicyMappingsResult result; if (policyType == null) { - result = metaStoreManager.loadPoliciesOnEntity(callContext.getPolarisCallContext(), target); + result = metaStoreManager.loadPoliciesOnEntity(target); } else { - result = - metaStoreManager.loadPoliciesOnEntityByType( - callContext.getPolarisCallContext(), target, policyType); + result = metaStoreManager.loadPoliciesOnEntityByType(target, policyType); } return result.getEntities().stream().map(PolicyEntity::of).toList(); diff --git a/runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java b/runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java index 6e25dbfc18..966535ee5b 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java @@ -44,7 +44,6 @@ import org.apache.polaris.core.context.CallContext; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.credentials.PolarisCredentialManager; -import org.apache.polaris.core.persistence.BasePersistence; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; @@ -126,11 +125,8 @@ public RealmContext realmContext(@Context ContainerRequestContext request) { @Produces @RequestScoped public CallContext polarisCallContext( - RealmContext realmContext, - PolarisConfigurationStore configurationStore, - MetaStoreManagerFactory metaStoreManagerFactory) { - BasePersistence metaStoreSession = metaStoreManagerFactory.getOrCreateSession(realmContext); - return new PolarisCallContext(realmContext, metaStoreSession, configurationStore); + RealmContext realmContext, PolarisConfigurationStore configurationStore) { + return new PolarisCallContext(realmContext, configurationStore); } @Produces @@ -150,16 +146,12 @@ public PolarisAuthorizer polarisAuthorizer(RealmConfig realmConfig) { public ResolverFactory resolverFactory( PolarisDiagnostics diagnostics, RealmContext realmContext, - RealmConfig realmConfig, MetaStoreManagerFactory metaStoreManagerFactory, - CallContext callContext, PolarisMetaStoreManager polarisMetaStoreManager) { - EntityCache entityCache = - metaStoreManagerFactory.getOrCreateEntityCache(realmContext, realmConfig); + EntityCache entityCache = metaStoreManagerFactory.getOrCreateEntityCache(realmContext); return (securityContext, referenceCatalogName) -> new Resolver( diagnostics, - callContext.getPolarisCallContext(), polarisMetaStoreManager, securityContext, entityCache, @@ -204,8 +196,8 @@ public MetaStoreManagerFactory metaStoreManagerFactory( @Produces @RequestScoped public PolarisMetaStoreManager polarisMetaStoreManager( - RealmContext realmContext, MetaStoreManagerFactory metaStoreManagerFactory) { - return metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); + MetaStoreManagerFactory metaStoreManagerFactory, RealmContext realmContext) { + return metaStoreManagerFactory.createMetaStoreManager(realmContext); } @Produces @@ -357,7 +349,7 @@ public TokenBroker tokenBroker( config.type() == AuthenticationType.EXTERNAL ? "none" : config.tokenBroker().type(); TokenBrokerFactory tokenBrokerFactory = tokenBrokerFactories.select(Identifier.Literal.of(type)).get(); - return tokenBrokerFactory.apply(realmContext); + return tokenBrokerFactory.newTokenBroker(realmContext); } // other beans diff --git a/runtime/service/src/main/java/org/apache/polaris/service/context/catalog/PolarisCallContextCatalogFactory.java b/runtime/service/src/main/java/org/apache/polaris/service/context/catalog/PolarisCallContextCatalogFactory.java index c9dcbefaee..b667be7866 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/context/catalog/PolarisCallContextCatalogFactory.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/context/catalog/PolarisCallContextCatalogFactory.java @@ -30,6 +30,7 @@ import org.apache.polaris.core.context.CallContext; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; +import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest; import org.apache.polaris.core.persistence.resolver.ResolverFactory; import org.apache.polaris.service.catalog.iceberg.IcebergCatalog; @@ -80,11 +81,13 @@ public Catalog createCallContextCatalog( String catalogKey = realm + "/" + catalogName; LOGGER.debug("Initializing new BasePolarisCatalog for key: {}", catalogKey); + PolarisMetaStoreManager metaStoreManager = + metaStoreManagerFactory.createMetaStoreManager(context.getRealmContext()); IcebergCatalog catalogInstance = new IcebergCatalog( diagnostics, resolverFactory, - metaStoreManagerFactory.getOrCreateMetaStoreManager(context.getRealmContext()), + metaStoreManager, context, resolvedManifest, securityContext, diff --git a/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListener.java b/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListener.java index 533e983ae5..880b8dbddb 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListener.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListener.java @@ -39,7 +39,6 @@ import java.time.Duration; import java.util.List; import java.util.Objects; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.context.CallContext; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.PolarisEvent; @@ -119,10 +118,8 @@ protected UnicastProcessor createProcessor(String realmId) { @Fallback(fallbackMethod = "onFlushError") protected void flush(String realmId, List events) { RealmContext realmContext = () -> realmId; - var metaStoreManager = metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); - var basePersistence = metaStoreManagerFactory.getOrCreateSession(realmContext); - var callContext = new PolarisCallContext(realmContext, basePersistence); - metaStoreManager.writeEvents(callContext, events); + var metaStoreManager = metaStoreManagerFactory.createMetaStoreManager(realmContext); + metaStoreManager.writeEvents(events); } @SuppressWarnings("unused") diff --git a/runtime/service/src/main/java/org/apache/polaris/service/persistence/InMemoryAtomicOperationMetaStoreManagerFactory.java b/runtime/service/src/main/java/org/apache/polaris/service/persistence/InMemoryAtomicOperationMetaStoreManagerFactory.java index fb45bc6c00..0748422c89 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/persistence/InMemoryAtomicOperationMetaStoreManagerFactory.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/persistence/InMemoryAtomicOperationMetaStoreManagerFactory.java @@ -23,6 +23,9 @@ import jakarta.inject.Inject; import java.time.Clock; import org.apache.polaris.core.PolarisDiagnostics; +import org.apache.polaris.core.config.PolarisConfigurationStore; +import org.apache.polaris.core.config.RealmConfig; +import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.persistence.AtomicOperationMetaStoreManager; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.storage.PolarisStorageIntegrationProvider; @@ -38,20 +41,29 @@ public class InMemoryAtomicOperationMetaStoreManagerFactory @SuppressWarnings("unused") // Required by CDI protected InMemoryAtomicOperationMetaStoreManagerFactory() { - this(null, null, null); + this(null, null, null, null); } @Inject public InMemoryAtomicOperationMetaStoreManagerFactory( Clock clock, PolarisDiagnostics diagnostics, + PolarisConfigurationStore configurationStore, PolarisStorageIntegrationProvider storageIntegration) { - super(clock, diagnostics, storageIntegration); + super(clock, diagnostics, configurationStore, storageIntegration); } @Override protected PolarisMetaStoreManager createNewMetaStoreManager( - Clock clock, PolarisDiagnostics diagnostics) { - return new AtomicOperationMetaStoreManager(clock, diagnostics); + Clock clock, + PolarisDiagnostics diagnostics, + RealmContext realmContext, + RealmConfig realmConfig) { + return new AtomicOperationMetaStoreManager( + clock, + diagnostics, + realmContext, + realmConfig, + () -> createPersistenceSession(realmContext)); } } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/persistence/InMemoryPolarisMetaStoreManagerFactory.java b/runtime/service/src/main/java/org/apache/polaris/service/persistence/InMemoryPolarisMetaStoreManagerFactory.java index 3e8b6e538b..60fc1163aa 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/persistence/InMemoryPolarisMetaStoreManagerFactory.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/persistence/InMemoryPolarisMetaStoreManagerFactory.java @@ -29,9 +29,9 @@ import java.util.Map; import java.util.Set; import org.apache.polaris.core.PolarisDiagnostics; +import org.apache.polaris.core.config.PolarisConfigurationStore; import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult; import org.apache.polaris.core.persistence.transactional.TransactionalPersistence; @@ -49,15 +49,16 @@ public class InMemoryPolarisMetaStoreManagerFactory @SuppressWarnings("unused") // Required by CDI protected InMemoryPolarisMetaStoreManagerFactory() { - this(null, null, null); + this(null, null, null, null); } @Inject public InMemoryPolarisMetaStoreManagerFactory( Clock clock, PolarisDiagnostics diagnostics, + PolarisConfigurationStore configurationStore, PolarisStorageIntegrationProvider storageIntegration) { - super(clock, diagnostics); + super(clock, diagnostics, configurationStore); this.storageIntegration = storageIntegration; } @@ -77,22 +78,13 @@ protected TransactionalPersistence createMetaStoreSession( } @Override - public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager( + protected synchronized TransactionalPersistence createPersistenceSession( RealmContext realmContext) { String realmId = realmContext.getRealmIdentifier(); if (!bootstrappedRealms.contains(realmId)) { bootstrapRealmsFromEnvironment(List.of(realmId)); } - return super.getOrCreateMetaStoreManager(realmContext); - } - - @Override - public synchronized TransactionalPersistence getOrCreateSession(RealmContext realmContext) { - String realmId = realmContext.getRealmIdentifier(); - if (!bootstrappedRealms.contains(realmId)) { - bootstrapRealmsFromEnvironment(List.of(realmId)); - } - return super.getOrCreateSession(realmContext); + return super.createPersistenceSession(realmContext); } private void bootstrapRealmsFromEnvironment(List realms) { diff --git a/runtime/service/src/main/java/org/apache/polaris/service/task/TableCleanupTaskHandler.java b/runtime/service/src/main/java/org/apache/polaris/service/task/TableCleanupTaskHandler.java index 777d9bc8db..1994eed9b5 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/task/TableCleanupTaskHandler.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/task/TableCleanupTaskHandler.java @@ -33,7 +33,6 @@ import org.apache.iceberg.TableMetadata; import org.apache.iceberg.TableMetadataParser; import org.apache.iceberg.io.FileIO; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.context.CallContext; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.PolarisBaseEntity; @@ -108,17 +107,10 @@ public boolean handleTask(TaskEntity cleanupTask, CallContext callContext) { TableMetadataParser.read(fileIO, tableEntity.getMetadataLocation()); PolarisMetaStoreManager metaStoreManager = - metaStoreManagerFactory.getOrCreateMetaStoreManager(callContext.getRealmContext()); - PolarisCallContext polarisCallContext = callContext.getPolarisCallContext(); + metaStoreManagerFactory.createMetaStoreManager(callContext.getRealmContext()); Stream manifestCleanupTasks = - getManifestTaskStream( - cleanupTask, - tableMetadata, - fileIO, - tableEntity, - metaStoreManager, - polarisCallContext); + getManifestTaskStream(cleanupTask, tableMetadata, fileIO, tableEntity, metaStoreManager); Stream metadataFileCleanupTasks = getMetadataTaskStream( @@ -128,9 +120,7 @@ public boolean handleTask(TaskEntity cleanupTask, CallContext callContext) { Stream.concat(manifestCleanupTasks, metadataFileCleanupTasks).toList(); List createdTasks = - metaStoreManager - .createEntitiesIfNotExist(polarisCallContext, null, taskEntities) - .getEntities(); + metaStoreManager.createEntitiesIfNotExist(null, taskEntities).getEntities(); if (createdTasks != null) { LOGGER .atInfo() @@ -140,7 +130,7 @@ public boolean handleTask(TaskEntity cleanupTask, CallContext callContext) { .log( "Successfully queued tasks to delete manifests, previous metadata, and statistics files - deleting table metadata file"); for (PolarisBaseEntity createdTask : createdTasks) { - taskExecutor.addTaskHandlerContext(createdTask.getId(), polarisCallContext); + taskExecutor.addTaskHandlerContext(createdTask.getId(), callContext); } fileIO.deleteFile(tableEntity.getMetadataLocation()); @@ -156,8 +146,7 @@ private Stream getManifestTaskStream( TableMetadata tableMetadata, FileIO fileIO, IcebergTableLikeEntity tableEntity, - PolarisMetaStoreManager metaStoreManager, - PolarisCallContext polarisCallContext) { + PolarisMetaStoreManager metaStoreManager) { // read the manifest list for each snapshot. dedupe the manifest files and schedule a // cleanupTask // for each manifest file and its data files to be deleted @@ -189,13 +178,13 @@ private Stream getManifestTaskStream( .log("Queueing task to delete manifest file"); return new TaskEntity.Builder() .setName(taskName) - .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setCreateTimestamp(clock.millis()) .withTaskType(AsyncTaskType.MANIFEST_FILE_CLEANUP) .withData( ManifestFileCleanupTaskHandler.ManifestCleanupTask.buildFrom( tableEntity.getTableIdentifier(), mf)) - .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) // copy the internal properties, which will have storage info .setInternalProperties(cleanupTask.getInternalPropertiesAsMap()) .build(); @@ -208,7 +197,6 @@ private Stream getMetadataTaskStream( IcebergTableLikeEntity tableEntity, PolarisMetaStoreManager metaStoreManager, CallContext callContext) { - PolarisCallContext polarisCallContext = callContext.getPolarisCallContext(); int batchSize = callContext.getRealmConfig().getConfig(BATCH_SIZE_CONFIG_KEY, 10); return getMetadataFileBatches(tableMetadata, batchSize).stream() .map( @@ -228,7 +216,7 @@ private Stream getMetadataTaskStream( "Queueing task to delete metadata files (prev metadata and statistics files)"); return new TaskEntity.Builder() .setName(taskName) - .setId(metaStoreManager.generateNewEntityId(polarisCallContext).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setCreateTimestamp(clock.millis()) .withTaskType(AsyncTaskType.BATCH_FILE_CLEANUP) .withData( diff --git a/runtime/service/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java b/runtime/service/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java index 55847b8eb8..ca3bf00952 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java @@ -149,11 +149,9 @@ protected void handleTask(long taskEntityId, CallContext ctx, int attempt) { try { LOGGER.info("Handling task entity id {}", taskEntityId); PolarisMetaStoreManager metaStoreManager = - metaStoreManagerFactory.getOrCreateMetaStoreManager(ctx.getRealmContext()); + metaStoreManagerFactory.createMetaStoreManager(ctx.getRealmContext()); PolarisBaseEntity taskEntity = - metaStoreManager - .loadEntity(ctx.getPolarisCallContext(), 0L, taskEntityId, PolarisEntityType.TASK) - .getEntity(); + metaStoreManager.loadEntity(0L, taskEntityId, PolarisEntityType.TASK).getEntity(); if (!PolarisEntityType.TASK.equals(taskEntity.getType())) { throw new IllegalArgumentException("Provided taskId must be a task entity type"); } @@ -176,8 +174,7 @@ protected void handleTask(long taskEntityId, CallContext ctx, int attempt) { .addKeyValue("taskEntityId", taskEntityId) .addKeyValue("handlerClass", handler.getClass()) .log("Task successfully handled"); - metaStoreManager.dropEntityIfExists( - ctx.getPolarisCallContext(), null, taskEntity, Map.of(), false); + metaStoreManager.dropEntityIfExists(null, taskEntity, Map.of(), false); } else { LOGGER .atWarn() diff --git a/runtime/service/src/test/java/org/apache/polaris/service/admin/ManagementServiceTest.java b/runtime/service/src/test/java/org/apache/polaris/service/admin/ManagementServiceTest.java index e13d6fe080..ea0b7a256b 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/admin/ManagementServiceTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/admin/ManagementServiceTest.java @@ -412,7 +412,7 @@ private PrincipalEntity createPrincipal( return new PrincipalEntity.Builder() .setName(name) .setCreateTimestamp(Instant.now().toEpochMilli()) - .setId(metaStoreManager.generateNewEntityId(callContext).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .build(); } @@ -422,7 +422,7 @@ private PrincipalRoleEntity createRole( String name, boolean isFederated) { return new PrincipalRoleEntity.Builder() - .setId(metaStoreManager.generateNewEntityId(callContext).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setName(name) .setFederated(isFederated) .setProperties(Map.of()) @@ -439,10 +439,10 @@ public void testCannotAssignFederatedEntities() { setupPolarisAdminService(metaStoreManager, callContext); PrincipalEntity principal = createPrincipal(metaStoreManager, callContext, "principal_id"); - metaStoreManager.createPrincipal(callContext, principal); + metaStoreManager.createPrincipal(principal); PrincipalRoleEntity role = createRole(metaStoreManager, callContext, "federated_role_id", true); - EntityResult result = metaStoreManager.createEntityIfNotExists(callContext, null, role); + EntityResult result = metaStoreManager.createEntityIfNotExists(null, role); assertThat(result.isSuccess()).isTrue(); assertThatThrownBy( @@ -459,10 +459,9 @@ public void testCanListCatalogs() { CreateCatalogResult catalog1 = metaStoreManager.createCatalog( - callContext, new PolarisBaseEntity( PolarisEntityConstants.getNullId(), - metaStoreManager.generateNewEntityId(callContext).getId(), + metaStoreManager.generateNewEntityId().getId(), PolarisEntityType.CATALOG, PolarisEntitySubType.NULL_SUBTYPE, PolarisEntityConstants.getRootEntityId(), @@ -472,10 +471,9 @@ public void testCanListCatalogs() { CreateCatalogResult catalog2 = metaStoreManager.createCatalog( - callContext, new PolarisBaseEntity( PolarisEntityConstants.getNullId(), - metaStoreManager.generateNewEntityId(callContext).getId(), + metaStoreManager.generateNewEntityId().getId(), PolarisEntityType.CATALOG, PolarisEntitySubType.NULL_SUBTYPE, PolarisEntityConstants.getRootEntityId(), @@ -518,7 +516,7 @@ public void testCreateCatalogReturnErrorOnFailure() { BaseResult.ReturnStatus.UNEXPECTED_ERROR_SIGNALED, "Unexpected Error Occurred"); Mockito.doAnswer(invocation -> resultWithError) .when(metaStoreManager) - .createCatalog(Mockito.any(), Mockito.any(), Mockito.any()); + .createCatalog(Mockito.any(), Mockito.any()); Assertions.assertThatThrownBy( () -> polarisAdminService.createCatalog(new CreateCatalogRequest(catalog))) .isInstanceOf(IllegalStateException.class) diff --git a/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java b/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java index fb58dc3442..7c908c1c88 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java @@ -88,6 +88,7 @@ public class PolarisAdminServiceTest { void setUp() throws Exception { MockitoAnnotations.openMocks(this); when(securityContext.getUserPrincipal()).thenReturn(authenticatedPrincipal); + when(callContext.getRealmConfig()).thenReturn(realmConfig); when(callContext.getPolarisCallContext()).thenReturn(polarisCallContext); when(polarisCallContext.getRealmConfig()).thenReturn(realmConfig); @@ -131,7 +132,7 @@ void testGrantPrivilegeOnNamespaceToRole() throws Exception { PrivilegeResult successResult = mock(PrivilegeResult.class); when(successResult.isSuccess()).thenReturn(true); - when(metaStoreManager.grantPrivilegeOnSecurableToRole(any(), any(), any(), any(), any())) + when(metaStoreManager.grantPrivilegeOnSecurableToRole(any(), any(), any(), any())) .thenReturn(successResult); PrivilegeResult result = @@ -220,7 +221,7 @@ void testRevokePrivilegeOnNamespaceFromRole() throws Exception { PrivilegeResult successResult = mock(PrivilegeResult.class); when(successResult.isSuccess()).thenReturn(true); - when(metaStoreManager.revokePrivilegeOnSecurableFromRole(any(), any(), any(), any(), any())) + when(metaStoreManager.revokePrivilegeOnSecurableFromRole(any(), any(), any(), any())) .thenReturn(successResult); PrivilegeResult result = @@ -313,7 +314,7 @@ void testGrantPrivilegeOnNamespaceToRole_PassthroughFacade() throws Exception { // Mock creation of team-ns. GenerateEntityIdResult idResult = mock(GenerateEntityIdResult.class); when(idResult.getId()).thenReturn(4L); - when(metaStoreManager.generateNewEntityId(any())).thenReturn(idResult); + when(metaStoreManager.generateNewEntityId()).thenReturn(idResult); EntityResult teamNsCreateResult = mock(EntityResult.class); EntityResult projectNsCreateResult = mock(EntityResult.class); when(teamNsCreateResult.isSuccess()).thenReturn(true); @@ -324,12 +325,12 @@ void testGrantPrivilegeOnNamespaceToRole_PassthroughFacade() throws Exception { // Mock creation of project-ns. when(idResult.getId()).thenReturn(5L); - when(metaStoreManager.generateNewEntityId(any())).thenReturn(idResult); + when(metaStoreManager.generateNewEntityId()).thenReturn(idResult); PolarisEntity projectNsEntity = createNamespaceEntity(Namespace.of("org-ns", "team-ns", "project-ns"), 5L, 4L); when(projectNsCreateResult.getEntity()).thenReturn(projectNsEntity); - when(metaStoreManager.createEntityIfNotExists(any(), any(), any())) + when(metaStoreManager.createEntityIfNotExists(any(), any())) .thenReturn(teamNsCreateResult, projectNsCreateResult); // Mock successful synthetic namespace resolution. @@ -340,7 +341,7 @@ void testGrantPrivilegeOnNamespaceToRole_PassthroughFacade() throws Exception { PrivilegeResult successResult = mock(PrivilegeResult.class); when(successResult.isSuccess()).thenReturn(true); - when(metaStoreManager.grantPrivilegeOnSecurableToRole(any(), any(), any(), any(), any())) + when(metaStoreManager.grantPrivilegeOnSecurableToRole(any(), any(), any(), any())) .thenReturn(successResult); PrivilegeResult result = @@ -415,12 +416,12 @@ void testGrantPrivilegeOnNamespaceToRole_SyntheticEntityCreationFails() throws E // Mock generateNewEntityId for team-ns GenerateEntityIdResult idResult = mock(GenerateEntityIdResult.class); when(idResult.getId()).thenReturn(4L); - when(metaStoreManager.generateNewEntityId(any())).thenReturn(idResult); + when(metaStoreManager.generateNewEntityId()).thenReturn(idResult); // Mock createEntityIfNotExists to fail EntityResult failedResult = mock(EntityResult.class); when(failedResult.isSuccess()).thenReturn(false); - when(metaStoreManager.createEntityIfNotExists(any(), any(), any())).thenReturn(failedResult); + when(metaStoreManager.createEntityIfNotExists(any(), any())).thenReturn(failedResult); // Mock getResolvedPath to return null for partial namespace PolarisResolvedPathWrapper partialPathWrapper = mock(PolarisResolvedPathWrapper.class); @@ -468,14 +469,13 @@ void testGrantPrivilegeOnTableLikeToRole_PassthroughFacade() throws Exception { GenerateEntityIdResult idResult = mock(GenerateEntityIdResult.class); when(idResult.getId()).thenReturn(5L); - when(metaStoreManager.generateNewEntityId(any())).thenReturn(idResult); + when(metaStoreManager.generateNewEntityId()).thenReturn(idResult); PolarisEntity projectNsEntity = createNamespaceEntity(Namespace.of("org-ns", "team-ns", "project-ns"), 5L, 4L); EntityResult projectNsCreateResult = mock(EntityResult.class); when(projectNsCreateResult.isSuccess()).thenReturn(true); when(projectNsCreateResult.getEntity()).thenReturn(projectNsEntity); - when(metaStoreManager.createEntityIfNotExists(any(), any(), any())) - .thenReturn(projectNsCreateResult); + when(metaStoreManager.createEntityIfNotExists(any(), any())).thenReturn(projectNsCreateResult); PolarisResolvedPathWrapper syntheticPathWrapper = mock(PolarisResolvedPathWrapper.class); when(syntheticPathWrapper.getRawFullPath()) @@ -486,13 +486,12 @@ void testGrantPrivilegeOnTableLikeToRole_PassthroughFacade() throws Exception { when(syntheticPathWrapper.getRawLeafEntity()).thenReturn(projectNsEntity); when(idResult.getId()).thenReturn(6L); - when(metaStoreManager.generateNewEntityId(any())).thenReturn(idResult); + when(metaStoreManager.generateNewEntityId()).thenReturn(idResult); PolarisEntity tableEntity = createTableEntity(identifier, ICEBERG_TABLE, 6L, 5L); EntityResult tableCreateResult = mock(EntityResult.class); when(tableCreateResult.isSuccess()).thenReturn(true); when(tableCreateResult.getEntity()).thenReturn(tableEntity); - when(metaStoreManager.createEntityIfNotExists(any(), any(), any())) - .thenReturn(tableCreateResult); + when(metaStoreManager.createEntityIfNotExists(any(), any())).thenReturn(tableCreateResult); PolarisResolvedPathWrapper tablePathWrapper = mock(PolarisResolvedPathWrapper.class); when(tablePathWrapper.getRawLeafEntity()).thenReturn(tableEntity); @@ -502,7 +501,7 @@ void testGrantPrivilegeOnTableLikeToRole_PassthroughFacade() throws Exception { PrivilegeResult successResult = mock(PrivilegeResult.class); when(successResult.isSuccess()).thenReturn(true); - when(metaStoreManager.grantPrivilegeOnSecurableToRole(any(), any(), any(), any(), any())) + when(metaStoreManager.grantPrivilegeOnSecurableToRole(any(), any(), any(), any())) .thenReturn(successResult); PrivilegeResult result = @@ -589,10 +588,9 @@ void testGrantPrivilegeOnTableLikeToRole_SyntheticEntityCreationFails() throws E GenerateEntityIdResult idResult = mock(GenerateEntityIdResult.class); when(idResult.getId()).thenReturn(3L); - when(metaStoreManager.generateNewEntityId(any())).thenReturn(idResult); + when(metaStoreManager.generateNewEntityId()).thenReturn(idResult); EntityResult tableCreateResult = mock(EntityResult.class); - when(metaStoreManager.createEntityIfNotExists(any(), any(), any())) - .thenReturn(tableCreateResult); + when(metaStoreManager.createEntityIfNotExists(any(), any())).thenReturn(tableCreateResult); when(tableCreateResult.isSuccess()).thenReturn(false); when(resolutionManifest.getResolvedPath(identifier)).thenReturn(existingPathWrapper); diff --git a/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAuthzTestBase.java b/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAuthzTestBase.java index 6db99fb34d..3d95d8932f 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAuthzTestBase.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAuthzTestBase.java @@ -246,20 +246,17 @@ public void before(TestInfo testInfo) { Mockito.when(containerRequestContext.getProperty(Mockito.anyString())) .thenReturn("request-id-1"); QuarkusMock.installMockForType(containerRequestContext, ContainerRequestContext.class); - metaStoreManager = managerFactory.getOrCreateMetaStoreManager(realmContext); - userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext); - polarisContext = - new PolarisCallContext( - realmContext, managerFactory.getOrCreateSession(realmContext), configurationStore); + polarisContext = new PolarisCallContext(realmContext, configurationStore); callContext = polarisContext; realmConfig = polarisContext.getRealmConfig(); + metaStoreManager = managerFactory.createMetaStoreManager(realmContext); + userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext); polarisAuthorizer = new PolarisAuthorizerImpl(realmConfig); - PrincipalEntity rootPrincipal = - metaStoreManager.findRootPrincipal(polarisContext).orElseThrow(); + PrincipalEntity rootPrincipal = metaStoreManager.findRootPrincipal().orElseThrow(); this.authenticatedRoot = PolarisPrincipal.of(rootPrincipal, Set.of()); this.adminService = @@ -344,8 +341,7 @@ public void before(TestInfo testInfo) { PrincipalWithCredentials principal = adminService.createPrincipal(new PrincipalEntity.Builder().setName(PRINCIPAL_NAME).build()); principalEntity = - rotateAndRefreshPrincipal( - metaStoreManager, PRINCIPAL_NAME, principal.getCredentials(), polarisContext); + rotateAndRefreshPrincipal(metaStoreManager, PRINCIPAL_NAME, principal.getCredentials()); // Pre-create the principal roles and catalog roles without any grants on securables, but // assign both principal roles to the principal, then CATALOG_ROLE1 to PRINCIPAL_ROLE1, @@ -453,7 +449,7 @@ public void after() { } } } finally { - metaStoreManager.purge(polarisContext); + metaStoreManager.purge(); } } @@ -471,22 +467,13 @@ protected static void assertSuccess(BaseResult result) { } protected @Nonnull Set loadPrincipalRolesNames(PolarisPrincipal p) { - PolarisBaseEntity principal = - metaStoreManager - .findPrincipalByName(callContext.getPolarisCallContext(), p.getName()) - .orElseThrow(); - return metaStoreManager - .loadGrantsToGrantee(callContext.getPolarisCallContext(), principal) - .getGrantRecords() - .stream() + PolarisBaseEntity principal = metaStoreManager.findPrincipalByName(p.getName()).orElseThrow(); + return metaStoreManager.loadGrantsToGrantee(principal).getGrantRecords().stream() .filter(gr -> gr.getPrivilegeCode() == PolarisPrivilege.PRINCIPAL_ROLE_USAGE.getCode()) .map( gr -> metaStoreManager.loadEntity( - callContext.getPolarisCallContext(), - 0L, - gr.getSecurableId(), - PolarisEntityType.PRINCIPAL_ROLE)) + 0L, gr.getSecurableId(), PolarisEntityType.PRINCIPAL_ROLE)) .map(EntityResult::getEntity) .map(PolarisBaseEntity::getName) .collect(Collectors.toSet()); @@ -495,17 +482,14 @@ protected static void assertSuccess(BaseResult result) { protected @Nonnull PrincipalEntity rotateAndRefreshPrincipal( PolarisMetaStoreManager metaStoreManager, String principalName, - PrincipalWithCredentialsCredentials credentials, - PolarisCallContext polarisContext) { - PrincipalEntity principal = - metaStoreManager.findPrincipalByName(polarisContext, principalName).orElseThrow(); + PrincipalWithCredentialsCredentials credentials) { + PrincipalEntity principal = metaStoreManager.findPrincipalByName(principalName).orElseThrow(); metaStoreManager.rotatePrincipalSecrets( - callContext.getPolarisCallContext(), credentials.getClientId(), principal.getId(), false, credentials.getClientSecret()); // This should actually be the secret's hash - return metaStoreManager.findPrincipalByName(polarisContext, principalName).orElseThrow(); + return metaStoreManager.findPrincipalByName(principalName).orElseThrow(); } /** @@ -543,8 +527,7 @@ private void initBaseCatalog() { CATALOG_NAME, ImmutableMap.of( CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.inmemory.InMemoryFileIO")); - this.genericTableCatalog = - new PolarisGenericTableCatalog(metaStoreManager, callContext, passthroughView); + this.genericTableCatalog = new PolarisGenericTableCatalog(metaStoreManager, passthroughView); this.genericTableCatalog.initialize(CATALOG_NAME, ImmutableMap.of()); this.policyCatalog = new PolicyCatalog(metaStoreManager, callContext, passthroughView); } diff --git a/runtime/service/src/test/java/org/apache/polaris/service/auth/DefaultAuthenticatorTest.java b/runtime/service/src/test/java/org/apache/polaris/service/auth/DefaultAuthenticatorTest.java index 5924745d96..283ab70cbd 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/auth/DefaultAuthenticatorTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/auth/DefaultAuthenticatorTest.java @@ -66,8 +66,7 @@ public void before(TestInfo testInfo) { .build()); principalNoRoles = - rotateAndRefreshPrincipal( - metaStoreManager, PRINCIPAL_NO_ROLES, principal.getCredentials(), polarisContext); + rotateAndRefreshPrincipal(metaStoreManager, PRINCIPAL_NO_ROLES, principal.getCredentials()); } @Test @@ -109,7 +108,7 @@ public void testFetchPrincipalThrowsServiceExceptionOnMetastoreException() { PolarisCredential.of(123L, null, Set.of(DefaultAuthenticator.PRINCIPAL_ROLE_ALL)); metaStoreManager = Mockito.spy(metaStoreManager); - when(metaStoreManager.loadEntity(polarisContext, 0L, 123L, PolarisEntityType.PRINCIPAL)) + when(metaStoreManager.loadEntity(0L, 123L, PolarisEntityType.PRINCIPAL)) .thenThrow(new RuntimeException("Metastore exception")); assertUnauthorized(credentials); diff --git a/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/JWTSymmetricKeyGeneratorTest.java b/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/JWTSymmetricKeyGeneratorTest.java index 651fc1a9d9..31741f2a5c 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/JWTSymmetricKeyGeneratorTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/JWTSymmetricKeyGeneratorTest.java @@ -25,7 +25,6 @@ import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.interfaces.DecodedJWT; import java.util.Optional; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; @@ -39,27 +38,26 @@ public class JWTSymmetricKeyGeneratorTest { /** Sanity test to verify that we can generate a token */ @Test public void testJWTSymmetricKeyGenerator() { - PolarisCallContext polarisCallContext = new PolarisCallContext(null, null, null); PolarisMetaStoreManager metastoreManager = Mockito.mock(PolarisMetaStoreManager.class); long principalId = 123L; String mainSecret = "test_secret"; String clientId = "test_client_id"; PolarisPrincipalSecrets principalSecrets = new PolarisPrincipalSecrets(principalId, clientId, mainSecret, "otherSecret"); - Mockito.when(metastoreManager.loadPrincipalSecrets(polarisCallContext, clientId)) + Mockito.when(metastoreManager.loadPrincipalSecrets(clientId)) .thenReturn(new PrincipalSecretsResult(principalSecrets)); PrincipalEntity principal = new PrincipalEntity.Builder().setId(principalId).setName("principal").build(); - Mockito.when(metastoreManager.findPrincipalById(polarisCallContext, principalId)) + Mockito.when(metastoreManager.findPrincipalById(principalId)) .thenReturn(Optional.of(principal)); - TokenBroker generator = new SymmetricKeyJWTBroker(metastoreManager, 666, () -> "polaris"); + TokenBroker generator = new SymmetricKeyJWTBroker(666, () -> "polaris"); TokenResponse token = generator.generateFromClientSecrets( clientId, mainSecret, TokenRequestValidator.CLIENT_CREDENTIALS, "PRINCIPAL_ROLE:TEST", - polarisCallContext, + metastoreManager, TokenType.ACCESS_TOKEN); assertThat(token).isNotNull(); diff --git a/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBrokerTest.java b/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBrokerTest.java index 13bd7f3df2..f541b5ac31 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBrokerTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/broker/RSAKeyPairJWTBrokerTest.java @@ -25,12 +25,9 @@ import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.interfaces.DecodedJWT; import io.quarkus.test.junit.QuarkusTest; -import jakarta.inject.Inject; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.util.Optional; -import org.apache.polaris.core.PolarisCallContext; -import org.apache.polaris.core.config.PolarisConfigurationStore; import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; @@ -42,8 +39,6 @@ @QuarkusTest public class RSAKeyPairJWTBrokerTest { - @Inject protected PolarisConfigurationStore configurationStore; - @Test public void testSuccessfulTokenGeneration() throws Exception { var keyPair = PemUtils.generateKeyPair(); @@ -52,26 +47,25 @@ public void testSuccessfulTokenGeneration() throws Exception { final String clientId = "test-client-id"; final String scope = "PRINCIPAL_ROLE:TEST"; - PolarisCallContext polarisCallContext = new PolarisCallContext(null, null, configurationStore); PolarisMetaStoreManager metastoreManager = Mockito.mock(PolarisMetaStoreManager.class); String mainSecret = "client-secret"; PolarisPrincipalSecrets principalSecrets = new PolarisPrincipalSecrets(principalId, clientId, mainSecret, "otherSecret"); - Mockito.when(metastoreManager.loadPrincipalSecrets(polarisCallContext, clientId)) + Mockito.when(metastoreManager.loadPrincipalSecrets(clientId)) .thenReturn(new PrincipalSecretsResult(principalSecrets)); PrincipalEntity principal = new PrincipalEntity.Builder().setId(principalId).setName("principal").build(); - Mockito.when(metastoreManager.findPrincipalById(polarisCallContext, principalId)) + Mockito.when(metastoreManager.findPrincipalById(principalId)) .thenReturn(Optional.of(principal)); KeyProvider provider = new LocalRSAKeyProvider(keyPair); - TokenBroker tokenBroker = new RSAKeyPairJWTBroker(metastoreManager, 420, provider); + TokenBroker tokenBroker = new RSAKeyPairJWTBroker(420, provider); TokenResponse token = tokenBroker.generateFromClientSecrets( clientId, mainSecret, TokenRequestValidator.CLIENT_CREDENTIALS, scope, - polarisCallContext, + metastoreManager, TokenType.ACCESS_TOKEN); assertThat(token).isNotNull(); assertThat(token.getExpiresIn()).isEqualTo(420); diff --git a/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/service/DefaultOAuth2ApiServiceTest.java b/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/service/DefaultOAuth2ApiServiceTest.java index 14bcc45bb3..ffee91feec 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/service/DefaultOAuth2ApiServiceTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/auth/internal/service/DefaultOAuth2ApiServiceTest.java @@ -24,9 +24,8 @@ import java.nio.charset.Charset; import java.util.Base64; import org.apache.iceberg.rest.responses.OAuthTokenResponse; -import org.apache.polaris.core.PolarisCallContext; -import org.apache.polaris.core.context.CallContext; import org.apache.polaris.core.context.RealmContext; +import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.service.auth.internal.broker.TokenBroker; import org.apache.polaris.service.auth.internal.broker.TokenResponse; import org.apache.polaris.service.types.TokenType; @@ -41,17 +40,16 @@ class DefaultOAuth2ApiServiceTest { private static final String CLIENT_CREDENTIALS = "client_credentials"; private static final String TOKEN_EXCHANGE = "urn:ietf:params:oauth:grant-type:token-exchange"; - private CallContext callContext; + private final RealmContext realmContext = () -> "realm"; + private PolarisMetaStoreManager metaStoreManager; @BeforeEach void setUp() { - callContext = Mockito.mock(CallContext.class); - when(callContext.getPolarisCallContext()).thenReturn(Mockito.mock(PolarisCallContext.class)); + metaStoreManager = Mockito.mock(PolarisMetaStoreManager.class); } @Test public void testNoSupportGrantType() { - RealmContext realmContext = () -> "realm"; TokenBroker tokenBroker = Mockito.mock(); when(tokenBroker.supportsGrantType(CLIENT_CREDENTIALS)).thenReturn(false); when(tokenBroker.supportsRequestedTokenType(TokenType.ACCESS_TOKEN)).thenReturn(true); @@ -60,7 +58,7 @@ public void testNoSupportGrantType() { "secret", CLIENT_CREDENTIALS, "scope", - callContext.getPolarisCallContext(), + metaStoreManager, TokenType.ACCESS_TOKEN)) .thenReturn(TokenResponse.of("token", TokenType.ACCESS_TOKEN.getValue(), 3600)); Response response = @@ -71,7 +69,7 @@ public void testNoSupportGrantType() { .grantType(CLIENT_CREDENTIALS) .requestedTokenType(TokenType.ACCESS_TOKEN) .realmContext(realmContext) - .invoke(new DefaultOAuth2ApiService(tokenBroker, callContext)); + .invoke(new DefaultOAuth2ApiService(tokenBroker, metaStoreManager)); Assertions.assertThat(response.getEntity()) .isInstanceOf(OAuthTokenErrorResponse.class) .asInstanceOf(InstanceOfAssertFactories.type(OAuthTokenErrorResponse.class)) @@ -80,7 +78,6 @@ public void testNoSupportGrantType() { @Test public void testNoSupportRequestedTokenType() { - RealmContext realmContext = () -> "realm"; TokenBroker tokenBroker = Mockito.mock(); when(tokenBroker.supportsGrantType(CLIENT_CREDENTIALS)).thenReturn(true); when(tokenBroker.supportsRequestedTokenType(TokenType.ACCESS_TOKEN)).thenReturn(false); @@ -89,7 +86,7 @@ public void testNoSupportRequestedTokenType() { "secret", CLIENT_CREDENTIALS, "scope", - callContext.getPolarisCallContext(), + metaStoreManager, TokenType.ACCESS_TOKEN)) .thenReturn(TokenResponse.of("token", TokenType.ACCESS_TOKEN.getValue(), 3600)); Response response = @@ -100,7 +97,7 @@ public void testNoSupportRequestedTokenType() { .grantType(CLIENT_CREDENTIALS) .requestedTokenType(TokenType.ACCESS_TOKEN) .realmContext(realmContext) - .invoke(new DefaultOAuth2ApiService(tokenBroker, callContext)); + .invoke(new DefaultOAuth2ApiService(tokenBroker, metaStoreManager)); Assertions.assertThat(response.getEntity()) .isInstanceOf(OAuthTokenErrorResponse.class) .asInstanceOf(InstanceOfAssertFactories.type(OAuthTokenErrorResponse.class)) @@ -109,17 +106,11 @@ public void testNoSupportRequestedTokenType() { @Test public void testSupportClientIdNoSecret() { - RealmContext realmContext = () -> "realm"; TokenBroker tokenBroker = Mockito.mock(); when(tokenBroker.supportsGrantType(CLIENT_CREDENTIALS)).thenReturn(true); when(tokenBroker.supportsRequestedTokenType(TokenType.ACCESS_TOKEN)).thenReturn(true); when(tokenBroker.generateFromClientSecrets( - null, - "secret", - CLIENT_CREDENTIALS, - "scope", - callContext.getPolarisCallContext(), - TokenType.ACCESS_TOKEN)) + null, "secret", CLIENT_CREDENTIALS, "scope", metaStoreManager, TokenType.ACCESS_TOKEN)) .thenReturn(TokenResponse.of("token", TokenType.ACCESS_TOKEN.getValue(), 3600)); Response response = new InvocationBuilder() @@ -128,7 +119,7 @@ public void testSupportClientIdNoSecret() { .grantType(CLIENT_CREDENTIALS) .requestedTokenType(TokenType.ACCESS_TOKEN) .realmContext(realmContext) - .invoke(new DefaultOAuth2ApiService(tokenBroker, callContext)); + .invoke(new DefaultOAuth2ApiService(tokenBroker, metaStoreManager)); Assertions.assertThat(response.getEntity()) .isInstanceOf(OAuthTokenResponse.class) .asInstanceOf(InstanceOfAssertFactories.type(OAuthTokenResponse.class)) @@ -137,7 +128,6 @@ public void testSupportClientIdNoSecret() { @Test public void testSupportClientIdAndSecret() { - RealmContext realmContext = () -> "realm"; TokenBroker tokenBroker = Mockito.mock(); when(tokenBroker.supportsGrantType(CLIENT_CREDENTIALS)).thenReturn(true); when(tokenBroker.supportsRequestedTokenType(TokenType.ACCESS_TOKEN)).thenReturn(true); @@ -146,7 +136,7 @@ public void testSupportClientIdAndSecret() { "secret", CLIENT_CREDENTIALS, "scope", - callContext.getPolarisCallContext(), + metaStoreManager, TokenType.ACCESS_TOKEN)) .thenReturn(TokenResponse.of("token", TokenType.ACCESS_TOKEN.getValue(), 3600)); Response response = @@ -157,7 +147,7 @@ public void testSupportClientIdAndSecret() { .grantType(CLIENT_CREDENTIALS) .requestedTokenType(TokenType.ACCESS_TOKEN) .realmContext(realmContext) - .invoke(new DefaultOAuth2ApiService(tokenBroker, callContext)); + .invoke(new DefaultOAuth2ApiService(tokenBroker, metaStoreManager)); Assertions.assertThat(response.getEntity()) .isInstanceOf(OAuthTokenResponse.class) .asInstanceOf(InstanceOfAssertFactories.type(OAuthTokenResponse.class)) @@ -166,17 +156,11 @@ public void testSupportClientIdAndSecret() { @Test public void testReadClientCredentialsFromAuthHeader() { - RealmContext realmContext = () -> "realm"; TokenBroker tokenBroker = Mockito.mock(); when(tokenBroker.supportsGrantType(TOKEN_EXCHANGE)).thenReturn(true); when(tokenBroker.supportsRequestedTokenType(TokenType.ACCESS_TOKEN)).thenReturn(true); when(tokenBroker.generateFromClientSecrets( - "client", - "secret", - TOKEN_EXCHANGE, - "scope", - callContext.getPolarisCallContext(), - TokenType.ACCESS_TOKEN)) + "client", "secret", TOKEN_EXCHANGE, "scope", metaStoreManager, TokenType.ACCESS_TOKEN)) .thenReturn(TokenResponse.of("token", TokenType.ACCESS_TOKEN.getValue(), 3600)); Response response = new InvocationBuilder() @@ -188,7 +172,7 @@ public void testReadClientCredentialsFromAuthHeader() { .grantType(TOKEN_EXCHANGE) .requestedTokenType(TokenType.ACCESS_TOKEN) .realmContext(realmContext) - .invoke(new DefaultOAuth2ApiService(tokenBroker, callContext)); + .invoke(new DefaultOAuth2ApiService(tokenBroker, metaStoreManager)); Assertions.assertThat(response.getEntity()) .isInstanceOf(OAuthTokenResponse.class) .asInstanceOf(InstanceOfAssertFactories.type(OAuthTokenResponse.class)) @@ -197,17 +181,11 @@ public void testReadClientCredentialsFromAuthHeader() { @Test public void testAuthHeaderRequiresValidCredentialPair() { - RealmContext realmContext = () -> "realm"; TokenBroker tokenBroker = Mockito.mock(); when(tokenBroker.supportsGrantType(TOKEN_EXCHANGE)).thenReturn(true); when(tokenBroker.supportsRequestedTokenType(TokenType.ACCESS_TOKEN)).thenReturn(true); when(tokenBroker.generateFromClientSecrets( - null, - "secret", - TOKEN_EXCHANGE, - "scope", - callContext.getPolarisCallContext(), - TokenType.ACCESS_TOKEN)) + null, "secret", TOKEN_EXCHANGE, "scope", metaStoreManager, TokenType.ACCESS_TOKEN)) .thenReturn(TokenResponse.of("token", TokenType.ACCESS_TOKEN.getValue(), 3600)); Response response = new InvocationBuilder() @@ -219,7 +197,7 @@ public void testAuthHeaderRequiresValidCredentialPair() { .grantType(TOKEN_EXCHANGE) .requestedTokenType(TokenType.ACCESS_TOKEN) .realmContext(realmContext) - .invoke(new DefaultOAuth2ApiService(tokenBroker, callContext)); + .invoke(new DefaultOAuth2ApiService(tokenBroker, metaStoreManager)); Assertions.assertThat(response.getEntity()) .isInstanceOf(OAuthTokenErrorResponse.class) .asInstanceOf(InstanceOfAssertFactories.type(OAuthTokenErrorResponse.class)) @@ -228,18 +206,12 @@ public void testAuthHeaderRequiresValidCredentialPair() { @Test public void testReadClientSecretFromAuthHeader() { - RealmContext realmContext = () -> "realm"; TokenBroker tokenBroker = Mockito.mock(); when(tokenBroker.supportsGrantType(TOKEN_EXCHANGE)).thenReturn(true); when(tokenBroker.supportsRequestedTokenType(TokenType.ACCESS_TOKEN)).thenReturn(true); when(tokenBroker.generateFromClientSecrets( - "", - "secret", - TOKEN_EXCHANGE, - "scope", - callContext.getPolarisCallContext(), - TokenType.ACCESS_TOKEN)) + "", "secret", TOKEN_EXCHANGE, "scope", metaStoreManager, TokenType.ACCESS_TOKEN)) .thenReturn(TokenResponse.of("token", TokenType.ACCESS_TOKEN.getValue(), 3600)); Response response = new InvocationBuilder() @@ -253,7 +225,7 @@ public void testReadClientSecretFromAuthHeader() { .grantType(TOKEN_EXCHANGE) .requestedTokenType(TokenType.ACCESS_TOKEN) .realmContext(realmContext) - .invoke(new DefaultOAuth2ApiService(tokenBroker, callContext)); + .invoke(new DefaultOAuth2ApiService(tokenBroker, metaStoreManager)); Assertions.assertThat(response.getEntity()) .isInstanceOf(OAuthTokenResponse.class) .asInstanceOf(InstanceOfAssertFactories.type(OAuthTokenResponse.class)) diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/generic/AbstractPolarisGenericTableCatalogTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/generic/AbstractPolarisGenericTableCatalogTest.java index 4f2ce23afc..5483f45c9a 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/catalog/generic/AbstractPolarisGenericTableCatalogTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/generic/AbstractPolarisGenericTableCatalogTest.java @@ -150,19 +150,15 @@ public void before(TestInfo testInfo) { RealmContext realmContext = () -> realmName; QuarkusMock.installMockForType(realmContext, RealmContext.class); - metaStoreManager = metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); - userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext); - polarisContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - configurationStore); + + polarisContext = new PolarisCallContext(realmContext, configurationStore); realmConfig = polarisContext.getRealmConfig(); + metaStoreManager = metaStoreManagerFactory.createMetaStoreManager(realmContext); + userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext); accessConfigProvider = new AccessConfigProvider(storageCredentialCache, metaStoreManagerFactory); - PrincipalEntity rootPrincipal = - metaStoreManager.findRootPrincipal(polarisContext).orElseThrow(); + PrincipalEntity rootPrincipal = metaStoreManager.findRootPrincipal().orElseThrow(); authenticatedRoot = PolarisPrincipal.of(rootPrincipal, Set.of()); securityContext = Mockito.mock(SecurityContext.class); @@ -237,8 +233,7 @@ public void before(TestInfo testInfo) { isA(AwsStorageConfigurationInfo.class))) .thenReturn((PolarisStorageIntegration) storageIntegration); - this.genericTableCatalog = - new PolarisGenericTableCatalog(metaStoreManager, polarisContext, passthroughView); + this.genericTableCatalog = new PolarisGenericTableCatalog(metaStoreManager, passthroughView); this.genericTableCatalog.initialize(CATALOG_NAME, Map.of()); this.icebergCatalog = new IcebergCatalog( @@ -259,7 +254,7 @@ public void before(TestInfo testInfo) { @AfterEach public void after() throws IOException { - metaStoreManager.purge(polarisContext); + metaStoreManager.purge(); } @Test diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogTest.java index cc7054ff1c..6b3906fda9 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogTest.java @@ -261,9 +261,7 @@ public static void setUpMocks() { @Nullable protected abstract EntityCache createEntityCache( - PolarisDiagnostics diagnostics, - RealmConfig realmConfig, - PolarisMetaStoreManager metaStoreManager); + PolarisDiagnostics diagnostics, RealmConfig realmConfig); protected void bootstrapRealm(String realmName) {} @@ -280,33 +278,25 @@ public void before(TestInfo testInfo) { RealmContext realmContext = () -> realmName; QuarkusMock.installMockForType(realmContext, RealmContext.class); - metaStoreManager = metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); - userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext); - polarisContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - configurationStore); - realmConfig = polarisContext.getRealmConfig(); + accessConfigProvider = new AccessConfigProvider(storageCredentialCache, metaStoreManagerFactory); - EntityCache entityCache = createEntityCache(diagServices, realmConfig, metaStoreManager); + polarisContext = new PolarisCallContext(realmContext, configurationStore); + realmConfig = polarisContext.getRealmConfig(); + metaStoreManager = metaStoreManagerFactory.createMetaStoreManager(realmContext); + userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext); + + EntityCache entityCache = createEntityCache(diagServices, realmConfig); resolverFactory = (securityContext, referenceCatalogName) -> new Resolver( - diagServices, - polarisContext, - metaStoreManager, - securityContext, - entityCache, - referenceCatalogName); + diagServices, metaStoreManager, securityContext, entityCache, referenceCatalogName); QuarkusMock.installMockForType(resolverFactory, ResolverFactory.class); resolutionManifestFactory = new ResolutionManifestFactoryImpl(diagServices, realmContext, resolverFactory); - PrincipalEntity rootPrincipal = - metaStoreManager.findRootPrincipal(polarisContext).orElseThrow(); + PrincipalEntity rootPrincipal = metaStoreManager.findRootPrincipal().orElseThrow(); PolarisPrincipal authenticatedRoot = PolarisPrincipal.of(rootPrincipal, Set.of()); securityContext = Mockito.mock(SecurityContext.class); @@ -385,7 +375,7 @@ public void before(TestInfo testInfo) { @AfterEach public void after() throws IOException { catalog().close(); - metaStoreManager.purge(polarisContext); + metaStoreManager.purge(); } @Override @@ -1109,7 +1099,7 @@ public void testUpdateNotificationWhenTableAndNamespacesDontExistNamespaceRaceCo // been the one to succeed creating the namespace first. doAnswer( invocation -> { - PolarisEntity entity = (PolarisEntity) invocation.getArgument(2); + PolarisEntity entity = invocation.getArgument(1); EntityResult result = (EntityResult) invocation.callRealMethod(); if (entity.getType() == PolarisEntityType.NAMESPACE) { return new EntityResult( @@ -1120,7 +1110,7 @@ public void testUpdateNotificationWhenTableAndNamespacesDontExistNamespaceRaceCo } }) .when(spyMetaStore) - .createEntityIfNotExists(any(), any(), any()); + .createEntityIfNotExists(any(), any()); Assertions.assertThat(catalog.sendNotification(table, request)) .as("Notification should be sent successfully") @@ -1190,7 +1180,6 @@ public void testCreateNotificationCreateTableInExternalLocation() { String.format("s3://my-bucket/path/to/data/another_table_%s/", tableSuffix); metaStoreManager.updateEntityPropertiesIfNotChanged( - polarisContext, List.of(PolarisEntity.toCore(catalogEntity)), new CatalogEntity.Builder(CatalogEntity.of(catalogEntity)) .addProperty( @@ -1250,7 +1239,6 @@ public void testCreateNotificationCreateTableOutsideOfMetadataLocation() { String.format("s3://my-bucket/path/to/data/another_table_%s", tableSuffix); metaStoreManager.updateEntityPropertiesIfNotChanged( - polarisContext, List.of(PolarisEntity.toCore(catalogEntity)), new CatalogEntity.Builder(CatalogEntity.of(catalogEntity)) .addProperty( @@ -1307,7 +1295,6 @@ public void testUpdateNotificationCreateTableInExternalLocation() { String.format("s3://my-bucket/path/to/data/another_table_%s/", tableSuffix); metaStoreManager.updateEntityPropertiesIfNotChanged( - polarisContext, List.of(PolarisEntity.toCore(catalogEntity)), new CatalogEntity.Builder(CatalogEntity.of(catalogEntity)) .addProperty( @@ -1891,15 +1878,12 @@ public void testDropTableWithPurge() { .as("Table should not exist after drop") .rejects(TABLE); List tasks = - metaStoreManager - .loadTasks(polarisContext, "testExecutor", PageToken.fromLimit(1)) - .getEntities(); + metaStoreManager.loadTasks("testExecutor", PageToken.fromLimit(1)).getEntities(); Assertions.assertThat(tasks).hasSize(1); TaskEntity taskEntity = TaskEntity.of(tasks.get(0)); Map credentials = metaStoreManager .getSubscopedCredsForEntity( - polarisContext, 0, taskEntity.getId(), taskEntity.getType(), @@ -2072,7 +2056,7 @@ public void testFileIOWrapper() { TaskEntity taskEntity = TaskEntity.of( metaStoreManager - .loadTasks(polarisContext, "testExecutor", PageToken.fromLimit(1)) + .loadTasks("testExecutor", PageToken.fromLimit(1)) .getEntities() .getFirst()); Map properties = taskEntity.getInternalPropertiesAsMap(); @@ -2150,7 +2134,7 @@ public void testConcurrencyConflictCreateTableUpdatedDuringFinalTransaction() { BaseResult.ReturnStatus.ENTITY_ALREADY_EXISTS, PolarisEntitySubType.ICEBERG_TABLE.getCode())) .when(spyMetaStore) - .createEntityIfNotExists(any(), any(), any()); + .createEntityIfNotExists(any(), any()); Assertions.assertThatThrownBy(() -> catalog.createTable(table, SCHEMA)) .isInstanceOf(AlreadyExistsException.class) .hasMessageContaining("conflict_table"); @@ -2185,7 +2169,7 @@ public void testConcurrencyConflictUpdateTableDuringFinalTransaction() { doReturn(new EntityResult(BaseResult.ReturnStatus.TARGET_ENTITY_CONCURRENTLY_MODIFIED, null)) .when(spyMetaStore) - .updateEntityPropertiesIfNotChanged(any(), any(), any()); + .updateEntityPropertiesIfNotChanged(any(), any()); UpdateSchema update = table.updateSchema().addColumn("new_col", Types.LongType.get()); Schema expected = update.apply(); diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogViewTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogViewTest.java index d6fc350050..5bcea6a3f0 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogViewTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogViewTest.java @@ -157,18 +157,14 @@ public void before(TestInfo testInfo) { RealmContext realmContext = () -> realmName; QuarkusMock.installMockForType(realmContext, RealmContext.class); - metaStoreManager = metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); - userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext); - polarisContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - configurationStore); - realmConfig = polarisContext.getRealmConfig(); accessConfigProvider = new AccessConfigProvider(storageCredentialCache, metaStoreManagerFactory); - PrincipalEntity rootPrincipal = - metaStoreManager.findRootPrincipal(polarisContext).orElseThrow(); + polarisContext = new PolarisCallContext(realmContext, configurationStore); + realmConfig = polarisContext.getRealmConfig(); + metaStoreManager = metaStoreManagerFactory.createMetaStoreManager(realmContext); + userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext); + + PrincipalEntity rootPrincipal = metaStoreManager.findRootPrincipal().orElseThrow(); PolarisPrincipal authenticatedRoot = PolarisPrincipal.of(rootPrincipal, Set.of()); SecurityContext securityContext = Mockito.mock(SecurityContext.class); @@ -236,7 +232,7 @@ public void before(TestInfo testInfo) { @AfterEach public void after() throws IOException { catalog().close(); - metaStoreManager.purge(polarisContext); + metaStoreManager.purge(); } @Override diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandlerAuthzTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandlerAuthzTest.java index f3cd56162d..cb396b4e3d 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandlerAuthzTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandlerAuthzTest.java @@ -249,7 +249,6 @@ public void testInsufficientPermissionsPriorToSecretRotation() { String principalName = "all_the_powers"; CreatePrincipalResult newPrincipal = metaStoreManager.createPrincipal( - callContext.getPolarisCallContext(), new PrincipalEntity.Builder() .setName(principalName) .setCreateTimestamp(Instant.now().toEpochMilli()) @@ -294,8 +293,7 @@ public void testInsufficientPermissionsPriorToSecretRotation() { newPrincipal.getPrincipalSecrets().getPrincipalClientId(), newPrincipal.getPrincipalSecrets().getMainSecret()); PrincipalEntity refreshPrincipal = - rotateAndRefreshPrincipal( - metaStoreManager, principalName, credentials, callContext.getPolarisCallContext()); + rotateAndRefreshPrincipal(metaStoreManager, principalName, credentials); PolarisPrincipal authenticatedPrincipal1 = PolarisPrincipal.of(refreshPrincipal, Set.of(PRINCIPAL_ROLE1, PRINCIPAL_ROLE2)); IcebergCatalogHandler refreshedWrapper = diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogRelationalNoEntityCacheTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogRelationalNoEntityCacheTest.java index 1060b6a013..89bd846d9f 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogRelationalNoEntityCacheTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogRelationalNoEntityCacheTest.java @@ -23,7 +23,6 @@ import jakarta.annotation.Nullable; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.config.RealmConfig; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.cache.InMemoryEntityCache; @QuarkusTest @@ -33,9 +32,7 @@ public class IcebergCatalogRelationalNoEntityCacheTest extends AbstractIcebergCa @Nullable @Override protected InMemoryEntityCache createEntityCache( - PolarisDiagnostics diagnostics, - RealmConfig realmConfig, - PolarisMetaStoreManager metaStoreManager) { + PolarisDiagnostics diagnostics, RealmConfig realmConfig) { return null; } } diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogRelationalWithEntityCacheTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogRelationalWithEntityCacheTest.java index c589e913ef..8b948b9a85 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogRelationalWithEntityCacheTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogRelationalWithEntityCacheTest.java @@ -23,7 +23,6 @@ import jakarta.annotation.Nullable; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.config.RealmConfig; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.cache.InMemoryEntityCache; @QuarkusTest @@ -33,9 +32,7 @@ public class IcebergCatalogRelationalWithEntityCacheTest extends AbstractIceberg @Nullable @Override protected InMemoryEntityCache createEntityCache( - PolarisDiagnostics diagnostics, - RealmConfig realmConfig, - PolarisMetaStoreManager metaStoreManager) { - return new InMemoryEntityCache(diagnostics, realmConfig, metaStoreManager); + PolarisDiagnostics diagnostics, RealmConfig realmConfig) { + return new InMemoryEntityCache(diagnostics, realmConfig); } } diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java index 53ebebf7a6..b54d5cb5ab 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java @@ -170,7 +170,7 @@ public void testLoadFileIOForCleanupTask(String scheme) { List tasks = testServices .metaStoreManager() - .loadTasks(callContext.getPolarisCallContext(), "testExecutor", PageToken.fromLimit(1)) + .loadTasks("testExecutor", PageToken.fromLimit(1)) .getEntities(); Assertions.assertThat(tasks).hasSize(1); TaskEntity taskEntity = TaskEntity.of(tasks.get(0)); diff --git a/runtime/service/src/test/java/org/apache/polaris/service/catalog/policy/AbstractPolicyCatalogTest.java b/runtime/service/src/test/java/org/apache/polaris/service/catalog/policy/AbstractPolicyCatalogTest.java index f03afecdbe..d8c706352b 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/catalog/policy/AbstractPolicyCatalogTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/catalog/policy/AbstractPolicyCatalogTest.java @@ -171,19 +171,15 @@ public void before(TestInfo testInfo) { RealmContext realmContext = () -> realmName; QuarkusMock.installMockForType(realmContext, RealmContext.class); - metaStoreManager = metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); - userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext); - polarisContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - configurationStore); - realmConfig = polarisContext.getRealmConfig(); + accessConfigProvider = new AccessConfigProvider(storageCredentialCache, metaStoreManagerFactory); + polarisContext = new PolarisCallContext(realmContext, configurationStore); + realmConfig = polarisContext.getRealmConfig(); + metaStoreManager = metaStoreManagerFactory.createMetaStoreManager(realmContext); + userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext); - PrincipalEntity rootPrincipal = - metaStoreManager.findRootPrincipal(polarisContext).orElseThrow(); + PrincipalEntity rootPrincipal = metaStoreManager.findRootPrincipal().orElseThrow(); authenticatedRoot = PolarisPrincipal.of(rootPrincipal, Set.of()); securityContext = Mockito.mock(SecurityContext.class); @@ -276,7 +272,7 @@ public void before(TestInfo testInfo) { @AfterEach public void after() throws IOException { - metaStoreManager.purge(polarisContext); + metaStoreManager.purge(); } @Test diff --git a/runtime/service/src/test/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListenerBufferSizeTest.java b/runtime/service/src/test/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListenerBufferSizeTest.java index 7ee12ebc02..3fbb33615a 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListenerBufferSizeTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListenerBufferSizeTest.java @@ -32,7 +32,6 @@ import io.smallrye.mutiny.subscription.BackPressureFailure; import java.util.Map; import org.apache.polaris.core.entity.PolarisEvent; -import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.mockito.Mockito; @@ -73,15 +72,17 @@ void testFlushOnShutdown() { @Test void testFlushFailureRecovery() { - var manager = Mockito.mock(PolarisMetaStoreManager.class); - doReturn(manager).when(metaStoreManagerFactory).getOrCreateMetaStoreManager(any()); + var manager = metaStoreManagerFactory.createMetaStoreManager(() -> "test1"); + var managerSpy = Mockito.spy(manager); + doReturn(managerSpy).when(metaStoreManagerFactory).createMetaStoreManager(any()); + RuntimeException error = new RuntimeException("error"); doThrow(error) .doThrow(error) // first batch will give up after 2 attempts .doThrow(error) .doCallRealMethod() // second batch will succeed on the 2nd attempt - .when(manager) - .writeEvents(any(), any()); + .when(managerSpy) + .writeEvents(any()); sendAsync("test1", 20); assertRows("test1", 10); } diff --git a/runtime/service/src/test/java/org/apache/polaris/service/task/BatchFileCleanupTaskHandlerTest.java b/runtime/service/src/test/java/org/apache/polaris/service/task/BatchFileCleanupTaskHandlerTest.java index 326664620b..521db2eaf1 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/task/BatchFileCleanupTaskHandlerTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/task/BatchFileCleanupTaskHandlerTest.java @@ -46,7 +46,6 @@ import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.TaskEntity; -import org.apache.polaris.core.persistence.BasePersistence; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.service.TestFileIOFactory; import org.junit.jupiter.api.Test; @@ -61,8 +60,7 @@ private TaskFileIOSupplier buildTaskFileIOSupplier(FileIO fileIO) { } private PolarisCallContext newCallContext() { - BasePersistence metaStore = metaStoreManagerFactory.getOrCreateSession(realmContext); - return new PolarisCallContext(realmContext, metaStore); + return new PolarisCallContext(realmContext); } @Test diff --git a/runtime/service/src/test/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandlerTest.java b/runtime/service/src/test/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandlerTest.java index 99eacdbe2e..8ff547fa8e 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandlerTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandlerTest.java @@ -42,7 +42,6 @@ import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.TaskEntity; -import org.apache.polaris.core.persistence.BasePersistence; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.service.TestFileIOFactory; import org.junit.jupiter.api.Test; @@ -58,8 +57,7 @@ private TaskFileIOSupplier buildTaskFileIOSupplier(FileIO fileIO) { } private PolarisCallContext newCallContext() { - BasePersistence metaStore = metaStoreManagerFactory.getOrCreateSession(realmContext); - return new PolarisCallContext(realmContext, metaStore); + return new PolarisCallContext(realmContext); } @Test diff --git a/runtime/service/src/test/java/org/apache/polaris/service/task/TableCleanupTaskHandlerTest.java b/runtime/service/src/test/java/org/apache/polaris/service/task/TableCleanupTaskHandlerTest.java index 336607913d..89763171cb 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/task/TableCleanupTaskHandlerTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/task/TableCleanupTaskHandlerTest.java @@ -78,12 +78,8 @@ private TableCleanupTaskHandler newTableCleanupTaskHandler(FileIO fileIO) { void setup() { QuarkusMock.installMockForType(realmContext, RealmContext.class); - metaStoreManager = metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); - callContext = - new PolarisCallContext( - realmContext, - metaStoreManagerFactory.getOrCreateSession(realmContext), - configurationStore); + callContext = new PolarisCallContext(realmContext, configurationStore); + metaStoreManager = metaStoreManagerFactory.createMetaStoreManager(realmContext); } @Test @@ -123,10 +119,7 @@ public void testTableCleanup() throws IOException { handler.handleTask(task, callContext); - assertThat( - metaStoreManager - .loadTasks(callContext.getPolarisCallContext(), "test", PageToken.fromLimit(2)) - .getEntities()) + assertThat(metaStoreManager.loadTasks("test", PageToken.fromLimit(2)).getEntities()) .hasSize(2) .satisfiesExactlyInAnyOrder( taskEntity -> @@ -197,11 +190,7 @@ public void close() { assertThat(results).containsExactly(true, true); // both tasks successfully executed, but only one should queue subtasks - assertThat( - metaStoreManager - .loadTasks(callContext.getPolarisCallContext(), "test", PageToken.fromLimit(5)) - .getEntities()) - .hasSize(2); + assertThat(metaStoreManager.loadTasks("test", PageToken.fromLimit(5)).getEntities()).hasSize(2); } @Test @@ -254,10 +243,7 @@ public void close() { assertThat(results).containsExactly(true, true); // both tasks successfully executed, but only one should queue subtasks - assertThat( - metaStoreManager - .loadTasks(callContext.getPolarisCallContext(), "test", PageToken.fromLimit(5)) - .getEntities()) + assertThat(metaStoreManager.loadTasks("test", PageToken.fromLimit(5)).getEntities()) .hasSize(4) .satisfiesExactlyInAnyOrder( taskEntity -> @@ -367,9 +353,7 @@ public void testTableCleanupMultipleSnapshots() throws IOException { handler.handleTask(task, callContext); List entities = - metaStoreManager - .loadTasks(callContext.getPolarisCallContext(), "test", PageToken.fromLimit(5)) - .getEntities(); + metaStoreManager.loadTasks("test", PageToken.fromLimit(5)).getEntities(); List manifestCleanupTasks = entities.stream() @@ -534,9 +518,7 @@ public void testTableCleanupMultipleMetadata() throws IOException { handler.handleTask(task, callContext); List entities = - metaStoreManager - .loadTasks(callContext.getPolarisCallContext(), "test", PageToken.fromLimit(6)) - .getEntities(); + metaStoreManager.loadTasks("test", PageToken.fromLimit(6)).getEntities(); List manifestCleanupTasks = entities.stream() diff --git a/runtime/service/src/test/java/org/apache/polaris/service/task/TaskExecutorImplTest.java b/runtime/service/src/test/java/org/apache/polaris/service/task/TaskExecutorImplTest.java index 3d59c481a2..c9d19b9dbd 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/task/TaskExecutorImplTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/task/TaskExecutorImplTest.java @@ -51,10 +51,10 @@ void testEventsAreEmitted() { TaskEntity taskEntity = new TaskEntity.Builder() .setName("mytask") - .setId(metaStoreManager.generateNewEntityId(polarisCallCtx).getId()) + .setId(metaStoreManager.generateNewEntityId().getId()) .setCreateTimestamp(testServices.clock().millis()) .build(); - metaStoreManager.createEntityIfNotExists(polarisCallCtx, null, taskEntity); + metaStoreManager.createEntityIfNotExists(null, taskEntity); int attempt = 1; diff --git a/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestFixture.java b/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestFixture.java index 19900e1200..52ac27a482 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestFixture.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestFixture.java @@ -29,7 +29,6 @@ import java.net.URI; import java.util.List; import java.util.Map; -import org.apache.polaris.core.PolarisCallContext; import org.apache.polaris.core.admin.model.GrantPrincipalRoleRequest; import org.apache.polaris.core.admin.model.Principal; import org.apache.polaris.core.admin.model.PrincipalRole; @@ -37,7 +36,6 @@ import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.entity.PrincipalEntity; -import org.apache.polaris.core.persistence.BasePersistence; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; import org.apache.polaris.service.auth.internal.broker.TokenUtils; @@ -104,16 +102,10 @@ private PolarisPrincipalSecrets fetchAdminSecrets() { .toCompletableFuture() .join(); - BasePersistence metaStoreSession = - helper.metaStoreManagerFactory.getOrCreateSession(realmContext); - PolarisCallContext polarisContext = - new PolarisCallContext(realmContext, metaStoreSession, helper.configurationStore); PolarisMetaStoreManager metaStoreManager = - helper.metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); - PrincipalEntity principal = metaStoreManager.findRootPrincipal(polarisContext).orElseThrow(); - return metaStoreManager - .loadPrincipalSecrets(polarisContext, principal.getClientId()) - .getPrincipalSecrets(); + helper.metaStoreManagerFactory.createMetaStoreManager(realmContext); + PrincipalEntity principal = metaStoreManager.findRootPrincipal().orElseThrow(); + return metaStoreManager.loadPrincipalSecrets(principal.getClientId()).getPrincipalSecrets(); } private SnowmanCredentials createSnowmanCredentials(TestEnvironment testEnv) { diff --git a/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestHelper.java b/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestHelper.java index 281b15b5f1..6784e8a728 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestHelper.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/test/PolarisIntegrationTestHelper.java @@ -22,6 +22,7 @@ import jakarta.inject.Singleton; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.config.PolarisConfigurationStore; +import org.apache.polaris.core.config.RealmConfig; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.service.context.RealmContextResolver; import org.junit.jupiter.api.TestInfo; @@ -33,6 +34,7 @@ public class PolarisIntegrationTestHelper { @Inject RealmContextResolver realmContextResolver; @Inject PolarisDiagnostics diagServices; @Inject PolarisConfigurationStore configurationStore; + @Inject RealmConfig realmConfig; public PolarisIntegrationTestFixture createFixture(TestEnvironment testEnv, TestInfo testInfo) { return new PolarisIntegrationTestFixture(this, testEnv, testInfo); diff --git a/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java b/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java index a6fa48ef85..2715cdb437 100644 --- a/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java +++ b/runtime/service/src/testFixtures/java/org/apache/polaris/service/TestServices.java @@ -49,7 +49,6 @@ import org.apache.polaris.core.credentials.connection.ConnectionCredentialVendor; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.identity.provider.ServiceIdentityProvider; -import org.apache.polaris.core.persistence.BasePersistence; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; import org.apache.polaris.core.persistence.cache.EntityCache; @@ -191,7 +190,7 @@ public TestServices build() { () -> GoogleCredentials.create(new AccessToken(GCP_ACCESS_TOKEN, new Date()))); InMemoryPolarisMetaStoreManagerFactory metaStoreManagerFactory = new InMemoryPolarisMetaStoreManagerFactory( - clock, diagnostics, storageIntegrationProvider); + clock, diagnostics, configurationStore, storageIntegrationProvider); StorageCredentialCacheConfig storageCredentialCacheConfig = () -> 10_000; StorageCredentialCache storageCredentialCache = @@ -200,21 +199,17 @@ public TestServices build() { UserSecretsManagerFactory userSecretsManagerFactory = new UnsafeInMemorySecretsManagerFactory(); - BasePersistence metaStoreSession = metaStoreManagerFactory.getOrCreateSession(realmContext); - CallContext callContext = - new PolarisCallContext(realmContext, metaStoreSession, configurationStore); + CallContext callContext = new PolarisCallContext(realmContext, configurationStore); RealmConfig realmConfig = callContext.getRealmConfig(); PolarisMetaStoreManager metaStoreManager = - metaStoreManagerFactory.getOrCreateMetaStoreManager(realmContext); + metaStoreManagerFactory.createMetaStoreManager(realmContext); - EntityCache entityCache = - metaStoreManagerFactory.getOrCreateEntityCache(realmContext, realmConfig); + EntityCache entityCache = metaStoreManagerFactory.getOrCreateEntityCache(realmContext); ResolverFactory resolverFactory = (securityContext, referenceCatalogName) -> new Resolver( diagnostics, - callContext.getPolarisCallContext(), metaStoreManager, securityContext, entityCache, @@ -291,7 +286,6 @@ public TestServices build() { CreatePrincipalResult createdPrincipal = metaStoreManager.createPrincipal( - callContext.getPolarisCallContext(), new PrincipalEntity.Builder() .setName("test-principal") .setCreateTimestamp(Instant.now().toEpochMilli()) @@ -362,7 +356,6 @@ public String getAuthenticationScheme() { } public PolarisCallContext newCallContext() { - BasePersistence metaStore = metaStoreManagerFactory.getOrCreateSession(realmContext); - return new PolarisCallContext(realmContext, metaStore, configurationStore); + return new PolarisCallContext(realmContext, configurationStore); } }