This is an automated email from the ASF dual-hosted git repository. dimas pushed a commit to branch dmitri-tmp1 in repository https://gitbox.apache.org/repos/asf/polaris.git
commit 827ec33d8fdb14021870f88edefaa8f27e85a0fb Author: Michael Collado <[email protected]> AuthorDate: Wed Oct 8 14:44:20 2025 -0700 Removed loadResolvedEntities method with lookup record param --- .../AtomicOperationMetaStoreManager.java | 15 -- .../core/persistence/PolarisMetaStoreManager.java | 16 -- .../TransactionWorkspaceMetaStoreManager.java | 10 - .../core/persistence/cache/EntityCache.java | 21 -- .../persistence/cache/InMemoryEntityCache.java | 50 ----- .../TransactionalMetaStoreManagerImpl.java | 16 -- .../persistence/cache/InMemoryEntityCacheTest.java | 215 +++++---------------- .../BasePolarisMetaStoreManagerTest.java | 6 - .../persistence/PolarisTestMetaStoreManager.java | 163 ---------------- 9 files changed, 44 insertions(+), 468 deletions(-) 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 3381da9ba..cd5a032ae 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 @@ -1765,21 +1765,6 @@ public class AtomicOperationMetaStoreManager extends BaseMetaStoreManager { return result; } - @Nonnull - @Override - public ResolvedEntitiesResult loadResolvedEntities( - @Nonnull PolarisCallContext callCtx, - @Nonnull List<EntityNameLookupRecord> entityLookupRecords) { - BasePersistence ms = callCtx.getMetaStore(); - List<PolarisEntityId> entityIds = - entityLookupRecords.stream() - .map(r -> new PolarisEntityId(r.getCatalogId(), r.getId())) - .collect(Collectors.toList()); - Function<Integer, PolarisEntityType> entityTypeForIndex = - i -> entityLookupRecords.get(i).getType(); - return getResolvedEntitiesResult(callCtx, ms, entityIds, entityTypeForIndex); - } - @Nonnull @Override public ResolvedEntitiesResult loadResolvedEntities( 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 ff49d9569..2273718d0 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 @@ -26,7 +26,6 @@ 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.EntityNameLookupRecord; import org.apache.polaris.core.entity.LocationBasedEntity; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntity; @@ -419,21 +418,6 @@ public interface PolarisMetaStoreManager @Nonnull PolarisEntityType entityType, @Nonnull String entityName); - /** - * Load a batch of resolved entities given their {@link EntityNameLookupRecord}. Will return an - * empty list if the input list is empty. Order in that returned list is the same as the input - * list. Some elements might be NULL if the entity has been dropped. - * - * @param callCtx call context - * @param entityLookupRecords the list of entity lookup records to load - * @return a non-null list of entities corresponding to the lookup keys. Some elements might be - * NULL if the entity has been dropped. - */ - @Nonnull - ResolvedEntitiesResult loadResolvedEntities( - @Nonnull PolarisCallContext callCtx, - @Nonnull List<EntityNameLookupRecord> entityLookupRecords); - /** * Load a batch of resolved entities of a specified entity type given their {@link * PolarisEntityId}. Will return an empty list if the input list is empty. Order in that returned 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 39c1f908f..99c1f8162 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 @@ -28,7 +28,6 @@ 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.EntityNameLookupRecord; import org.apache.polaris.core.entity.LocationBasedEntity; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntity; @@ -381,15 +380,6 @@ public class TransactionWorkspaceMetaStoreManager implements PolarisMetaStoreMan return null; } - @Nonnull - @Override - public ResolvedEntitiesResult loadResolvedEntities( - @Nonnull PolarisCallContext callCtx, - @Nonnull List<EntityNameLookupRecord> entityLookupRecords) { - diagnostics.fail("illegal_method_in_transaction_workspace", "loadEntities"); - return null; - } - @Nonnull @Override public ResolvedEntitiesResult loadResolvedEntities( 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 7cfea2a84..481fa7a9e 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 @@ -22,7 +22,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.EntityNameLookupRecord; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntityId; import org.apache.polaris.core.entity.PolarisEntityType; @@ -111,24 +110,4 @@ public interface EntityCache { @Nonnull PolarisCallContext callCtx, @Nonnull PolarisEntityType entityType, @Nonnull List<PolarisEntityId> entityIds); - - /** - * Load multiple entities by {@link EntityNameLookupRecord}, returning those found in the cache - * and loading those not found. - * - * <p>see note in {@link #getOrLoadResolvedEntities(PolarisCallContext, PolarisEntityType, List)} - * re: the need to validate cache contents against the {@link - * org.apache.polaris.core.persistence.PolarisMetaStoreManager#loadEntitiesChangeTracking(PolarisCallContext, - * List)} to avoid invalid authorization or conflict detection decisions based on stale entries. - * - * @param callCtx the Polaris call context - * @param lookupRecords the list of entity name to load - * @return the list of resolved entities, in the same order as the requested entity records. As in - * {@link - * org.apache.polaris.core.persistence.PolarisMetaStoreManager#loadResolvedEntities(PolarisCallContext, - * PolarisEntityType, List)}, elements in the returned list may be null if the corresponding - * entity id does not exist. - */ - List<EntityCacheLookupResult> getOrLoadResolvedEntities( - @Nonnull PolarisCallContext callCtx, @Nonnull List<EntityNameLookupRecord> lookupRecords); } 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 e8b4163e7..784bcf2a4 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 @@ -28,7 +28,6 @@ import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.config.BehaviorChangeConfiguration; import org.apache.polaris.core.config.FeatureConfiguration; import org.apache.polaris.core.config.RealmConfig; -import org.apache.polaris.core.entity.EntityNameLookupRecord; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisChangeTrackingVersions; import org.apache.polaris.core.entity.PolarisEntityId; @@ -504,55 +503,6 @@ public class InMemoryEntityCache implements EntityCache { .collect(Collectors.toList()); } - @Override - public List<EntityCacheLookupResult> getOrLoadResolvedEntities( - @Nonnull PolarisCallContext callCtx, @Nonnull List<EntityNameLookupRecord> lookupRecords) { - Map<PolarisEntityId, EntityNameLookupRecord> entityIdMap = - lookupRecords.stream() - .collect( - Collectors.toMap( - e -> new PolarisEntityId(e.getCatalogId(), e.getId()), - Function.identity(), - (a, b) -> a)); - Function<List<PolarisEntityId>, ResolvedEntitiesResult> loaderFunc = - idsToLoad -> - polarisMetaStoreManager.loadResolvedEntities( - callCtx, idsToLoad.stream().map(entityIdMap::get).collect(Collectors.toList())); - - // use a map to collect cached entries to avoid concurrency problems in case a second thread is - // trying to populate - // the cache from a different snapshot - Map<PolarisEntityId, ResolvedPolarisEntity> resolvedEntities = new HashMap<>(); - List<PolarisEntityId> entityIds = - lookupRecords.stream() - .map(e -> new PolarisEntityId(e.getCatalogId(), e.getId())) - .collect(Collectors.toList()); - boolean stateResolved = false; - for (int i = 0; i < MAX_CACHE_REFRESH_ATTEMPTS; i++) { - if (isCacheStateValid(callCtx, resolvedEntities, entityIds, loaderFunc)) { - stateResolved = true; - break; - } - } - if (!stateResolved) { - LOGGER.warn( - "Unable to resolve entities in cache after multiple attempts {} - resolved: {}", - entityIds, - resolvedEntities); - diagnostics.fail("cannot_resolve_all_entities", "Unable to resolve entities in cache"); - } - - return lookupRecords.stream() - .map( - lookupRecord -> { - ResolvedPolarisEntity entity = - resolvedEntities.get( - new PolarisEntityId(lookupRecord.getCatalogId(), lookupRecord.getId())); - return entity == null ? null : new EntityCacheLookupResult(entity, true); - }) - .collect(Collectors.toList()); - } - private boolean isCacheStateValid( @Nonnull PolarisCallContext callCtx, @Nonnull Map<PolarisEntityId, ResolvedPolarisEntity> resolvedEntities, 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 87fa9ac04..0bbaf1e6a 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 @@ -2336,22 +2336,6 @@ public class TransactionalMetaStoreManagerImpl extends BaseMetaStoreManager { return new ResolvedEntitiesResult(ret); } - @Nonnull - @Override - public ResolvedEntitiesResult loadResolvedEntities( - @Nonnull PolarisCallContext callCtx, - @Nonnull List<EntityNameLookupRecord> entityLookupRecords) { - TransactionalPersistence ms = ((TransactionalPersistence) callCtx.getMetaStore()); - List<PolarisEntityId> entityIds = - entityLookupRecords.stream() - .map(r -> new PolarisEntityId(r.getCatalogId(), r.getId())) - .collect(Collectors.toList()); - Function<Integer, PolarisEntityType> entityTypeForIndex = - i -> entityLookupRecords.get(i).getType(); - return ms.runInReadTransaction( - callCtx, () -> getResolvedEntitiesResult(callCtx, ms, entityIds, entityTypeForIndex)); - } - @Nonnull @Override public ResolvedEntitiesResult loadResolvedEntities( 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 43d9c8820..95774364d 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 @@ -34,7 +34,6 @@ 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.entity.EntityNameLookupRecord; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisChangeTrackingVersions; import org.apache.polaris.core.entity.PolarisEntity; @@ -55,8 +54,6 @@ import org.apache.polaris.core.persistence.transactional.TreeMapMetaStore; import org.apache.polaris.core.persistence.transactional.TreeMapTransactionalPersistenceImpl; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mockito; import org.mockito.stubbing.Answer; import org.slf4j.Logger; @@ -582,63 +579,7 @@ public class InMemoryEntityCacheTest { } @Test - public void testBatchLoadByNameLookupRecords() { - // get a new cache - InMemoryEntityCache cache = this.allocateNewCache(); - - // Load catalog into cache - EntityCacheLookupResult lookup = - cache.getOrLoadEntityByName( - this.callCtx, new EntityCacheByNameKey(PolarisEntityType.CATALOG, "test")); - assertThat(lookup).isNotNull(); - PolarisBaseEntity catalog = lookup.getCacheEntry().getEntity(); - - // Get some entities that exist in the test setup - PolarisBaseEntity N1 = - this.tm.ensureExistsByName(List.of(catalog), PolarisEntityType.NAMESPACE, "N1"); - PolarisBaseEntity N2 = - this.tm.ensureExistsByName(List.of(catalog, N1), PolarisEntityType.NAMESPACE, "N2"); - PolarisBaseEntity R1 = - this.tm.ensureExistsByName(List.of(catalog), PolarisEntityType.CATALOG_ROLE, "R1"); - - // Pre-load N1 into cache by name - cache.getOrLoadEntityByName( - this.callCtx, - new EntityCacheByNameKey( - catalog.getId(), catalog.getId(), PolarisEntityType.NAMESPACE, "N1")); - - // Create list of EntityNameLookupRecords - List<EntityNameLookupRecord> lookupRecords = - List.of( - new EntityNameLookupRecord(N1), // already cached - new EntityNameLookupRecord(N2), // not cached - new EntityNameLookupRecord(R1) // not cached - ); - - // Test batch loading by name lookup records - List<EntityCacheLookupResult> results = - cache.getOrLoadResolvedEntities(this.callCtx, lookupRecords); - - // Verify all entities were found - assertThat(results).hasSize(3); - assertThat(results.get(0)).isNotNull(); // N1 - was cached - assertThat(results.get(1)).isNotNull(); // N2 - was loaded - assertThat(results.get(2)).isNotNull(); // R1 - was loaded - - // Verify the entities are correct - assertThat(results.get(0).getCacheEntry().getEntity().getId()).isEqualTo(N1.getId()); - assertThat(results.get(1).getCacheEntry().getEntity().getId()).isEqualTo(N2.getId()); - assertThat(results.get(2).getCacheEntry().getEntity().getId()).isEqualTo(R1.getId()); - - // All should be cache hits now - assertThat(results.get(0).isCacheHit()).isTrue(); - assertThat(results.get(1).isCacheHit()).isTrue(); - assertThat(results.get(2).isCacheHit()).isTrue(); - } - - @ParameterizedTest - @ValueSource(strings = {"id", "name"}) - public void testBatchLoadWithStaleVersions(String loadType) { + public void testBatchLoadWithStaleVersions() { // get a new cache InMemoryEntityCache cache = this.allocateNewCache(); @@ -680,17 +621,12 @@ public class InMemoryEntityCacheTest { assertThat(T6v2.getEntityVersion()).isGreaterThan(T6v1.getEntityVersion()); List<EntityCacheLookupResult> results; - if (loadType.equals("id")) { - // Create entity ID list with the updated entity - List<PolarisEntityId> entityIds = List.of(getPolarisEntityId(T6v2)); - - // Call batch load - this should detect the stale version and reload - results = - cache.getOrLoadResolvedEntities(this.callCtx, PolarisEntityType.TABLE_LIKE, entityIds); - } else { - results = - cache.getOrLoadResolvedEntities(this.callCtx, List.of(new EntityNameLookupRecord(T6v2))); - } + // Create entity ID list with the updated entity + List<PolarisEntityId> entityIds = List.of(getPolarisEntityId(T6v2)); + + // Call batch load - this should detect the stale version and reload + results = + cache.getOrLoadResolvedEntities(this.callCtx, PolarisEntityType.TABLE_LIKE, entityIds); // Verify the entity was reloaded with the new version assertThat(results).hasSize(1); @@ -706,9 +642,8 @@ public class InMemoryEntityCacheTest { assertThat(cachedT6.getEntity().getEntityVersion()).isEqualTo(T6v2.getEntityVersion()); } - @ParameterizedTest - @ValueSource(strings = {"id", "name"}) - public void testBatchLoadWithStaleGrantVersions(String loadType) { + @Test + public void testBatchLoadWithStaleGrantVersions() { // get a new cache InMemoryEntityCache cache = this.allocateNewCache(); @@ -745,19 +680,12 @@ public class InMemoryEntityCacheTest { this.tm.ensureExistsByName(List.of(catalog, N1), PolarisEntityType.NAMESPACE, "N2"); assertThat(N2Updated.getGrantRecordsVersion()).isGreaterThan(originalGrantVersion); - List<EntityCacheLookupResult> results; - if (loadType.equals("id")) { - // Create entity ID list - List<PolarisEntityId> entityIds = List.of(getPolarisEntityId(N2Updated)); - - // Call batch load - this should detect the stale grant version and reload - results = - cache.getOrLoadResolvedEntities(this.callCtx, PolarisEntityType.NAMESPACE, entityIds); - } else { - results = - cache.getOrLoadResolvedEntities( - this.callCtx, List.of(new EntityNameLookupRecord(N2Updated))); - } + // Create entity ID list + List<PolarisEntityId> entityIds = List.of(getPolarisEntityId(N2Updated)); + + // Call batch load - this should detect the stale grant version and reload + List<EntityCacheLookupResult> results = + cache.getOrLoadResolvedEntities(this.callCtx, PolarisEntityType.NAMESPACE, entityIds); // Verify the entity was reloaded with the new grant version assertThat(results).hasSize(1); @@ -778,9 +706,8 @@ public class InMemoryEntityCacheTest { .isEqualTo(N2Updated.getGrantRecordsVersion()); } - @ParameterizedTest - @ValueSource(strings = {"id", "name"}) - public void testBatchLoadVersionRetryLogic(String loadType) { + @Test + public void testBatchLoadVersionRetryLogic() { // get a new cache PolarisMetaStoreManager metaStoreManager = Mockito.spy(this.metaStoreManager); InMemoryEntityCache cache = @@ -833,24 +760,13 @@ public class InMemoryEntityCacheTest { assertThat(N2v2.getEntityVersion()).isGreaterThan(originalEntityVersion); assertThat(N2v3.getEntityVersion()).isGreaterThan(N2v2.getEntityVersion()); - List<EntityCacheLookupResult> results; - if (loadType.equals("id")) { - // Create entity ID list - List<PolarisEntityId> entityIds = - List.of(getPolarisEntityId(catalog), getPolarisEntityId(N1), getPolarisEntityId(N2)); - - // Call batch load - this should detect the stale versions and reload until consistent - results = - cache.getOrLoadResolvedEntities(this.callCtx, PolarisEntityType.NAMESPACE, entityIds); - } else { - results = - cache.getOrLoadResolvedEntities( - this.callCtx, - List.of( - new EntityNameLookupRecord(catalog), - new EntityNameLookupRecord(N1), - new EntityNameLookupRecord(N2))); - } + // Create entity ID list + List<PolarisEntityId> entityIds = + List.of(getPolarisEntityId(catalog), getPolarisEntityId(N1), getPolarisEntityId(N2)); + + // Call batch load - this should detect the stale versions and reload until consistent + List<EntityCacheLookupResult> results = + cache.getOrLoadResolvedEntities(this.callCtx, PolarisEntityType.NAMESPACE, entityIds); // Verify the entity was reloaded with the latest version assertThat(results).hasSize(3); @@ -871,9 +787,8 @@ public class InMemoryEntityCacheTest { assertThat(cachedN2.getEntity().getEntityVersion()).isEqualTo(N2v3.getEntityVersion()); } - @ParameterizedTest - @ValueSource(strings = {"id", "name"}) - public void testBatchLoadVersionRetryFailsAfterMaxAttempts(String loadType) { + @Test + public void testBatchLoadVersionRetryFailsAfterMaxAttempts() { // get a new cache PolarisMetaStoreManager metaStoreManager = Mockito.spy(this.metaStoreManager); InMemoryEntityCache cache = @@ -922,35 +837,22 @@ public class InMemoryEntityCacheTest { assertThat(N2v2.getEntityVersion()).isGreaterThan(originalEntityVersion); assertThat(N2v3.getEntityVersion()).isGreaterThan(N2v2.getEntityVersion()); - if (loadType.equals("id")) { - // Create entity ID list - List<PolarisEntityId> entityIds = - List.of(getPolarisEntityId(catalog), getPolarisEntityId(N1), getPolarisEntityId(N2)); - Assertions.assertThatThrownBy( - () -> - cache.getOrLoadResolvedEntities( - this.callCtx, PolarisEntityType.NAMESPACE, entityIds)) - .isInstanceOf(RuntimeException.class); - } else { - Assertions.assertThatThrownBy( - () -> - cache.getOrLoadResolvedEntities( - this.callCtx, - List.of( - new EntityNameLookupRecord(catalog), - new EntityNameLookupRecord(N1), - new EntityNameLookupRecord(N2)))) - .isInstanceOf(RuntimeException.class); - } + // Create entity ID list + List<PolarisEntityId> entityIds = + List.of(getPolarisEntityId(catalog), getPolarisEntityId(N1), getPolarisEntityId(N2)); + Assertions.assertThatThrownBy( + () -> + cache.getOrLoadResolvedEntities( + this.callCtx, PolarisEntityType.NAMESPACE, entityIds)) + .isInstanceOf(RuntimeException.class); } private static PolarisEntityId getPolarisEntityId(PolarisBaseEntity catalog) { return new PolarisEntityId(catalog.getCatalogId(), catalog.getId()); } - @ParameterizedTest - @ValueSource(strings = {"id", "name"}) - public void testConcurrentClientLoadingBehavior(String loadType) throws Exception { + @Test + public void testConcurrentClientLoadingBehavior() throws Exception { // Load catalog into cache EntityCacheLookupResult lookup = allocateNewCache() @@ -1080,17 +982,10 @@ public class InMemoryEntityCacheTest { throw e; } }; - if (loadType.equals("id")) { - Mockito.doAnswer(client1Answer) - .doAnswer(client2Answer) - .when(mockedMetaStoreManager) - .loadResolvedEntities(Mockito.any(), Mockito.any(), Mockito.any()); - } else { - Mockito.doAnswer(client1Answer) - .doAnswer(client2Answer) - .when(mockedMetaStoreManager) - .loadResolvedEntities(Mockito.any(), Mockito.any()); - } + Mockito.doAnswer(client1Answer) + .doAnswer(client2Answer) + .when(mockedMetaStoreManager) + .loadResolvedEntities(Mockito.any(), Mockito.any(), Mockito.any()); // ExecutorService isn't AutoCloseable in JDK 11 :( ExecutorService executorService = Executors.newFixedThreadPool(2); @@ -1103,19 +998,8 @@ public class InMemoryEntityCacheTest { // Client1 calls getOrLoadResolvedEntities // - loadEntitiesChangeTracking returns older version for N2 // - loadResolvedEntities will block until client2 completes - if (loadType.equals("id")) { - return cache.getOrLoadResolvedEntities( - this.callCtx, PolarisEntityType.NAMESPACE, entityIds); - } else { - return cache.getOrLoadResolvedEntities( - this.callCtx, - List.of( - new EntityNameLookupRecord(N1), - new EntityNameLookupRecord(N2), - new EntityNameLookupRecord(N3), - new EntityNameLookupRecord(N5), - new EntityNameLookupRecord(N5_N6))); - } + return cache.getOrLoadResolvedEntities( + this.callCtx, PolarisEntityType.NAMESPACE, entityIds); } catch (Exception e) { client1Exception.set(e); return null; @@ -1131,19 +1015,8 @@ public class InMemoryEntityCacheTest { // - loadEntitiesChangeTracking returns newer version for N2 // - loadResolvedEntities executes normally and signals client1 when done client1ChangeTrackingResult.await(); - if (loadType.equals("id")) { - return cache.getOrLoadResolvedEntities( - this.callCtx, PolarisEntityType.NAMESPACE, entityIds); - } else { - return cache.getOrLoadResolvedEntities( - this.callCtx, - List.of( - new EntityNameLookupRecord(N1), - new EntityNameLookupRecord(N2), - new EntityNameLookupRecord(N3), - new EntityNameLookupRecord(N5), - new EntityNameLookupRecord(N5_N6))); - } + return cache.getOrLoadResolvedEntities( + this.callCtx, PolarisEntityType.NAMESPACE, entityIds); } catch (Exception e) { client2Exception.set(e); client1ResolvedEntitiesBlocker.release(); // Release in case of error 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 0675e7bf1..f8816260a 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 @@ -238,12 +238,6 @@ public abstract class BasePolarisMetaStoreManagerTest { polarisTestMetaStoreManager.testLookup(); } - /** test batch entity load */ - @Test - protected void testLoadResolvedEntities() { - polarisTestMetaStoreManager.testLoadResolvedEntities(); - } - /** test batch entity load */ @Test protected void testLoadResolvedEntitiesById() { 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 6a073c136..e79209aa7 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 @@ -2694,169 +2694,6 @@ public class PolarisTestMetaStoreManager { this.ensureNotExistsById(catalog.getId(), T1.getId(), PolarisEntityType.NAMESPACE); } - public void testLoadResolvedEntities() { - // load all principals - List<EntityNameLookupRecord> principals = - polarisMetaStoreManager - .listEntities( - this.polarisCallContext, - null, - PolarisEntityType.PRINCIPAL, - PolarisEntitySubType.NULL_SUBTYPE, - PageToken.readEverything()) - .getEntities(); - - // create new catalog - PolarisBaseEntity catalog = - new PolarisBaseEntity( - PolarisEntityConstants.getNullId(), - polarisMetaStoreManager.generateNewEntityId(this.polarisCallContext).getId(), - PolarisEntityType.CATALOG, - PolarisEntitySubType.NULL_SUBTYPE, - PolarisEntityConstants.getRootEntityId(), - "test"); - CreateCatalogResult catalogCreated = - polarisMetaStoreManager.createCatalog(this.polarisCallContext, catalog, List.of()); - Assertions.assertThat(catalogCreated).isNotNull(); - - // load the catalog again, since the grant versions are different - catalog = - polarisMetaStoreManager - .loadEntity( - polarisCallContext, - 0L, - catalogCreated.getCatalog().getId(), - PolarisEntityType.CATALOG) - .getEntity(); - - // now create all objects - PolarisBaseEntity N1 = this.createEntity(List.of(catalog), PolarisEntityType.NAMESPACE, "N1"); - PolarisBaseEntity N1_N2 = - this.createEntity(List.of(catalog, N1), PolarisEntityType.NAMESPACE, "N2"); - PolarisBaseEntity T1 = - this.createEntity( - List.of(catalog, N1, N1_N2), - PolarisEntityType.TABLE_LIKE, - PolarisEntitySubType.ICEBERG_TABLE, - "T1"); - - // batch load all entities. They should all be present and non-null - ResolvedEntitiesResult entitiesResult = - polarisMetaStoreManager.loadResolvedEntities( - polarisCallContext, - List.of( - new EntityNameLookupRecord(catalog), - new EntityNameLookupRecord(N1), - new EntityNameLookupRecord(N1_N2), - new EntityNameLookupRecord(T1))); - Assertions.assertThat(entitiesResult) - .isNotNull() - .returns(BaseResult.ReturnStatus.SUCCESS, ResolvedEntitiesResult::getReturnStatus) - .extracting( - ResolvedEntitiesResult::getResolvedEntities, - InstanceOfAssertFactories.list(ResolvedPolarisEntity.class)) - .hasSize(4) - .allSatisfy(entity -> Assertions.assertThat(entity).isNotNull()) - .extracting(r -> getEntityCore(r.getEntity())) - .containsExactly( - getEntityCore(catalog), getEntityCore(N1), getEntityCore(N1_N2), getEntityCore(T1)); - - ResolvedPolarisEntity catalogEntity = entitiesResult.getResolvedEntities().get(0); - Assertions.assertThat(catalogEntity) - .extracting(ResolvedPolarisEntity::getAllGrantRecords) - .isNotNull() - .asInstanceOf(InstanceOfAssertFactories.list(PolarisGrantRecord.class)) - .hasSize(2) - .containsExactlyInAnyOrder( - new PolarisGrantRecord( - 0L, - catalog.getId(), - catalogCreated.getCatalogAdminRole().getCatalogId(), - catalogCreated.getCatalogAdminRole().getId(), - PolarisPrivilege.CATALOG_MANAGE_ACCESS.getCode()), - new PolarisGrantRecord( - 0L, - catalog.getId(), - catalogCreated.getCatalogAdminRole().getCatalogId(), - catalogCreated.getCatalogAdminRole().getId(), - PolarisPrivilege.CATALOG_MANAGE_METADATA.getCode())); - - // try entities which do not exist - entitiesResult = - polarisMetaStoreManager.loadResolvedEntities( - polarisCallContext, - List.of( - new EntityNameLookupRecord( - catalog.getId(), - 27, - 0L, - "CATALOG_DOES_NOT_EXIST", - PolarisEntityType.CATALOG.getCode(), - PolarisEntitySubType.NULL_SUBTYPE.getCode()), - new EntityNameLookupRecord( - catalog.getId(), - 35, - 0L, - "PRINCIPAL_DOES_NOT_EXIST", - PolarisEntityType.PRINCIPAL.getCode(), - PolarisEntitySubType.NULL_SUBTYPE.getCode()))); - Assertions.assertThat(entitiesResult) - .isNotNull() - .returns(BaseResult.ReturnStatus.SUCCESS, ResolvedEntitiesResult::getReturnStatus) - .extracting( - ResolvedEntitiesResult::getResolvedEntities, - InstanceOfAssertFactories.list(ResolvedPolarisEntity.class)) - .hasSize(2) - .allSatisfy(entity -> Assertions.assertThat(entity).isNull()); - - // mix of existing entities and entities with wrong type - entitiesResult = - polarisMetaStoreManager.loadResolvedEntities( - polarisCallContext, - List.of( - new EntityNameLookupRecord( - catalog.getId(), - 27, - 0L, - "CATALOG_DOES_NOT_EXIST", - PolarisEntityType.CATALOG.getCode(), - PolarisEntitySubType.NULL_SUBTYPE.getCode()), - new EntityNameLookupRecord( - catalog.getId(), - 35, - 0L, - "PRINCIPAL_DOES_NOT_EXIST", - PolarisEntityType.PRINCIPAL.getCode(), - PolarisEntitySubType.NULL_SUBTYPE.getCode()), - new EntityNameLookupRecord(catalog), - new EntityNameLookupRecord( - N1.getCatalogId(), - N1.getId(), - N1.getParentId(), - N1.getName(), - PolarisEntityType.CATALOG_ROLE.getCode(), - PolarisEntitySubType.NULL_SUBTYPE.getCode()), - new EntityNameLookupRecord( - N1_N2.getCatalogId(), - N1_N2.getId(), - N1_N2.getParentId(), - N1_N2.getName(), - PolarisEntityType.TABLE_LIKE.getCode(), - PolarisEntitySubType.ANY_SUBTYPE.getCode()), - new EntityNameLookupRecord(T1))); - Assertions.assertThat(entitiesResult) - .isNotNull() - .returns(BaseResult.ReturnStatus.SUCCESS, ResolvedEntitiesResult::getReturnStatus) - .extracting( - ResolvedEntitiesResult::getResolvedEntities, - InstanceOfAssertFactories.list(ResolvedPolarisEntity.class)) - .hasSize(6) - .filteredOn(Objects::nonNull) - .hasSize(2) - .extracting(r -> getEntityCore(r.getEntity())) - .containsExactly(getEntityCore(catalog), getEntityCore(T1)); - } - public void testLoadResolvedEntitiesById() { // load all principals List<EntityNameLookupRecord> principals =
