Skip to content

Commit 9dd47d5

Browse files
authored
Remove PolarisMetaStoreSession from FileIOFactory/FileIOUtil in favor of CallContext (#1057)
This appeared to be some leaky divergence that occurred after CallContext had been removed, but PolarisMetaStoreSession really is only a low-level implementation detail that should never be handled by BasePolarisCatalog/FileIOFactory. This plumbs CallContext explicitly into the FileIOFactory and FileIOUtil methods and thus removes a large source of CallContext.getCurrentContext calls; now the threadlocal doesn't have to be set at all in BasePolarisCatalogTest.
1 parent 9fc0632 commit 9dd47d5

File tree

13 files changed

+33
-50
lines changed

13 files changed

+33
-50
lines changed

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public Map<String, String> getConfigOverrides() {
161161
@Inject PolarisDiagnostics diagServices;
162162

163163
private BasePolarisCatalog catalog;
164+
private CallContext callContext;
164165
private AwsStorageConfigInfo storageConfigModel;
165166
private StsClient stsClient;
166167
private String realmName;
@@ -199,8 +200,7 @@ public void before(TestInfo testInfo) {
199200
new PolarisEntityManager(
200201
metaStoreManager, new StorageCredentialCache(), new EntityCache(metaStoreManager));
201202

202-
CallContext callContext = CallContext.of(realmContext, polarisContext);
203-
CallContext.setCurrentContext(callContext);
203+
callContext = CallContext.of(realmContext, polarisContext);
204204

205205
PrincipalEntity rootEntity =
206206
new PrincipalEntity(
@@ -527,7 +527,7 @@ public void testValidateNotificationFailToCreateFileIO() {
527527
final String tableMetadataLocation = tableLocation + "metadata/";
528528
PolarisPassthroughResolutionView passthroughView =
529529
new PolarisPassthroughResolutionView(
530-
CallContext.getCurrentContext(), entityManager, securityContext, catalog().name());
530+
callContext, entityManager, securityContext, catalog().name());
531531
FileIOFactory fileIOFactory =
532532
spy(
533533
new DefaultFileIOFactory(
@@ -538,7 +538,7 @@ public void testValidateNotificationFailToCreateFileIO() {
538538
new BasePolarisCatalog(
539539
entityManager,
540540
metaStoreManager,
541-
CallContext.getCurrentContext(),
541+
callContext,
542542
passthroughView,
543543
securityContext,
544544
Mockito.mock(TaskExecutor.class),
@@ -854,7 +854,6 @@ public void testUpdateNotificationCreateTableWithLocalFilePrefix() {
854854
.setName(catalogWithoutStorage)
855855
.build());
856856

857-
CallContext callContext = CallContext.getCurrentContext();
858857
PolarisPassthroughResolutionView passthroughView =
859858
new PolarisPassthroughResolutionView(
860859
callContext, entityManager, securityContext, catalogWithoutStorage);
@@ -919,7 +918,6 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() {
919918
.setName(catalogName)
920919
.build());
921920

922-
CallContext callContext = CallContext.getCurrentContext();
923921
PolarisPassthroughResolutionView passthroughView =
924922
new PolarisPassthroughResolutionView(
925923
callContext, entityManager, securityContext, catalogName);
@@ -1434,7 +1432,7 @@ public void testDropTableWithPurge() {
14341432
new RealmEntityManagerFactory(metaStoreManagerFactory),
14351433
metaStoreManagerFactory,
14361434
configurationStore))
1437-
.apply(taskEntity, () -> realmName);
1435+
.apply(taskEntity, callContext);
14381436
Assertions.assertThat(fileIO).isNotNull().isInstanceOf(InMemoryFileIO.class);
14391437
}
14401438

@@ -1461,8 +1459,6 @@ public void testDropTableWithPurgeDisabled() {
14611459
.addProperty(PolarisConfiguration.DROP_WITH_PURGE_ENABLED.catalogConfig(), "false")
14621460
.setStorageConfigurationInfo(noPurgeStorageConfigModel, storageLocation)
14631461
.build());
1464-
RealmContext realmContext = () -> "realm";
1465-
CallContext callContext = CallContext.of(realmContext, polarisContext);
14661462
PolarisPassthroughResolutionView passthroughView =
14671463
new PolarisPassthroughResolutionView(
14681464
callContext, entityManager, securityContext, noPurgeCatalogName);
@@ -1542,9 +1538,6 @@ public void testRetriableException() {
15421538

15431539
@Test
15441540
public void testFileIOWrapper() {
1545-
RealmContext realmContext = () -> "realm";
1546-
CallContext callContext = CallContext.of(realmContext, polarisContext);
1547-
CallContext.setCurrentContext(callContext);
15481541
PolarisPassthroughResolutionView passthroughView =
15491542
new PolarisPassthroughResolutionView(
15501543
callContext, entityManager, securityContext, CATALOG_NAME);
@@ -1600,15 +1593,15 @@ public void testFileIOWrapper() {
16001593
new FileIOFactory() {
16011594
@Override
16021595
public FileIO loadFileIO(
1603-
@NotNull RealmContext realmContext,
1596+
@NotNull CallContext callContext,
16041597
@NotNull String ioImplClassName,
16051598
@NotNull Map<String, String> properties,
16061599
@NotNull TableIdentifier identifier,
16071600
@NotNull Set<String> tableLocations,
16081601
@NotNull Set<PolarisStorageActions> storageActions,
16091602
@NotNull PolarisResolvedPathWrapper resolvedEntityPath) {
16101603
return measured.loadFileIO(
1611-
realmContext,
1604+
callContext,
16121605
"org.apache.iceberg.inmemory.InMemoryFileIO",
16131606
Map.of(),
16141607
TABLE,

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/task/ManifestFileCleanupTaskHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private TaskFileIOSupplier buildTaskFileIOSupplier(FileIO fileIO) {
7676
new FileIOFactory() {
7777
@Override
7878
public FileIO loadFileIO(
79-
@NotNull RealmContext realmContext,
79+
@NotNull CallContext callContext,
8080
@NotNull String ioImplClassName,
8181
@NotNull Map<String, String> properties,
8282
@NotNull TableIdentifier identifier,

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/task/TableCleanupTaskHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private TaskFileIOSupplier buildTaskFileIOSupplier(FileIO fileIO) {
7575
new FileIOFactory() {
7676
@Override
7777
public FileIO loadFileIO(
78-
@Nonnull RealmContext realmContext,
78+
@Nonnull CallContext callContext,
7979
@Nonnull String ioImplClassName,
8080
@Nonnull Map<String, String> properties,
8181
@Nonnull TableIdentifier identifier,

service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,9 @@ public Map<String, String> getCredentialConfig(
836836
return Map.of();
837837
}
838838
return FileIOUtil.refreshCredentials(
839-
callContext.getRealmContext(),
839+
callContext,
840840
entityManager,
841841
getCredentialVendor(),
842-
callContext.getPolarisCallContext().getMetaStore(),
843842
callContext.getPolarisCallContext().getConfigurationStore(),
844843
tableIdentifier,
845844
getLocationsAllowedToBeAccessed(tableMetadata),
@@ -1614,7 +1613,7 @@ private FileIO loadFileIOForTableLike(
16141613
// Reload fileIO based on table specific context
16151614
FileIO fileIO =
16161615
fileIOFactory.loadFileIO(
1617-
callContext.getRealmContext(),
1616+
callContext,
16181617
ioImplClassName,
16191618
tableProperties,
16201619
identifier,
@@ -2077,13 +2076,7 @@ private FileIO loadFileIO(String ioImpl, Map<String, String> properties) {
20772076
new PolarisResolvedPathWrapper(List.of(resolvedCatalogEntity));
20782077
Set<PolarisStorageActions> storageActions = Set.of(PolarisStorageActions.ALL);
20792078
return fileIOFactory.loadFileIO(
2080-
callContext.getRealmContext(),
2081-
ioImpl,
2082-
properties,
2083-
identifier,
2084-
locations,
2085-
storageActions,
2086-
resolvedPath);
2079+
callContext, ioImpl, properties, identifier, locations, storageActions, resolvedPath);
20872080
}
20882081

20892082
private void blockedUserSpecifiedWriteLocation(Map<String, String> properties) {

service/common/src/main/java/org/apache/polaris/service/catalog/io/DefaultFileIOFactory.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.iceberg.catalog.TableIdentifier;
3333
import org.apache.iceberg.io.FileIO;
3434
import org.apache.polaris.core.PolarisConfigurationStore;
35+
import org.apache.polaris.core.context.CallContext;
3536
import org.apache.polaris.core.context.RealmContext;
3637
import org.apache.polaris.core.entity.PolarisEntity;
3738
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
@@ -70,13 +71,14 @@ public DefaultFileIOFactory(
7071

7172
@Override
7273
public FileIO loadFileIO(
73-
@Nonnull RealmContext realmContext,
74+
@Nonnull CallContext callContext,
7475
@Nonnull String ioImplClassName,
7576
@Nonnull Map<String, String> properties,
7677
@Nonnull TableIdentifier identifier,
7778
@Nonnull Set<String> tableLocations,
7879
@Nonnull Set<PolarisStorageActions> storageActions,
7980
@Nonnull PolarisResolvedPathWrapper resolvedEntityPath) {
81+
RealmContext realmContext = callContext.getRealmContext();
8082
PolarisEntityManager entityManager =
8183
realmEntityManagerFactory.getOrCreateEntityManager(realmContext);
8284
PolarisCredentialVendor credentialVendor =
@@ -93,10 +95,9 @@ public FileIO loadFileIO(
9395
.map(
9496
storageInfo ->
9597
FileIOUtil.refreshCredentials(
96-
realmContext,
98+
callContext,
9799
entityManager,
98100
credentialVendor,
99-
metaStoreSession,
100101
configurationStore,
101102
identifier,
102103
tableLocations,

service/common/src/main/java/org/apache/polaris/service/catalog/io/FileIOFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.Set;
2525
import org.apache.iceberg.catalog.TableIdentifier;
2626
import org.apache.iceberg.io.FileIO;
27-
import org.apache.polaris.core.context.RealmContext;
27+
import org.apache.polaris.core.context.CallContext;
2828
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
2929
import org.apache.polaris.core.storage.PolarisStorageActions;
3030

@@ -41,7 +41,7 @@ public interface FileIOFactory {
4141
* <p>This method may obtain subscoped credentials to restrict the FileIO's permissions, ensuring
4242
* secure and limited access to the table's data and locations.
4343
*
44-
* @param realmContext the realm for which the FileIO is being loaded.
44+
* @param callContext the call for which the FileIO is being loaded.
4545
* @param ioImplClassName the class name of the FileIO implementation to load.
4646
* @param properties configuration properties for the FileIO.
4747
* @param identifier the table identifier.
@@ -51,7 +51,7 @@ public interface FileIOFactory {
5151
* @return a configured FileIO instance.
5252
*/
5353
FileIO loadFileIO(
54-
@Nonnull RealmContext realmContext,
54+
@Nonnull CallContext callContext,
5555
@Nonnull String ioImplClassName,
5656
@Nonnull Map<String, String> properties,
5757
@Nonnull TableIdentifier identifier,

service/common/src/main/java/org/apache/polaris/service/catalog/io/FileIOUtil.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
import org.apache.polaris.core.PolarisConfiguration;
2626
import org.apache.polaris.core.PolarisConfigurationStore;
2727
import org.apache.polaris.core.context.CallContext;
28-
import org.apache.polaris.core.context.RealmContext;
2928
import org.apache.polaris.core.entity.PolarisEntity;
3029
import org.apache.polaris.core.entity.PolarisEntityConstants;
3130
import org.apache.polaris.core.persistence.PolarisEntityManager;
32-
import org.apache.polaris.core.persistence.PolarisMetaStoreSession;
3331
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
3432
import org.apache.polaris.core.storage.PolarisCredentialVendor;
3533
import org.apache.polaris.core.storage.PolarisStorageActions;
@@ -78,16 +76,14 @@ public static Optional<PolarisEntity> findStorageInfoFromHierarchy(
7876
* </ul>
7977
*/
8078
public static Map<String, String> refreshCredentials(
81-
RealmContext realmContext,
79+
CallContext callContext,
8280
PolarisEntityManager entityManager,
8381
PolarisCredentialVendor credentialVendor,
84-
PolarisMetaStoreSession metaStoreSession,
8582
PolarisConfigurationStore configurationStore,
8683
TableIdentifier tableIdentifier,
8784
Set<String> tableLocations,
8885
Set<PolarisStorageActions> storageActions,
8986
PolarisEntity entity) {
90-
CallContext callContext = CallContext.getCurrentContext();
9187

9288
boolean skipCredentialSubscopingIndirection =
9389
configurationStore.getConfiguration(

service/common/src/main/java/org/apache/polaris/service/catalog/io/WasbTranslatingFileIOFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.apache.iceberg.catalog.TableIdentifier;
2828
import org.apache.iceberg.io.FileIO;
2929
import org.apache.polaris.core.PolarisConfigurationStore;
30-
import org.apache.polaris.core.context.RealmContext;
30+
import org.apache.polaris.core.context.CallContext;
3131
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
3232
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
3333
import org.apache.polaris.core.storage.PolarisStorageActions;
@@ -52,7 +52,7 @@ public WasbTranslatingFileIOFactory(
5252

5353
@Override
5454
public FileIO loadFileIO(
55-
@Nonnull RealmContext realmContext,
55+
@Nonnull CallContext callContext,
5656
@Nonnull String ioImplClassName,
5757
@Nonnull Map<String, String> properties,
5858
@Nonnull TableIdentifier identifier,
@@ -61,7 +61,7 @@ public FileIO loadFileIO(
6161
@Nonnull PolarisResolvedPathWrapper resolvedEntityPath) {
6262
return new WasbTranslatingFileIO(
6363
defaultFileIOFactory.loadFileIO(
64-
realmContext,
64+
callContext,
6565
ioImplClassName,
6666
properties,
6767
identifier,

service/common/src/main/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public boolean canHandleTask(TaskEntity task) {
7373
public boolean handleTask(TaskEntity task, CallContext callContext) {
7474
ManifestCleanupTask cleanupTask = task.readData(ManifestCleanupTask.class);
7575
TableIdentifier tableId = cleanupTask.getTableId();
76-
try (FileIO authorizedFileIO = fileIOSupplier.apply(task, callContext.getRealmContext())) {
76+
try (FileIO authorizedFileIO = fileIOSupplier.apply(task, callContext)) {
7777
if (task.getTaskType() == AsyncTaskType.MANIFEST_FILE_CLEANUP) {
7878
ManifestFile manifestFile = decodeManifestData(cleanupTask.getManifestFileData());
7979
return cleanUpManifestFile(manifestFile, authorizedFileIO, tableId);

service/common/src/main/java/org/apache/polaris/service/task/TableCleanupTaskHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public boolean handleTask(TaskEntity cleanupTask, CallContext callContext) {
8989
// It's likely the cleanupTask has already been completed, but wasn't dropped successfully.
9090
// Log a
9191
// warning and move on
92-
try (FileIO fileIO = fileIOSupplier.apply(cleanupTask, callContext.getRealmContext())) {
92+
try (FileIO fileIO = fileIOSupplier.apply(cleanupTask, callContext)) {
9393
if (!TaskUtils.exists(tableEntity.getMetadataLocation(), fileIO)) {
9494
LOGGER
9595
.atWarn()

0 commit comments

Comments
 (0)