You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2022/03/28 00:00:42 UTC
[iceberg] branch master updated: Core: CachingCatalog.invalidateTable should also invalidate in the wrapped catalog (#4388)
This is an automated email from the ASF dual-hosted git repository.
blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new 74b51ca Core: CachingCatalog.invalidateTable should also invalidate in the wrapped catalog (#4388)
74b51ca is described below
commit 74b51ca2458cc73723f26c8a22df2795c1271544
Author: Samarth Jain <sa...@apache.org>
AuthorDate: Sun Mar 27 17:00:30 2022 -0700
Core: CachingCatalog.invalidateTable should also invalidate in the wrapped catalog (#4388)
---
core/src/main/java/org/apache/iceberg/CachingCatalog.java | 13 +++++--------
.../java/org/apache/iceberg/hadoop/TestCachingCatalog.java | 13 +++++++++++++
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/core/src/main/java/org/apache/iceberg/CachingCatalog.java b/core/src/main/java/org/apache/iceberg/CachingCatalog.java
index 8f78ac0..99ff076 100644
--- a/core/src/main/java/org/apache/iceberg/CachingCatalog.java
+++ b/core/src/main/java/org/apache/iceberg/CachingCatalog.java
@@ -164,22 +164,19 @@ public class CachingCatalog implements Catalog {
@Override
public boolean dropTable(TableIdentifier ident, boolean purge) {
boolean dropped = catalog.dropTable(ident, purge);
- invalidate(ident);
+ invalidateTable(ident);
return dropped;
}
@Override
public void renameTable(TableIdentifier from, TableIdentifier to) {
catalog.renameTable(from, to);
- invalidate(from);
+ invalidateTable(from);
}
@Override
public void invalidateTable(TableIdentifier ident) {
- invalidate(ident);
- }
-
- private void invalidate(TableIdentifier ident) {
+ catalog.invalidateTable(ident);
TableIdentifier canonicalized = canonicalizeIdentifier(ident);
tableCache.invalidate(canonicalized);
tableCache.invalidateAll(metadataTableIdentifiers(canonicalized));
@@ -270,7 +267,7 @@ public class CachingCatalog implements Catalog {
// committed. when the transaction commits, invalidate the table in the cache if it is present.
return CommitCallbackTransaction.addCallback(
innerBuilder.replaceTransaction(),
- () -> invalidate(ident));
+ () -> invalidateTable(ident));
}
@Override
@@ -279,7 +276,7 @@ public class CachingCatalog implements Catalog {
// committed. when the transaction commits, invalidate the table in the cache if it is present.
return CommitCallbackTransaction.addCallback(
innerBuilder.createOrReplaceTransaction(),
- () -> invalidate(ident));
+ () -> invalidateTable(ident));
}
}
}
diff --git a/core/src/test/java/org/apache/iceberg/hadoop/TestCachingCatalog.java b/core/src/test/java/org/apache/iceberg/hadoop/TestCachingCatalog.java
index 55bca6d..7c82369 100644
--- a/core/src/test/java/org/apache/iceberg/hadoop/TestCachingCatalog.java
+++ b/core/src/test/java/org/apache/iceberg/hadoop/TestCachingCatalog.java
@@ -324,6 +324,19 @@ public class TestCachingCatalog extends HadoopTableTestBase {
catalog.isCacheExpirationEnabled());
}
+ @Test
+ public void testInvalidateTableForChainedCachingCatalogs() throws Exception {
+ TestableCachingCatalog wrappedCatalog = TestableCachingCatalog.wrap(hadoopCatalog(), EXPIRATION_TTL, ticker);
+ TestableCachingCatalog catalog = TestableCachingCatalog.wrap(wrappedCatalog, EXPIRATION_TTL, ticker);
+ Namespace namespace = Namespace.of("db", "ns1", "ns2");
+ TableIdentifier tableIdent = TableIdentifier.of(namespace, "tbl");
+ catalog.createTable(tableIdent, SCHEMA, SPEC, ImmutableMap.of("key2", "value2"));
+ Assertions.assertThat(catalog.cache().asMap()).containsKey(tableIdent);
+ catalog.invalidateTable(tableIdent);
+ Assertions.assertThat(catalog.cache().asMap()).doesNotContainKey(tableIdent);
+ Assertions.assertThat(wrappedCatalog.cache().asMap()).doesNotContainKey(tableIdent);
+ }
+
public static TableIdentifier[] metadataTables(TableIdentifier tableIdent) {
return Arrays.stream(MetadataTableType.values())
.map(type -> TableIdentifier.parse(tableIdent + "." + type.name().toLowerCase(Locale.ROOT)))