branch-2.1: (fix)[db] Fix create database and create table data race #44600 (#44683)

Cherry-picked from #44600

Co-authored-by: deardeng <dengxin@selectdb.com>
This commit is contained in:
github-actions[bot]
2024-11-29 20:50:10 +08:00
committed by GitHub
parent 22b7c4ca21
commit 9533bd3e8b
2 changed files with 12 additions and 3 deletions

View File

@ -91,7 +91,7 @@ public class Database extends MetaObject implements Writable, DatabaseIf<Table>
@SerializedName(value = "nameToTable")
private Map<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")

View File

@ -432,8 +432,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();