This is an automated email from the ASF dual-hosted git repository.
dataroaring 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 5e54970d26e (fix)[db] Fix create database and create table data race
(#44600)
5e54970d26e is described below
commit 5e54970d26eb0db803cfe14b7bac5a831218d8b0
Author: deardeng <[email protected]>
AuthorDate: Wed Nov 27 18:59:49 2024 +0800
(fix)[db] Fix create database and create table data race (#44600)
There may be a race condition between CREATE DATABASE and CREATE TABLE.
When CREATE DATABASE is being executed, the edit log may get stuck,
while fullNameToDb in getDbNullable can still return the database. As a
result, the CREATE TABLE process continues, which may ultimately lead to
a strange order in the edit log of BDBJE, where CREATE TABLE appears
before CREATE DATABASE.
---
.../src/main/java/org/apache/doris/catalog/Database.java | 2 +-
.../java/org/apache/doris/datasource/InternalCatalog.java | 13 +++++++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
index 09e2ae350c5..4f205be0381 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
@@ -93,7 +93,7 @@ public class Database extends MetaObject implements Writable,
DatabaseIf<Table>,
private final Map<Long, Table> idToTable;
private ConcurrentMap<String, Table> nameToTable;
// table name lower case -> table name
- private final Map<String, String> lowerCaseToTableName;
+ private final ConcurrentMap<String, String> lowerCaseToTableName;
// user define function
@SerializedName(value = "name2Function")
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 3a9e96bade6..18f2e333e91 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
@@ -441,8 +441,17 @@ public class InternalCatalog implements
CatalogIf<Database> {
ErrorReport.reportDdlException(ErrorCode.ERR_DB_CREATE_EXISTS, fullDbName);
}
} else {
- unprotectCreateDb(db);
- Env.getCurrentEnv().getEditLog().logCreateDb(db);
+ if (!db.tryWriteLock(100, TimeUnit.SECONDS)) {
+ LOG.warn("try lock failed, create database failed {}",
fullDbName);
+
ErrorReport.reportDdlException(ErrorCode.ERR_EXECUTE_TIMEOUT,
+ "create database " + fullDbName + " time out");
+ }
+ try {
+ unprotectCreateDb(db);
+ Env.getCurrentEnv().getEditLog().logCreateDb(db);
+ } finally {
+ db.writeUnlock();
+ }
}
} finally {
unlock();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]