This is an automated email from the ASF dual-hosted git repository.
singhpk234 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 8fa6bf224 Materialize Realm ID for Session Supplier in JDBC (#1988)
8fa6bf224 is described below
commit 8fa6bf2247b1b07b1cc721d476bde74ad808c074
Author: Adnan Hemani <[email protected]>
AuthorDate: Thu Jul 3 23:21:30 2025 -0700
Materialize Realm ID for Session Supplier in JDBC (#1988)
It was discovered that the Session Supplier maps used in the
MetaStoreManagerFactory implementations were passing in RealmContext objects to
the supplier directly and then using the RealmContext objects to create
BasePersistence implementation objects within the supplier. This supplier is
cached on a per-realm basis in most MetaStoreManagerFactory implementations.
RealmContext objects are request-scoped beans.
As a result, if any work is being done outside the scope of the request,
such as during a Task, any calls to getOrCreateSessionSupplier for creating a
BasePersistence implementation will fail as the RealmContext object is no
longer available.
This PR will ensure for the JdbcMetaStoreManagerFactory that the Realm ID
is materialized from the RealmContext and used inside the supplier so that the
potentially deactivated RealmContext object does not need to be used in
creating the BasePersistence object. Given that we are caching on a per-realm
basis, this should not introduce any unforeseen behavior for the
JdbcMetaStoreManagerFactory as the Realm ID must match exactly for the same
supplier to be returned from the Session Supp [...]
---
.../relational/jdbc/JdbcMetaStoreManagerFactory.java | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 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 a69410a94..7f4368c36 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
@@ -83,10 +83,9 @@ public class JdbcMetaStoreManagerFactory implements
MetaStoreManagerFactory {
protected JdbcMetaStoreManagerFactory() {}
protected PrincipalSecretsGenerator secretsGenerator(
- RealmContext realmContext, @Nullable RootCredentialsSet
rootCredentialsSet) {
+ String realmId, @Nullable RootCredentialsSet rootCredentialsSet) {
if (rootCredentialsSet != null) {
- return PrincipalSecretsGenerator.bootstrap(
- realmContext.getRealmIdentifier(), rootCredentialsSet);
+ return PrincipalSecretsGenerator.bootstrap(realmId, rootCredentialsSet);
} else {
return PrincipalSecretsGenerator.RANDOM_SECRETS;
}
@@ -100,17 +99,20 @@ public class JdbcMetaStoreManagerFactory implements
MetaStoreManagerFactory {
DatasourceOperations datasourceOperations,
RealmContext realmContext,
RootCredentialsSet rootCredentialsSet) {
+ // Materialize realmId so that background tasks that don't have an active
+ // RealmContext (request-scoped bean) can still create a
JdbcBasePersistenceImpl
+ String realmId = realmContext.getRealmIdentifier();
sessionSupplierMap.put(
- realmContext.getRealmIdentifier(),
+ realmId,
() ->
new JdbcBasePersistenceImpl(
datasourceOperations,
- secretsGenerator(realmContext, rootCredentialsSet),
+ secretsGenerator(realmId, rootCredentialsSet),
storageIntegrationProvider,
- realmContext.getRealmIdentifier()));
+ realmId));
PolarisMetaStoreManager metaStoreManager = createNewMetaStoreManager();
- metaStoreManagerMap.put(realmContext.getRealmIdentifier(),
metaStoreManager);
+ metaStoreManagerMap.put(realmId, metaStoreManager);
}
public DatasourceOperations getDatasourceOperations() {