dimas-b commented on code in PR #4054:
URL: https://github.com/apache/polaris/pull/4054#discussion_r2991188913


##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java:
##########
@@ -208,45 +219,90 @@ public Map<String, BaseResult> 
purgeRealms(Iterable<String> realms) {
       BaseResult result = metaStoreManager.purge(callContext);
       results.put(realm, result);
 
+      // Evict all cached state for this realm so it can be fully 
re-initialized if needed
       sessionSupplierMap.remove(realm);
       metaStoreManagerMap.remove(realm);
+      entityCacheMap.remove(realm);
+      verifiedRealms.remove(realm);
+      realmLocks.remove(realm);
     }
 
     return Map.copyOf(results);
   }
 
   @Override
-  public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager(
-      RealmContext realmContext) {
-    if (!metaStoreManagerMap.containsKey(realmContext.getRealmIdentifier())) {
+  public PolarisMetaStoreManager getOrCreateMetaStoreManager(RealmContext 
realmContext) {
+    String realmId = realmContext.getRealmIdentifier();
+    // Fast path: lock-free CHM read (common case — realm already initialized)
+    PolarisMetaStoreManager result = metaStoreManagerMap.get(realmId);
+    if (result != null) {
+      return result;
+    }
+    // Slow path: per-realm lock for first-time initialization
+    Object lock = realmLocks.computeIfAbsent(realmId, k -> new Object());

Review Comment:
   Hi @singhpk234 , I have a radical proposal since we're touching this code 😅 
   
   The JDBC persistence objects do not have any state. So, we should be able to 
create them on demand (as request-scoped objects).
   
   WDYT?



-- 
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