Skip to content

Commit f0c99a6

Browse files
authored
Revert "Refactor RealmContext to RealmId (#741)" (#920)
* Revert "Copy RealmId when passing it to TaskExecutorImpl (#879)" This reverts commit febe4e8. * Revert #741
1 parent 143d6e5 commit f0c99a6

File tree

88 files changed

+694
-657
lines changed

Some content is hidden

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

88 files changed

+694
-657
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.time.Clock;
2828
import org.apache.polaris.core.PolarisConfigurationStore;
2929
import org.apache.polaris.core.PolarisDiagnostics;
30-
import org.apache.polaris.core.context.RealmId;
30+
import org.apache.polaris.core.context.RealmContext;
3131
import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory;
3232
import org.apache.polaris.core.persistence.PolarisCredentialsBootstrap;
3333
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
@@ -71,16 +71,16 @@ protected PolarisEclipseLinkStore createBackingStore(@Nonnull PolarisDiagnostics
7171
@Override
7272
protected PolarisMetaStoreSession createMetaStoreSession(
7373
@Nonnull PolarisEclipseLinkStore store,
74-
@Nonnull RealmId realmId,
74+
@Nonnull RealmContext realmContext,
7575
@Nullable PolarisCredentialsBootstrap credentialsBootstrap,
7676
@Nonnull PolarisDiagnostics diagnostics) {
7777
return new PolarisEclipseLinkMetaStoreSessionImpl(
7878
store,
7979
storageIntegrationProvider,
80-
realmId,
80+
realmContext,
8181
configurationFile(),
8282
persistenceUnitName(),
83-
secretsGenerator(realmId, credentialsBootstrap),
83+
secretsGenerator(realmContext, credentialsBootstrap),
8484
diagnostics);
8585
}
8686

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import java.util.function.Supplier;
3939
import java.util.stream.Collectors;
4040
import org.apache.polaris.core.PolarisDiagnostics;
41-
import org.apache.polaris.core.context.RealmId;
41+
import org.apache.polaris.core.context.RealmContext;
4242
import org.apache.polaris.core.entity.PolarisBaseEntity;
4343
import org.apache.polaris.core.entity.PolarisChangeTrackingVersions;
4444
import org.apache.polaris.core.entity.PolarisEntitiesActiveKey;
@@ -88,21 +88,22 @@ public class PolarisEclipseLinkMetaStoreSessionImpl implements PolarisMetaStoreS
8888
*
8989
* @param store Backing store of EclipseLink implementation
9090
* @param storageIntegrationProvider Storage integration provider
91-
* @param realmId Realm context used to communicate with different database.
91+
* @param realmContext Realm context used to communicate with different database.
9292
* @param confFile Optional EclipseLink configuration file. Default to 'META-INF/persistence.xml'.
9393
* @param persistenceUnitName Optional persistence-unit name in confFile. Default to 'polaris'.
9494
*/
9595
public PolarisEclipseLinkMetaStoreSessionImpl(
9696
@Nonnull PolarisEclipseLinkStore store,
9797
@Nonnull PolarisStorageIntegrationProvider storageIntegrationProvider,
98-
@Nonnull RealmId realmId,
98+
@Nonnull RealmContext realmContext,
9999
@Nullable String confFile,
100100
@Nullable String persistenceUnitName,
101101
@Nonnull PrincipalSecretsGenerator secretsGenerator,
102102
@Nonnull PolarisDiagnostics diagnostics) {
103103
this.diagnostics = diagnostics;
104-
LOGGER.debug("Creating EclipseLink Meta Store Session for realm {}", realmId.id());
105-
emf = createEntityManagerFactory(realmId, confFile, persistenceUnitName);
104+
LOGGER.debug(
105+
"Creating EclipseLink Meta Store Session for realm {}", realmContext.getRealmIdentifier());
106+
emf = createEntityManagerFactory(realmContext, confFile, persistenceUnitName);
106107

107108
// init store
108109
this.store = store;
@@ -120,16 +121,18 @@ public PolarisEclipseLinkMetaStoreSessionImpl(
120121
* realm.
121122
*/
122123
private EntityManagerFactory createEntityManagerFactory(
123-
@Nonnull RealmId realmId, @Nullable String confFile, @Nullable String persistenceUnitName) {
124-
String realm = realmId.id();
124+
@Nonnull RealmContext realmContext,
125+
@Nullable String confFile,
126+
@Nullable String persistenceUnitName) {
127+
String realm = realmContext.getRealmIdentifier();
125128
return realmFactories.computeIfAbsent(
126129
realm,
127130
key -> {
128131
try {
129132
PolarisEclipseLinkPersistenceUnit persistenceUnit =
130133
PolarisEclipseLinkPersistenceUnit.locatePersistenceUnit(
131134
confFile, persistenceUnitName);
132-
return persistenceUnit.createEntityManagerFactory(realmId);
135+
return persistenceUnit.createEntityManagerFactory(realmContext);
133136
} catch (IOException e) {
134137
throw new UncheckedIOException(e);
135138
}

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import javax.xml.xpath.XPathConstants;
4444
import javax.xml.xpath.XPathExpressionException;
4545
import javax.xml.xpath.XPathFactory;
46-
import org.apache.polaris.core.context.RealmId;
46+
import org.apache.polaris.core.context.RealmContext;
4747
import org.apache.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkPersistenceUnit.ClasspathResourcePolarisEclipseLinkPersistenceUnit;
4848
import org.apache.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkPersistenceUnit.FileSystemPolarisEclipseLinkPersistenceUnit;
4949
import org.apache.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkPersistenceUnit.JarFilePolarisEclipseLinkPersistenceUnit;
@@ -57,15 +57,16 @@ sealed interface PolarisEclipseLinkPersistenceUnit
5757
FileSystemPolarisEclipseLinkPersistenceUnit,
5858
JarFilePolarisEclipseLinkPersistenceUnit {
5959

60-
EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException;
60+
EntityManagerFactory createEntityManagerFactory(RealmContext realmContext) throws IOException;
6161

6262
record ClasspathResourcePolarisEclipseLinkPersistenceUnit(
6363
URL resource, String resourceName, String persistenceUnitName)
6464
implements PolarisEclipseLinkPersistenceUnit {
6565

6666
@Override
67-
public EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException {
68-
Map<String, String> properties = loadProperties(resource, persistenceUnitName, realmId);
67+
public EntityManagerFactory createEntityManagerFactory(RealmContext realmContext)
68+
throws IOException {
69+
Map<String, String> properties = loadProperties(resource, persistenceUnitName, realmContext);
6970
properties.put(ECLIPSELINK_PERSISTENCE_XML, resourceName);
7071
return Persistence.createEntityManagerFactory(persistenceUnitName, properties);
7172
}
@@ -75,9 +76,10 @@ record FileSystemPolarisEclipseLinkPersistenceUnit(Path path, String persistence
7576
implements PolarisEclipseLinkPersistenceUnit {
7677

7778
@Override
78-
public EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException {
79+
public EntityManagerFactory createEntityManagerFactory(RealmContext realmContext)
80+
throws IOException {
7981
Map<String, String> properties =
80-
loadProperties(path.toUri().toURL(), persistenceUnitName, realmId);
82+
loadProperties(path.toUri().toURL(), persistenceUnitName, realmContext);
8183
Path archiveDirectory = path.getParent();
8284
String descriptorPath = archiveDirectory.getParent().relativize(path).toString();
8385
properties.put(ECLIPSELINK_PERSISTENCE_XML, descriptorPath);
@@ -99,8 +101,9 @@ record JarFilePolarisEclipseLinkPersistenceUnit(
99101
implements PolarisEclipseLinkPersistenceUnit {
100102

101103
@Override
102-
public EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException {
103-
Map<String, String> properties = loadProperties(confUrl, persistenceUnitName, realmId);
104+
public EntityManagerFactory createEntityManagerFactory(RealmContext realmContext)
105+
throws IOException {
106+
Map<String, String> properties = loadProperties(confUrl, persistenceUnitName, realmContext);
104107
properties.put(ECLIPSELINK_PERSISTENCE_XML, descriptorPath);
105108
ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
106109
try (URLClassLoader currentClassLoader =
@@ -180,7 +183,9 @@ private static URL classpathResource(String resourceName) throws IOException {
180183

181184
/** Load the persistence unit properties from a given configuration file */
182185
private static Map<String, String> loadProperties(
183-
@Nonnull URL confFile, @Nonnull String persistenceUnitName, @Nonnull RealmId realmId)
186+
@Nonnull URL confFile,
187+
@Nonnull String persistenceUnitName,
188+
@Nonnull RealmContext realmContext)
184189
throws IOException {
185190
try (InputStream input = confFile.openStream()) {
186191
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -200,7 +205,9 @@ private static Map<String, String> loadProperties(
200205
}
201206
// Replace database name in JDBC URL with realm
202207
if (properties.containsKey(JDBC_URL)) {
203-
properties.put(JDBC_URL, properties.get(JDBC_URL).replace("{realm}", realmId.id()));
208+
properties.put(
209+
JDBC_URL,
210+
properties.get(JDBC_URL).replace("{realm}", realmContext.getRealmIdentifier()));
204211
}
205212
return properties;
206213
} catch (XPathExpressionException

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import org.apache.polaris.core.PolarisConfigurationStore;
3939
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
4040
import org.apache.polaris.core.PolarisDiagnostics;
41-
import org.apache.polaris.core.context.RealmId;
41+
import org.apache.polaris.core.context.RealmContext;
4242
import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
4343
import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest;
4444
import org.apache.polaris.core.persistence.PolarisMetaStoreManagerImpl;
@@ -101,13 +101,13 @@ static void deleteConfFiles() throws IOException {
101101
protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
102102
PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl();
103103
PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices);
104-
RealmId realmId = RealmId.newRealmId("realm");
104+
RealmContext realmContext = () -> "realm";
105105
PolarisMetaStoreSession session =
106106
new PolarisEclipseLinkMetaStoreSessionImpl(
107-
store, Mockito.mock(), realmId, null, "polaris", RANDOM_SECRETS, diagServices);
107+
store, Mockito.mock(), realmContext, null, "polaris", RANDOM_SECRETS, diagServices);
108108
return new PolarisTestMetaStoreManager(
109109
new PolarisMetaStoreManagerImpl(
110-
realmId,
110+
realmContext,
111111
diagServices,
112112
new PolarisConfigurationStore() {},
113113
timeSource.withZone(ZoneId.systemDefault())),
@@ -128,7 +128,7 @@ void testCreateStoreSession(String confFile, boolean success) {
128128
new PolarisEclipseLinkMetaStoreSessionImpl(
129129
store,
130130
Mockito.mock(),
131-
RealmId.newRealmId("realm"),
131+
() -> "realm",
132132
confFile,
133133
"polaris",
134134
RANDOM_SECRETS,

polaris-core/build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ dependencies {
4444
compileOnly(libs.jetbrains.annotations)
4545
compileOnly(libs.spotbugs.annotations)
4646

47-
compileOnly(project(":polaris-immutables"))
48-
annotationProcessor(project(":polaris-immutables", configuration = "processor"))
49-
5047
constraints {
5148
implementation("org.xerial.snappy:snappy-java:1.1.10.7") {
5249
because("Vulnerability detected in 1.1.8.2")

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import jakarta.annotation.Nullable;
2424
import java.util.ArrayList;
2525
import java.util.List;
26-
import org.apache.polaris.core.context.RealmId;
26+
import org.apache.polaris.core.context.RealmContext;
2727
import org.apache.polaris.core.entity.CatalogEntity;
2828

2929
/**
@@ -35,11 +35,11 @@ public interface PolarisConfigurationStore {
3535
* Retrieve the current value for a configuration key. May be null if not set.
3636
*
3737
* @param <T> the type of the configuration value
38-
* @param realmId the realm context to check for overrides; may be null.
38+
* @param realmContext the realm context to check for overrides; may be null.
3939
* @param configName the name of the configuration key to check
4040
* @return the current value set for the configuration key or null if not set
4141
*/
42-
default <T> @Nullable T getConfiguration(@Nullable RealmId realmId, String configName) {
42+
default <T> @Nullable T getConfiguration(@Nullable RealmContext realmContext, String configName) {
4343
return null;
4444
}
4545

@@ -48,15 +48,15 @@ public interface PolarisConfigurationStore {
4848
* value.
4949
*
5050
* @param <T> the type of the configuration value
51-
* @param realmId the realm context to check for overrides; may be null.
51+
* @param realmContext the realm context to check for overrides; may be null.
5252
* @param configName the name of the configuration key to check
5353
* @param defaultValue the default value if the configuration key has no value
5454
* @return the current value or the supplied default value
5555
*/
5656
default <T> @Nonnull T getConfiguration(
57-
@Nullable RealmId realmId, String configName, @Nonnull T defaultValue) {
57+
@Nullable RealmContext realmContext, String configName, @Nonnull T defaultValue) {
5858
Preconditions.checkNotNull(defaultValue, "Cannot pass null as a default value");
59-
T configValue = getConfiguration(realmId, configName);
59+
T configValue = getConfiguration(realmContext, configName);
6060
return configValue != null ? configValue : defaultValue;
6161
}
6262

@@ -88,13 +88,13 @@ public interface PolarisConfigurationStore {
8888
* Retrieve the current value for a configuration.
8989
*
9090
* @param <T> the type of the configuration value
91-
* @param realmId the realm context to check for overrides; may be null.
91+
* @param realmContext the realm context to check for overrides; may be null.
9292
* @param config the configuration to load
9393
* @return the current value set for the configuration key or null if not set
9494
*/
9595
default <T> @Nonnull T getConfiguration(
96-
@Nullable RealmId realmId, PolarisConfiguration<T> config) {
97-
T result = getConfiguration(realmId, config.key, config.defaultValue);
96+
@Nullable RealmContext realmContext, PolarisConfiguration<T> config) {
97+
T result = getConfiguration(realmContext, config.key, config.defaultValue);
9898
return tryCast(config, result);
9999
}
100100

@@ -103,20 +103,20 @@ public interface PolarisConfigurationStore {
103103
* present.
104104
*
105105
* @param <T> the type of the configuration value
106-
* @param realmId the realm context to check for overrides; may be null.
106+
* @param realmContext the realm context to check for overrides; may be null.
107107
* @param catalogEntity the catalog to check for an override
108108
* @param config the configuration to load
109109
* @return the current value set for the configuration key or null if not set
110110
*/
111111
default <T> @Nonnull T getConfiguration(
112-
@Nullable RealmId realmId,
112+
@Nullable RealmContext realmContext,
113113
@Nonnull CatalogEntity catalogEntity,
114114
PolarisConfiguration<T> config) {
115115
if (config.hasCatalogConfig()
116116
&& catalogEntity.getPropertiesAsMap().containsKey(config.catalogConfig())) {
117117
return tryCast(config, catalogEntity.getPropertiesAsMap().get(config.catalogConfig()));
118118
} else {
119-
return getConfiguration(realmId, config);
119+
return getConfiguration(realmContext, config);
120120
}
121121
}
122122
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@
2222
import jakarta.annotation.Nullable;
2323
import java.util.List;
2424
import java.util.Set;
25-
import org.apache.polaris.core.context.RealmId;
25+
import org.apache.polaris.core.context.RealmContext;
2626
import org.apache.polaris.core.entity.PolarisBaseEntity;
2727
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
2828

2929
/** Interface for invoking authorization checks. */
3030
public interface PolarisAuthorizer {
3131

3232
void authorizeOrThrow(
33-
@Nonnull RealmId realmId,
33+
@Nonnull RealmContext realmContext,
3434
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
3535
@Nonnull Set<PolarisBaseEntity> activatedEntities,
3636
@Nonnull PolarisAuthorizableOperation authzOp,
3737
@Nullable PolarisResolvedPathWrapper target,
3838
@Nullable PolarisResolvedPathWrapper secondary);
3939

4040
void authorizeOrThrow(
41-
@Nonnull RealmId realmId,
41+
@Nonnull RealmContext realmContext,
4242
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
4343
@Nonnull Set<PolarisBaseEntity> activatedEntities,
4444
@Nonnull PolarisAuthorizableOperation authzOp,

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
import org.apache.iceberg.exceptions.ForbiddenException;
101101
import org.apache.polaris.core.PolarisConfiguration;
102102
import org.apache.polaris.core.PolarisConfigurationStore;
103-
import org.apache.polaris.core.context.RealmId;
103+
import org.apache.polaris.core.context.RealmContext;
104104
import org.apache.polaris.core.entity.PolarisBaseEntity;
105105
import org.apache.polaris.core.entity.PolarisEntityConstants;
106106
import org.apache.polaris.core.entity.PolarisEntityCore;
@@ -487,14 +487,14 @@ public boolean matchesOrIsSubsumedBy(
487487

488488
@Override
489489
public void authorizeOrThrow(
490-
@Nonnull RealmId realmId,
490+
@Nonnull RealmContext realmContext,
491491
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
492492
@Nonnull Set<PolarisBaseEntity> activatedEntities,
493493
@Nonnull PolarisAuthorizableOperation authzOp,
494494
@Nullable PolarisResolvedPathWrapper target,
495495
@Nullable PolarisResolvedPathWrapper secondary) {
496496
authorizeOrThrow(
497-
realmId,
497+
realmContext,
498498
authenticatedPrincipal,
499499
activatedEntities,
500500
authzOp,
@@ -504,15 +504,16 @@ public void authorizeOrThrow(
504504

505505
@Override
506506
public void authorizeOrThrow(
507-
@Nonnull RealmId realmId,
507+
@Nonnull RealmContext realmContext,
508508
@Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal,
509509
@Nonnull Set<PolarisBaseEntity> activatedEntities,
510510
@Nonnull PolarisAuthorizableOperation authzOp,
511511
@Nullable List<PolarisResolvedPathWrapper> targets,
512512
@Nullable List<PolarisResolvedPathWrapper> secondaries) {
513513
boolean enforceCredentialRotationRequiredState =
514514
featureConfig.getConfiguration(
515-
realmId, PolarisConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING);
515+
realmContext,
516+
PolarisConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING);
516517
if (enforceCredentialRotationRequiredState
517518
&& authenticatedPrincipal
518519
.getPrincipalEntity()

0 commit comments

Comments
 (0)