abbccdda commented on a change in pull request #8833:
URL: https://github.com/apache/kafka/pull/8833#discussion_r437688409
##########
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:
Review comment:
Could we merge RESTORING and SUSPENDED?
##########
File path:
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamTask.java
##########
@@ -891,6 +821,9 @@ private void initializeTopology() {
}
private void closeTopology(final boolean clean) {
+ if (state() != State.RUNNING) {
Review comment:
Sg, should we move the log on L811 inside the if statement?
##########
File path:
streams/src/test/java/org/apache/kafka/streams/processor/internals/StandbyTaskTest.java
##########
@@ -476,6 +445,26 @@ public void
shouldDeleteStateDirOnTaskCreatedAndEosBetaUncleanClose() {
assertEquals(Task.State.CLOSED, task.state());
}
+ @Test
+ public void shouldRecycleTask() {
+ EasyMock.expectLastCall();
Review comment:
What does this `lastCall` suggest?
##########
File path:
streams/src/main/java/org/apache/kafka/streams/processor/internals/TaskManager.java
##########
@@ -623,7 +618,11 @@ private long sumOfChangelogOffsets(final TaskId id, final
Map<TopicPartition, Lo
}
private void closeTaskDirty(final Task task) {
- task.prepareCloseDirty();
+ try {
+ task.suspend();
+ } catch (final RuntimeException swallow) {
Review comment:
I could get a follow-up newbie ticket, but it seems that we have a
couple of catch and swallow cases in the task manager with `clean` flag, does
it make sense to extract the `executeAndMaybeSwallow` to TaskManager class and
share between cases?
##########
File path:
streams/src/main/java/org/apache/kafka/streams/processor/internals/Task.java
##########
@@ -122,44 +123,23 @@ public boolean isValidTransition(final State newState) {
/**
* @throws StreamsException fatal error, should close the thread
*/
- void prepareCommit();
+ Map<TopicPartition, OffsetAndMetadata> prepareCommit();
Review comment:
add a `@return` comment for the struct
----------------------------------------------------------------
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]