Skip to content

Commit 21d1e65

Browse files
eric-maynardssvinarchuk
authored andcommitted
Remove PolarisConfiguration.loadConfig (v2) (apache#1858)
(cherry picked from commit 8942f68)
1 parent 34815e9 commit 21d1e65

File tree

35 files changed

+221
-135
lines changed

35 files changed

+221
-135
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import jakarta.inject.Inject;
2626
import java.nio.file.Path;
2727
import org.apache.polaris.core.PolarisDiagnostics;
28+
import org.apache.polaris.core.config.PolarisConfigurationStore;
2829
import org.apache.polaris.core.context.RealmContext;
2930
import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory;
3031
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
@@ -46,12 +47,13 @@ public class EclipseLinkPolarisMetaStoreManagerFactory
4647
@Inject PolarisStorageIntegrationProvider storageIntegrationProvider;
4748

4849
protected EclipseLinkPolarisMetaStoreManagerFactory() {
49-
this(null);
50+
this(null, null);
5051
}
5152

5253
@Inject
53-
protected EclipseLinkPolarisMetaStoreManagerFactory(PolarisDiagnostics diagnostics) {
54-
super(diagnostics);
54+
protected EclipseLinkPolarisMetaStoreManagerFactory(
55+
PolarisDiagnostics diagnostics, PolarisConfigurationStore configurationStore) {
56+
super(diagnostics, configurationStore);
5557
}
5658

5759
@Override

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.polaris.core.PolarisCallContext;
3333
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
3434
import org.apache.polaris.core.PolarisDiagnostics;
35+
import org.apache.polaris.core.config.PolarisConfigurationStore;
3536
import org.apache.polaris.core.context.CallContext;
3637
import org.apache.polaris.core.context.RealmContext;
3738
import org.apache.polaris.core.entity.PolarisEntity;
@@ -74,6 +75,7 @@ public class JdbcMetaStoreManagerFactory implements MetaStoreManagerFactory {
7475
@Inject PolarisStorageIntegrationProvider storageIntegrationProvider;
7576
@Inject Instance<DataSource> dataSource;
7677
@Inject RelationalJdbcConfiguration relationalJdbcConfiguration;
78+
@Inject PolarisConfigurationStore configurationStore;
7779

7880
protected JdbcMetaStoreManagerFactory() {}
7981

@@ -205,7 +207,8 @@ public synchronized StorageCredentialCache getOrCreateStorageCredentialCache(
205207
RealmContext realmContext) {
206208
if (!storageCredentialCacheMap.containsKey(realmContext.getRealmIdentifier())) {
207209
storageCredentialCacheMap.put(
208-
realmContext.getRealmIdentifier(), new StorageCredentialCache());
210+
realmContext.getRealmIdentifier(),
211+
new StorageCredentialCache(realmContext, configurationStore));
209212
}
210213

211214
return storageCredentialCacheMap.get(realmContext.getRealmIdentifier());
@@ -216,7 +219,8 @@ public synchronized EntityCache getOrCreateEntityCache(RealmContext realmContext
216219
if (!entityCacheMap.containsKey(realmContext.getRealmIdentifier())) {
217220
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
218221
entityCacheMap.put(
219-
realmContext.getRealmIdentifier(), new InMemoryEntityCache(metaStoreManager));
222+
realmContext.getRealmIdentifier(),
223+
new InMemoryEntityCache(realmContext, configurationStore, metaStoreManager));
220224
}
221225

222226
return entityCacheMap.get(realmContext.getRealmIdentifier());

polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.function.Function;
2525
import java.util.stream.Collectors;
2626
import java.util.stream.Stream;
27-
import org.apache.polaris.core.context.CallContext;
2827
import org.slf4j.Logger;
2928
import org.slf4j.LoggerFactory;
3029

@@ -210,25 +209,6 @@ public BehaviorChangeConfiguration<T> buildBehaviorChangeConfiguration() {
210209
}
211210
}
212211

213-
/**
214-
* Returns the value of a `PolarisConfiguration`, or the default if it cannot be loaded. This
215-
* method does not need to be used when a `CallContext` is already available
216-
*/
217-
public static <T> T loadConfig(PolarisConfiguration<T> configuration) {
218-
var callContext = CallContext.getCurrentContext();
219-
if (callContext == null) {
220-
LOGGER.warn(
221-
String.format(
222-
"Unable to load current call context; using %s = %s",
223-
configuration.key, configuration.defaultValue));
224-
return configuration.defaultValue;
225-
}
226-
return callContext
227-
.getPolarisCallContext()
228-
.getConfigurationStore()
229-
.getConfiguration(callContext.getRealmContext(), configuration);
230-
}
231-
232212
public static <T> Builder<T> builder() {
233213
return new Builder<>();
234214
}

polaris-core/src/main/java/org/apache/polaris/core/entity/CatalogEntity.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.polaris.core.admin.model.StorageConfigInfo;
4444
import org.apache.polaris.core.config.BehaviorChangeConfiguration;
4545
import org.apache.polaris.core.connection.ConnectionConfigInfoDpo;
46+
import org.apache.polaris.core.context.CallContext;
4647
import org.apache.polaris.core.secrets.UserSecretReference;
4748
import org.apache.polaris.core.storage.FileStorageConfigurationInfo;
4849
import org.apache.polaris.core.storage.PolarisStorageConfigurationInfo;
@@ -80,7 +81,7 @@ public static CatalogEntity of(PolarisBaseEntity sourceEntity) {
8081
return null;
8182
}
8283

83-
public static CatalogEntity fromCatalog(Catalog catalog) {
84+
public static CatalogEntity fromCatalog(CallContext callContext, Catalog catalog) {
8485
Builder builder =
8586
new Builder()
8687
.setName(catalog.getName())
@@ -90,7 +91,7 @@ public static CatalogEntity fromCatalog(Catalog catalog) {
9091
internalProperties.put(CATALOG_TYPE_PROPERTY, catalog.getType().name());
9192
builder.setInternalProperties(internalProperties);
9293
builder.setStorageConfigurationInfo(
93-
catalog.getStorageConfigInfo(), getDefaultBaseLocation(catalog));
94+
callContext, catalog.getStorageConfigInfo(), getDefaultBaseLocation(catalog));
9495
return builder.build();
9596
}
9697

@@ -247,7 +248,7 @@ public Builder setReplaceNewLocationPrefixWithCatalogDefault(String value) {
247248
}
248249

249250
public Builder setStorageConfigurationInfo(
250-
StorageConfigInfo storageConfigModel, String defaultBaseLocation) {
251+
CallContext callContext, StorageConfigInfo storageConfigModel, String defaultBaseLocation) {
251252
if (storageConfigModel != null) {
252253
PolarisStorageConfigurationInfo config;
253254
Set<String> allowedLocations = new HashSet<>(storageConfigModel.getAllowedLocations());
@@ -261,7 +262,7 @@ public Builder setStorageConfigurationInfo(
261262
throw new BadRequestException("Must specify default base location");
262263
}
263264
allowedLocations.add(defaultBaseLocation);
264-
validateMaxAllowedLocations(allowedLocations);
265+
validateMaxAllowedLocations(callContext, allowedLocations);
265266
switch (storageConfigModel.getStorageType()) {
266267
case S3:
267268
AwsStorageConfigInfo awsConfigModel = (AwsStorageConfigInfo) storageConfigModel;
@@ -305,10 +306,15 @@ public Builder setStorageConfigurationInfo(
305306
}
306307

307308
/** Validate the number of allowed locations not exceeding the max value. */
308-
private void validateMaxAllowedLocations(Collection<String> allowedLocations) {
309+
private void validateMaxAllowedLocations(
310+
CallContext callContext, Collection<String> allowedLocations) {
309311
int maxAllowedLocations =
310-
BehaviorChangeConfiguration.loadConfig(
311-
BehaviorChangeConfiguration.STORAGE_CONFIGURATION_MAX_LOCATIONS);
312+
callContext
313+
.getPolarisCallContext()
314+
.getConfigurationStore()
315+
.getConfiguration(
316+
callContext.getRealmContext(),
317+
BehaviorChangeConfiguration.STORAGE_CONFIGURATION_MAX_LOCATIONS);
312318
if (maxAllowedLocations != -1 && allowedLocations.size() > maxAllowedLocations) {
313319
throw new IllegalArgumentException(
314320
String.format(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ private void revokeGrantRecord(
16191619
try {
16201620
EnumMap<StorageAccessProperty, String> creds =
16211621
storageIntegration.getSubscopedCreds(
1622-
callCtx.getDiagServices(),
1622+
callCtx,
16231623
storageConfigurationInfo,
16241624
allowListOperation,
16251625
allowedReadLocations,

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.polaris.core.PolarisCallContext;
2727
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
2828
import org.apache.polaris.core.PolarisDiagnostics;
29+
import org.apache.polaris.core.config.PolarisConfigurationStore;
2930
import org.apache.polaris.core.context.CallContext;
3031
import org.apache.polaris.core.context.RealmContext;
3132
import org.apache.polaris.core.entity.PolarisEntity;
@@ -63,10 +64,14 @@ public abstract class LocalPolarisMetaStoreManagerFactory<StoreType>
6364
LoggerFactory.getLogger(LocalPolarisMetaStoreManagerFactory.class);
6465

6566
private final PolarisDiagnostics diagnostics;
67+
private final PolarisConfigurationStore configurationStore;
6668
private boolean bootstrap;
6769

68-
protected LocalPolarisMetaStoreManagerFactory(@Nonnull PolarisDiagnostics diagnostics) {
70+
protected LocalPolarisMetaStoreManagerFactory(
71+
@Nonnull PolarisDiagnostics diagnostics,
72+
@Nonnull PolarisConfigurationStore configurationStore) {
6973
this.diagnostics = diagnostics;
74+
this.configurationStore = configurationStore;
7075
}
7176

7277
protected abstract StoreType createBackingStore(@Nonnull PolarisDiagnostics diagnostics);
@@ -177,7 +182,8 @@ public synchronized StorageCredentialCache getOrCreateStorageCredentialCache(
177182
RealmContext realmContext) {
178183
if (!storageCredentialCacheMap.containsKey(realmContext.getRealmIdentifier())) {
179184
storageCredentialCacheMap.put(
180-
realmContext.getRealmIdentifier(), new StorageCredentialCache());
185+
realmContext.getRealmIdentifier(),
186+
new StorageCredentialCache(realmContext, configurationStore));
181187
}
182188

183189
return storageCredentialCacheMap.get(realmContext.getRealmIdentifier());
@@ -188,7 +194,8 @@ public synchronized EntityCache getOrCreateEntityCache(RealmContext realmContext
188194
if (!entityCacheMap.containsKey(realmContext.getRealmIdentifier())) {
189195
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
190196
entityCacheMap.put(
191-
realmContext.getRealmIdentifier(), new InMemoryEntityCache(metaStoreManager));
197+
realmContext.getRealmIdentifier(),
198+
new InMemoryEntityCache(realmContext, configurationStore, metaStoreManager));
192199
}
193200

194201
return entityCacheMap.get(realmContext.getRealmIdentifier());

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
import org.apache.polaris.core.PolarisCallContext;
3131
import org.apache.polaris.core.config.BehaviorChangeConfiguration;
3232
import org.apache.polaris.core.config.FeatureConfiguration;
33-
import org.apache.polaris.core.config.PolarisConfiguration;
33+
import org.apache.polaris.core.config.PolarisConfigurationStore;
34+
import org.apache.polaris.core.context.RealmContext;
3435
import org.apache.polaris.core.entity.PolarisBaseEntity;
3536
import org.apache.polaris.core.entity.PolarisEntityType;
3637
import org.apache.polaris.core.entity.PolarisGrantRecord;
@@ -58,7 +59,10 @@ public class InMemoryEntityCache implements EntityCache {
5859
*
5960
* @param polarisMetaStoreManager the meta store manager implementation
6061
*/
61-
public InMemoryEntityCache(@Nonnull PolarisMetaStoreManager polarisMetaStoreManager) {
62+
public InMemoryEntityCache(
63+
@Nonnull RealmContext realmContext,
64+
@Nonnull PolarisConfigurationStore configurationStore,
65+
@Nonnull PolarisMetaStoreManager polarisMetaStoreManager) {
6266

6367
// by name cache
6468
this.byName = new ConcurrentHashMap<>();
@@ -76,15 +80,19 @@ public InMemoryEntityCache(@Nonnull PolarisMetaStoreManager polarisMetaStoreMana
7680
};
7781

7882
long weigherTarget =
79-
PolarisConfiguration.loadConfig(FeatureConfiguration.ENTITY_CACHE_WEIGHER_TARGET);
83+
configurationStore.getConfiguration(
84+
realmContext, FeatureConfiguration.ENTITY_CACHE_WEIGHER_TARGET);
8085
Caffeine<Long, ResolvedPolarisEntity> byIdBuilder =
8186
Caffeine.newBuilder()
8287
.maximumWeight(weigherTarget)
8388
.weigher(EntityWeigher.asWeigher())
8489
.expireAfterAccess(1, TimeUnit.HOURS) // Expire entries after 1 hour of no access
8590
.removalListener(removalListener); // Set the removal listener
8691

87-
if (PolarisConfiguration.loadConfig(BehaviorChangeConfiguration.ENTITY_CACHE_SOFT_VALUES)) {
92+
boolean useSoftValues =
93+
configurationStore.getConfiguration(
94+
realmContext, BehaviorChangeConfiguration.ENTITY_CACHE_SOFT_VALUES);
95+
if (useSoftValues) {
8896
byIdBuilder.softValues();
8997
}
9098

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant(
20532053
try {
20542054
EnumMap<StorageAccessProperty, String> creds =
20552055
storageIntegration.getSubscopedCreds(
2056-
callCtx.getDiagServices(),
2056+
callCtx,
20572057
storageConfigurationInfo,
20582058
allowListOperation,
20592059
allowedReadLocations,

polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageIntegration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.EnumMap;
2323
import java.util.Map;
2424
import java.util.Set;
25-
import org.apache.polaris.core.PolarisDiagnostics;
25+
import org.apache.polaris.core.context.CallContext;
2626

2727
/**
2828
* Abstract of Polaris Storage Integration. It holds the reference to an object that having the
@@ -45,7 +45,7 @@ public String getStorageIdentifierOrId() {
4545
/**
4646
* Subscope the creds against the allowed read and write locations.
4747
*
48-
* @param diagnostics the diagnostics service
48+
* @param callContext the call context
4949
* @param storageConfig storage configuration
5050
* @param allowListOperation whether to allow LIST on all the provided allowed read/write
5151
* locations
@@ -54,7 +54,7 @@ public String getStorageIdentifierOrId() {
5454
* @return An enum map including the scoped credentials
5555
*/
5656
public abstract EnumMap<StorageAccessProperty, String> getSubscopedCreds(
57-
@Nonnull PolarisDiagnostics diagnostics,
57+
@Nonnull CallContext callContext,
5858
@Nonnull T storageConfig,
5959
boolean allowListOperation,
6060
@Nonnull Set<String> allowedReadLocations,

polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.polaris.core.storage.aws;
2020

2121
import static org.apache.polaris.core.config.FeatureConfiguration.STORAGE_CREDENTIAL_DURATION_SECONDS;
22-
import static org.apache.polaris.core.config.PolarisConfiguration.loadConfig;
2322

2423
import jakarta.annotation.Nonnull;
2524
import java.net.URI;
@@ -29,7 +28,7 @@
2928
import java.util.Optional;
3029
import java.util.Set;
3130
import java.util.stream.Stream;
32-
import org.apache.polaris.core.PolarisDiagnostics;
31+
import org.apache.polaris.core.context.CallContext;
3332
import org.apache.polaris.core.storage.InMemoryStorageIntegration;
3433
import org.apache.polaris.core.storage.StorageAccessProperty;
3534
import org.apache.polaris.core.storage.StorageUtil;
@@ -63,11 +62,16 @@ public AwsCredentialsStorageIntegration(
6362
/** {@inheritDoc} */
6463
@Override
6564
public EnumMap<StorageAccessProperty, String> getSubscopedCreds(
66-
@Nonnull PolarisDiagnostics diagnostics,
65+
@Nonnull CallContext callContext,
6766
@Nonnull AwsStorageConfigurationInfo storageConfig,
6867
boolean allowListOperation,
6968
@Nonnull Set<String> allowedReadLocations,
7069
@Nonnull Set<String> allowedWriteLocations) {
70+
int storageCredentialDurationSeconds =
71+
callContext
72+
.getPolarisCallContext()
73+
.getConfigurationStore()
74+
.getConfiguration(callContext.getRealmContext(), STORAGE_CREDENTIAL_DURATION_SECONDS);
7175
AssumeRoleRequest.Builder request =
7276
AssumeRoleRequest.builder()
7377
.externalId(storageConfig.getExternalId())
@@ -80,7 +84,7 @@ public EnumMap<StorageAccessProperty, String> getSubscopedCreds(
8084
allowedReadLocations,
8185
allowedWriteLocations)
8286
.toJson())
83-
.durationSeconds(loadConfig(STORAGE_CREDENTIAL_DURATION_SECONDS));
87+
.durationSeconds(storageCredentialDurationSeconds);
8488
credentialsProvider.ifPresent(
8589
cp -> request.overrideConfiguration(b -> b.credentialsProvider(cp)));
8690
AssumeRoleResponse response = stsClient.assumeRole(request.build());

0 commit comments

Comments
 (0)