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 3c09b50beb..abcaa165f6 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 @@ -228,9 +228,11 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm // 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 = @@ -286,9 +288,11 @@ private void checkPolarisServiceBootstrappedForRealm( 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 c7033a50d1..4d5dfe9844 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 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 PolarisConfigurationStore getConfigurationStore() { 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 54859647d0..340cf4a6e3 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 @@ static void unsetCurrentContext() { 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 PolarisCallContext getPolarisCallContext() { 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 RealmContext getRealmContext() { @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 dc615341ae..8d385bd0c3 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 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm 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 @@ private void checkPolarisServiceBootstrappedForRealm( 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 c4b3a3ae1b..593853c409 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 RealmContext realmContext(@Context ContainerRequestContext request) { @Produces @RequestScoped - public PolarisCallContext polarisCallContext( + public CallContext polarisCallContext( RealmContext realmContext, PolarisDiagnostics diagServices, PolarisConfigurationStore configurationStore, @@ -129,13 +129,8 @@ public PolarisCallContext polarisCallContext( 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 8c5ae391d8..62b113daea 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 CallContext resolveCallContext( // 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); } }