From f44608a8c0ac5e0fb511a46499cb435bd9543003 Mon Sep 17 00:00:00 2001 From: woyumen4597 Date: Mon, 22 Mar 2021 09:03:46 +0000 Subject: [PATCH] [SPARK-34800][SQL] Use fine-grained lock in SessionCatalog.tableExists ### What changes were proposed in this pull request? Use fine-grained lock in SessionCatalog.tableExists, in order to lock currentDB variable rather than lock `tableExists` method which will block inner external catalog's behaviour. ### Why are the changes needed? We have modified the underlying hive meta store which a different hive database is placed in its own shard for performance. However, we found that the synchronized lock limits the concurrency. ### How was this patch tested? Existing tests. Closes #31891 from woyumen4597/SPARK-34800. Authored-by: woyumen4597 Signed-off-by: Wenchen Fan --- .../apache/spark/sql/catalyst/catalog/SessionCatalog.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala index 8ad1b12942..41c74bfab4 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala @@ -460,8 +460,8 @@ class SessionCatalog( * Return whether a table/view with the specified name exists. If no database is specified, check * with current database. */ - def tableExists(name: TableIdentifier): Boolean = synchronized { - val db = formatDatabaseName(name.database.getOrElse(currentDb)) + def tableExists(name: TableIdentifier): Boolean = { + val db = formatDatabaseName(name.database.getOrElse(getCurrentDatabase)) val table = formatTableName(name.table) externalCatalog.tableExists(db, table) }