eatmoreduck opened a new pull request, #24299:
URL: https://github.com/apache/kafka/pull/24299

   Fixes KAFKA-21548.
   
   `UnifiedLog` registers its `kafka.log:type=Log` gauges in its constructor, 
and `LogManager#loadLog` constructs a log for every directory it finds at 
startup. For the three untracked outcomes nothing removed those gauges 
afterwards:
   
   - a directory ending with `-stray` ("Loaded stray log"),
   - a log the metadata image flags as stray (renamed to `*-stray`),
   - a directory ending with `-delete` (`addLogToBeDeleted`; 
`UnifiedLog#delete` does not remove metrics either).
   
   The runtime path is clean — `asyncDelete` goes through `removeLogAndMetrics` 
before queueing — so only the startup path leaked. The ticket describes the 
production impact: the leaked gauges keep the `UnifiedLog` reachable for the 
JVM's lifetime, and when the broker also hosts a live replica of the same 
partition, yammer's `newGauge` returns the already-registered gauge, so the 
series can be bound to the stray log instead of the live one (`Size` reported 
the stray directory's size, ~3x the live replica, on 4.3.0).
   
   **Fix**: all three branches remove the gauges. The `-delete` case is handled 
inside `addLogToBeDeleted` — queueing a log for deletion now always drops its 
gauges, which covers the startup entry point and is a harmless idempotent 
second removal on the `asyncDelete` entry point (which already removed them).
   
   **Verification of the ticket's open question**: the reporter suspected the 
`-delete` branch ("I have not verified that one"). It does leak, by the same 
construction — `loadLog` builds the log (gauges registered) and hands it 
straight to `addLogToBeDeleted`, which bypasses `removeLogAndMetrics`. 
`testLoadDeleteDirDoesNotLeaveLogMetrics` pins it.
   
   **Tests** (LogManagerTest): one per branch — a `*-stray` directory found at 
restart, a replica flagged stray at load (asserting the rename and the empty 
metric set), and a `*-delete` directory found at restart. All three fail on 
trunk and pass with the fix.
   


-- 
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]

Reply via email to