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/14 05:06:16 UTC

[doris] 01/06: [fix](multi-catalog) check new catalog name is used or not before rename (#14891)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 15561cfc9c9aee8c46c6b31b7e65e6ff606724bf
Author: Yulei-Yang <yu...@gmail.com>
AuthorDate: Wed Dec 7 21:54:44 2022 +0800

    [fix](multi-catalog) check new catalog name is used or not before rename (#14891)
---
 .../main/java/org/apache/doris/datasource/CatalogMgr.java    |  3 +++
 .../java/org/apache/doris/datasource/CatalogMgrTest.java     | 12 ++++++++++++
 2 files changed, 15 insertions(+)

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 419bf71f24..e1fbb55062 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
@@ -254,6 +254,9 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
             if (catalog == null) {
                 throw new DdlException("No catalog found with name: " + stmt.getCatalogName());
             }
+            if (nameToCatalog.get(stmt.getNewCatalogName()) != null) {
+                throw new DdlException("Catalog with name " + stmt.getNewCatalogName() + " already exist");
+            }
             CatalogLog log = CatalogFactory.constructorCatalogLog(catalog.getId(), stmt);
             replayAlterCatalogName(log);
             Env.getCurrentEnv().getEditLog().logCatalogLog(OperationType.OP_ALTER_CATALOG_NAME, log);
diff --git a/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java b/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java
index 647d5ee690..7340cd8f18 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/datasource/CatalogMgrTest.java
@@ -36,6 +36,7 @@ import org.apache.doris.catalog.external.HMSExternalDatabase;
 import org.apache.doris.catalog.external.HMSExternalTable;
 import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.Config;
+import org.apache.doris.common.DdlException;
 import org.apache.doris.common.FeConstants;
 import org.apache.doris.mysql.privilege.PaloAuth;
 import org.apache.doris.qe.ConnectContext;
@@ -167,6 +168,17 @@ public class CatalogMgrTest extends TestWithFeService {
         showResultSet = mgr.showCatalogs(showStmt);
         Assertions.assertEquals(1, showResultSet.getResultRows().size());
 
+        String alterCatalogNameFailSql = "ALTER CATALOG hms_catalog RENAME hive;";
+        AlterCatalogNameStmt alterNameFailStmt = (AlterCatalogNameStmt) parseAndAnalyzeStmt(alterCatalogNameFailSql);
+
+        try {
+            mgr.alterCatalogName(alterNameFailStmt);
+            Assert.fail("Catalog with name hive already exist, rename should be failed");
+        } catch (DdlException e) {
+            Assert.assertEquals(e.getMessage(),
+                    "errCode = 2, detailMessage = Catalog with name hive already exist");
+        }
+
         String alterCatalogNameSql = "ALTER CATALOG hms_catalog RENAME " + MY_CATALOG + ";";
         AlterCatalogNameStmt alterNameStmt = (AlterCatalogNameStmt) parseAndAnalyzeStmt(alterCatalogNameSql);
         mgr.alterCatalogName(alterNameStmt);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org