-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-10097: Internalize checkpoint data #8820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,6 +107,8 @@ public class StreamTask extends AbstractTask implements ProcessorNodePunctuator, | |
| private boolean commitNeeded = false; | ||
| private boolean commitRequested = false; | ||
|
|
||
| private Map<TopicPartition, Long> checkpoint = null; | ||
|
|
||
| public StreamTask(final TaskId id, | ||
| final Set<TopicPartition> partitions, | ||
| final ProcessorTopology topology, | ||
|
|
@@ -465,17 +467,15 @@ private Map<TopicPartition, Long> extractPartitionTimes() { | |
| } | ||
|
|
||
| @Override | ||
| public Map<TopicPartition, Long> prepareCloseClean() { | ||
| final Map<TopicPartition, Long> checkpoint = prepareClose(true); | ||
| public void prepareCloseClean() { | ||
| prepareClose(true); | ||
|
|
||
| log.info("Prepared clean close"); | ||
|
|
||
| return checkpoint; | ||
| } | ||
|
|
||
| @Override | ||
| public void closeClean(final Map<TopicPartition, Long> checkpoint) { | ||
| close(true, checkpoint); | ||
| public void closeClean() { | ||
| close(true); | ||
|
|
||
| log.info("Closed clean"); | ||
| } | ||
|
|
@@ -489,7 +489,8 @@ public void prepareCloseDirty() { | |
|
|
||
| @Override | ||
| public void closeDirty() { | ||
| close(false, null); | ||
|
|
||
| close(false); | ||
|
|
||
| log.info("Closed dirty"); | ||
| } | ||
|
|
@@ -505,11 +506,10 @@ public void update(final Set<TopicPartition> topicPartitions, final ProcessorTop | |
|
|
||
| @Override | ||
| public void closeAndRecycleState() { | ||
| final Map<TopicPartition, Long> checkpoint = prepareClose(true); | ||
| prepareClose(true); | ||
|
|
||
| writeCheckpointIfNeed(); | ||
|
|
||
| if (checkpoint != null) { | ||
| stateMgr.checkpoint(checkpoint); | ||
| } | ||
| switch (state()) { | ||
| case CREATED: | ||
| case RUNNING: | ||
|
|
@@ -546,14 +546,14 @@ public void closeAndRecycleState() { | |
| * otherwise, just close open resources | ||
| * @throws TaskMigratedException if the task producer got fenced (EOS) | ||
| */ | ||
| private Map<TopicPartition, Long> prepareClose(final boolean clean) { | ||
| final Map<TopicPartition, Long> checkpoint; | ||
| private void prepareClose(final boolean clean) { | ||
| // Reset any previously scheduled checkpoint. | ||
| checkpoint = null; | ||
|
|
||
| switch (state()) { | ||
| case CREATED: | ||
| // the task is created and not initialized, just re-write the checkpoint file | ||
| checkpoint = Collections.emptyMap(); | ||
|
|
||
| scheduleCheckpoint(emptyMap()); | ||
| break; | ||
|
|
||
| case RUNNING: | ||
|
|
@@ -562,32 +562,38 @@ private Map<TopicPartition, Long> prepareClose(final boolean clean) { | |
| if (clean) { | ||
| stateMgr.flush(); | ||
| recordCollector.flush(); | ||
| checkpoint = checkpointableOffsets(); | ||
| scheduleCheckpoint(checkpointableOffsets()); | ||
| } else { | ||
| checkpoint = null; // `null` indicates to not write a checkpoint | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to set |
||
| executeAndMaybeSwallow(false, stateMgr::flush, "state manager flush", log); | ||
| } | ||
|
|
||
| break; | ||
|
|
||
| case RESTORING: | ||
| executeAndMaybeSwallow(clean, stateMgr::flush, "state manager flush", log); | ||
| checkpoint = Collections.emptyMap(); | ||
| scheduleCheckpoint(emptyMap()); | ||
|
|
||
| break; | ||
|
|
||
| case SUSPENDED: | ||
| case CLOSED: | ||
| // not need to checkpoint, since when suspending we've already committed the state | ||
| checkpoint = null; // `null` indicates to not write a checkpoint | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above? |
||
|
|
||
| break; | ||
|
|
||
| default: | ||
| throw new IllegalStateException("Unknown state " + state() + " while prepare closing active task " + id); | ||
| } | ||
| } | ||
|
|
||
| private void scheduleCheckpoint(final Map<TopicPartition, Long> checkpoint) { | ||
| this.checkpoint = checkpoint; | ||
| } | ||
|
|
||
| return checkpoint; | ||
| private void writeCheckpointIfNeed() { | ||
| if (checkpoint != null) { | ||
| stateMgr.checkpoint(checkpoint); | ||
| checkpoint = null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -598,9 +604,9 @@ private Map<TopicPartition, Long> prepareClose(final boolean clean) { | |
| * 3. finally release the state manager lock | ||
| * </pre> | ||
| */ | ||
| private void close(final boolean clean, final Map<TopicPartition, Long> checkpoint) { | ||
| if (clean && checkpoint != null) { | ||
| executeAndMaybeSwallow(clean, () -> stateMgr.checkpoint(checkpoint), "state manager checkpoint", log); | ||
| private void close(final boolean clean) { | ||
| if (clean) { | ||
| executeAndMaybeSwallow(true, this::writeCheckpointIfNeed, "state manager checkpoint", log); | ||
| } | ||
|
|
||
| switch (state()) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could just reset any checkpoint at the beginning, so that we only do checkpointing if this call thinks so. @mjsax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should work.