This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push: new c4786e8775f branch-3.0: (fix)[db] Fix create database and create table data race #44600 (#44682) c4786e8775f is described below commit c4786e8775f7420d9254a6ed5d919186f515a408 Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> AuthorDate: Thu Nov 28 13:54:30 2024 +0800 branch-3.0: (fix)[db] Fix create database and create table data race #44600 (#44682) Cherry-picked from #44600 Co-authored-by: deardeng <deng...@selectdb.com> --- .../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 2cdd46e6227..5e1782d109a 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 6acc5a871b9..c7877c925db 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: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org