Skip to content

Commit

Permalink
Remove table listing cache from FileHiveMetastore
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Jan 31, 2025
1 parent 7179f45 commit f735fc8
Showing 1 changed file with 2 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@
package io.trino.plugin.hive.metastore.file;

import com.google.common.base.Splitter;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.errorprone.annotations.ThreadSafe;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import io.airlift.json.JsonCodec;
import io.trino.cache.EvictableCacheBuilder;
import io.trino.filesystem.FileIterator;
import io.trino.filesystem.Location;
import io.trino.filesystem.TrinoFileSystem;
Expand Down Expand Up @@ -128,7 +124,6 @@
import static java.lang.String.format;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;

Expand Down Expand Up @@ -164,9 +159,6 @@ public class FileHiveMetastore
private final JsonCodec<List<String>> rolesCodec = JsonCodec.listJsonCodec(String.class);
private final JsonCodec<List<RoleGrant>> roleGrantsCodec = JsonCodec.listJsonCodec(RoleGrant.class);

// TODO Remove this speed-up workaround once that https://github.com/trinodb/trino/issues/13115 gets implemented
private final LoadingCache<String, List<TableInfo>> listTablesCache;

public FileHiveMetastore(NodeVersion nodeVersion, TrinoFileSystemFactory fileSystemFactory, boolean hideDeltaLakeTables, FileHiveMetastoreConfig config)
{
this.currentVersion = nodeVersion.toString();
Expand All @@ -175,10 +167,6 @@ public FileHiveMetastore(NodeVersion nodeVersion, TrinoFileSystemFactory fileSys
this.catalogDirectory = Location.of(requireNonNull(config.getCatalogDirectory(), "catalogDirectory is null"));
this.disableLocationChecks = config.isDisableLocationChecks();
this.hideDeltaLakeTables = hideDeltaLakeTables;

listTablesCache = EvictableCacheBuilder.newBuilder()
.expireAfterWrite(10, SECONDS)
.build(CacheLoader.from(databaseName -> doListAllTables(databaseName, _ -> true)));
}

@Override
Expand Down Expand Up @@ -227,7 +215,7 @@ public synchronized void dropDatabase(String databaseName, boolean deleteData)
databaseName = databaseName.toLowerCase(ENGLISH);

getRequiredDatabase(databaseName);
if (!listAllTables(databaseName).isEmpty()) {
if (!getTables(databaseName).isEmpty()) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Database " + databaseName + " is not empty");
}

Expand Down Expand Up @@ -524,13 +512,7 @@ public synchronized void updatePartitionStatistics(Table table, StatisticsUpdate
@Override
public synchronized List<TableInfo> getTables(String databaseName)
{
return listAllTables(databaseName);
}

@GuardedBy("this")
private List<TableInfo> listAllTables(String databaseName)
{
return listTablesCache.getUnchecked(databaseName);
return doListAllTables(databaseName, _ -> true);
}

@Override
Expand Down Expand Up @@ -661,9 +643,6 @@ public synchronized void renameTable(String databaseName, String tableName, Stri
catch (IOException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
}
finally {
listTablesCache.invalidateAll();
}
}

@Override
Expand Down Expand Up @@ -1450,9 +1429,6 @@ private <T> void writeFile(String type, Location location, JsonCodec<T> codec, T
catch (Exception e) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not write " + type, e);
}
finally {
listTablesCache.invalidateAll();
}
}

private void renameSchemaFile(SchemaType type, Location oldMetadataDirectory, Location newMetadataDirectory)
Expand All @@ -1463,9 +1439,6 @@ private void renameSchemaFile(SchemaType type, Location oldMetadataDirectory, Lo
catch (IOException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not rename " + type + " schema", e);
}
finally {
listTablesCache.invalidateAll();
}
}

private void deleteSchemaFile(SchemaType type, Location metadataDirectory)
Expand All @@ -1476,9 +1449,6 @@ private void deleteSchemaFile(SchemaType type, Location metadataDirectory)
catch (IOException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not delete " + type + " schema", e);
}
finally {
listTablesCache.invalidateAll();
}
}

private Location getDatabaseMetadataDirectory(String databaseName)
Expand Down

0 comments on commit f735fc8

Please sign in to comment.