You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/12/08 02:32:37 UTC
[doris] branch master updated: [fix](multi-catalog) use last used database for catalog when switch back (#14793)
This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 27c8147a2b [fix](multi-catalog) use last used database for catalog when switch back (#14793)
27c8147a2b is described below
commit 27c8147a2bbbbb708dbc57dd32b20a1aef76ae04
Author: Yulei-Yang <yu...@gmail.com>
AuthorDate: Thu Dec 8 10:32:30 2022 +0800
[fix](multi-catalog) use last used database for catalog when switch back (#14793)
remember last used database of every catalog and use it when switch back
---
.../src/main/java/org/apache/doris/catalog/Env.java | 9 +++++++++
.../java/org/apache/doris/datasource/CatalogMgr.java | 19 +++++++++++++++++++
.../hive/test_external_catalog_hive.groovy | 19 +++++++++++++++++++
.../hive/test_external_hive.groovy | 1 -
4 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index 7321ddbb51..eb4f6d93ab 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -4410,7 +4410,16 @@ public class Env {
throw new DdlException(ErrorCode.ERR_UNKNOWN_CATALOG.formatErrorMsg(catalogName),
ErrorCode.ERR_UNKNOWN_CATALOG);
}
+
+ String currentDB = ctx.getDatabase();
+ if (StringUtils.isNotEmpty(currentDB)) {
+ catalogMgr.addLastDBOfCatalog(ctx.getCurrentCatalog().getName(), currentDB);
+ }
ctx.changeDefaultCatalog(catalogName);
+ String lastDb = catalogMgr.getLastDB(catalogName);
+ if (StringUtils.isNotEmpty(lastDb)) {
+ ctx.setDatabase(lastDb);
+ }
if (catalogIf instanceof EsExternalCatalog) {
ctx.setDatabase(SystemInfoService.DEFAULT_CLUSTER + ClusterNamespace.CLUSTER_DELIMITER
+ EsExternalCatalog.DEFAULT_DB);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
index 8f959030a3..7071433049 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java
@@ -76,6 +76,8 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
private final Map<Long, CatalogIf> idToCatalog = Maps.newConcurrentMap();
// this map will be regenerated from idToCatalog, so not need to persist.
private final Map<String, CatalogIf> nameToCatalog = Maps.newConcurrentMap();
+ // record last used database of every catalog
+ private final Map<String, String> lastDBOfCatalog = Maps.newConcurrentMap();
// Use a separate instance to facilitate access.
// internalDataSource still exists in idToDataSource and nameToDataSource
@@ -105,6 +107,7 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
if (catalog != null) {
catalog.onClose();
nameToCatalog.remove(catalog.getName());
+ lastDBOfCatalog.remove(catalog.getName());
Env.getCurrentEnv().getExtMetaCacheMgr().removeCache(catalog.getName());
}
return catalog;
@@ -146,6 +149,14 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
ErrorCode.ERR_UNKNOWN_CATALOG));
}
+ public void addLastDBOfCatalog(String catalog, String db) {
+ lastDBOfCatalog.put(catalog, db);
+ }
+
+ public String getLastDB(String catalog) {
+ return lastDBOfCatalog.get(catalog);
+ }
+
public List<Long> getCatalogIds() {
return Lists.newArrayList(idToCatalog.keySet());
}
@@ -241,6 +252,8 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
CatalogLog log = CatalogFactory.constructorCatalogLog(catalog.getId(), stmt);
replayDropCatalog(log);
Env.getCurrentEnv().getEditLog().logCatalogLog(OperationType.OP_DROP_CATALOG, log);
+
+ lastDBOfCatalog.remove(stmt.getCatalogName());
} finally {
writeUnlock();
}
@@ -262,6 +275,12 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
CatalogLog log = CatalogFactory.constructorCatalogLog(catalog.getId(), stmt);
replayAlterCatalogName(log);
Env.getCurrentEnv().getEditLog().logCatalogLog(OperationType.OP_ALTER_CATALOG_NAME, log);
+
+ String db = lastDBOfCatalog.get(stmt.getCatalogName());
+ if (db != null) {
+ lastDBOfCatalog.remove(stmt.getCatalogName());
+ lastDBOfCatalog.put(log.getNewCatalogName(), db);
+ }
} finally {
writeUnlock();
}
diff --git a/regression-test/suites/external_table_emr_p2/hive/test_external_catalog_hive.groovy b/regression-test/suites/external_table_emr_p2/hive/test_external_catalog_hive.groovy
index 7917a1c902..ba25807c51 100644
--- a/regression-test/suites/external_table_emr_p2/hive/test_external_catalog_hive.groovy
+++ b/regression-test/suites/external_table_emr_p2/hive/test_external_catalog_hive.groovy
@@ -89,6 +89,25 @@ suite("test_external_catalog_hive", "p2") {
sql """ use tpch_1000_orc; """
q03()
+
+ // test remember last used database after switch / rename catalog
+ sql """switch ${catalog_name};"""
+
+ sql """use test;"""
+
+ def res2 = sql """select count(*) from hive_test limit 10;"""
+ logger.info("recoding select: " + res2.toString())
+
+ sql """switch internal;"""
+
+ sql """alter catalog ${catalog_name} rename hms;"""
+
+ sql """switch hms;"""
+
+ def res3 = sql """select count(*) from hive_test limit 10;"""
+ logger.info("recoding select: " + res3.toString())
+
+ sql """alter catalog hms rename ${catalog_name};"""
} finally {
// sql """admin set frontend config ("enable_multi_catalog" = "false")"""
}
diff --git a/regression-test/suites/external_table_emr_p2/hive/test_external_hive.groovy b/regression-test/suites/external_table_emr_p2/hive/test_external_hive.groovy
index f80940ecb2..9ac49a0aa4 100644
--- a/regression-test/suites/external_table_emr_p2/hive/test_external_hive.groovy
+++ b/regression-test/suites/external_table_emr_p2/hive/test_external_hive.groovy
@@ -56,4 +56,3 @@ suite("test_external_hive", "p2") {
-
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org