Skip to content

Commit 6b4f8e1

Browse files
authored
Remove PolarisCallContext.getDiagServices (#2415)
* Remove PolarisCallContext.getDiagServices usage * Remove diagnostics from PolarisCallContext
1 parent d841431 commit 6b4f8e1

File tree

55 files changed

+279
-217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+279
-217
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
8989
diagServices, store, Mockito.mock(), realmContext, null, "polaris", RANDOM_SECRETS);
9090
TransactionalMetaStoreManagerImpl metaStoreManager =
9191
new TransactionalMetaStoreManagerImpl(clock, diagServices);
92-
PolarisCallContext callCtx = new PolarisCallContext(realmContext, session, diagServices);
92+
PolarisCallContext callCtx = new PolarisCallContext(realmContext, session);
9393
return new PolarisTestMetaStoreManager(metaStoreManager, callCtx);
9494
}
9595

persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.function.Predicate;
3838
import java.util.stream.Collectors;
3939
import org.apache.polaris.core.PolarisCallContext;
40+
import org.apache.polaris.core.PolarisDiagnostics;
4041
import org.apache.polaris.core.entity.EntityNameLookupRecord;
4142
import org.apache.polaris.core.entity.LocationBasedEntity;
4243
import org.apache.polaris.core.entity.PolarisBaseEntity;
@@ -77,6 +78,7 @@ public class JdbcBasePersistenceImpl implements BasePersistence, IntegrationPers
7778

7879
private static final Logger LOGGER = LoggerFactory.getLogger(JdbcBasePersistenceImpl.class);
7980

81+
private final PolarisDiagnostics diagnostics;
8082
private final DatasourceOperations datasourceOperations;
8183
private final PrincipalSecretsGenerator secretsGenerator;
8284
private final PolarisStorageIntegrationProvider storageIntegrationProvider;
@@ -87,11 +89,13 @@ public class JdbcBasePersistenceImpl implements BasePersistence, IntegrationPers
8789
private static final int MAX_LOCATION_COMPONENTS = 40;
8890

8991
public JdbcBasePersistenceImpl(
92+
PolarisDiagnostics diagnostics,
9093
DatasourceOperations databaseOperations,
9194
PrincipalSecretsGenerator secretsGenerator,
9295
PolarisStorageIntegrationProvider storageIntegrationProvider,
9396
String realmId,
9497
int schemaVersion) {
98+
this.diagnostics = diagnostics;
9599
this.datasourceOperations = databaseOperations;
96100
this.secretsGenerator = secretsGenerator;
97101
this.storageIntegrationProvider = storageIntegrationProvider;
@@ -785,24 +789,20 @@ public PolarisPrincipalSecrets rotatePrincipalSecrets(
785789
PolarisPrincipalSecrets principalSecrets = loadPrincipalSecrets(callCtx, clientId);
786790

787791
// should be found
788-
callCtx
789-
.getDiagServices()
790-
.checkNotNull(
791-
principalSecrets,
792-
"cannot_find_secrets",
793-
"client_id={} principalId={}",
794-
clientId,
795-
principalId);
792+
diagnostics.checkNotNull(
793+
principalSecrets,
794+
"cannot_find_secrets",
795+
"client_id={} principalId={}",
796+
clientId,
797+
principalId);
796798

797799
// ensure principal id is matching
798-
callCtx
799-
.getDiagServices()
800-
.check(
801-
principalId == principalSecrets.getPrincipalId(),
802-
"principal_id_mismatch",
803-
"expectedId={} id={}",
804-
principalId,
805-
principalSecrets.getPrincipalId());
800+
diagnostics.check(
801+
principalId == principalSecrets.getPrincipalId(),
802+
"principal_id_mismatch",
803+
"expectedId={} id={}",
804+
principalId,
805+
principalSecrets.getPrincipalId());
806806

807807
// rotate the secrets
808808
principalSecrets.rotateSecrets(oldSecretHash);
@@ -1119,7 +1119,7 @@ public <T extends PolarisStorageConfigurationInfo> void persistStorageIntegratio
11191119
PolarisStorageIntegration<T> loadPolarisStorageIntegration(
11201120
@Nonnull PolarisCallContext callContext, @Nonnull PolarisBaseEntity entity) {
11211121
PolarisStorageConfigurationInfo storageConfig =
1122-
BaseMetaStoreManager.extractStorageConfiguration(callContext.getDiagServices(), entity);
1122+
BaseMetaStoreManager.extractStorageConfiguration(diagnostics, entity);
11231123
return storageIntegrationProvider.getStorageIntegrationForConfig(storageConfig);
11241124
}
11251125

persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ private void initializeForRealm(
103103
realmId,
104104
() ->
105105
new JdbcBasePersistenceImpl(
106+
diagnostics,
106107
datasourceOperations,
107108
secretsGenerator(realmId, rootCredentialsSet),
108109
storageIntegrationProvider,
@@ -177,7 +178,7 @@ public Map<String, BaseResult> purgeRealms(Iterable<String> realms) {
177178
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
178179
BasePersistence session = getOrCreateSession(realmContext);
179180

180-
PolarisCallContext callContext = new PolarisCallContext(realmContext, session, diagnostics);
181+
PolarisCallContext callContext = new PolarisCallContext(realmContext, session);
181182
BaseResult result = metaStoreManager.purge(callContext);
182183
results.put(realm, result);
183184

@@ -216,7 +217,7 @@ public synchronized EntityCache getOrCreateEntityCache(
216217
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
217218
entityCacheMap.put(
218219
realmContext.getRealmIdentifier(),
219-
new InMemoryEntityCache(realmConfig, metaStoreManager));
220+
new InMemoryEntityCache(diagnostics, realmConfig, metaStoreManager));
220221
}
221222

222223
return entityCacheMap.get(realmContext.getRealmIdentifier());
@@ -233,8 +234,7 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
233234
PolarisMetaStoreManager metaStoreManager =
234235
metaStoreManagerMap.get(realmContext.getRealmIdentifier());
235236
BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
236-
PolarisCallContext polarisContext =
237-
new PolarisCallContext(realmContext, metaStore, diagnostics);
237+
PolarisCallContext polarisContext = new PolarisCallContext(realmContext, metaStore);
238238

239239
Optional<PrincipalEntity> preliminaryRootPrincipal =
240240
metaStoreManager.findRootPrincipal(polarisContext);
@@ -268,8 +268,7 @@ private void checkPolarisServiceBootstrappedForRealm(RealmContext realmContext)
268268
PolarisMetaStoreManager metaStoreManager =
269269
metaStoreManagerMap.get(realmContext.getRealmIdentifier());
270270
BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
271-
PolarisCallContext polarisContext =
272-
new PolarisCallContext(realmContext, metaStore, diagnostics);
271+
PolarisCallContext polarisContext = new PolarisCallContext(realmContext, metaStore);
273272

274273
Optional<PrincipalEntity> rootPrincipal = metaStoreManager.findRootPrincipal(polarisContext);
275274
if (rootPrincipal.isEmpty()) {

persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
6464
RealmContext realmContext = () -> "REALM";
6565
JdbcBasePersistenceImpl basePersistence =
6666
new JdbcBasePersistenceImpl(
67+
diagServices,
6768
datasourceOperations,
6869
RANDOM_SECRETS,
6970
Mockito.mock(),
7071
realmContext.getRealmIdentifier(),
7172
schemaVersion);
7273
AtomicOperationMetaStoreManager metaStoreManager =
7374
new AtomicOperationMetaStoreManager(clock, diagServices);
74-
PolarisCallContext callCtx =
75-
new PolarisCallContext(realmContext, basePersistence, diagServices);
75+
PolarisCallContext callCtx = new PolarisCallContext(realmContext, basePersistence);
7676
return new PolarisTestMetaStoreManager(metaStoreManager, callCtx);
7777
}
7878

polaris-core/src/main/java/org/apache/polaris/core/PolarisCallContext.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,29 @@ public class PolarisCallContext implements CallContext {
3434

3535
// meta store which is used to persist Polaris entity metadata
3636
private final BasePersistence metaStore;
37-
private final PolarisDiagnostics diagServices;
3837
private final PolarisConfigurationStore configurationStore;
3938
private final RealmContext realmContext;
4039
private final RealmConfig realmConfig;
4140

4241
public PolarisCallContext(
4342
@Nonnull RealmContext realmContext,
4443
@Nonnull BasePersistence metaStore,
45-
@Nonnull PolarisDiagnostics diagServices,
4644
@Nonnull PolarisConfigurationStore configurationStore) {
4745
this.realmContext = realmContext;
4846
this.metaStore = metaStore;
49-
this.diagServices = diagServices;
5047
this.configurationStore = configurationStore;
5148
this.realmConfig = new RealmConfigImpl(this.configurationStore, this.realmContext);
5249
}
5350

5451
public PolarisCallContext(
55-
@Nonnull RealmContext realmContext,
56-
@Nonnull BasePersistence metaStore,
57-
@Nonnull PolarisDiagnostics diagServices) {
58-
this(realmContext, metaStore, diagServices, new PolarisConfigurationStore() {});
52+
@Nonnull RealmContext realmContext, @Nonnull BasePersistence metaStore) {
53+
this(realmContext, metaStore, new PolarisConfigurationStore() {});
5954
}
6055

6156
public BasePersistence getMetaStore() {
6257
return metaStore;
6358
}
6459

65-
public PolarisDiagnostics getDiagServices() {
66-
return diagServices;
67-
}
68-
6960
@Override
7061
public RealmContext getRealmContext() {
7162
return realmContext;
@@ -90,7 +81,6 @@ public PolarisCallContext copy() {
9081
// copy of the RealmContext to ensure the access during the task executor.
9182
String realmId = this.realmContext.getRealmIdentifier();
9283
RealmContext realmContext = () -> realmId;
93-
return new PolarisCallContext(
94-
realmContext, this.metaStore, this.diagServices, this.configurationStore);
84+
return new PolarisCallContext(realmContext, this.metaStore, this.configurationStore);
9585
}
9686
}

polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public Map<String, BaseResult> purgeRealms(Iterable<String> realms) {
131131
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
132132
TransactionalPersistence session = getOrCreateSession(realmContext);
133133

134-
PolarisCallContext callContext = new PolarisCallContext(realmContext, session, diagnostics);
134+
PolarisCallContext callContext = new PolarisCallContext(realmContext, session);
135135
BaseResult result = metaStoreManager.purge(callContext);
136136
results.put(realm, result);
137137

@@ -169,7 +169,7 @@ public synchronized EntityCache getOrCreateEntityCache(
169169
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
170170
entityCacheMap.put(
171171
realmContext.getRealmIdentifier(),
172-
new InMemoryEntityCache(realmConfig, metaStoreManager));
172+
new InMemoryEntityCache(diagnostics, realmConfig, metaStoreManager));
173173
}
174174

175175
return entityCacheMap.get(realmContext.getRealmIdentifier());
@@ -186,8 +186,7 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
186186
PolarisMetaStoreManager metaStoreManager =
187187
metaStoreManagerMap.get(realmContext.getRealmIdentifier());
188188
BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
189-
PolarisCallContext polarisContext =
190-
new PolarisCallContext(realmContext, metaStore, diagnostics);
189+
PolarisCallContext polarisContext = new PolarisCallContext(realmContext, metaStore);
191190

192191
Optional<PrincipalEntity> preliminaryRootPrincipal =
193192
metaStoreManager.findRootPrincipal(polarisContext);
@@ -221,8 +220,7 @@ private void checkPolarisServiceBootstrappedForRealm(RealmContext realmContext)
221220
PolarisMetaStoreManager metaStoreManager =
222221
metaStoreManagerMap.get(realmContext.getRealmIdentifier());
223222
BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
224-
PolarisCallContext polarisContext =
225-
new PolarisCallContext(realmContext, metaStore, diagnostics);
223+
PolarisCallContext polarisContext = new PolarisCallContext(realmContext, metaStore);
226224

227225
Optional<PrincipalEntity> rootPrincipal = metaStoreManager.findRootPrincipal(polarisContext);
228226
if (rootPrincipal.isEmpty()) {

polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public EntityResult readEntityByName(
137137
@Nonnull PolarisEntityType entityType,
138138
@Nonnull PolarisEntitySubType entitySubType,
139139
@Nonnull PageToken pageToken) {
140-
callCtx.getDiagServices().fail("illegal_method_in_transaction_workspace", "loadEntities");
140+
diagnostics.fail("illegal_method_in_transaction_workspace", "loadEntities");
141141
return null;
142142
}
143143

polaris-core/src/main/java/org/apache/polaris/core/persistence/cache/InMemoryEntityCache.java

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.concurrent.ConcurrentHashMap;
2929
import java.util.concurrent.TimeUnit;
3030
import org.apache.polaris.core.PolarisCallContext;
31+
import org.apache.polaris.core.PolarisDiagnostics;
3132
import org.apache.polaris.core.config.BehaviorChangeConfiguration;
3233
import org.apache.polaris.core.config.FeatureConfiguration;
3334
import org.apache.polaris.core.config.RealmConfig;
@@ -41,16 +42,10 @@
4142
/** An in-memory entity cache with a limit of 100k entities and a 1h TTL. */
4243
public class InMemoryEntityCache implements EntityCache {
4344

44-
// cache mode
4545
private EntityCacheMode cacheMode;
46-
47-
// the meta store manager
46+
private final PolarisDiagnostics diagnostics;
4847
private final PolarisMetaStoreManager polarisMetaStoreManager;
49-
50-
// Caffeine cache to keep entries by id
5148
private final Cache<Long, ResolvedPolarisEntity> byId;
52-
53-
// index by name
5449
private final AbstractMap<EntityCacheByNameKey, ResolvedPolarisEntity> byName;
5550

5651
/**
@@ -59,7 +54,10 @@ public class InMemoryEntityCache implements EntityCache {
5954
* @param polarisMetaStoreManager the meta store manager implementation
6055
*/
6156
public InMemoryEntityCache(
62-
@Nonnull RealmConfig realmConfig, @Nonnull PolarisMetaStoreManager polarisMetaStoreManager) {
57+
@Nonnull PolarisDiagnostics diagnostics,
58+
@Nonnull RealmConfig realmConfig,
59+
@Nonnull PolarisMetaStoreManager polarisMetaStoreManager) {
60+
this.diagnostics = diagnostics;
6361

6462
// by name cache
6563
this.byName = new ConcurrentHashMap<>();
@@ -344,16 +342,13 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) {
344342
}
345343

346344
// assert that entity, grant records and version are all set
347-
callContext.getDiagServices().checkNotNull(entity, "unexpected_null_entity");
348-
callContext.getDiagServices().checkNotNull(grantRecords, "unexpected_null_grant_records");
349-
callContext
350-
.getDiagServices()
351-
.check(grantRecordsVersion > 0, "unexpected_null_grant_records_version");
345+
diagnostics.checkNotNull(entity, "unexpected_null_entity");
346+
diagnostics.checkNotNull(grantRecords, "unexpected_null_grant_records");
347+
diagnostics.check(grantRecordsVersion > 0, "unexpected_null_grant_records_version");
352348

353349
// create new cache entry
354350
newCacheEntry =
355-
new ResolvedPolarisEntity(
356-
callContext.getDiagServices(), entity, grantRecords, grantRecordsVersion);
351+
new ResolvedPolarisEntity(diagnostics, entity, grantRecords, grantRecordsVersion);
357352

358353
// insert cache entry
359354
this.replaceCacheEntry(existingCacheEntry, newCacheEntry);
@@ -401,13 +396,12 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) {
401396
}
402397

403398
// if found, setup entry
404-
callContext.getDiagServices().checkNotNull(result.getEntity(), "entity_should_loaded");
405-
callContext
406-
.getDiagServices()
407-
.checkNotNull(result.getEntityGrantRecords(), "entity_grant_records_should_loaded");
399+
diagnostics.checkNotNull(result.getEntity(), "entity_should_loaded");
400+
diagnostics.checkNotNull(
401+
result.getEntityGrantRecords(), "entity_grant_records_should_loaded");
408402
entry =
409403
new ResolvedPolarisEntity(
410-
callContext.getDiagServices(),
404+
diagnostics,
411405
result.getEntity(),
412406
result.getEntityGrantRecords(),
413407
result.getGrantRecordsVersion());
@@ -458,15 +452,14 @@ && isNewer(existingCacheEntry, existingCacheEntryByName)) {
458452
}
459453

460454
// validate return
461-
callContext.getDiagServices().checkNotNull(result.getEntity(), "entity_should_loaded");
462-
callContext
463-
.getDiagServices()
464-
.checkNotNull(result.getEntityGrantRecords(), "entity_grant_records_should_loaded");
455+
diagnostics.checkNotNull(result.getEntity(), "entity_should_loaded");
456+
diagnostics.checkNotNull(
457+
result.getEntityGrantRecords(), "entity_grant_records_should_loaded");
465458

466459
// if found, setup entry
467460
entry =
468461
new ResolvedPolarisEntity(
469-
callContext.getDiagServices(),
462+
diagnostics,
470463
result.getEntity(),
471464
result.getEntityGrantRecords(),
472465
result.getGrantRecordsVersion());

polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/PolarisResolutionManifest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class PolarisResolutionManifest implements PolarisResolutionManifestCatal
7070
private ResolverStatus primaryResolverStatus = null;
7171

7272
public PolarisResolutionManifest(
73+
PolarisDiagnostics diagnostics,
7374
CallContext callContext,
7475
ResolverFactory resolverFactory,
7576
SecurityContext securityContext,
@@ -79,7 +80,7 @@ public PolarisResolutionManifest(
7980
this.catalogName = catalogName;
8081
this.primaryResolver =
8182
resolverFactory.createResolver(callContext, securityContext, catalogName);
82-
this.diagnostics = callContext.getPolarisCallContext().getDiagServices();
83+
this.diagnostics = diagnostics;
8384
this.diagnostics.checkNotNull(securityContext, "null_security_context_for_resolution_manifest");
8485
this.securityContext = securityContext;
8586
diagnostics.check(

polaris-core/src/main/java/org/apache/polaris/core/persistence/resolver/ResolutionManifestFactoryImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@
2222
import jakarta.annotation.Nonnull;
2323
import jakarta.annotation.Nullable;
2424
import jakarta.ws.rs.core.SecurityContext;
25+
import org.apache.polaris.core.PolarisDiagnostics;
2526
import org.apache.polaris.core.context.CallContext;
2627

2728
public class ResolutionManifestFactoryImpl implements ResolutionManifestFactory {
2829

30+
private final PolarisDiagnostics diagnostics;
2931
private final ResolverFactory resolverFactory;
3032

31-
public ResolutionManifestFactoryImpl(@Nonnull ResolverFactory resolverFactory) {
33+
public ResolutionManifestFactoryImpl(
34+
@Nonnull PolarisDiagnostics diagnostics, @Nonnull ResolverFactory resolverFactory) {
35+
this.diagnostics = diagnostics;
3236
this.resolverFactory = resolverFactory;
3337
}
3438

@@ -39,6 +43,6 @@ public PolarisResolutionManifest createResolutionManifest(
3943
@Nonnull SecurityContext securityContext,
4044
@Nullable String referenceCatalogName) {
4145
return new PolarisResolutionManifest(
42-
callContext, resolverFactory, securityContext, referenceCatalogName);
46+
diagnostics, callContext, resolverFactory, securityContext, referenceCatalogName);
4347
}
4448
}

0 commit comments

Comments
 (0)