flyrain commented on code in PR #4054:
URL: https://github.com/apache/polaris/pull/4054#discussion_r3023826370


##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java:
##########
@@ -178,75 +177,87 @@ public synchronized Map<String, PrincipalSecretsResult> 
bootstrapRealms(
           throw new RuntimeException(
               String.format("Error executing sql script: %s", e.getMessage()), 
e);
         }
-        initializeForRealm(
-            datasourceOperations, realmContext, 
bootstrapOptions.rootCredentialsSet());
+        // Cache the effective schema version for this realm
+        schemaVersionCache.put(realm, effectiveSchemaVersion);
 
-        PolarisMetaStoreManager metaStoreManager =
-            metaStoreManagerMap.get(realmContext.getRealmIdentifier());
-        BasePersistence metaStore = 
sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
+        PolarisMetaStoreManager metaStoreManager = createNewMetaStoreManager();
+        BasePersistence metaStore = createSession(realm, 
bootstrapOptions.rootCredentialsSet());
         PolarisCallContext polarisContext = new 
PolarisCallContext(realmContext, metaStore);
 
         PrincipalSecretsResult secretsResult =
             createPolarisPrincipalForRealm(metaStoreManager, polarisContext);
         results.put(realm, secretsResult);
+        verifiedRealms.add(realm);
       }
     }
 
     return Map.copyOf(results);
   }
 
   @Override
-  public Map<String, BaseResult> purgeRealms(Iterable<String> realms) {
+  public synchronized Map<String, BaseResult> purgeRealms(Iterable<String> 
realms) {
     Map<String, BaseResult> results = new HashMap<>();
 
     for (String realm : realms) {
       RealmContext realmContext = () -> realm;
-      PolarisMetaStoreManager metaStoreManager = 
getOrCreateMetaStoreManager(realmContext);
-      BasePersistence session = getOrCreateSession(realmContext);
+      PolarisMetaStoreManager metaStoreManager = createNewMetaStoreManager();
+      BasePersistence session = createSession(realm, null);
 
       PolarisCallContext callContext = new PolarisCallContext(realmContext, 
session);
+
+      // Verify the realm is bootstrapped before purging — a non-bootstrapped 
realm
+      // has no root principal, so purging it is a no-op that should be 
reported as failure.
+      Optional<PrincipalEntity> rootPrincipal = 
metaStoreManager.findRootPrincipal(callContext);

Review Comment:
   +1, I think this is the right thing to do. 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to