Skip to content

Commit de351de

Browse files
authored
Introduce RealmConfig (#2015)
Getting a config value currently requires quite a ceremony: ``` ctx.getPolarisCallContext() .getConfigurationStore() .getConfiguration(ctx.getRealmContext(), "ALLOW_WILDCARD_LOCATION", false)) ``` since a `PolarisConfigurationStore` cant be used without a `RealmContext` it makes sense to add a dedicated interface. this allows removal of verbose code and also moves towards injecting that interface via CDI at a request/realm scope in the future.
1 parent ad77bd9 commit de351de

File tree

51 files changed

+365
-429
lines changed

Some content is hidden

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

51 files changed

+365
-429
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
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;
2928
import org.apache.polaris.core.context.RealmContext;
3029
import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory;
3130
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
@@ -47,13 +46,12 @@ public class EclipseLinkPolarisMetaStoreManagerFactory
4746
@Inject PolarisStorageIntegrationProvider storageIntegrationProvider;
4847

4948
protected EclipseLinkPolarisMetaStoreManagerFactory() {
50-
this(null, null);
49+
this(null);
5150
}
5251

5352
@Inject
54-
protected EclipseLinkPolarisMetaStoreManagerFactory(
55-
PolarisDiagnostics diagnostics, PolarisConfigurationStore configurationStore) {
56-
super(diagnostics, configurationStore);
53+
protected EclipseLinkPolarisMetaStoreManagerFactory(PolarisDiagnostics diagnostics) {
54+
super(diagnostics);
5755
}
5856

5957
@Override

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.apache.polaris.core.PolarisCallContext;
3232
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
3333
import org.apache.polaris.core.PolarisDiagnostics;
34-
import org.apache.polaris.core.config.PolarisConfigurationStore;
34+
import org.apache.polaris.core.config.RealmConfig;
3535
import org.apache.polaris.core.context.CallContext;
3636
import org.apache.polaris.core.context.RealmContext;
3737
import org.apache.polaris.core.entity.PolarisEntity;
@@ -78,7 +78,6 @@ public class JdbcMetaStoreManagerFactory implements MetaStoreManagerFactory {
7878
@Inject PolarisStorageIntegrationProvider storageIntegrationProvider;
7979
@Inject Instance<DataSource> dataSource;
8080
@Inject RelationalJdbcConfiguration relationalJdbcConfiguration;
81-
@Inject PolarisConfigurationStore configurationStore;
8281

8382
protected JdbcMetaStoreManagerFactory() {}
8483

@@ -221,22 +220,23 @@ public synchronized Supplier<BasePersistence> getOrCreateSessionSupplier(
221220

222221
@Override
223222
public synchronized StorageCredentialCache getOrCreateStorageCredentialCache(
224-
RealmContext realmContext) {
223+
RealmContext realmContext, RealmConfig realmConfig) {
225224
if (!storageCredentialCacheMap.containsKey(realmContext.getRealmIdentifier())) {
226225
storageCredentialCacheMap.put(
227-
realmContext.getRealmIdentifier(), new StorageCredentialCache(configurationStore));
226+
realmContext.getRealmIdentifier(), new StorageCredentialCache());
228227
}
229228

230229
return storageCredentialCacheMap.get(realmContext.getRealmIdentifier());
231230
}
232231

233232
@Override
234-
public synchronized EntityCache getOrCreateEntityCache(RealmContext realmContext) {
233+
public synchronized EntityCache getOrCreateEntityCache(
234+
RealmContext realmContext, RealmConfig realmConfig) {
235235
if (!entityCacheMap.containsKey(realmContext.getRealmIdentifier())) {
236236
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
237237
entityCacheMap.put(
238238
realmContext.getRealmIdentifier(),
239-
new InMemoryEntityCache(realmContext, configurationStore, metaStoreManager));
239+
new InMemoryEntityCache(realmConfig, metaStoreManager));
240240
}
241241

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

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.time.Clock;
2323
import java.time.ZoneId;
2424
import org.apache.polaris.core.config.PolarisConfigurationStore;
25+
import org.apache.polaris.core.config.RealmConfig;
26+
import org.apache.polaris.core.config.RealmConfigImpl;
2527
import org.apache.polaris.core.context.CallContext;
2628
import org.apache.polaris.core.context.RealmContext;
2729
import org.apache.polaris.core.persistence.BasePersistence;
@@ -42,8 +44,9 @@ public class PolarisCallContext implements CallContext {
4244

4345
private final Clock clock;
4446

45-
// will make it final once we remove deprecated constructor
46-
private RealmContext realmContext = null;
47+
private final RealmContext realmContext;
48+
49+
private final RealmConfig realmConfig;
4750

4851
public PolarisCallContext(
4952
@Nonnull RealmContext realmContext,
@@ -56,17 +59,19 @@ public PolarisCallContext(
5659
this.diagServices = diagServices;
5760
this.configurationStore = configurationStore;
5861
this.clock = clock;
62+
this.realmConfig = new RealmConfigImpl(this.configurationStore, this.realmContext);
5963
}
6064

6165
public PolarisCallContext(
6266
@Nonnull RealmContext realmContext,
6367
@Nonnull BasePersistence metaStore,
6468
@Nonnull PolarisDiagnostics diagServices) {
65-
this.realmContext = realmContext;
66-
this.metaStore = metaStore;
67-
this.diagServices = diagServices;
68-
this.configurationStore = new PolarisConfigurationStore() {};
69-
this.clock = Clock.system(ZoneId.systemDefault());
69+
this(
70+
realmContext,
71+
metaStore,
72+
diagServices,
73+
new PolarisConfigurationStore() {},
74+
Clock.system(ZoneId.systemDefault()));
7075
}
7176

7277
public BasePersistence getMetaStore() {
@@ -77,10 +82,6 @@ public PolarisDiagnostics getDiagServices() {
7782
return diagServices;
7883
}
7984

80-
public PolarisConfigurationStore getConfigurationStore() {
81-
return configurationStore;
82-
}
83-
8485
public Clock getClock() {
8586
return clock;
8687
}
@@ -90,6 +91,11 @@ public RealmContext getRealmContext() {
9091
return realmContext;
9192
}
9293

94+
@Override
95+
public RealmConfig getRealmConfig() {
96+
return realmConfig;
97+
}
98+
9399
@Override
94100
public PolarisCallContext getPolarisCallContext() {
95101
return this;

polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
import java.util.stream.Collectors;
115115
import org.apache.iceberg.exceptions.ForbiddenException;
116116
import org.apache.polaris.core.config.FeatureConfiguration;
117-
import org.apache.polaris.core.config.PolarisConfigurationStore;
118117
import org.apache.polaris.core.context.CallContext;
119118
import org.apache.polaris.core.entity.PolarisBaseEntity;
120119
import org.apache.polaris.core.entity.PolarisEntityConstants;
@@ -531,12 +530,8 @@ public class PolarisAuthorizerImpl implements PolarisAuthorizer {
531530
List.of(TABLE_DETACH_POLICY, CATALOG_MANAGE_METADATA, CATALOG_MANAGE_CONTENT));
532531
}
533532

534-
private final PolarisConfigurationStore featureConfig;
535-
536533
@Inject
537-
public PolarisAuthorizerImpl(PolarisConfigurationStore featureConfig) {
538-
this.featureConfig = featureConfig;
539-
}
534+
public PolarisAuthorizerImpl() {}
540535

541536
/**
542537
* Checks whether the {@code grantedPrivilege} is sufficient to confer {@code desiredPrivilege},
@@ -583,9 +578,10 @@ public void authorizeOrThrow(
583578
@Nullable List<PolarisResolvedPathWrapper> targets,
584579
@Nullable List<PolarisResolvedPathWrapper> secondaries) {
585580
boolean enforceCredentialRotationRequiredState =
586-
featureConfig.getConfiguration(
587-
callContext.getRealmContext(),
588-
FeatureConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING);
581+
callContext
582+
.getRealmConfig()
583+
.getConfig(
584+
FeatureConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING);
589585
if (enforceCredentialRotationRequiredState
590586
&& authenticatedPrincipal
591587
.getPrincipalEntity()

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ protected FeatureConfiguration(
4949
*/
5050
public static void enforceFeatureEnabledOrThrow(
5151
CallContext callContext, FeatureConfiguration<Boolean> featureConfig) {
52-
boolean enabled =
53-
callContext
54-
.getPolarisCallContext()
55-
.getConfigurationStore()
56-
.getConfiguration(callContext.getRealmContext(), featureConfig);
52+
boolean enabled = callContext.getRealmConfig().getConfig(featureConfig);
5753
if (!enabled) {
5854
throw new UnsupportedOperationException("Feature not enabled: " + featureConfig.key());
5955
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.core.config;
20+
21+
import jakarta.annotation.Nullable;
22+
import org.apache.polaris.core.entity.CatalogEntity;
23+
24+
/** Realm-specific configuration used to retrieve runtime parameters. */
25+
public interface RealmConfig {
26+
27+
/**
28+
* Retrieve the current value for a configuration key. May be null if not set.
29+
*
30+
* @param <T> the type of the configuration value
31+
* @param configName the name of the configuration key to check
32+
* @return the current value set for the configuration key, or null if not set
33+
*/
34+
<T> @Nullable T getConfig(String configName);
35+
36+
/**
37+
* Retrieve the current value for a configuration key. If not set, return the non-null default
38+
* value.
39+
*
40+
* @param <T> the type of the configuration value
41+
* @param configName the name of the configuration key to check
42+
* @param defaultValue the default value if the configuration key has no value
43+
* @return the current value or the supplied default value
44+
*/
45+
<T> T getConfig(String configName, T defaultValue);
46+
47+
/**
48+
* Retrieve the current value for a configuration.
49+
*
50+
* @param <T> the type of the configuration value
51+
* @param config the configuration to load
52+
* @return the current value set for the configuration key or null if not set
53+
*/
54+
<T> T getConfig(PolarisConfiguration<T> config);
55+
56+
/**
57+
* Retrieve the current value for a configuration, overriding with a catalog config if it is
58+
* present.
59+
*
60+
* @param <T> the type of the configuration value
61+
* @param config the configuration to load
62+
* @param catalogEntity the catalog to check for an override
63+
* @return the current value set for the configuration key or null if not set
64+
*/
65+
<T> T getConfig(PolarisConfiguration<T> config, CatalogEntity catalogEntity);
66+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.core.config;
20+
21+
import jakarta.annotation.Nullable;
22+
import org.apache.polaris.core.context.RealmContext;
23+
import org.apache.polaris.core.entity.CatalogEntity;
24+
25+
public class RealmConfigImpl implements RealmConfig {
26+
27+
private final PolarisConfigurationStore configurationStore;
28+
private final RealmContext realmContext;
29+
30+
public RealmConfigImpl(PolarisConfigurationStore configurationStore, RealmContext realmContext) {
31+
this.configurationStore = configurationStore;
32+
this.realmContext = realmContext;
33+
}
34+
35+
@Override
36+
public <T> @Nullable T getConfig(String configName) {
37+
return configurationStore.getConfiguration(realmContext, configName);
38+
}
39+
40+
@Override
41+
public <T> T getConfig(String configName, T defaultValue) {
42+
return configurationStore.getConfiguration(realmContext, configName, defaultValue);
43+
}
44+
45+
@Override
46+
public <T> T getConfig(PolarisConfiguration<T> config) {
47+
return configurationStore.getConfiguration(realmContext, config);
48+
}
49+
50+
@Override
51+
public <T> T getConfig(PolarisConfiguration<T> config, CatalogEntity catalogEntity) {
52+
return configurationStore.getConfiguration(realmContext, catalogEntity, config);
53+
}
54+
}

polaris-core/src/main/java/org/apache/polaris/core/context/CallContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.polaris.core.context;
2020

2121
import org.apache.polaris.core.PolarisCallContext;
22+
import org.apache.polaris.core.config.RealmConfig;
2223

2324
/**
2425
* Stores elements associated with an individual REST request such as RealmContext, caller
@@ -53,4 +54,6 @@ static void unsetCurrentContext() {
5354
* @return the inner context used for delegating services
5455
*/
5556
PolarisCallContext getPolarisCallContext();
57+
58+
RealmConfig getRealmConfig();
5659
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,8 @@ private void validateMaxAllowedLocations(
313313
CallContext callContext, Collection<String> allowedLocations) {
314314
int maxAllowedLocations =
315315
callContext
316-
.getPolarisCallContext()
317-
.getConfigurationStore()
318-
.getConfiguration(
319-
callContext.getRealmContext(),
320-
BehaviorChangeConfiguration.STORAGE_CONFIGURATION_MAX_LOCATIONS);
316+
.getRealmConfig()
317+
.getConfig(BehaviorChangeConfiguration.STORAGE_CONFIGURATION_MAX_LOCATIONS);
321318
if (maxAllowedLocations != -1 && allowedLocations.size() > maxAllowedLocations) {
322319
throw new IllegalArgumentException(
323320
String.format(

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,9 +1508,8 @@ private void revokeGrantRecord(
15081508
PolarisObjectMapperUtil.parseTaskState(entity);
15091509
long taskAgeTimeout =
15101510
callCtx
1511-
.getConfigurationStore()
1512-
.getConfiguration(
1513-
callCtx.getRealmContext(),
1511+
.getRealmConfig()
1512+
.getConfig(
15141513
PolarisTaskConstants.TASK_TIMEOUT_MILLIS_CONFIG,
15151514
PolarisTaskConstants.TASK_TIMEOUT_MILLIS);
15161515
return taskState == null

0 commit comments

Comments
 (0)