Skip to content

Commit 89bf06e

Browse files
committed
Add PolarisDiagnostics field to AbstractTransactionalPersistence
the ultimate goal is removing the `PolarisCallContext` parameter from every `PolarisMetaStoreManager` interface method, so we make steps towards reducing its usage first.
1 parent 83d09cc commit 89bf06e

File tree

11 files changed

+108
-110
lines changed

11 files changed

+108
-110
lines changed

persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/EclipseLinkPolarisMetaStoreManagerFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ protected TransactionalPersistence createMetaStoreSession(
6868
@Nullable RootCredentialsSet rootCredentialsSet,
6969
@Nonnull PolarisDiagnostics diagnostics) {
7070
return new PolarisEclipseLinkMetaStoreSessionImpl(
71+
diagnostics,
7172
store,
7273
storageIntegrationProvider,
7374
realmContext,

persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.stream.Collectors;
4040
import java.util.stream.Stream;
4141
import org.apache.polaris.core.PolarisCallContext;
42+
import org.apache.polaris.core.PolarisDiagnostics;
4243
import org.apache.polaris.core.context.RealmContext;
4344
import org.apache.polaris.core.entity.EntityNameLookupRecord;
4445
import org.apache.polaris.core.entity.LocationBasedEntity;
@@ -106,12 +107,14 @@ public class PolarisEclipseLinkMetaStoreSessionImpl extends AbstractTransactiona
106107
* @param persistenceUnitName Optional persistence-unit name in confFile. Default to 'polaris'.
107108
*/
108109
public PolarisEclipseLinkMetaStoreSessionImpl(
110+
@Nonnull PolarisDiagnostics diagnostics,
109111
@Nonnull PolarisEclipseLinkStore store,
110112
@Nonnull PolarisStorageIntegrationProvider storageIntegrationProvider,
111113
@Nonnull RealmContext realmContext,
112114
@Nullable String confFile,
113115
@Nullable String persistenceUnitName,
114116
@Nonnull PrincipalSecretsGenerator secretsGenerator) {
117+
super(diagnostics);
115118
LOGGER.debug(
116119
"Creating EclipseLink Meta Store Session for realm {}", realmContext.getRealmIdentifier());
117120
emf = createEntityManagerFactory(realmContext, confFile, persistenceUnitName);
@@ -159,7 +162,7 @@ static void clearEntityManagerFactories() {
159162
@Override
160163
public <T> T runInTransaction(
161164
@Nonnull PolarisCallContext callCtx, @Nonnull Supplier<T> transactionCode) {
162-
callCtx.getDiagServices().check(localSession.get() == null, "cannot nest transaction");
165+
diagnostics.check(localSession.get() == null, "cannot nest transaction");
163166

164167
try (EntityManager session = emf.createEntityManager()) {
165168
localSession.set(session);
@@ -206,7 +209,7 @@ public <T> T runInTransaction(
206209
@Override
207210
public void runActionInTransaction(
208211
@Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) {
209-
callCtx.getDiagServices().check(localSession.get() == null, "cannot nest transaction");
212+
diagnostics.check(localSession.get() == null, "cannot nest transaction");
210213

211214
try (EntityManager session = emf.createEntityManager()) {
212215
localSession.set(session);
@@ -560,24 +563,20 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn(
560563
this.store.lookupPrincipalSecrets(localSession.get(), clientId));
561564

562565
// should be found
563-
callCtx
564-
.getDiagServices()
565-
.checkNotNull(
566-
principalSecrets,
567-
"cannot_find_secrets",
568-
"client_id={} principalId={}",
569-
clientId,
570-
principalId);
566+
diagnostics.checkNotNull(
567+
principalSecrets,
568+
"cannot_find_secrets",
569+
"client_id={} principalId={}",
570+
clientId,
571+
principalId);
571572

572573
// ensure principal id is matching
573-
callCtx
574-
.getDiagServices()
575-
.check(
576-
principalId == principalSecrets.getPrincipalId(),
577-
"principal_id_mismatch",
578-
"expectedId={} id={}",
579-
principalId,
580-
principalSecrets.getPrincipalId());
574+
diagnostics.check(
575+
principalId == principalSecrets.getPrincipalId(),
576+
"principal_id_mismatch",
577+
"expectedId={} id={}",
578+
principalId,
579+
principalSecrets.getPrincipalId());
581580

582581
// rotate the secrets
583582
principalSecrets.rotateSecrets(oldSecretHash);
@@ -601,24 +600,20 @@ public void deletePrincipalSecretsInCurrentTxn(
601600
this.store.lookupPrincipalSecrets(localSession.get(), clientId);
602601

603602
// should be found
604-
callCtx
605-
.getDiagServices()
606-
.checkNotNull(
607-
principalSecrets,
608-
"cannot_find_secrets",
609-
"client_id={} principalId={}",
610-
clientId,
611-
principalId);
603+
diagnostics.checkNotNull(
604+
principalSecrets,
605+
"cannot_find_secrets",
606+
"client_id={} principalId={}",
607+
clientId,
608+
principalId);
612609

613610
// ensure principal id is matching
614-
callCtx
615-
.getDiagServices()
616-
.check(
617-
principalId == principalSecrets.getPrincipalId(),
618-
"principal_id_mismatch",
619-
"expectedId={} id={}",
620-
principalId,
621-
principalSecrets.getPrincipalId());
611+
diagnostics.check(
612+
principalId == principalSecrets.getPrincipalId(),
613+
"principal_id_mismatch",
614+
"expectedId={} id={}",
615+
principalId,
616+
principalSecrets.getPrincipalId());
622617

623618
// delete these secrets
624619
this.store.deletePrincipalSecrets(localSession.get(), clientId);
@@ -642,7 +637,7 @@ PolarisStorageIntegration<T> createStorageIntegrationInCurrentTxn(
642637
PolarisStorageIntegration<T> loadPolarisStorageIntegrationInCurrentTxn(
643638
@Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) {
644639
PolarisStorageConfigurationInfo storageConfig =
645-
BaseMetaStoreManager.extractStorageConfiguration(callCtx.getDiagServices(), entity);
640+
BaseMetaStoreManager.extractStorageConfiguration(diagnostics, entity);
646641
return storageIntegrationProvider.getStorageIntegrationForConfig(storageConfig);
647642
}
648643

persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
8686
RealmContext realmContext = () -> "realm";
8787
PolarisEclipseLinkMetaStoreSessionImpl session =
8888
new PolarisEclipseLinkMetaStoreSessionImpl(
89-
store, Mockito.mock(), realmContext, null, "polaris", RANDOM_SECRETS);
89+
diagServices, store, Mockito.mock(), realmContext, null, "polaris", RANDOM_SECRETS);
9090
TransactionalMetaStoreManagerImpl metaStoreManager =
9191
new TransactionalMetaStoreManagerImpl(clock, diagServices);
9292
PolarisCallContext callCtx = new PolarisCallContext(realmContext, session, diagServices);
@@ -104,7 +104,13 @@ void testCreateStoreSession(String confFile, boolean success) {
104104
try {
105105
var session =
106106
new PolarisEclipseLinkMetaStoreSessionImpl(
107-
store, Mockito.mock(), () -> "realm", confFile, "polaris", RANDOM_SECRETS);
107+
diagServices,
108+
store,
109+
Mockito.mock(),
110+
() -> "realm",
111+
confFile,
112+
"polaris",
113+
RANDOM_SECRETS);
108114
assertNotNull(session);
109115
assertTrue(success);
110116
} catch (Exception e) {

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/AbstractTransactionalPersistence.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.function.Function;
2626
import java.util.function.Predicate;
2727
import org.apache.polaris.core.PolarisCallContext;
28+
import org.apache.polaris.core.PolarisDiagnostics;
2829
import org.apache.polaris.core.entity.EntityNameLookupRecord;
2930
import org.apache.polaris.core.entity.PolarisBaseEntity;
3031
import org.apache.polaris.core.entity.PolarisChangeTrackingVersions;
@@ -51,6 +52,13 @@
5152
* the BasePersistence methods in terms of lower-level methods that subclasses must implement.
5253
*/
5354
public abstract class AbstractTransactionalPersistence implements TransactionalPersistence {
55+
56+
protected final PolarisDiagnostics diagnostics;
57+
58+
protected AbstractTransactionalPersistence(PolarisDiagnostics diagnostics) {
59+
this.diagnostics = diagnostics;
60+
}
61+
5462
//
5563
// New abstract methods specific to this slice-based transactional persistence that subclasses
5664
// must implement to inherit implementations of lookup/write/delete
@@ -210,14 +218,12 @@ public void writeEntities(
210218
@Nonnull List<PolarisBaseEntity> entities,
211219
@Nullable List<PolarisBaseEntity> originalEntities) {
212220
if (originalEntities != null) {
213-
callCtx
214-
.getDiagServices()
215-
.check(
216-
entities.size() == originalEntities.size(),
217-
"mismatched_entities_and_original_entities_size",
218-
"entities.size()={}, originalEntities.size()={}",
219-
entities.size(),
220-
originalEntities.size());
221+
diagnostics.check(
222+
entities.size() == originalEntities.size(),
223+
"mismatched_entities_and_original_entities_size",
224+
"entities.size()={}, originalEntities.size()={}",
225+
entities.size(),
226+
originalEntities.size());
221227
}
222228
runActionInTransaction(
223229
callCtx,
@@ -580,14 +586,12 @@ public void writeEntitiesInCurrentTxn(
580586
@Nonnull List<PolarisBaseEntity> entities,
581587
@Nullable List<PolarisBaseEntity> originalEntities) {
582588
if (originalEntities != null) {
583-
callCtx
584-
.getDiagServices()
585-
.check(
586-
entities.size() == originalEntities.size(),
587-
"mismatched_entities_and_original_entities_size",
588-
"entities.size()={}, originalEntities.size()={}",
589-
entities.size(),
590-
originalEntities.size());
589+
diagnostics.check(
590+
entities.size() == originalEntities.size(),
591+
"mismatched_entities_and_original_entities_size",
592+
"entities.size()={}, originalEntities.size()={}",
593+
entities.size(),
594+
originalEntities.size());
591595
}
592596
for (int i = 0; i < entities.size(); ++i) {
593597
PolarisBaseEntity entity = entities.get(i);
@@ -643,10 +647,8 @@ public PolarisBaseEntity lookupEntityByNameInCurrentTxn(
643647
entityActiveRecord.getCatalogId(),
644648
entityActiveRecord.getId(),
645649
entityActiveRecord.getTypeCode());
646-
callCtx
647-
.getDiagServices()
648-
.checkNotNull(
649-
entity, "unexpected_not_found_entity", "entityActiveRecord={}", entityActiveRecord);
650+
diagnostics.checkNotNull(
651+
entity, "unexpected_not_found_entity", "entityActiveRecord={}", entityActiveRecord);
650652

651653
// return it now
652654
return entity;

polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/TreeMapTransactionalPersistenceImpl.java

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.stream.Collectors;
3030
import java.util.stream.Stream;
3131
import org.apache.polaris.core.PolarisCallContext;
32+
import org.apache.polaris.core.PolarisDiagnostics;
3233
import org.apache.polaris.core.entity.EntityNameLookupRecord;
3334
import org.apache.polaris.core.entity.LocationBasedEntity;
3435
import org.apache.polaris.core.entity.PolarisBaseEntity;
@@ -62,11 +63,11 @@ public class TreeMapTransactionalPersistenceImpl extends AbstractTransactionalPe
6263
private final PrincipalSecretsGenerator secretsGenerator;
6364

6465
public TreeMapTransactionalPersistenceImpl(
66+
@Nonnull PolarisDiagnostics diagnostics,
6567
@Nonnull TreeMapMetaStore store,
6668
@Nonnull PolarisStorageIntegrationProvider storageIntegrationProvider,
6769
@Nonnull PrincipalSecretsGenerator secretsGenerator) {
68-
69-
// init store
70+
super(diagnostics);
7071
this.store = store;
7172
this.storageIntegrationProvider = storageIntegrationProvider;
7273
this.secretsGenerator = secretsGenerator;
@@ -78,7 +79,7 @@ public <T> T runInTransaction(
7879
@Nonnull PolarisCallContext callCtx, @Nonnull Supplier<T> transactionCode) {
7980

8081
// run transaction on our underlying store
81-
return store.runInTransaction(callCtx.getDiagServices(), transactionCode);
82+
return store.runInTransaction(diagnostics, transactionCode);
8283
}
8384

8485
/** {@inheritDoc} */
@@ -87,15 +88,15 @@ public void runActionInTransaction(
8788
@Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) {
8889

8990
// run transaction on our underlying store
90-
store.runActionInTransaction(callCtx.getDiagServices(), transactionCode);
91+
store.runActionInTransaction(diagnostics, transactionCode);
9192
}
9293

9394
/** {@inheritDoc} */
9495
@Override
9596
public <T> T runInReadTransaction(
9697
@Nonnull PolarisCallContext callCtx, @Nonnull Supplier<T> transactionCode) {
9798
// run transaction on our underlying store
98-
return store.runInReadTransaction(callCtx.getDiagServices(), transactionCode);
99+
return store.runInReadTransaction(diagnostics, transactionCode);
99100
}
100101

101102
/** {@inheritDoc} */
@@ -104,7 +105,7 @@ public void runActionInReadTransaction(
104105
@Nonnull PolarisCallContext callCtx, @Nonnull Runnable transactionCode) {
105106

106107
// run transaction on our underlying store
107-
store.runActionInReadTransaction(callCtx.getDiagServices(), transactionCode);
108+
store.runActionInReadTransaction(diagnostics, transactionCode);
108109
}
109110

110111
/**
@@ -462,24 +463,20 @@ public int lookupEntityGrantRecordsVersionInCurrentTxn(
462463
PolarisPrincipalSecrets principalSecrets = this.store.getSlicePrincipalSecrets().read(clientId);
463464

464465
// should be found
465-
callCtx
466-
.getDiagServices()
467-
.checkNotNull(
468-
principalSecrets,
469-
"cannot_find_secrets",
470-
"client_id={} principalId={}",
471-
clientId,
472-
principalId);
466+
diagnostics.checkNotNull(
467+
principalSecrets,
468+
"cannot_find_secrets",
469+
"client_id={} principalId={}",
470+
clientId,
471+
principalId);
473472

474473
// ensure principal id is matching
475-
callCtx
476-
.getDiagServices()
477-
.check(
478-
principalId == principalSecrets.getPrincipalId(),
479-
"principal_id_mismatch",
480-
"expectedId={} id={}",
481-
principalId,
482-
principalSecrets.getPrincipalId());
474+
diagnostics.check(
475+
principalId == principalSecrets.getPrincipalId(),
476+
"principal_id_mismatch",
477+
"expectedId={} id={}",
478+
principalId,
479+
principalSecrets.getPrincipalId());
483480

484481
// rotate the secrets
485482
principalSecrets.rotateSecrets(oldSecretHash);
@@ -502,24 +499,20 @@ public void deletePrincipalSecretsInCurrentTxn(
502499
PolarisPrincipalSecrets principalSecrets = this.store.getSlicePrincipalSecrets().read(clientId);
503500

504501
// should be found
505-
callCtx
506-
.getDiagServices()
507-
.checkNotNull(
508-
principalSecrets,
509-
"cannot_find_secrets",
510-
"client_id={} principalId={}",
511-
clientId,
512-
principalId);
502+
diagnostics.checkNotNull(
503+
principalSecrets,
504+
"cannot_find_secrets",
505+
"client_id={} principalId={}",
506+
clientId,
507+
principalId);
513508

514509
// ensure principal id is matching
515-
callCtx
516-
.getDiagServices()
517-
.check(
518-
principalId == principalSecrets.getPrincipalId(),
519-
"principal_id_mismatch",
520-
"expectedId={} id={}",
521-
principalId,
522-
principalSecrets.getPrincipalId());
510+
diagnostics.check(
511+
principalId == principalSecrets.getPrincipalId(),
512+
"principal_id_mismatch",
513+
"expectedId={} id={}",
514+
principalId,
515+
principalSecrets.getPrincipalId());
523516

524517
// delete these secrets
525518
this.store.getSlicePrincipalSecrets().delete(clientId);
@@ -543,7 +536,7 @@ PolarisStorageIntegration<T> createStorageIntegrationInCurrentTxn(
543536
PolarisStorageIntegration<T> loadPolarisStorageIntegrationInCurrentTxn(
544537
@Nonnull PolarisCallContext callCtx, @Nonnull PolarisBaseEntity entity) {
545538
PolarisStorageConfigurationInfo storageConfig =
546-
BaseMetaStoreManager.extractStorageConfiguration(callCtx.getDiagServices(), entity);
539+
BaseMetaStoreManager.extractStorageConfiguration(diagnostics, entity);
547540
return storageIntegrationProvider.getStorageIntegrationForConfig(storageConfig);
548541
}
549542

polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapAtomicOperationMetaStoreManagerTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ public class PolarisTreeMapAtomicOperationMetaStoreManagerTest
3333
public PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
3434
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl();
3535
TreeMapMetaStore store = new TreeMapMetaStore(diagServices);
36+
TreeMapTransactionalPersistenceImpl metaStore =
37+
new TreeMapTransactionalPersistenceImpl(
38+
diagServices, store, Mockito.mock(), RANDOM_SECRETS);
3639
AtomicOperationMetaStoreManager metaStoreManager = new AtomicOperationMetaStoreManager(clock);
37-
PolarisCallContext callCtx =
38-
new PolarisCallContext(
39-
() -> "testRealm",
40-
new TreeMapTransactionalPersistenceImpl(store, Mockito.mock(), RANDOM_SECRETS),
41-
diagServices);
40+
PolarisCallContext callCtx = new PolarisCallContext(() -> "testRealm", metaStore, diagServices);
4241
return new PolarisTestMetaStoreManager(metaStoreManager, callCtx);
4342
}
4443
}

0 commit comments

Comments
 (0)