Skip to content

Commit febcc48

Browse files
committed
add PolarisRealmConfig
1 parent f80b4f3 commit febcc48

File tree

48 files changed

+380
-402
lines changed

Some content is hidden

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

48 files changed

+380
-402
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
3333
import org.apache.polaris.core.PolarisDiagnostics;
3434
import org.apache.polaris.core.config.PolarisConfigurationStore;
35+
import org.apache.polaris.core.config.PolarisRealmConfig;
3536
import org.apache.polaris.core.context.CallContext;
3637
import org.apache.polaris.core.context.RealmContext;
3738
import org.apache.polaris.core.entity.PolarisEntity;
@@ -221,23 +222,23 @@ public synchronized Supplier<BasePersistence> getOrCreateSessionSupplier(
221222

222223
@Override
223224
public synchronized StorageCredentialCache getOrCreateStorageCredentialCache(
224-
RealmContext realmContext) {
225+
RealmContext realmContext, PolarisRealmConfig realmConfig) {
225226
if (!storageCredentialCacheMap.containsKey(realmContext.getRealmIdentifier())) {
226227
storageCredentialCacheMap.put(
227-
realmContext.getRealmIdentifier(),
228-
new StorageCredentialCache(realmContext, configurationStore));
228+
realmContext.getRealmIdentifier(), new StorageCredentialCache(realmConfig));
229229
}
230230

231231
return storageCredentialCacheMap.get(realmContext.getRealmIdentifier());
232232
}
233233

234234
@Override
235-
public synchronized EntityCache getOrCreateEntityCache(RealmContext realmContext) {
235+
public synchronized EntityCache getOrCreateEntityCache(
236+
RealmContext realmContext, PolarisRealmConfig realmConfig) {
236237
if (!entityCacheMap.containsKey(realmContext.getRealmIdentifier())) {
237238
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
238239
entityCacheMap.put(
239240
realmContext.getRealmIdentifier(),
240-
new InMemoryEntityCache(realmContext, configurationStore, metaStoreManager));
241+
new InMemoryEntityCache(realmConfig, metaStoreManager));
241242
}
242243

243244
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.PolarisRealmConfig;
26+
import org.apache.polaris.core.config.PolarisRealmConfigImpl;
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 PolarisRealmConfig 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 PolarisRealmConfigImpl(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 PolarisRealmConfig 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+
.getConfiguration(
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().getConfiguration(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 PolarisRealmConfig {
26+
27+
/**
28+
* Retrieve the current value for a configuration key. May be null if not set.
29+
*
30+
* @param configName the name of the configuration key to check
31+
* @return the current value set for the configuration key, or null if not set
32+
* @param <T> the type of the configuration value
33+
*/
34+
<T> @Nullable T getConfiguration(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 configName the name of the configuration key to check
41+
* @param defaultValue the default value if the configuration key has no value
42+
* @return the current value or the supplied default value
43+
* @param <T> the type of the configuration value
44+
*/
45+
<T> T getConfiguration(String configName, T defaultValue);
46+
47+
/**
48+
* Retrieve the current value for a configuration.
49+
*
50+
* @param config the configuration to load
51+
* @return the current value set for the configuration key or null if not set
52+
* @param <T> the type of the configuration value
53+
*/
54+
<T> T getConfiguration(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 catalogEntity the catalog to check for an override
61+
* @param config the configuration to load
62+
* @return the current value set for the configuration key or null if not set
63+
* @param <T> the type of the configuration value
64+
*/
65+
<T> T getConfiguration(CatalogEntity catalogEntity, PolarisConfiguration<T> config);
66+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 PolarisRealmConfigImpl implements PolarisRealmConfig {
26+
27+
private final PolarisConfigurationStore configurationStore;
28+
private final RealmContext realmContext;
29+
30+
public PolarisRealmConfigImpl(
31+
PolarisConfigurationStore configurationStore, RealmContext realmContext) {
32+
this.configurationStore = configurationStore;
33+
this.realmContext = realmContext;
34+
}
35+
36+
@Override
37+
public <T> @Nullable T getConfiguration(String configName) {
38+
return configurationStore.getConfiguration(realmContext, configName);
39+
}
40+
41+
@Override
42+
public <T> T getConfiguration(String configName, T defaultValue) {
43+
return configurationStore.getConfiguration(realmContext, configName, defaultValue);
44+
}
45+
46+
@Override
47+
public <T> T getConfiguration(PolarisConfiguration<T> config) {
48+
return configurationStore.getConfiguration(realmContext, config);
49+
}
50+
51+
@Override
52+
public <T> T getConfiguration(CatalogEntity catalogEntity, PolarisConfiguration<T> config) {
53+
return configurationStore.getConfiguration(realmContext, catalogEntity, config);
54+
}
55+
}

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.PolarisRealmConfig;
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+
PolarisRealmConfig 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+
.getConfiguration(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: 1 addition & 2 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()
1511+
.getRealmConfig()
15121512
.getConfiguration(
1513-
callCtx.getRealmContext(),
15141513
PolarisTaskConstants.TASK_TIMEOUT_MILLIS_CONFIG,
15151514
PolarisTaskConstants.TASK_TIMEOUT_MILLIS);
15161515
return taskState == null

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
2828
import org.apache.polaris.core.PolarisDiagnostics;
2929
import org.apache.polaris.core.config.PolarisConfigurationStore;
30+
import org.apache.polaris.core.config.PolarisRealmConfig;
3031
import org.apache.polaris.core.context.CallContext;
3132
import org.apache.polaris.core.context.RealmContext;
3233
import org.apache.polaris.core.entity.PolarisEntity;
@@ -65,7 +66,6 @@ public abstract class LocalPolarisMetaStoreManagerFactory<StoreType>
6566

6667
private final PolarisDiagnostics diagnostics;
6768
private final PolarisConfigurationStore configurationStore;
68-
private boolean bootstrap;
6969

7070
protected LocalPolarisMetaStoreManagerFactory(
7171
@Nonnull PolarisDiagnostics diagnostics,
@@ -179,23 +179,23 @@ public synchronized Supplier<TransactionalPersistence> getOrCreateSessionSupplie
179179

180180
@Override
181181
public synchronized StorageCredentialCache getOrCreateStorageCredentialCache(
182-
RealmContext realmContext) {
182+
RealmContext realmContext, PolarisRealmConfig realmConfig) {
183183
if (!storageCredentialCacheMap.containsKey(realmContext.getRealmIdentifier())) {
184184
storageCredentialCacheMap.put(
185-
realmContext.getRealmIdentifier(),
186-
new StorageCredentialCache(realmContext, configurationStore));
185+
realmContext.getRealmIdentifier(), new StorageCredentialCache(realmConfig));
187186
}
188187

189188
return storageCredentialCacheMap.get(realmContext.getRealmIdentifier());
190189
}
191190

192191
@Override
193-
public synchronized EntityCache getOrCreateEntityCache(RealmContext realmContext) {
192+
public synchronized EntityCache getOrCreateEntityCache(
193+
RealmContext realmContext, PolarisRealmConfig realmConfig) {
194194
if (!entityCacheMap.containsKey(realmContext.getRealmIdentifier())) {
195195
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmContext);
196196
entityCacheMap.put(
197197
realmContext.getRealmIdentifier(),
198-
new InMemoryEntityCache(realmContext, configurationStore, metaStoreManager));
198+
new InMemoryEntityCache(realmConfig, metaStoreManager));
199199
}
200200

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

0 commit comments

Comments
 (0)