-
Notifications
You must be signed in to change notification settings - Fork 368
Allow BasePolarisTableOperations to skip refreshing metadata after a commit #1456
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
Changes from all commits
8fda2da
041a362
c0e1c3e
7921004
a2ed637
15a0eac
a0c7694
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,8 @@ | |
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.Mockito; | ||
| import software.amazon.awssdk.core.exception.NonRetryableException; | ||
| import software.amazon.awssdk.core.exception.RetryableException; | ||
|
|
@@ -1693,8 +1695,8 @@ public void testFileIOWrapper() { | |
|
|
||
| table.updateProperties().set("foo", "bar").commit(); | ||
| Assertions.assertThat(measured.getInputBytes()) | ||
| .as("A table was read and written") | ||
| .isGreaterThan(0); | ||
| .as("A table was read and written, but a trip to storage was made") | ||
| .isEqualTo(0); | ||
|
|
||
| Assertions.assertThat(catalog.dropTable(TABLE)).as("Table deletion should succeed").isTrue(); | ||
| TaskEntity taskEntity = | ||
|
|
@@ -1843,6 +1845,56 @@ public void testConcurrencyConflictUpdateTableDuringFinalTransaction() { | |
| .hasMessageContaining("conflict_table"); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(booleans = {false, true}) | ||
| public void testTableOperationsDoesNotRefreshAfterCommit(boolean updateMetadataOnCommit) { | ||
| Assumptions.assumeTrue( | ||
| requiresNamespaceCreate(), | ||
|
Comment on lines
+1851
to
+1852
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair enough |
||
| "Only applicable if namespaces must be created before adding children"); | ||
|
|
||
| catalog.createNamespace(NS); | ||
| catalog.buildTable(TABLE, SCHEMA).create(); | ||
|
|
||
| IcebergCatalog.BasePolarisTableOperations realOps = | ||
| (IcebergCatalog.BasePolarisTableOperations) | ||
| catalog.newTableOps(TABLE, updateMetadataOnCommit); | ||
| IcebergCatalog.BasePolarisTableOperations ops = Mockito.spy(realOps); | ||
|
|
||
| try (MockedStatic<TableMetadataParser> mocked = | ||
| Mockito.mockStatic(TableMetadataParser.class, Mockito.CALLS_REAL_METHODS)) { | ||
| TableMetadata base1 = ops.current(); | ||
| mocked.verify( | ||
| () -> TableMetadataParser.read(Mockito.any(), Mockito.anyString()), Mockito.times(1)); | ||
|
|
||
| TableMetadata base2 = ops.refresh(); | ||
| mocked.verify( | ||
| () -> TableMetadataParser.read(Mockito.any(), Mockito.anyString()), Mockito.times(1)); | ||
|
|
||
| Assertions.assertThat(base1.metadataFileLocation()).isEqualTo(base2.metadataFileLocation()); | ||
| Assertions.assertThat(base1).isEqualTo(base2); | ||
|
|
||
| Schema newSchema = | ||
| new Schema(Types.NestedField.optional(100, "new_col", Types.LongType.get())); | ||
| TableMetadata newMetadata = | ||
| TableMetadata.buildFrom(base1).setCurrentSchema(newSchema, 100).build(); | ||
| ops.commit(base2, newMetadata); | ||
| mocked.verify( | ||
| () -> TableMetadataParser.read(Mockito.any(), Mockito.anyString()), Mockito.times(1)); | ||
|
|
||
| ops.current(); | ||
| int expectedReads = updateMetadataOnCommit ? 1 : 2; | ||
| mocked.verify( | ||
| () -> TableMetadataParser.read(Mockito.any(), Mockito.anyString()), | ||
| Mockito.times(expectedReads)); | ||
| ops.refresh(); | ||
| mocked.verify( | ||
| () -> TableMetadataParser.read(Mockito.any(), Mockito.anyString()), | ||
| Mockito.times(expectedReads)); | ||
| } finally { | ||
| catalog.dropTable(TABLE, true); | ||
| } | ||
| } | ||
|
|
||
| private static InMemoryFileIO getInMemoryIo(IcebergCatalog catalog) { | ||
| return (InMemoryFileIO) ((ExceptionMappingFileIO) catalog.getIo()).getInnerIo(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -360,9 +360,22 @@ public ViewBuilder buildView(TableIdentifier identifier) { | |
| return new PolarisIcebergCatalogViewBuilder(identifier); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public TableOperations newTableOps( | ||
| TableIdentifier tableIdentifier, boolean makeMetadataCurrentOnCommit) { | ||
| return new BasePolarisTableOperations( | ||
| catalogFileIO, tableIdentifier, makeMetadataCurrentOnCommit); | ||
| } | ||
|
|
||
| @Override | ||
| protected TableOperations newTableOps(TableIdentifier tableIdentifier) { | ||
| return new BasePolarisTableOperations(catalogFileIO, tableIdentifier); | ||
| boolean makeMetadataCurrentOnCommit = | ||
| getCurrentPolarisContext() | ||
| .getConfigurationStore() | ||
| .getConfiguration( | ||
| getCurrentPolarisContext(), | ||
| BehaviorChangeConfiguration.TABLE_OPERATIONS_MAKE_METADATA_CURRENT_ON_COMMIT); | ||
| return newTableOps(tableIdentifier, makeMetadataCurrentOnCommit); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -1207,17 +1220,24 @@ public ViewBuilder withLocation(String newLocation) { | |
| * org.apache.iceberg.BaseMetastoreTableOperations}. CODE_COPIED_TO_POLARIS From Apache Iceberg | ||
| * Version: 1.8 | ||
| */ | ||
| private class BasePolarisTableOperations extends PolarisOperationsBase<TableMetadata> | ||
| @VisibleForTesting | ||
| public class BasePolarisTableOperations extends PolarisOperationsBase<TableMetadata> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we need to make this public?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| implements TableOperations { | ||
| private final TableIdentifier tableIdentifier; | ||
| private final String fullTableName; | ||
| private final boolean makeMetadataCurrentOnCommit; | ||
|
|
||
| private FileIO tableFileIO; | ||
|
|
||
| BasePolarisTableOperations(FileIO defaultFileIO, TableIdentifier tableIdentifier) { | ||
| BasePolarisTableOperations( | ||
| FileIO defaultFileIO, | ||
| TableIdentifier tableIdentifier, | ||
| boolean makeMetadataCurrentOnCommit) { | ||
| LOGGER.debug("new BasePolarisTableOperations for {}", tableIdentifier); | ||
| this.tableIdentifier = tableIdentifier; | ||
| this.fullTableName = fullTableName(catalogName, tableIdentifier); | ||
| this.tableFileIO = defaultFileIO; | ||
| this.makeMetadataCurrentOnCommit = makeMetadataCurrentOnCommit; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -1476,6 +1496,17 @@ public void doCommit(TableMetadata base, TableMetadata metadata) { | |
| + "because it has been concurrently modified to %s", | ||
| tableIdentifier, oldLocation, newLocation, existingLocation); | ||
| } | ||
|
|
||
| // We diverge from `BaseMetastoreTableOperations` in the below code block | ||
| if (makeMetadataCurrentOnCommit) { | ||
| currentMetadata = | ||
| TableMetadata.buildFrom(metadata) | ||
| .withMetadataLocation(newLocation) | ||
| .discardChanges() | ||
| .build(); | ||
| currentMetadataLocation = newLocation; | ||
|
Comment on lines
+1502
to
+1507
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 👍
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great |
||
| } | ||
|
|
||
| if (null == existingLocation) { | ||
| createTableLike(tableIdentifier, entity); | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviving thread incorrectly marked as outdated!
#1456 (comment)