Skip to content

Commit

Permalink
branch-2.1: [fix](catalog) rebuild idToCatalog map after replay #43772 (
Browse files Browse the repository at this point in the history
#43963)

Cherry-picked from #43772

Co-authored-by: Mingyu Chen (Rayner) <[email protected]>
  • Loading branch information
github-actions[bot] and morningman authored Nov 16, 2024
1 parent 42b190c commit 03eae76
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
private final MonitoredReentrantReadWriteLock lock = new MonitoredReentrantReadWriteLock(true);

@SerializedName(value = "idToCatalog")
private final Map<Long, CatalogIf<? extends DatabaseIf<? extends TableIf>>> idToCatalog = Maps.newConcurrentMap();
private Map<Long, CatalogIf<? extends DatabaseIf<? extends TableIf>>> idToCatalog = Maps.newConcurrentMap();
// this map will be regenerated from idToCatalog, so not need to persist.
private final Map<String, CatalogIf> nameToCatalog = Maps.newConcurrentMap();
private Map<String, CatalogIf> nameToCatalog = Maps.newConcurrentMap();

// Use a separate instance to facilitate access.
// internalDataSource still exists in idToCatalog and nameToCatalog
Expand Down Expand Up @@ -816,10 +816,17 @@ public void write(DataOutput out) throws IOException {

@Override
public void gsonPostProcess() throws IOException {
// After deserializing from Gson, the concurrent map may become a normal map.
// So here we reconstruct the concurrent map.
Map<Long, CatalogIf<? extends DatabaseIf<? extends TableIf>>> newIdToCatalog = Maps.newConcurrentMap();
Map<String, CatalogIf> newNameToCatalog = Maps.newConcurrentMap();
for (CatalogIf catalog : idToCatalog.values()) {
nameToCatalog.put(catalog.getName(), catalog);
newNameToCatalog.put(catalog.getName(), catalog);
newIdToCatalog.put(catalog.getId(), catalog);
// ATTN: can not call catalog.getProperties() here, because ResourceMgr is not replayed yet.
}
this.idToCatalog = newIdToCatalog;
this.nameToCatalog = newNameToCatalog;
internalCatalog = (InternalCatalog) idToCatalog.get(InternalCatalog.INTERNAL_CATALOG_ID);
}

Expand Down

0 comments on commit 03eae76

Please sign in to comment.