lucasbru commented on code in PR #23991:
URL: https://github.com/apache/kafka/pull/23991#discussion_r4552697890
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StoreChangelogReaderTest.java:
##########
@@ -388,7 +388,10 @@ public void
shouldInitializeChangelogAndCheckForCompletion(final Task.TaskType t
setupStore();
@SuppressWarnings("unchecked")
final Map<TaskId, Task> mockTasks = mock(Map.class);
- when(mockTasks.get(null)).thenReturn(mock(Task.class));
+ // the reader starts out restoring actives, so it never restores the
standby changelog
Review Comment:
nit: could the STANDBY branch also assert that `standbyListener` got no
calls, so it pins down that the standby isn't touched while actives restore?
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/StoreChangelogReaderCaughtUpOffsetTest.java:
##########
@@ -207,12 +207,151 @@ public void
shouldNotAdvanceStandbyOffsetOnEmptyPollWhileLagIsPositive() throws
assertEquals(StoreChangelogReader.ChangelogState.RESTORING,
reader.changelogMetadata(tp).state());
assertNull(stateManager.storeMetadata(tp).offset());
assertEquals(Collections.singletonMap(tp, 0L),
stateManager.changelogOffsets());
+ assertNull(reader.logicalChangelogEndOffsets().get(tp));
} finally {
stateManager.close();
Utils.delete(stateDir);
}
}
+ @Test
+ public void shouldReportEndOffsetOfStandbyWithNothingToRestore() throws
IOException {
Review Comment:
With beginning == end == 20000 this is really the "everything removed by
retention" case. Could we add one where the standby starts from a checkpoint at
the end of the changelog? That's the "local state already at the end" case from
the description, and it goes through the seek-to-checkpoint path, which none of
the new tests hit.
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StoreChangelogReader.java:
##########
@@ -800,7 +801,11 @@ private void maybeAdvanceStandbyRestoredOffset(final
ProcessorStateManager state
// the next offset to fetch, not last-applied
final OptionalLong lag = restoreConsumer.currentLag(partition);
if (lag.isPresent() && lag.getAsLong() == 0L) {
- stateManager.advanceRestoredOffsetTo(storeMetadata,
restoreConsumer.position(partition, Duration.ZERO));
+ final long position = restoreConsumer.position(partition,
Duration.ZERO);
+ stateManager.advanceRestoredOffsetTo(storeMetadata,
position);
+ // the end offset is otherwise only learned from a
restored batch, which never comes when
+ // there is nothing to restore; like there, it is the last
offset, -1 for an empty changelog
+ storeMetadata.setEndOffset(position - 1L);
Review Comment:
Thanks, agreed that not iterating paused partitions is cleaner than checking
`paused()`, and pausing standbys explicitly while actives restore is a nice fix
on top.
One thing to be clear about though: this covers a standby that gets
registered while actives restore, but not quite the case I described. If the
warm-up already caught up before the reader goes back to restoring actives,
`endOffset` just stays where it was while the partition is paused, so it keeps
reporting lag 0 for the whole active restore. That's the general staleness you
describe, and I agree with your reasoning: promoting a warm-up that was hot is
better than holding it back until the active restore is done. So fine to leave
it, I just wanted to make sure we see it as the accepted trade-off rather than
something the refactor fixes.
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StoreChangelogReader.java:
##########
@@ -479,17 +479,17 @@ public Set<TopicPartition> completedChangelogs() {
.collect(Collectors.toSet());
}
- // Report a conservative value (higher than the real value) as fallback.
- // Only "source topic optimized" changelogs have a logical end offset from
`ChangelogMetadata` (the committed offset on the source topic).
- // If not known (not set yet, or no "source topic optimization"), fall
back to physical end offset.
+ // The end offset of each changelog as the next offset to fetch: the
restore end offset if known (for an active task,
Review Comment:
Could this contract go on the javadoc of
`ChangelogReader#logicalChangelogEndOffsets`? That's what `DefaultStateUpdater`
codes against, and right now it doesn't say whether the value is exclusive or
that null means unknown. Related: the `// Will be updated on batch restored`
comment on `StateStoreMetadata.endOffset` is now outdated, and it would help to
say there that it holds the last offset (-1 for an empty changelog), since the
+1 here relies on that.
--
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]