Skip to content

Commit

Permalink
branch-2.1: (fix)[db] Fix create database and create table data race #…
Browse files Browse the repository at this point in the history
…44600 (#44683)

Cherry-picked from #44600

Co-authored-by: deardeng <[email protected]>
  • Loading branch information
github-actions[bot] and deardeng authored Nov 29, 2024
1 parent 22b7c4c commit 9533bd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,17 @@ public void createDb(CreateDbStmt stmt) throws DdlException {
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();
Expand Down

0 comments on commit 9533bd3

Please sign in to comment.