ableegoldman commented on a change in pull request #8833:
URL: https://github.com/apache/kafka/pull/8833#discussion_r439075789
##########
File path:
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java
##########
@@ -504,88 +438,66 @@ public void update(final Set<TopicPartition>
topicPartitions, final Map<String,
@Override
public void closeAndRecycleState() {
- prepareClose(true);
-
+ suspend();
+ prepareCommit();
writeCheckpointIfNeed();
switch (state()) {
case CREATED:
- case RESTORING:
- case RUNNING:
case SUSPENDED:
stateMgr.recycle();
recordCollector.close();
+
break;
+
+ case RESTORING: // we should have transitioned to `SUSPENDED`
already
+ case RUNNING: // we should have transitioned to `SUSPENDED` already
case CLOSED:
throw new IllegalStateException("Illegal state " + state() + "
while recycling active task " + id);
default:
throw new IllegalStateException("Unknown state " + state() + "
while recycling active task " + id);
}
- partitionGroup.close();
+ partitionGroup.clear();
closeTaskSensor.record();
transitionTo(State.CLOSED);
log.info("Closed clean and recycled state");
}
- /**
- * <pre>
- * the following order must be followed:
- * 1. first close topology to make sure all cached records in the
topology are processed
- * 2. then flush the state, send any left changelog records
- * 3. then flush the record collector
- * </pre>
- *
- * @param clean shut down cleanly (ie, incl. flush) if {@code true} --
- * otherwise, just close open resources
- * @throws TaskMigratedException if the task producer got fenced (EOS)
- */
- private void prepareClose(final boolean clean) {
- // Reset any previously scheduled checkpoint.
- checkpoint = null;
-
+ private void maybeScheduleCheckpoint() {
switch (state()) {
- case CREATED:
- // the task is created and not initialized, just re-write the
checkpoint file
- scheduleCheckpoint(emptyMap());
+ case RESTORING:
+ this.checkpoint = checkpointableOffsets();
+
break;
case RUNNING:
- closeTopology(clean);
-
- if (clean) {
- stateMgr.flush();
- recordCollector.flush();
- scheduleCheckpoint(checkpointableOffsets());
- } else {
- executeAndMaybeSwallow(false, stateMgr::flush, "state
manager flush", log);
+ if (!eosEnabled) {
+ this.checkpoint = checkpointableOffsets();
}
break;
- case RESTORING:
- executeAndMaybeSwallow(clean, stateMgr::flush, "state manager
flush", log);
- scheduleCheckpoint(emptyMap());
+ case SUSPENDED:
+ this.checkpoint = checkpointableOffsets();
break;
- case SUSPENDED:
+ case CREATED:
case CLOSED:
- // not need to checkpoint, since when suspending we've already
committed the state
- break;
+ throw new IllegalStateException("Illegal state " + state() + "
while scheduling checkpoint for active task " + id);
default:
- throw new IllegalStateException("Unknown state " + state() + "
while prepare closing active task " + id);
+ throw new IllegalStateException("Unknown state " + state() + "
while scheduling checkpoint for active task " + id);
}
}
- private void scheduleCheckpoint(final Map<TopicPartition, Long>
checkpoint) {
- this.checkpoint = checkpoint;
- }
-
private void writeCheckpointIfNeed() {
+ if (commitNeeded) {
Review comment:
Too late, I already created a ticket for it 🙂 But after starting to work
on it, I agree, they should be addressed in one PR
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]