Skip to content
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

Improve test time for testReadMetadataWithRelationsConcurrentModifications in Iceberg #13642

Closed
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.plugin.hive.HdfsConfig;
import io.trino.plugin.hive.HdfsConfiguration;
import io.trino.plugin.hive.HdfsConfigurationInitializer;
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 @@ -156,6 +160,8 @@ public class FileHiveMetastore
private final JsonCodec<List<String>> rolesCodec = JsonCodec.listJsonCodec(String.class);
private final JsonCodec<List<RoleGrant>> roleGrantsCodec = JsonCodec.listJsonCodec(RoleGrant.class);

private final LoadingCache<String,List<String>> listTablesCache;

@VisibleForTesting
public static FileHiveMetastore createTestingFileHiveMetastore(File catalogDirectory)
{
Expand Down Expand Up @@ -186,6 +192,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 @@ -499,6 +509,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 @@ -1333,6 +1349,8 @@ 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);
}

listTablesCache.invalidateAll();
}

private void renameSchemaFile(SchemaType type, Path oldMetadataDirectory, Path newMetadataDirectory)
Expand All @@ -1345,6 +1363,8 @@ private void renameSchemaFile(SchemaType type, Path oldMetadataDirectory, Path n
catch (IOException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not rename " + type + " schema", e);
}

listTablesCache.invalidateAll();
}

private void deleteSchemaFile(SchemaType type, Path metadataDirectory)
Expand All @@ -1357,6 +1377,8 @@ private void deleteSchemaFile(SchemaType type, Path metadataDirectory)
catch (IOException e) {
throw new TrinoException(HIVE_METASTORE_ERROR, "Could not delete " + type + " schema", e);
}

listTablesCache.invalidateAll();
}

private Path getDatabaseMetadataDirectory(String databaseName)
Expand Down