yuriymalygin commented on PR #24299:
URL: https://github.com/apache/kafka/pull/24299#issuecomment-7108045006
Thanks for picking this up. Unfortunately the fix in this form removes the
gauges of a live replica when one exists for the same partition. This is the
same problem I described in my comment on KAFKA-21548 (the "Suggested fix" in
the ticket description is incorrect for that reason).
`UnifiedLog#removeLogMetrics` removes metrics by name
(`kafka.log:type=Log,name=...,topic=...,partition=...`). Those names are
identical for the stray/to-be-deleted log and for the live replica of the same
partition. When the live replica is registered first, the constructor of the
stray log does not create gauges of its own (Yammer's `newGauge` returns the
already-registered one), so `removeLogMetrics()` on the stray log unregisters
the live replica's gauges. When the stray log is loaded first, the live log
registers its gauges afterwards, so the outcome depends on the order in which
`loadLogs` processes the directories in parallel.
The tests in this PR only cover the case where no live replica exists, so
they do not notice this. I checked it against the PR branch with three
additional tests, each creating a live log first via `getOrCreateLog` and then
calling `loadLog` for the same partition:
- a `*-stray` directory
- a `*-delete` directory
- a directory in another log dir for which `isStray` returns true
All three fail with the live replica's
`LogStartOffset`/`LogEndOffset`/`NumLogSegments`/`Size` gauges missing. The
rest of `LogManagerTest` passes. Patch with the tests (applies on top of this
PR):
```java
@Test
public void testLoadStrayDirKeepsLiveReplicaMetrics() throws IOException {
String testTopic = "test-collide-stray-topic";
TopicPartition tp = new TopicPartition(testTopic, 0);
logManager.getOrCreateLog(tp, Optional.of(Uuid.randomUuid()));
Set<com.yammer.metrics.core.MetricName> before =
logMetricsOfTopic(testTopic);
assertFalse(before.isEmpty());
File strayDir = new File(logDir, UnifiedLog.logStrayDirName(tp));
strayDir.mkdirs();
logManager.loadLog(strayDir, true, Map.of(), Map.of(), LOG_CONFIG,
Map.of(), new ConcurrentHashMap<>(), log -> false);
assertEquals(before, logMetricsOfTopic(testTopic), "live replica metrics
were removed");
}
```
(the `*-delete` and `isStray` variants differ only in the directory name and
the `isStray` predicate).
A second, narrower concern: the extra `removeLogMetrics()` in
`addLogToBeDeleted` also runs on the `asyncDelete` path. If a new log for the
same partition is created between `removeLogAndMetrics` and
`addLogToBeDeleted`, its gauges would be removed as well.
I think a correct fix has to decide whether a log is stray (or
`-delete`/`-stray` by name) before any gauges are registered, e.g. by not
registering them from the `UnifiedLog` constructor and registering only for
logs that end up tracked in `currentLogs`/`futureLogs`. That overlaps with
KAFKA-20567, so it may be worth agreeing on the direction there first.
--
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]