-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Allow Delta flush_metadata_cache after table creation #17174
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
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 |
|---|---|---|
|
|
@@ -23,8 +23,6 @@ | |
| import io.trino.spi.TrinoException; | ||
| import io.trino.spi.classloader.ThreadContextClassLoader; | ||
| import io.trino.spi.connector.ConnectorSession; | ||
| import io.trino.spi.connector.SchemaTableName; | ||
| import io.trino.spi.connector.TableNotFoundException; | ||
| import io.trino.spi.procedure.Procedure; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
@@ -106,13 +104,16 @@ private void doFlushMetadataCache(ConnectorSession session, Optional<String> sch | |
| } | ||
| else if (schemaName.isPresent() && tableName.isPresent()) { | ||
| HiveMetastore metastore = metastoreFactory.createMetastore(Optional.of(session.getIdentity())); | ||
| Table table = metastore.getTable(schemaName.get(), tableName.get()) | ||
| .orElseThrow(() -> new TableNotFoundException(new SchemaTableName(schemaName.get(), tableName.get()))); | ||
| verifyDeltaLakeTable(table); | ||
| cachingHiveMetastore.ifPresent(caching -> caching.invalidateTable(table.getDatabaseName(), table.getTableName())); | ||
| String tableLocation = getTableLocation(table); | ||
| transactionLogAccess.invalidateCaches(tableLocation); | ||
| extendedStatisticsAccess.invalidateCache(tableLocation); | ||
| // This may insert into a cache, but this will get invalidated below. TODO fix Delta so that flush_metadata_cache doesn't have to read from metastore | ||
| Optional<Table> tableBeforeFlush = metastore.getTable(schemaName.get(), tableName.get()); | ||
| cachingHiveMetastore.ifPresent(caching -> caching.invalidateTable(schemaName.get(), tableName.get())); | ||
|
|
||
| Optional<String> tableLocation = tableBeforeFlush.map(table -> { | ||
| verifyDeltaLakeTable(table); | ||
| return getTableLocation(table); | ||
| }); | ||
| tableLocation.ifPresent(transactionLogAccess::invalidateCaches); | ||
| tableLocation.ifPresent(extendedStatisticsAccess::invalidateCache); | ||
|
Comment on lines
+115
to
+116
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. Maybe the cache key for these should be a
Member
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. yes, i think so
Member
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. i added
Member
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. -> #17214 |
||
| } | ||
| else { | ||
| throw new TrinoException(INVALID_PROCEDURE_ARGUMENT, "Illegal parameter set passed"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,8 @@ | |||||
| import static io.trino.plugin.deltalake.DeltaLakeQueryRunner.createS3DeltaLakeQueryRunner; | ||||||
| import static io.trino.plugin.hive.TestingThriftHiveMetastoreBuilder.testingThriftHiveMetastoreBuilder; | ||||||
| import static io.trino.plugin.hive.containers.HiveHadoop.HIVE3_IMAGE; | ||||||
| import static io.trino.testing.TestingNames.randomNameSuffix; | ||||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||||
|
|
||||||
| public class TestDeltaLakeFlushMetadataCacheProcedure | ||||||
| extends AbstractTestQueryFramework | ||||||
|
|
@@ -105,10 +107,34 @@ public void testFlushMetadataCache() | |||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| public void testFlushMetadataCacheTableNotFound() | ||||||
| public void testFlushMetadataCacheAfterTableCreated() | ||||||
| { | ||||||
| assertQueryFails( | ||||||
| "CALL system.flush_metadata_cache(schema_name => 'test_not_existing_schema', table_name => 'test_not_existing_table')", | ||||||
| "Table 'test_not_existing_schema.test_not_existing_table' not found"); | ||||||
| String schema = getSession().getSchema().orElseThrow(); | ||||||
| String tableName = "flush_metadata_after_table_created"; | ||||||
| String intermediateTableName = "test_flush_intermediate_" + randomNameSuffix(); | ||||||
|
|
||||||
| String location = "s3://%s/%s".formatted(BUCKET_NAME, intermediateTableName); | ||||||
| assertUpdate("CREATE TABLE " + intermediateTableName + " WITH (location = '" + location + "') AS TABLE tpch.tiny.region", 5); | ||||||
|
|
||||||
| // This may cause the connector to cache the fact that the table does not exist | ||||||
| assertQueryFails("TABLE " + tableName, "\\Qline 1:1: Table 'delta_lake.default.flush_metadata_after_table_created' does not exist"); | ||||||
|
|
||||||
| metastore.renameTable(schema, intermediateTableName, schema, tableName); | ||||||
|
|
||||||
| // Verify cached state (we currently cache missing objects in CachingMetastore) | ||||||
| assertQueryFails("TABLE " + tableName, "\\Qline 1:1: Table 'delta_lake.default.flush_metadata_after_table_created' does not exist"); | ||||||
|
|
||||||
| assertUpdate("CALL system.flush_metadata_cache(schema_name => CURRENT_SCHEMA, table_name => '" + tableName + "')"); | ||||||
| assertThat(query("TABLE " + tableName)) | ||||||
| .skippingTypesCheck() // Delta has no parametric varchar | ||||||
| .matches("TABLE tpch.tiny.region"); | ||||||
|
|
||||||
| assertUpdate("DROP TABLE flush_metadata_after_table_created"); | ||||||
|
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. nit:
Suggested change
Member
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. missed this one. will resolve in #17214 |
||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| public void testFlushMetadataCacheNonExistentTable() | ||||||
| { | ||||||
| assertUpdate("CALL system.flush_metadata_cache(schema_name => 'test_not_existing_schema', table_name => 'test_not_existing_table')"); | ||||||
| } | ||||||
| } | ||||||
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.
Does
invalidateTablethrow something if you call it with a schema/table that isn't cached? Seems like we should be able to just call it blindly without callinggetTablefirst.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.
it does not
we call getTable to know the location (pre-existing)
we invalidate after calling, so that the cache is empty in the end state.