[fix](memory) fix BinlogConfigCache leak when tables or databases dro… #60721
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…pped
What problem does this PR solve?
BinlogConfigCache maintains two internal maps (dbTableBinlogEnableMap and tableTypeMap) that cache BinlogConfig and table type info by db/table ID. These caches are populated lazily when binlog-related operations query a table or database for the first time.
However, when a table or database is dropped, BinlogManager.removeTable() and removeDB() only clean up dbBinlogMap (the binlog data itself) but never call binlogConfigCache.remove() to evict the corresponding cache entries.
Since each newly created table gets a globally incrementing ID, dropped table entries are never overwritten — the cache grows without bound.
Reproduction
Run p0 regression tests in a loop (create tables → run tests → DROP all databases). After 12 rounds:
BinlogConfig instances: 32,213 → 158,744 (+392.8%), strictly increasing every round
dbTableBinlogEnableMap accumulated 105,936 entries (backing array expanded to 262,144 slots, retained ~22MB)
Heap dump reference chain:
Env (serving)
→ BinlogManager
→ BinlogConfigCache
→ dbTableBinlogEnableMap (HashMap, 105,936 entries)
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)