This is an automated email from the ASF dual-hosted git repository.

yufei pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new 187d7002a Turn CallContext.copyOf into an interface instead of static 
function (#1816)
187d7002a is described below

commit 187d7002a6785f13a656a3fdacfed1f8d4b1f8a8
Author: gh-yzou <167037035+gh-y...@users.noreply.github.com>
AuthorDate: Thu Jun 5 10:35:08 2025 -0700

    Turn CallContext.copyOf into an interface instead of static function (#1816)
---
 .../apache/polaris/core/PolarisCallContext.java    | 13 +++++++++++
 .../apache/polaris/core/context/CallContext.java   | 25 +---------------------
 .../polaris/service/task/TaskExecutorImpl.java     |  2 +-
 .../service/catalog/io/FileIOFactoryTest.java      | 25 ++++++----------------
 .../org/apache/polaris/service/TestServices.java   | 22 ++++++-------------
 5 files changed, 27 insertions(+), 60 deletions(-)

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 e0f1f7d57..9e5a7a8b4 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
@@ -94,4 +94,17 @@ public class PolarisCallContext implements CallContext {
   public PolarisCallContext getPolarisCallContext() {
     return this;
   }
+
+  @Override
+  public PolarisCallContext copy() {
+    // The realm context is a request scoped bean injected by CDI,
+    // which will be closed after the http request. This copy is currently
+    // only used by TaskExecutor right before the task is handled, since the
+    // task is executed outside the active request scope, we need to make a
+    // 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.diagServices, 
this.configurationStore, this.clock);
+  }
 }
diff --git 
a/polaris-core/src/main/java/org/apache/polaris/core/context/CallContext.java 
b/polaris-core/src/main/java/org/apache/polaris/core/context/CallContext.java
index d718e9129..84fec60ae 100644
--- 
a/polaris-core/src/main/java/org/apache/polaris/core/context/CallContext.java
+++ 
b/polaris-core/src/main/java/org/apache/polaris/core/context/CallContext.java
@@ -45,30 +45,7 @@ public interface CallContext {
   }
 
   /** Copy the {@link CallContext}. */
-  static CallContext copyOf(CallContext base) {
-    String realmId = base.getRealmContext().getRealmIdentifier();
-    RealmContext realmContext = () -> realmId;
-    PolarisCallContext originalPolarisCallContext = 
base.getPolarisCallContext();
-    PolarisCallContext newPolarisCallContext =
-        new PolarisCallContext(
-            realmContext,
-            originalPolarisCallContext.getMetaStore(),
-            originalPolarisCallContext.getDiagServices(),
-            originalPolarisCallContext.getConfigurationStore(),
-            originalPolarisCallContext.getClock());
-
-    return new CallContext() {
-      @Override
-      public RealmContext getRealmContext() {
-        return realmContext;
-      }
-
-      @Override
-      public PolarisCallContext getPolarisCallContext() {
-        return newPolarisCallContext;
-      }
-    };
-  }
+  CallContext copy();
 
   RealmContext getRealmContext();
 
diff --git 
a/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java
 
b/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java
index 140931031..c1c775bf4 100644
--- 
a/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java
+++ 
b/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java
@@ -96,7 +96,7 @@ public class TaskExecutorImpl implements TaskExecutor {
     // the task is still running.
     // Note: PolarisCallContext has request-scoped beans as well, and must be 
cloned.
     // FIXME replace with context propagation?
-    CallContext clone = CallContext.copyOf(callContext);
+    CallContext clone = callContext.copy();
     tryHandleTask(taskEntityId, clone, null, 1);
   }
 
diff --git 
a/service/common/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java
 
b/service/common/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java
index 0303ecb57..ee47c14f2 100644
--- 
a/service/common/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java
+++ 
b/service/common/src/test/java/org/apache/polaris/service/catalog/io/FileIOFactoryTest.java
@@ -136,25 +136,12 @@ public class FileIOFactoryTest {
             .build();
 
     callContext =
-        new CallContext() {
-          @Override
-          public RealmContext getRealmContext() {
-            return testServices.realmContext();
-          }
-
-          @Override
-          public PolarisCallContext getPolarisCallContext() {
-            return new PolarisCallContext(
-                realmContext,
-                testServices
-                    .metaStoreManagerFactory()
-                    .getOrCreateSessionSupplier(realmContext)
-                    .get(),
-                testServices.polarisDiagnostics(),
-                testServices.configurationStore(),
-                Mockito.mock(Clock.class));
-          }
-        };
+        new PolarisCallContext(
+            realmContext,
+            
testServices.metaStoreManagerFactory().getOrCreateSessionSupplier(realmContext).get(),
+            testServices.polarisDiagnostics(),
+            testServices.configurationStore(),
+            Clock.systemUTC());
   }
 
   @AfterEach
diff --git 
a/service/common/src/testFixtures/java/org/apache/polaris/service/TestServices.java
 
b/service/common/src/testFixtures/java/org/apache/polaris/service/TestServices.java
index 3e0bc6d13..d3622126f 100644
--- 
a/service/common/src/testFixtures/java/org/apache/polaris/service/TestServices.java
+++ 
b/service/common/src/testFixtures/java/org/apache/polaris/service/TestServices.java
@@ -163,22 +163,12 @@ public record TestServices(
       BasePersistence metaStoreSession =
           
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get();
       CallContext callContext =
-          new CallContext() {
-            @Override
-            public RealmContext getRealmContext() {
-              return realmContext;
-            }
-
-            @Override
-            public PolarisCallContext getPolarisCallContext() {
-              return new PolarisCallContext(
-                  realmContext,
-                  metaStoreSession,
-                  polarisDiagnostics,
-                  configurationStore,
-                  Mockito.mock(Clock.class));
-            }
-          };
+          new PolarisCallContext(
+              realmContext,
+              metaStoreSession,
+              polarisDiagnostics,
+              configurationStore,
+              Clock.systemUTC());
       PolarisEntityManager entityManager =
           realmEntityManagerFactory.getOrCreateEntityManager(realmContext);
       PolarisMetaStoreManager metaStoreManager =

Reply via email to