matanper opened a new issue, #69866: URL: https://github.com/apache/doris/issues/69866
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no similar issues. ### Version 4.1.4 (cloud mode). master is the same: `be/src/cloud/cloud_tablet.cpp:677-684`: ```cpp void CloudTablet::add_unused_rowsets(const std::vector<RowsetSharedPtr>& rowsets) { std::lock_guard<std::mutex> lock(_gc_mutex); for (const auto& rowset : rowsets) { _unused_rowsets[rowset->rowset_id()] = rowset; g_unused_rowsets_bytes << rowset->total_disk_size(); } g_unused_rowsets_count << rowsets.size(); } ``` ### Description The `unused_rowsets_count` / `unused_rowsets_bytes` bvars drift above the real number of unused rowsets: 1. `add_unused_rowsets` adds to both bvars for every rowset passed in, even when the rowset is already in `_unused_rowsets` (the map assignment is a no-op), while `remove_unused_rowsets` subtracts each rowset once. 2. When a tablet is dropped from the tablet map while it still has unused rowsets, nothing subtracts them: the destructor does not touch the bvars. So the metrics, which are the natural signal for "rowsets waiting to be vacuumed / pinned by readers", keep growing on long-running BEs and can't be used for alerting. ### Solution - In `add_unused_rowsets`, use `try_emplace` and only count a rowset that was actually inserted; remember the bytes added per rowset and subtract the same amount on removal. - In `~CloudTablet`, subtract the count and bytes of the unused rowsets still held. ### How to Reproduce? Unit test: call `add_unused_rowsets` twice with the same rowset, then `remove_unused_rowsets`: `unused_rowsets_count` stays at 1. Or drop a tablet that has unused rowsets from the cache: the counts never go back down. ### Anything Else? ### Are you willing to submit PR? - [x] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
