Skip to content

Reduce getRealmConfig calls #2337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.apache.polaris.core.auth.PolarisAuthorizer;
import org.apache.polaris.core.catalog.PolarisCatalogHelpers;
import org.apache.polaris.core.config.FeatureConfiguration;
import org.apache.polaris.core.config.RealmConfig;
import org.apache.polaris.core.connection.AuthenticationParametersDpo;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.entity.CatalogEntity;
Expand Down Expand Up @@ -138,6 +139,7 @@ public class PolarisAdminService {
private static final Logger LOGGER = LoggerFactory.getLogger(PolarisAdminService.class);

private final CallContext callContext;
private final RealmConfig realmConfig;
private final ResolutionManifestFactory resolutionManifestFactory;
private final SecurityContext securityContext;
private final AuthenticatedPolarisPrincipal authenticatedPrincipal;
Expand All @@ -158,6 +160,7 @@ public PolarisAdminService(
@NotNull PolarisAuthorizer authorizer,
@NotNull ReservedProperties reservedProperties) {
this.callContext = callContext;
this.realmConfig = callContext.getRealmConfig();
this.resolutionManifestFactory = resolutionManifestFactory;
this.metaStoreManager = metaStoreManager;
this.securityContext = securityContext;
Expand Down Expand Up @@ -644,7 +647,7 @@ private String terminateWithSlash(String path) {
*/
private boolean catalogOverlapsWithExistingCatalog(CatalogEntity catalogEntity) {
boolean allowOverlappingCatalogUrls =
callContext.getRealmConfig().getConfig(FeatureConfiguration.ALLOW_OVERLAPPING_CATALOG_URLS);
realmConfig.getConfig(FeatureConfiguration.ALLOW_OVERLAPPING_CATALOG_URLS);
if (allowOverlappingCatalogUrls) {
return false;
}
Expand Down Expand Up @@ -745,8 +748,7 @@ public PolarisEntity createCatalog(CreateCatalogRequest catalogRequest) {
PolarisAuthorizableOperation op = PolarisAuthorizableOperation.CREATE_CATALOG;
authorizeBasicRootOperationOrThrow(op);

CatalogEntity entity =
CatalogEntity.fromCatalog(callContext.getRealmConfig(), catalogRequest.getCatalog());
CatalogEntity entity = CatalogEntity.fromCatalog(realmConfig, catalogRequest.getCatalog());

checkArgument(entity.getId() == -1, "Entity to be created must have no ID assigned");

Expand Down Expand Up @@ -774,11 +776,10 @@ public PolarisEntity createCatalog(CreateCatalogRequest catalogRequest) {
.addKeyValue("catalogName", entity.getName())
.log("Creating a federated catalog");
FeatureConfiguration.enforceFeatureEnabledOrThrow(
callContext.getRealmConfig(), FeatureConfiguration.ENABLE_CATALOG_FEDERATION);
realmConfig, FeatureConfiguration.ENABLE_CATALOG_FEDERATION);
Map<String, SecretReference> processedSecretReferences = Map.of();
List<String> supportedAuthenticationTypes =
callContext
.getRealmConfig()
realmConfig
.getConfig(FeatureConfiguration.SUPPORTED_EXTERNAL_CATALOG_AUTHENTICATION_TYPES)
.stream()
.map(s -> s.toUpperCase(Locale.ROOT))
Expand Down Expand Up @@ -831,8 +832,7 @@ public void deleteCatalog(String name) {
findCatalogByName(name)
.orElseThrow(() -> new NotFoundException("Catalog %s not found", name));
// TODO: Handle return value in case of concurrent modification
boolean cleanup =
callContext.getRealmConfig().getConfig(FeatureConfiguration.CLEANUP_ON_CATALOG_DROP);
boolean cleanup = realmConfig.getConfig(FeatureConfiguration.CLEANUP_ON_CATALOG_DROP);
DropEntityResult dropEntityResult =
metaStoreManager.dropEntityIfExists(
getCurrentPolarisContext(), null, entity, Map.of(), cleanup);
Expand Down Expand Up @@ -951,7 +951,7 @@ private void validateUpdateCatalogDiffOrThrow(
}
if (updateRequest.getStorageConfigInfo() != null) {
updateBuilder.setStorageConfigurationInfo(
callContext.getRealmConfig(), updateRequest.getStorageConfigInfo(), defaultBaseLocation);
realmConfig, updateRequest.getStorageConfigInfo(), defaultBaseLocation);
}
CatalogEntity updatedEntity = updateBuilder.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal;
import org.apache.polaris.core.auth.PolarisAuthorizer;
import org.apache.polaris.core.config.FeatureConfiguration;
import org.apache.polaris.core.config.RealmConfig;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.CatalogEntity;
Expand Down Expand Up @@ -98,6 +99,7 @@ public class PolarisServiceImpl
private final MetaStoreManagerFactory metaStoreManagerFactory;
private final UserSecretsManagerFactory userSecretsManagerFactory;
private final CallContext callContext;
private final RealmConfig realmConfig;
private final ReservedProperties reservedProperties;

@Inject
Expand All @@ -113,6 +115,7 @@ public PolarisServiceImpl(
this.userSecretsManagerFactory = userSecretsManagerFactory;
this.polarisAuthorizer = polarisAuthorizer;
this.callContext = callContext;
this.realmConfig = callContext.getRealmConfig();
this.reservedProperties = reservedProperties;
}

Expand Down Expand Up @@ -169,9 +172,7 @@ public Response createCatalog(

private void validateStorageConfig(StorageConfigInfo storageConfigInfo) {
List<String> allowedStorageTypes =
callContext
.getRealmConfig()
.getConfig(FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES);
realmConfig.getConfig(FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES);
if (!allowedStorageTypes.contains(storageConfigInfo.getStorageType().name())) {
LOGGER
.atWarn()
Expand All @@ -198,10 +199,7 @@ private void validateConnectionConfigInfo(ConnectionConfigInfo connectionConfigI

String connectionType = connectionConfigInfo.getConnectionType().name();
List<String> supportedConnectionTypes =
callContext
.getRealmConfig()
.getConfig(FeatureConfiguration.SUPPORTED_CATALOG_CONNECTION_TYPES)
.stream()
realmConfig.getConfig(FeatureConfiguration.SUPPORTED_CATALOG_CONNECTION_TYPES).stream()
.map(s -> s.toUpperCase(Locale.ROOT))
.toList();
if (!supportedConnectionTypes.contains(connectionType)) {
Expand All @@ -213,8 +211,7 @@ private void validateAuthenticationParameters(AuthenticationParameters authentic

String authenticationType = authenticationParameters.getAuthenticationType().name();
List<String> supportedAuthenticationTypes =
callContext
.getRealmConfig()
realmConfig
.getConfig(FeatureConfiguration.SUPPORTED_EXTERNAL_CATALOG_AUTHENTICATION_TYPES)
.stream()
.map(s -> s.toUpperCase(Locale.ROOT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.polaris.core.auth.PolarisAuthorizableOperation;
import org.apache.polaris.core.auth.PolarisAuthorizer;
import org.apache.polaris.core.catalog.PolarisCatalogHelpers;
import org.apache.polaris.core.config.RealmConfig;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.entity.PolarisEntitySubType;
import org.apache.polaris.core.entity.PolarisEntityType;
Expand All @@ -60,6 +61,7 @@ public abstract class CatalogHandler {
protected final PolarisAuthorizer authorizer;

protected final CallContext callContext;
protected final RealmConfig realmConfig;
protected final AuthenticatedPolarisPrincipal authenticatedPrincipal;
protected final SecurityContext securityContext;

Expand All @@ -70,6 +72,7 @@ public CatalogHandler(
String catalogName,
PolarisAuthorizer authorizer) {
this.callContext = callContext;
this.realmConfig = callContext.getRealmConfig();
this.resolutionManifestFactory = resolutionManifestFactory;
this.catalogName = catalogName;
PolarisDiagnostics diagServices = callContext.getPolarisCallContext().getDiagServices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.polaris.core.auth.PolarisAuthorizer;
import org.apache.polaris.core.config.FeatureConfiguration;
import org.apache.polaris.core.config.RealmConfig;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
Expand All @@ -46,6 +47,7 @@ public class GenericTableCatalogAdapter
private static final Logger LOGGER = LoggerFactory.getLogger(GenericTableCatalogAdapter.class);

private final RealmContext realmContext;
private final RealmConfig realmConfig;
private final CallContext callContext;
private final ResolutionManifestFactory resolutionManifestFactory;
private final PolarisMetaStoreManager metaStoreManager;
Expand All @@ -64,6 +66,7 @@ public GenericTableCatalogAdapter(
ReservedProperties reservedProperties) {
this.realmContext = realmContext;
this.callContext = callContext;
this.realmConfig = callContext.getRealmConfig();
this.resolutionManifestFactory = resolutionManifestFactory;
this.metaStoreManager = metaStoreManager;
this.polarisAuthorizer = polarisAuthorizer;
Expand All @@ -74,7 +77,7 @@ public GenericTableCatalogAdapter(
private GenericTableCatalogHandler newHandlerWrapper(
SecurityContext securityContext, String prefix) {
FeatureConfiguration.enforceFeatureEnabledOrThrow(
callContext.getRealmConfig(), FeatureConfiguration.ENABLE_GENERIC_TABLES);
realmConfig, FeatureConfiguration.ENABLE_GENERIC_TABLES);
validatePrincipal(securityContext);

return new GenericTableCatalogHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public class IcebergCatalog extends BaseMetastoreViewCatalog
private final StorageCredentialCache storageCredentialCache;
private final ResolverFactory resolverFactory;
private final CallContext callContext;
private final RealmConfig realmConfig;
private final PolarisResolutionManifestCatalogView resolvedEntityView;
private final CatalogEntity catalogEntity;
private final TaskExecutor taskExecutor;
Expand Down Expand Up @@ -209,6 +210,7 @@ public IcebergCatalog(
this.storageCredentialCache = storageCredentialCache;
this.resolverFactory = resolverFactory;
this.callContext = callContext;
this.realmConfig = callContext.getRealmConfig();
this.resolvedEntityView = resolvedEntityView;
this.catalogEntity =
CatalogEntity.of(resolvedEntityView.getResolvedReferenceCatalogEntity().getRawLeafEntity());
Expand Down Expand Up @@ -256,7 +258,7 @@ public void initialize(String name, Map<String, String> properties) {
var storageConfigurationInfo = catalogEntity.getStorageConfigurationInfo();
ioImplClassName =
IcebergPropertiesValidation.determineFileIOClassName(
callContext.getRealmConfig(), properties, storageConfigurationInfo);
realmConfig, properties, storageConfigurationInfo);

if (ioImplClassName == null) {
LOGGER.warn(
Expand Down Expand Up @@ -346,10 +348,8 @@ public TableOperations newTableOps(
@Override
protected TableOperations newTableOps(TableIdentifier tableIdentifier) {
boolean makeMetadataCurrentOnCommit =
callContext
.getRealmConfig()
.getConfig(
BehaviorChangeConfiguration.TABLE_OPERATIONS_MAKE_METADATA_CURRENT_ON_COMMIT);
realmConfig.getConfig(
BehaviorChangeConfiguration.TABLE_OPERATIONS_MAKE_METADATA_CURRENT_ON_COMMIT);
return newTableOps(tableIdentifier, makeMetadataCurrentOnCommit);
}

Expand Down Expand Up @@ -488,7 +488,7 @@ private void createNamespaceInternal(

// Set / suffix
boolean requireTrailingSlash =
callContext.getRealmConfig().getConfig(FeatureConfiguration.ADD_TRAILING_SLASH_TO_LOCATION);
realmConfig.getConfig(FeatureConfiguration.ADD_TRAILING_SLASH_TO_LOCATION);
if (requireTrailingSlash && !baseLocation.endsWith("/")) {
baseLocation += "/";
}
Expand All @@ -502,9 +502,7 @@ private void createNamespaceInternal(
.setCreateTimestamp(System.currentTimeMillis())
.setBaseLocation(baseLocation)
.build();
if (!callContext
.getRealmConfig()
.getConfig(FeatureConfiguration.ALLOW_NAMESPACE_LOCATION_OVERLAP)) {
if (!realmConfig.getConfig(FeatureConfiguration.ALLOW_NAMESPACE_LOCATION_OVERLAP)) {
LOGGER.debug("Validating no overlap for {} with sibling tables or namespaces", namespace);
validateNoLocationOverlap(entity, resolvedParent.getRawFullPath());
} else {
Expand Down Expand Up @@ -641,9 +639,7 @@ public boolean dropNamespace(Namespace namespace) throws NamespaceNotEmptyExcept
PolarisEntity.toCoreList(catalogPath),
leafEntity,
Map.of(),
callContext
.getRealmConfig()
.getConfig(FeatureConfiguration.CLEANUP_ON_NAMESPACE_DROP));
realmConfig.getConfig(FeatureConfiguration.CLEANUP_ON_NAMESPACE_DROP));

if (!dropEntityResult.isSuccess() && dropEntityResult.failedBecauseNotEmpty()) {
throw new NamespaceNotEmptyException("Namespace %s is not empty", namespace);
Expand All @@ -668,9 +664,7 @@ public boolean setProperties(Namespace namespace, Map<String, String> properties
PolarisEntity updatedEntity =
new PolarisEntity.Builder(entity).setProperties(newProperties).build();

if (!callContext
.getRealmConfig()
.getConfig(FeatureConfiguration.ALLOW_NAMESPACE_LOCATION_OVERLAP)) {
if (!realmConfig.getConfig(FeatureConfiguration.ALLOW_NAMESPACE_LOCATION_OVERLAP)) {
LOGGER.debug("Validating no overlap with sibling tables or namespaces");
validateNoLocationOverlap(
NamespaceEntity.of(updatedEntity), resolvedEntities.getRawParentPath());
Expand Down Expand Up @@ -874,7 +868,6 @@ private String buildPrefixedLocation(TableIdentifier tableIdentifier) {
*/
private String applyDefaultLocationObjectStoragePrefix(
TableIdentifier tableIdentifier, String location) {
RealmConfig realmConfig = callContext.getRealmConfig();
boolean prefixEnabled =
realmConfig.getConfig(
FeatureConfiguration.DEFAULT_LOCATION_OBJECT_STORAGE_PREFIX_ENABLED, catalogEntity);
Expand Down Expand Up @@ -1007,17 +1000,14 @@ private void validateLocationsForTableLike(
PolarisResolvedPathWrapper resolvedStorageEntity) {
Optional<PolarisStorageConfigurationInfo> optStorageConfiguration =
PolarisStorageConfigurationInfo.forEntityPath(
callContext.getRealmConfig(), resolvedStorageEntity.getRawFullPath());
realmConfig, resolvedStorageEntity.getRawFullPath());

optStorageConfiguration.ifPresentOrElse(
storageConfigInfo -> {
Map<String, Map<PolarisStorageActions, PolarisStorageIntegration.ValidationResult>>
validationResults =
InMemoryStorageIntegration.validateSubpathsOfAllowedLocations(
callContext.getRealmConfig(),
storageConfigInfo,
Set.of(PolarisStorageActions.ALL),
locations);
realmConfig, storageConfigInfo, Set.of(PolarisStorageActions.ALL), locations);
validationResults
.values()
.forEach(
Expand All @@ -1040,9 +1030,7 @@ private void validateLocationsForTableLike(
},
() -> {
List<String> allowedStorageTypes =
callContext
.getRealmConfig()
.getConfig(FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES);
realmConfig.getConfig(FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES);
if (!allowedStorageTypes.contains(StorageConfigInfo.StorageTypeEnum.FILE.name())) {
List<String> invalidLocations =
locations.stream()
Expand All @@ -1068,13 +1056,9 @@ private void validateNoLocationOverlap(
String location,
PolarisEntity entity) {
boolean validateViewOverlap =
callContext
.getRealmConfig()
.getConfig(BehaviorChangeConfiguration.VALIDATE_VIEW_LOCATION_OVERLAP);
realmConfig.getConfig(BehaviorChangeConfiguration.VALIDATE_VIEW_LOCATION_OVERLAP);

if (callContext
.getRealmConfig()
.getConfig(FeatureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP, catalog)) {
if (realmConfig.getConfig(FeatureConfiguration.ALLOW_TABLE_LOCATION_OVERLAP, catalog)) {
LOGGER.debug("Skipping location overlap validation for identifier '{}'", identifier);
} else if (validateViewOverlap
|| entity.getSubType().equals(PolarisEntitySubType.ICEBERG_TABLE)) {
Expand Down Expand Up @@ -1108,7 +1092,7 @@ private <T extends PolarisEntity & LocationBasedEntity> void validateNoLocationO

// Attempt to directly query for siblings
boolean useOptimizedSiblingCheck =
callContext.getRealmConfig().getConfig(FeatureConfiguration.OPTIMIZED_SIBLING_CHECK);
realmConfig.getConfig(FeatureConfiguration.OPTIMIZED_SIBLING_CHECK);
if (useOptimizedSiblingCheck) {
Optional<Optional<String>> directSiblingCheckResult =
getMetaStoreManager().hasOverlappingSiblings(callContext.getPolarisCallContext(), entity);
Expand Down Expand Up @@ -2018,12 +2002,9 @@ protected void refreshFromMetadataLocation(
}

private void validateMetadataFileInTableDir(TableIdentifier identifier, TableMetadata metadata) {
boolean allowEscape =
callContext.getRealmConfig().getConfig(FeatureConfiguration.ALLOW_EXTERNAL_TABLE_LOCATION);
boolean allowEscape = realmConfig.getConfig(FeatureConfiguration.ALLOW_EXTERNAL_TABLE_LOCATION);
if (!allowEscape
&& !callContext
.getRealmConfig()
.getConfig(FeatureConfiguration.ALLOW_EXTERNAL_METADATA_FILE_LOCATION)) {
&& !realmConfig.getConfig(FeatureConfiguration.ALLOW_EXTERNAL_METADATA_FILE_LOCATION)) {
LOGGER.debug(
"Validating base location {} for table {} in metadata file {}",
metadata.location(),
Expand Down Expand Up @@ -2223,7 +2204,7 @@ private void createTableLike(
IcebergTableLikeEntity icebergTableLikeEntity = IcebergTableLikeEntity.of(entity);
// Set / suffix
boolean requireTrailingSlash =
callContext.getRealmConfig().getConfig(FeatureConfiguration.ADD_TRAILING_SLASH_TO_LOCATION);
realmConfig.getConfig(FeatureConfiguration.ADD_TRAILING_SLASH_TO_LOCATION);
if (requireTrailingSlash
&& icebergTableLikeEntity.getBaseLocation() != null
&& !icebergTableLikeEntity.getBaseLocation().endsWith("/")) {
Expand Down Expand Up @@ -2288,7 +2269,7 @@ private void updateTableLike(TableIdentifier identifier, PolarisEntity entity) {

// Set / suffix
boolean requireTrailingSlash =
callContext.getRealmConfig().getConfig(FeatureConfiguration.ADD_TRAILING_SLASH_TO_LOCATION);
realmConfig.getConfig(FeatureConfiguration.ADD_TRAILING_SLASH_TO_LOCATION);
if (requireTrailingSlash
&& icebergTableLikeEntity.getBaseLocation() != null
&& !icebergTableLikeEntity.getBaseLocation().endsWith("/")) {
Expand Down Expand Up @@ -2348,9 +2329,7 @@ private void updateTableLike(TableIdentifier identifier, PolarisEntity entity) {
// Check that purge is enabled, if it is set:
if (catalogPath != null && !catalogPath.isEmpty() && purge) {
boolean dropWithPurgeEnabled =
callContext
.getRealmConfig()
.getConfig(FeatureConfiguration.DROP_WITH_PURGE_ENABLED, catalogEntity);
realmConfig.getConfig(FeatureConfiguration.DROP_WITH_PURGE_ENABLED, catalogEntity);
if (!dropWithPurgeEnabled) {
throw new ForbiddenException(
String.format(
Expand Down Expand Up @@ -2575,8 +2554,6 @@ protected FileIO loadFileIO(String ioImpl, Map<String, String> properties) {
}

private int getMaxMetadataRefreshRetries() {
return callContext
.getRealmConfig()
.getConfig(FeatureConfiguration.MAX_METADATA_REFRESH_RETRIES);
return realmConfig.getConfig(FeatureConfiguration.MAX_METADATA_REFRESH_RETRIES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public class IcebergCatalogAdapter
.build();

private final RealmContext realmContext;
private final CallContext callContext;
private final RealmConfig realmConfig;
private final CallContext callContext;
private final CallContextCatalogFactory catalogFactory;
private final ResolutionManifestFactory resolutionManifestFactory;
private final ResolverFactory resolverFactory;
Expand Down
Loading
Loading