XN137 commented on code in PR #2261:
URL: https://github.com/apache/polaris/pull/2261#discussion_r2254462012


##########
service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java:
##########
@@ -200,6 +205,43 @@ private Optional<CatalogRoleEntity> 
findCatalogRoleByName(String catalogName, St
         .map(path -> CatalogRoleEntity.of(path.getRawLeafEntity()));
   }
 
+  private <T> Stream<T> loadEntities(
+      @Nonnull PolarisEntityType entityType,
+      @Nonnull PolarisEntitySubType entitySubType,
+      @Nullable PolarisEntity catalogEntity,
+      @Nonnull Function<PolarisBaseEntity, T> transformer) {
+    List<PolarisEntityCore> catalogPath;
+    long catalogId;
+    if (catalogEntity == null) {
+      catalogPath = null;
+      catalogId = 0;
+    } else {
+      catalogPath = PolarisEntity.toCoreList(List.of(catalogEntity));
+      catalogId = catalogEntity.getId();
+    }
+    // TODO: add loadEntities method to PolarisMetaStoreManager
+    // loadEntity may return null due to multiple non-atomic API calls to the 
persistence layer.
+    // Specifically, this can happen when a PolarisEntity is returned by 
listEntities, but cannot be
+    // loaded afterward because it was purged by another process before it 
could be loaded.
+    return metaStoreManager
+        .listEntities(
+            getCurrentPolarisContext(),
+            catalogPath,
+            entityType,
+            entitySubType,
+            PageToken.readEverything())
+        .getEntities()
+        .stream()
+        .map(
+            nameAndId ->
+                metaStoreManager.loadEntity(
+                    getCurrentPolarisContext(), catalogId, nameAndId.getId(), 
nameAndId.getType()))

Review Comment:
   it might be true but i am only following what the existing code was doing... 
whether `getCatalogId()` always returns the right value for all types of 
entities idk, so i was just sticking to the existing code



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@polaris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to