Skip to content

Commit

Permalink
Invalidate partition cache as well when dropping table
Browse files Browse the repository at this point in the history
  • Loading branch information
hackeryang authored and findepi committed Sep 20, 2022
1 parent 22dd82d commit f2b212b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,32 @@ public Map<String, Optional<Partition>> getPartitionsByNames(Table table, List<S
}
}

@Test
public void testDropTable()
{
// make sure the table and partition caches hit
assertEquals(mockClient.getAccessCount(), 0);
Table table = metastore.getTable(TEST_DATABASE, TEST_TABLE).orElseThrow();
assertEquals(mockClient.getAccessCount(), 1);
assertNotNull(metastore.getTable(TEST_DATABASE, TEST_TABLE));
assertEquals(mockClient.getAccessCount(), 1);

assertNotNull(metastore.getPartition(table, TEST_PARTITION_VALUES1));
assertEquals(mockClient.getAccessCount(), 2);
assertNotNull(metastore.getPartition(table, TEST_PARTITION_VALUES1));
assertEquals(mockClient.getAccessCount(), 2);

// the mock table is not really dropped, because it doesn't really exist in hive,
// we just need to go through the cache invalidation logic in the try finally code block
metastore.dropTable(TEST_DATABASE, TEST_TABLE, false);

// pretend that the mock table is recreated, if the cache is invalidated, the access count should increment
assertNotNull(metastore.getTable(TEST_DATABASE, TEST_TABLE));
assertEquals(mockClient.getAccessCount(), 4);
assertNotNull(metastore.getPartition(table, TEST_PARTITION_VALUES1));
assertEquals(mockClient.getAccessCount(), 5);
}

private static void await(CountDownLatch latch, long timeout, TimeUnit unit)
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public void createTable(Table table)
@Override
public void dropTable(String databaseName, String name, boolean deleteData)
{
throw new UnsupportedOperationException();
// No-op, make sure the cache invalidation logic in CachingHiveMetastore will be passed through
}

@Override
Expand Down

0 comments on commit f2b212b

Please sign in to comment.