flyrain commented on code in PR #4397:
URL: https://github.com/apache/polaris/pull/4397#discussion_r3251629944
##########
runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java:
##########
@@ -136,8 +135,11 @@ public CallContext polarisCallContext(
RealmContext realmContext,
RealmConfigurationSource configurationSource,
MetaStoreManagerFactory metaStoreManagerFactory) {
- BasePersistence metaStoreSession =
metaStoreManagerFactory.getOrCreateSession(realmContext);
- return new PolarisCallContext(realmContext, metaStoreSession,
configurationSource);
+ return new PolarisCallContext(
+ realmContext,
+ metaStoreManagerFactory.getOrCreateSession(realmContext),
+ metaStoreManagerFactory.getOrCreateMetricsPersistence(realmContext),
+ configurationSource);
Review Comment:
This instantiates `JdbcBasePersistenceImpl` twice per request — once via
`getOrCreateSession`, once via `getOrCreateMetricsPersistence` — even though
that class implements both SPIs. Stateless and cheap, but wasteful. Either
reuse the session here (it's a `BasePersistence & MetricsPersistence`, so the
generic 3-arg `PolarisCallContext` ctor accepts it), or have
`JdbcMetaStoreManagerFactory.getOrCreateMetricsPersistence` return the same
instance produced by `getOrCreateSession`.
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java:
##########
@@ -26,13 +26,25 @@
import org.apache.polaris.core.persistence.cache.EntityCache;
import org.apache.polaris.core.persistence.dao.entity.BaseResult;
import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult;
+import org.apache.polaris.core.persistence.metrics.MetricsPersistence;
+import org.apache.polaris.core.policy.PolicyMappingPersistence;
/** Configuration interface for configuring the {@link
PolarisMetaStoreManager}. */
public interface MetaStoreManagerFactory {
PolarisMetaStoreManager getOrCreateMetaStoreManager(RealmContext
realmContext);
- BasePersistence getOrCreateSession(RealmContext realmContext);
+ /** Returns the per-realm {@link BasePersistence}. */
+ BasePersistence getOrCreateBasePersistence(RealmContext realmContext);
+
+ /** Returns the per-realm {@link PolicyMappingPersistence}. */
+ PolicyMappingPersistence getOrCreatePolicyMappingPersistence(RealmContext
realmContext);
+
+ /** Returns the per-realm {@link MetricsPersistence}. */
+ MetricsPersistence getOrCreateMetricsPersistence(RealmContext realmContext);
Review Comment:
> MetricsPersistence is very different from "meta store" persistence.
Hi @dimas-b , would you mind elaborate it so that I can understand better?
##########
persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java:
##########
@@ -233,20 +247,12 @@ public PolarisMetaStoreManager
getOrCreateMetaStoreManager(RealmContext realmCon
@Override
public BasePersistence getOrCreateSession(RealmContext realmContext) {
- String realmId = realmContext.getRealmIdentifier();
- RealmConfig realmConfig = new RealmConfigImpl(realmConfigurationSource,
realmContext);
- boolean fallbackOnDne =
-
realmConfig.getConfig(BehaviorChangeConfiguration.SCHEMA_VERSION_FALL_BACK_ON_DNE);
-
- // Verify bootstrap once per realm lifetime; skip on subsequent calls.
- // On cold start, multiple threads may verify concurrently — this is benign
- // (idempotent DB query), trading a few redundant queries for simpler code.
- if (!verifiedRealms.contains(realmId)) {
- checkPolarisServiceBootstrappedForRealm(realmContext, fallbackOnDne);
- }
+ return createJdbcPersistence(realmContext);
+ }
- // Stateless — create a fresh instance on every call; schemaVersion is
cached per realm
- return createSession(realmId, null, fallbackOnDne);
+ @Override
+ public MetricsPersistence getOrCreateMetricsPersistence(RealmContext
realmContext) {
+ return createJdbcPersistence(realmContext);
}
Review Comment:
`getOrCreateMetricsPersistence` is identical to `getOrCreateSession` (both
call `createJdbcPersistence`). Since `JdbcBasePersistenceImpl` implements both
SPIs, this duplication just doubles allocation per request. Delegate to
`getOrCreateSession` or note why the duplication is intentional.
--
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]