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

   `UnifiedLog` registers its `kafka.log:type=Log` gauges at the end of its 
constructor, and `LogManager#loadLog` constructs a log for every directory it 
finds at startup. Three outcomes of `loadLog` do not track the log: a directory 
ending with `-stray`, a log flagged stray by the metadata image (renamed to 
`*-stray`), and a directory ending with `-delete`. Nothing removed the gauges 
of those logs afterwards, so they stayed registered for the lifetime of the 
JVM, keeping the `UnifiedLog` reachable.
   
   The gauge names contain only the topic partition. When the broker also hosts 
a live replica of the same partition, `newGauge` returns the gauge that is 
already registered, so the series can be bound to the stray log. Calling 
`removeLogMetrics()` on the dropped log is not a fix: it removes by name and 
therefore also unregisters the live replica's gauges, depending on the order in 
which `loadLogs` processes the directories.
   
   This is an alternative to #24299, which removes the gauges of the dropped 
log; see the discussion there for why that breaks a live replica. This change 
defers the registration instead of undoing it:
   
   - `UnifiedLog` gets a constructor and a `create` overload with 
`registerMetrics`. The existing signatures delegate with `true`, so all other 
callers are unchanged.
   - `LogManager#loadLog` creates the log without registering and calls 
`newMetrics()` only in the branch that tracks the log in 
`currentLogs`/`futureLogs`, after the duplicate check. A log that is dropped 
never registers anything, so there is nothing to collide with and nothing to 
clean up (`removeLogMetrics()` stays a no-op for it). The runtime path 
(`asyncDelete` through `removeLogAndMetrics`) is untouched.
   
   Tests (`LogManagerTest`):
   
   - no gauges are registered for a `*-stray` directory, a replica flagged 
stray at load (also asserting the rename), and a `*-delete` directory. These 
three fail on trunk.
   - a live replica's gauges are unchanged after loading a `*-stray` directory, 
a `*-delete` directory, or a same-partition replica from another log dir that 
is flagged stray. These guard against the "remove gauges of the dropped log" 
approach.
   - gauges are still registered for a tracked log loaded through `loadLog`.
   
   This is independent of KAFKA-20567 (skipping `UnifiedLog` creation for stray 
replicas): that would avoid the leak for the metadata-flagged case, while the 
`-stray`/`-delete` directory cases are still decided by name after the log is 
built.
   


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