Skip to content

Commit

Permalink
sync with database drop
Browse files Browse the repository at this point in the history
  • Loading branch information
zclllyybb committed Dec 25, 2024
1 parent a77e390 commit 79752fc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,14 @@ public void dropDb(DropDbStmt stmt) throws DdlException {

Env.getCurrentRecycleBin().recycleDatabase(db, tableNames, tableIds, false, stmt.isForceDrop(), 0);
recycleTime = Env.getCurrentRecycleBin().getRecycleTimeById(db.getId());

// 3. drop db dictionaries
Env.getCurrentEnv().getDictionaryManager().dropDbDictionaries(dbName);
} finally {
db.writeUnlock();
}

// 3. remove db from catalog
// 4. remove db from catalog
idToDb.remove(db.getId());
fullNameToDb.remove(db.getFullName());
DropDbInfo info = new DropDbInfo(dbName, stmt.isForceDrop(), recycleTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,25 @@ public void dropDictionary(String dbName, String dictName, boolean ifExists) thr
}
}

/**
* Drop all dictionaries in a database. Used when dropping a database.
*/
public void dropDbDictionaries(String dbName) {
lockWrite();
try {
// pop and save item from dictionaries
Map<String, Dictionary> dbDictionaries = dictionaries.remove(dbName);
// Log the drop operation
if (dbDictionaries != null) {
for (Map.Entry<String, Dictionary> entry : dbDictionaries.entrySet()) {
Env.getCurrentEnv().getEditLog().logDropDictionary(dbName, entry.getKey());
}
}
} finally {
unlockWrite();
}
}

/**
* Check if a dictionary exists.
*/
Expand Down Expand Up @@ -211,6 +230,10 @@ public void replayCreateDictionary(CreateDictionaryPersistInfo info) {
// Add to dictionaries map
Map<String, Dictionary> dbDictionaries = dictionaries.computeIfAbsent(dictionary.getDbName(),
k -> Maps.newConcurrentMap());
if (dbDictionaries.containsKey(dictionary.getName())) {
LOG.warn("Dictionary {} already exists when replaying create dictionary", dictionary.getName());
return;
}
dbDictionaries.put(dictionary.getName(), dictionary);
uniqueId = Math.max(uniqueId, dictionary.getId());
} finally {
Expand All @@ -227,6 +250,8 @@ public void replayDropDictionary(DropDictionaryPersistInfo info) {
if (dbDictionaries.isEmpty()) {
dictionaries.remove(info.getDbName());
}
} else {
LOG.warn("Database {} does not exist when replaying drop dictionary", info.getDbName());
}
} finally {
unlockWrite();
Expand Down

0 comments on commit 79752fc

Please sign in to comment.