This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 7ae91a70806 branch-4.2: [fix](fe) Preserve recycled databases when
recovery times out (#70581) (#70805)
7ae91a70806 is described below
commit 7ae91a708068f4670dfb125ff30b31a5fb11187a
Author: linrrarity <[email protected]>
AuthorDate: Sun Nov 22 21:40:29 2026 +0800
branch-4.2: [fix](fe) Preserve recycled databases when recovery times out
(#70581) (#70805)
pick: https://github.com/apache/doris/pull/70581
---
.../apache/doris/datasource/InternalCatalog.java | 66 +++++--------
.../doris/datasource/RecoverDatabaseLockTest.java | 106 +++++++++++++++++++++
2 files changed, 131 insertions(+), 41 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
index b0459567dea..a76f265cede 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
@@ -608,56 +608,40 @@ public class InternalCatalog implements
CatalogIf<Database> {
}
public void recoverDatabase(String dbName, long dbId, String newDbName)
throws DdlException {
- // check is new db with same name already exist
- if (!Strings.isNullOrEmpty(newDbName)) {
- if (getDb(newDbName).isPresent()) {
- throw new DdlException("Database[" + newDbName + "] already
exist.");
- }
- } else {
- if (getDb(dbName).isPresent()) {
- throw new DdlException("Database[" + dbName + "] already
exist.");
- }
- }
-
- Database db = Env.getCurrentRecycleBin().recoverDatabase(dbName, dbId);
-
- // add db to catalog
if (!tryLock(false)) {
throw new DdlException("Failed to acquire catalog lock. Try
again");
}
- db.writeLock();
- List<Table> tableList = db.getTablesOnIdOrder();
- MetaLockUtils.writeLockTables(tableList);
try {
- if (!Strings.isNullOrEmpty(newDbName)) {
- if (fullNameToDb.containsKey(newDbName)) {
- throw new DdlException("Database[" + newDbName + "]
already exist.");
- // it's ok that we do not put db back to CatalogRecycleBin
- // cause this db cannot recover any more
- }
- } else {
- if (fullNameToDb.containsKey(db.getFullName())) {
- throw new DdlException("Database[" + db.getFullName() + "]
already exist.");
- // it's ok that we do not put db back to CatalogRecycleBin
- // cause this db cannot recover any more
- }
+ // check is new db with same name already exist
+ String targetDbName = Strings.isNullOrEmpty(newDbName) ? dbName :
newDbName;
+ if (getDb(targetDbName).isPresent()) {
+ throw new DdlException("Database[" + targetDbName + "] already
exist.");
}
- if (!Strings.isNullOrEmpty(newDbName)) {
- db.setNameWithLock(newDbName);
+
+ Database db = Env.getCurrentRecycleBin().recoverDatabase(dbName,
dbId);
+ db.writeLock();
+ List<Table> tableList = db.getTablesOnIdOrder();
+ MetaLockUtils.writeLockTables(tableList);
+ try {
+ if (!Strings.isNullOrEmpty(newDbName)) {
+ db.setNameWithLock(newDbName);
+ }
+ // add db to catalog
+ fullNameToDb.put(db.getFullName(), db);
+ idToDb.put(db.getId(), db);
+ // log
+ RecoverInfo recoverInfo = new RecoverInfo(db.getId(), -1L,
-1L, newDbName, "", "", "", "");
+ Env.getCurrentEnv().getEditLog().logRecoverDb(recoverInfo);
+ db.unmarkDropped();
+ registerDbFunctionsToNereids(db);
+ } finally {
+ MetaLockUtils.writeUnlockTables(tableList);
+ db.writeUnlock();
}
- fullNameToDb.put(db.getFullName(), db);
- idToDb.put(db.getId(), db);
- // log
- RecoverInfo recoverInfo = new RecoverInfo(db.getId(), -1L, -1L,
newDbName, "", "", "", "");
- Env.getCurrentEnv().getEditLog().logRecoverDb(recoverInfo);
- db.unmarkDropped();
- registerDbFunctionsToNereids(db);
+ LOG.info("recover database[{}]", db.getId());
} finally {
- MetaLockUtils.writeUnlockTables(tableList);
- db.writeUnlock();
unlock();
}
- LOG.info("recover database[{}]", db.getId());
}
public void recoverTable(String dbName, String tableName, String
newTableName, long tableId) throws DdlException {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/RecoverDatabaseLockTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/RecoverDatabaseLockTest.java
new file mode 100644
index 00000000000..3f1a08466f4
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/RecoverDatabaseLockTest.java
@@ -0,0 +1,106 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.datasource;
+
+import org.apache.doris.catalog.CatalogRecycleBin;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.HashDistributionInfo;
+import org.apache.doris.catalog.KeysType;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.SinglePartitionInfo;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.DdlException;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class RecoverDatabaseLockTest {
+ @Test
+ public void testLockTimeoutKeepsDatabaseAndTableInRecycleBin() throws
Exception {
+ InternalCatalog catalog = Env.getCurrentInternalCatalog();
+ CatalogRecycleBin recycleBin = Env.getCurrentRecycleBin();
+ Database db = new Database(9100000L, "recover_catalog_lock_timeout");
+ Column column = new Column("k", Type.INT);
+ OlapTable table = new OlapTable(9100001L, "t",
Collections.singletonList(column), KeysType.DUP_KEYS,
+ new SinglePartitionInfo(),
+ new HashDistributionInfo(1,
Collections.singletonList(column)));
+ Assertions.assertTrue(recycleBin.recycleTable(db.getId(), table,
false, false, 0));
+ Assertions.assertTrue(recycleBin.recycleDatabase(db,
Collections.singleton(table.getName()),
+ Collections.singleton(table.getId()), false, false, 0));
+ long recycleTime = recycleBin.getRecycleTimeById(db.getId());
+ long oldTimeout = Config.catalog_try_lock_timeout_ms;
+ ReentrantLock catalogLock = getCatalogLock(catalog);
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ catalogLock.lock();
+ try {
+ Config.catalog_try_lock_timeout_ms = 50;
+ DdlException error = executor.submit(() ->
Assertions.assertThrows(DdlException.class,
+ () -> catalog.recoverDatabase(db.getFullName(),
db.getId(), "")))
+ .get(5, TimeUnit.SECONDS);
+ Assertions.assertTrue(error.getMessage().contains("Failed to
acquire catalog lock"));
+ Assertions.assertNull(catalog.getDbNullable(db.getId()));
+ Assertions.assertTrue(recycleBin.isRecycleDatabase(db.getId()));
+ Assertions.assertTrue(recycleBin.isRecycleTable(db.getId(),
table.getId()));
+ Assertions.assertEquals(recycleTime,
recycleBin.getRecycleTimeById(db.getId()));
+ Assertions.assertTrue(db.getTables().isEmpty());
+ } finally {
+ Config.catalog_try_lock_timeout_ms = oldTimeout;
+ catalogLock.unlock();
+ executor.shutdownNow();
+ }
+
+ Assertions.assertSame(db, recycleBin.recoverDatabase(db.getFullName(),
db.getId()));
+ Assertions.assertSame(table, db.getTableNullable(table.getId()));
+ Assertions.assertFalse(recycleBin.isRecycleDatabase(db.getId()));
+ Assertions.assertFalse(recycleBin.isRecycleTable(db.getId(),
table.getId()));
+ }
+
+ @Test
+ public void testUnknownDatabaseReleasesCatalogLock() throws Exception {
+ InternalCatalog catalog = Env.getCurrentInternalCatalog();
+ Assertions.assertThrows(DdlException.class,
+ () ->
catalog.recoverDatabase("unknown_recover_catalog_database", -1, ""));
+ ReentrantLock catalogLock = getCatalogLock(catalog);
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ try {
+ executor.submit(() -> {
+ Assertions.assertTrue(catalogLock.tryLock(5,
TimeUnit.SECONDS));
+ catalogLock.unlock();
+ return null;
+ }).get(10, TimeUnit.SECONDS);
+ } finally {
+ executor.shutdownNow();
+ }
+ }
+
+ private ReentrantLock getCatalogLock(InternalCatalog catalog) throws
Exception {
+ Field field = InternalCatalog.class.getDeclaredField("lock");
+ field.setAccessible(true);
+ return (ReentrantLock) field.get(catalog);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]