From ab76e55a251a2af4d9fed6a1962f22d816295604 Mon Sep 17 00:00:00 2001 From: Raunaq Morarka Date: Thu, 24 Oct 2024 10:43:42 +0530 Subject: [PATCH] Reduce synchronization for metadata calls in SemiTransactionalHiveMetastore We don't need to hold lock on SemiTransactionalHiveMetastore object for remote calls which just read metadata. Listing views/tables/databases on metastore can be potentially slow. Holding lock blocks cleanupQuery, which prevents QueryTracker#enforceTimeLimits from failing queries which exceed time limit. --- .../SemiTransactionalHiveMetastore.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/SemiTransactionalHiveMetastore.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/SemiTransactionalHiveMetastore.java index 274641269dcc6..5f4015494c93c 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/SemiTransactionalHiveMetastore.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/SemiTransactionalHiveMetastore.java @@ -238,9 +238,11 @@ public SemiTransactionalHiveMetastore( this.tableInvalidationCallback = requireNonNull(tableInvalidationCallback, "tableInvalidationCallback is null"); } - public synchronized List getAllDatabases() + public List getAllDatabases() { - checkReadable(); + synchronized (this) { + checkReadable(); + } return delegate.getAllDatabases(); } @@ -259,11 +261,13 @@ public synchronized Optional getDatabase(String databaseName) return delegate.getDatabase(databaseName); } - public synchronized List getTables(String databaseName) + public List getTables(String databaseName) { - checkReadable(); - if (!tableActions.isEmpty()) { - throw new UnsupportedOperationException("Listing all tables after adding/dropping/altering tables/views in a transaction is not supported"); + synchronized (this) { + checkReadable(); + if (!tableActions.isEmpty()) { + throw new UnsupportedOperationException("Listing all tables after adding/dropping/altering tables/views in a transaction is not supported"); + } } return delegate.getTables(databaseName); }