Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
package io.trino.plugin.hive.metastore.file;

import com.google.common.annotations.VisibleForTesting;
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.Sets;
import com.google.common.io.ByteStreams;
import io.airlift.json.JsonCodec;
import io.trino.collect.cache.EvictableCacheBuilder;
import io.trino.hdfs.DynamicHdfsConfiguration;
import io.trino.hdfs.HdfsConfig;
import io.trino.hdfs.HdfsConfiguration;
Expand Down Expand Up @@ -120,6 +123,7 @@
import static io.trino.spi.security.PrincipalType.USER;
import static java.lang.String.format;
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;
import static org.apache.hadoop.hive.common.FileUtils.unescapePathName;
Expand Down Expand Up @@ -159,6 +163,9 @@ 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<String>> listTablesCache;

@VisibleForTesting
public static FileHiveMetastore createTestingFileHiveMetastore(File catalogDirectory)
{
Expand Down Expand Up @@ -189,6 +196,10 @@ public FileHiveMetastore(NodeVersion nodeVersion, HdfsEnvironment hdfsEnvironmen
catch (IOException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, e);
}

listTablesCache = EvictableCacheBuilder.newBuilder()
.expireAfterWrite(10, SECONDS)
.build(CacheLoader.from(this::doListAllTables));
}

@Override
Expand Down Expand Up @@ -511,6 +522,12 @@ public synchronized List<String> getTablesWithParameter(String databaseName, Str

@GuardedBy("this")
private List<String> listAllTables(String databaseName)
{
return listTablesCache.getUnchecked(databaseName);
}

@GuardedBy("this")
private List<String> doListAllTables(String databaseName)
{
requireNonNull(databaseName, "databaseName is null");

Expand Down Expand Up @@ -620,6 +637,9 @@ 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 @@ -1345,6 +1365,9 @@ private <T> void writeFile(String type, Path path, JsonCodec<T> codec, T value,
catch (Exception e) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not write " + type, e);
}
finally {
listTablesCache.invalidateAll();
}
}

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

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

private Path getDatabaseMetadataDirectory(String databaseName)
Expand Down