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 0a8d8b805 Core: Consolidate CallContext with PolarisCallContext part 1(#1806) 0a8d8b805 is described below commit 0a8d8b8053ca37d5d95757b416a9a42814630135 Author: Yufei Gu <yu...@apache.org> AuthorDate: Wed Jun 4 12:13:13 2025 -0700 Core: Consolidate CallContext with PolarisCallContext part 1(#1806) --- .../jdbc/JdbcMetaStoreManagerFactory.java | 12 ++++-- .../apache/polaris/core/PolarisCallContext.java | 49 ++++++++++++++++++---- .../apache/polaris/core/context/CallContext.java | 13 +++++- .../LocalPolarisMetaStoreManagerFactory.java | 14 ++++--- .../service/quarkus/config/QuarkusProducers.java | 11 ++--- .../context/DefaultCallContextResolver.java | 5 +-- 6 files changed, 74 insertions(+), 30 deletions(-) diff --git a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java index e3547eb2f..7ad83fe8a 100644 --- a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java +++ b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java @@ -226,9 +226,11 @@ public class JdbcMetaStoreManagerFactory implements MetaStoreManagerFactory { // CallContext may not have been resolved yet. PolarisCallContext polarisContext = new PolarisCallContext( - sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), diagServices); + realmContext, + sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), + diagServices); if (CallContext.getCurrentContext() == null) { - CallContext.setCurrentContext(CallContext.of(realmContext, polarisContext)); + CallContext.setCurrentContext(polarisContext); } EntityResult preliminaryRootPrincipalLookup = @@ -275,9 +277,11 @@ public class JdbcMetaStoreManagerFactory implements MetaStoreManagerFactory { RealmContext realmContext, PolarisMetaStoreManager metaStoreManager) { PolarisCallContext polarisContext = new PolarisCallContext( - sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), diagServices); + realmContext, + sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), + diagServices); if (CallContext.getCurrentContext() == null) { - CallContext.setCurrentContext(CallContext.of(realmContext, polarisContext)); + CallContext.setCurrentContext(polarisContext); } EntityResult rootPrincipalLookup = 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 c7033a50d..4d5dfe984 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 @@ -22,13 +22,15 @@ import jakarta.annotation.Nonnull; import java.time.Clock; import java.time.ZoneId; import org.apache.polaris.core.config.PolarisConfigurationStore; +import org.apache.polaris.core.context.CallContext; +import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.core.persistence.BasePersistence; /** * The Call context is allocated each time a new REST request is processed. It contains instances of * low-level services required to process that request */ -public class PolarisCallContext { +public class PolarisCallContext implements CallContext { // meta store which is used to persist Polaris entity metadata private final BasePersistence metaStore; @@ -40,31 +42,52 @@ public class PolarisCallContext { private final Clock clock; + // will make it final once we remove deprecated constructor + private RealmContext realmContext = null; + public PolarisCallContext( + @Nonnull RealmContext realmContext, @Nonnull BasePersistence metaStore, @Nonnull PolarisDiagnostics diagServices, @Nonnull PolarisConfigurationStore configurationStore, @Nonnull Clock clock) { + this.realmContext = realmContext; this.metaStore = metaStore; this.diagServices = diagServices; this.configurationStore = configurationStore; this.clock = clock; } + @Deprecated public PolarisCallContext( - @Nonnull BasePersistence metaStore, @Nonnull PolarisDiagnostics diagServices) { + @Nonnull BasePersistence metaStore, + @Nonnull PolarisDiagnostics diagServices, + @Nonnull PolarisConfigurationStore configurationStore, + @Nonnull Clock clock) { + this.metaStore = metaStore; + this.diagServices = diagServices; + this.configurationStore = configurationStore; + this.clock = clock; + } + + public PolarisCallContext( + @Nonnull RealmContext realmContext, + @Nonnull BasePersistence metaStore, + @Nonnull PolarisDiagnostics diagServices) { + this.realmContext = realmContext; this.metaStore = metaStore; this.diagServices = diagServices; this.configurationStore = new PolarisConfigurationStore() {}; this.clock = Clock.system(ZoneId.systemDefault()); } - public static PolarisCallContext copyOf(PolarisCallContext original) { - return new PolarisCallContext( - original.getMetaStore().detach(), - original.getDiagServices(), - original.getConfigurationStore(), - original.getClock()); + @Deprecated + public PolarisCallContext( + @Nonnull BasePersistence metaStore, @Nonnull PolarisDiagnostics diagServices) { + this.metaStore = metaStore; + this.diagServices = diagServices; + this.configurationStore = new PolarisConfigurationStore() {}; + this.clock = Clock.system(ZoneId.systemDefault()); } public BasePersistence getMetaStore() { @@ -82,4 +105,14 @@ public class PolarisCallContext { public Clock getClock() { return clock; } + + @Override + public RealmContext getRealmContext() { + return realmContext; + } + + @Override + public PolarisCallContext getPolarisCallContext() { + return this; + } } 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 54859647d..340cf4a6e 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 @@ -49,6 +49,7 @@ public interface CallContext { CURRENT_CONTEXT.remove(); } + // only tests are using this method now, we can get rid of them easily in a followup static CallContext of( final RealmContext realmContext, final PolarisCallContext polarisCallContext) { return new CallContext() { @@ -68,7 +69,15 @@ public interface CallContext { static CallContext copyOf(CallContext base) { String realmId = base.getRealmContext().getRealmIdentifier(); RealmContext realmContext = () -> realmId; - PolarisCallContext polarisCallContext = PolarisCallContext.copyOf(base.getPolarisCallContext()); + PolarisCallContext originalPolarisCallContext = base.getPolarisCallContext(); + PolarisCallContext newPolarisCallContext = + new PolarisCallContext( + realmContext, + originalPolarisCallContext.getMetaStore(), + originalPolarisCallContext.getDiagServices(), + originalPolarisCallContext.getConfigurationStore(), + originalPolarisCallContext.getClock()); + return new CallContext() { @Override public RealmContext getRealmContext() { @@ -77,7 +86,7 @@ public interface CallContext { @Override public PolarisCallContext getPolarisCallContext() { - return polarisCallContext; + return newPolarisCallContext; } }; } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java index dc615341a..8d385bd0c 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java @@ -202,11 +202,13 @@ public abstract class LocalPolarisMetaStoreManagerFactory<StoreType> RealmContext realmContext, PolarisMetaStoreManager metaStoreManager) { // While bootstrapping we need to act as a fake privileged context since the real // CallContext may not have been resolved yet. - PolarisCallContext polarisContext = + var polarisContext = new PolarisCallContext( - sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), diagServices); + realmContext, + sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), + diagServices); if (CallContext.getCurrentContext() == null) { - CallContext.setCurrentContext(CallContext.of(realmContext, polarisContext)); + CallContext.setCurrentContext(polarisContext); } EntityResult preliminaryRootPrincipalLookup = @@ -251,9 +253,11 @@ public abstract class LocalPolarisMetaStoreManagerFactory<StoreType> RealmContext realmContext, PolarisMetaStoreManager metaStoreManager) { PolarisCallContext polarisContext = new PolarisCallContext( - sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), diagServices); + realmContext, + sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), + diagServices); if (CallContext.getCurrentContext() == null) { - CallContext.setCurrentContext(CallContext.of(realmContext, polarisContext)); + CallContext.setCurrentContext(polarisContext); } EntityResult rootPrincipalLookup = diff --git a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java index c4b3a3ae1..593853c40 100644 --- a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java +++ b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java @@ -121,7 +121,7 @@ public class QuarkusProducers { @Produces @RequestScoped - public PolarisCallContext polarisCallContext( + public CallContext polarisCallContext( RealmContext realmContext, PolarisDiagnostics diagServices, PolarisConfigurationStore configurationStore, @@ -129,13 +129,8 @@ public class QuarkusProducers { Clock clock) { BasePersistence metaStoreSession = metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(); - return new PolarisCallContext(metaStoreSession, diagServices, configurationStore, clock); - } - - @Produces - @RequestScoped - public CallContext callContext(RealmContext realmContext, PolarisCallContext polarisCallContext) { - return CallContext.of(realmContext, polarisCallContext); + return new PolarisCallContext( + realmContext, metaStoreSession, diagServices, configurationStore, clock); } // Polaris service beans - selected from @Identifier-annotated beans diff --git a/service/common/src/main/java/org/apache/polaris/service/context/DefaultCallContextResolver.java b/service/common/src/main/java/org/apache/polaris/service/context/DefaultCallContextResolver.java index 8c5ae391d..62b113dae 100644 --- a/service/common/src/main/java/org/apache/polaris/service/context/DefaultCallContextResolver.java +++ b/service/common/src/main/java/org/apache/polaris/service/context/DefaultCallContextResolver.java @@ -66,8 +66,7 @@ public class DefaultCallContextResolver implements CallContextResolver { // factories would then inject something else instead if needed. BasePersistence metaStoreSession = metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(); - PolarisCallContext polarisContext = - new PolarisCallContext(metaStoreSession, diagnostics, configurationStore, clock); - return CallContext.of(realmContext, polarisContext); + return new PolarisCallContext( + realmContext, metaStoreSession, diagnostics, configurationStore, clock); } }