Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
37b5c63
first version
guozhangwang Sep 6, 2019
4a34116
add unit tests
guozhangwang Sep 7, 2019
d964cea
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Sep 10, 2019
f5b8f96
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Sep 11, 2019
b07bac2
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Sep 12, 2019
29f8942
fix unit tests
guozhangwang Sep 12, 2019
3000d6f
add RebalanceInProgressException
guozhangwang Sep 13, 2019
8464fa7
rebase from trunk
guozhangwang Sep 17, 2019
f804b3d
refactor unit tests
guozhangwang Sep 17, 2019
3c62029
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Sep 17, 2019
284ef77
poll with 1ms than 0ms for discover coordinator
guozhangwang Sep 18, 2019
9825063
refactor the newly added test with auto-tick 1ms
guozhangwang Sep 18, 2019
929048a
rebase from trunk
guozhangwang Oct 21, 2019
58adc09
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Oct 22, 2019
c79a93d
fix unit tests
guozhangwang Oct 22, 2019
75c4e88
rebase from trunk again
guozhangwang Oct 22, 2019
95ef3fb
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Oct 27, 2019
3b844ff
use RetriableCommitFailedException
guozhangwang Oct 27, 2019
781514d
unit tests
guozhangwang Oct 27, 2019
8b08a3e
handle retrialbe commit failed in streams
guozhangwang Oct 27, 2019
8fa5d74
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Oct 29, 2019
d75fcb9
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Oct 29, 2019
b176e4e
fix unit tests
guozhangwang Oct 29, 2019
7a826f9
remove imports
guozhangwang Oct 29, 2019
31e372e
fix a real bug exposed by flaky test
guozhangwang Oct 30, 2019
366739b
remove debugging info
guozhangwang Oct 30, 2019
faf787e
minor fix on CommitFailed class
guozhangwang Oct 30, 2019
c71af82
rebase from trunk
guozhangwang Nov 8, 2019
ffe6146
more java doc
guozhangwang Nov 8, 2019
518049c
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Dec 11, 2019
30d5e53
address comments
guozhangwang Dec 12, 2019
fa3456d
address comments
guozhangwang Dec 24, 2019
0220d96
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Jan 2, 2020
27d013a
address comment
guozhangwang Jan 2, 2020
94611cc
do not reset if generation has changed
guozhangwang Jan 2, 2020
b529847
remove restrictive check on commit
guozhangwang Jan 3, 2020
33fd785
check assignment
guozhangwang Jan 3, 2020
1df9808
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Jan 3, 2020
3057405
more comments
guozhangwang Jan 3, 2020
21f531d
remember the fatal exception and throw
guozhangwang Jan 4, 2020
effb29d
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Jan 6, 2020
6fbd976
comments
guozhangwang Jan 6, 2020
f4e7111
Merge branch 'trunk' of https://github.com/apache/kafka into K8421-re…
guozhangwang Jan 8, 2020
91b6606
move back to RebalanceInProgressException
guozhangwang Jan 8, 2020
0ad52ec
address comments
guozhangwang Jan 9, 2020
27f76b7
rebase from trunk
guozhangwang Jan 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1333,13 +1333,12 @@ private Map<TopicPartition, List<ConsumerRecord<K, V>>> pollForFetches(Timer tim
* or if there is an active group with the same <code>group.id</code> which is using group management. In such cases,
* when you are trying to commit to partitions that are no longer assigned to this consumer because the
* consumer is for example no longer part of the group this exception would be thrown.
* @throws org.apache.kafka.common.errors.RebalanceInProgressException if the commit failed but can be retried.
* This can occur if, e.g. consumer instance is in the middle of a rebalance so it is not yet determined
* which partitions would be assigned to the consumer yet. In such cases you can first complete the rebalance
* by calling {@link #poll(Duration)} and retry committing offsets again. NOTE when you retry after the
* rebalance the assigned partitions may have changed, and also for those partitions that are still assigned
* their fetch positions may have changed too if more records are returned from the {@link #poll(Duration)}
* call, so when you retry committing only those assigned partitions would be committed with the current positions.
* @throws org.apache.kafka.common.errors.RebalanceInProgressException if the consumer instance is in the middle of a rebalance
* so it is not yet determined which partitions would be assigned to the consumer. In such cases you can first
* complete the rebalance by calling {@link #poll(Duration)} and commit can be reconsidered afterwards.
* NOTE when you reconsider committing after the rebalance, the assigned partitions may have changed,
* and also for those partitions that are still assigned their fetch positions may have changed too
* if more records are returned from the {@link #poll(Duration)} call.
* @throws org.apache.kafka.common.errors.WakeupException if {@link #wakeup()} is called before or while this
* function is called
* @throws org.apache.kafka.common.errors.InterruptException if the calling thread is interrupted before or while
Expand Down Expand Up @@ -1377,13 +1376,12 @@ public void commitSync() {
* or if there is an active group with the same <code>group.id</code> which is using group management. In such cases,
* when you are trying to commit to partitions that are no longer assigned to this consumer because the
* consumer is for example no longer part of the group this exception would be thrown.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little self-contradictory... The next throws declaration says that if I'm not in the group, I can call poll to rejoin and retry the commit. But this javadoc seems to suggest that if I get the CommitFailedException, I can definitely not retry the commit. Should it instead just simply say that I'm trying to commit partitions that I no longer own? I.e., that I am an active member of the group (because I have assigned partitions), but I don't own some of the partitions I'm trying to commit offsets on?

Also, what happens if I do still own some other partitions? How can I know whether or not those got committed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you try to commit and it fails because you no longer own some (or any) partitions because a rebalance just occurred, that's retriable. If you dropped out of the group and for that reason do not own those (or any) partitions, that's not retriable.
@guozhangwang I do agree that we could clarify the wording a bit: in particular, it seems to matter explicitly why the consumer no longer owns those partitions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I've reworded the statement a bit.

* @throws org.apache.kafka.common.errors.RebalanceInProgressException if the commit failed because
* it is in the middle of a rebalance so it is not yet determined
* which partitions would be assigned to the consumer yet. In such cases you can first complete the rebalance
* by calling {@link #poll(Duration)} and retry committing offsets again. NOTE when you retry after the
* rebalance the assigned partitions may have changed, and also for those partitions that are still assigned
* their fetch positions may have changed too if more records are returned from the {@link #poll(Duration)}
* call, so when you retry committing only those assigned partitions would be committed with the current positions.
* @throws org.apache.kafka.common.errors.RebalanceInProgressException if the consumer instance is in the middle of a rebalance
* so it is not yet determined which partitions would be assigned to the consumer. In such cases you can first
* complete the rebalance by calling {@link #poll(Duration)} and commit can be reconsidered afterwards.
* NOTE when you reconsider committing after the rebalance, the assigned partitions may have changed,
* and also for those partitions that are still assigned their fetch positions may have changed too
* if more records are returned from the {@link #poll(Duration)} call.
* @throws org.apache.kafka.common.errors.WakeupException if {@link #wakeup()} is called before or while this
* function is called
* @throws org.apache.kafka.common.errors.InterruptException if the calling thread is interrupted before or while
Expand Down Expand Up @@ -1433,14 +1431,13 @@ public void commitSync(Duration timeout) {
* or if there is an active group with the same <code>group.id</code> which is using group management. In such cases,
* when you are trying to commit to partitions that are no longer assigned to this consumer because the
* consumer is for example no longer part of the group this exception would be thrown.
* @throws org.apache.kafka.common.errors.RebalanceInProgressException if the commit failed because
* it is in the middle of a rebalance so it is not yet determined
* which partitions would be assigned to the consumer yet. In such cases you can first complete the rebalance
* by calling {@link #poll(Duration)} and retry committing offsets again. NOTE when you retry after the
* rebalance the assigned partitions may have changed, and also for those partitions that are still assigned
* their fetch positions may also have changed too if more records are returned from the {@link #poll(Duration)}
* call, so when you retry committing you should include only those assigned partitions after the rebalance
* with the current fetch position; otherwise a fatal {@link CommitFailedException} will be thrown.
* @throws org.apache.kafka.common.errors.RebalanceInProgressException if the consumer instance is in the middle of a rebalance
* so it is not yet determined which partitions would be assigned to the consumer. In such cases you can first
* complete the rebalance by calling {@link #poll(Duration)} and commit can be reconsidered afterwards.
* NOTE when you reconsider committing after the rebalance, the assigned partitions may have changed,
* and also for those partitions that are still assigned their fetch positions may have changed too
* if more records are returned from the {@link #poll(Duration)} call, so when you retry committing
* you should consider updating the passed in {@code offset} parameter.
* @throws org.apache.kafka.common.errors.WakeupException if {@link #wakeup()} is called before or while this
* function is called
* @throws org.apache.kafka.common.errors.InterruptException if the calling thread is interrupted before or while
Expand Down Expand Up @@ -1482,14 +1479,13 @@ public void commitSync(final Map<TopicPartition, OffsetAndMetadata> offsets) {
* or if there is an active group with the same <code>group.id</code> which is using group management. In such cases,
* when you are trying to commit to partitions that are no longer assigned to this consumer because the
* consumer is for example no longer part of the group this exception would be thrown.
* @throws org.apache.kafka.common.errors.RebalanceInProgressException if the commit failed because
* it is in the middle of a rebalance so it is not yet determined
* which partitions would be assigned to the consumer yet. In such cases you can first complete the rebalance
* by calling {@link #poll(Duration)} and retry committing offsets again. NOTE when you retry after the
* rebalance the assigned partitions may have changed, and also for those partitions that are still assigned
* their fetch positions may also have changed too if more records are returned from the {@link #poll(Duration)}
* call, so when you retry committing you should include only those assigned partitions after the rebalance
* with the current fetch position; otherwise a fatal {@link CommitFailedException} will be thrown.
* @throws org.apache.kafka.common.errors.RebalanceInProgressException if the consumer instance is in the middle of a rebalance
* so it is not yet determined which partitions would be assigned to the consumer. In such cases you can first
* complete the rebalance by calling {@link #poll(Duration)} and commit can be reconsidered afterwards.
* NOTE when you reconsider committing after the rebalance, the assigned partitions may have changed,
* and also for those partitions that are still assigned their fetch positions may have changed too
* if more records are returned from the {@link #poll(Duration)} call, so when you retry committing
* you should consider updating the passed in {@code offset} parameter.
* @throws org.apache.kafka.common.errors.WakeupException if {@link #wakeup()} is called before or while this
* function is called
* @throws org.apache.kafka.common.errors.InterruptException if the calling thread is interrupted before or while
Expand Down Expand Up @@ -1582,9 +1578,6 @@ public void commitAsync(final Map<TopicPartition, OffsetAndMetadata> offsets, Of
log.debug("Committing offsets: {}", offsets);
offsets.forEach(this::updateLastSeenEpochIfNewer);
coordinator.commitOffsetsAsync(new HashMap<>(offsets), callback);
} catch (CommitFailedException e) {
log.error("Failed to commit offsets asynchronously because they do not belong to dynamically assigned partitions");
callback.onComplete(offsets, e);
} finally {
release();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,22 @@ public class RetriableCommitFailedException extends RetriableException {

private static final long serialVersionUID = 1L;

public static RetriableCommitFailedException withUnderlyingMessage(String additionalMessage) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok removing this API in spite of the compatibility concern. It's just that the other constructors are "standard" exception constructors and we have no real need to remove them.

return new RetriableCommitFailedException("Offset commit failed with a retriable exception. " +
"You should retry committing the latest consumed offsets. " +
"The underlying error was: " + additionalMessage);
}

public RetriableCommitFailedException(Throwable t) {
super("Offset commit failed with a retriable exception. You should retry committing " +
"the latest consumed offsets.", t);
}

public RetriableCommitFailedException(String message) {
super(message);
}

public RetriableCommitFailedException(String message, Throwable t) {
super(message, t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected enum MemberState {
private HeartbeatThread heartbeatThread = null;
private RequestFuture<ByteBuffer> joinFuture = null;
private RequestFuture<Void> findCoordinatorFuture = null;
private RuntimeException findCoordinatorException = null;
volatile private RuntimeException findCoordinatorException = null;
private Generation generation = Generation.NO_GENERATION;
private long lastRebalanceStartMs = -1L;
private long lastRebalanceEndMs = -1L;
Expand Down Expand Up @@ -237,16 +237,6 @@ protected synchronized boolean ensureCoordinatorReady(final Timer timer) {

if (!future.isDone()) {
// ran out of time
future.addListener(new RequestFutureListener<Void>() {
@Override
public void onSuccess(Void value) {} // do nothing

@Override
public void onFailure(RuntimeException e) {
findCoordinatorException = e;
}
});

break;
}

Expand Down Expand Up @@ -274,8 +264,20 @@ protected synchronized RequestFuture<Void> lookupCoordinator() {
if (node == null) {
log.debug("No broker available to send FindCoordinator request");
return RequestFuture.noBrokersAvailable();
} else
} else{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this probably breaks checkstyle

findCoordinatorFuture = sendFindCoordinatorRequest(node);
// remember the exception even after the future is cleared so that
// it can still be thrown by the ensureCoordinatorReady caller
findCoordinatorFuture.addListener(new RequestFutureListener<Void>() {
@Override
public void onSuccess(Void value) {} // do nothing

@Override
public void onFailure(RuntimeException e) {
findCoordinatorException = e;
}
});
}
}
return findCoordinatorFuture;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ public boolean refreshCommittedOffsetsIfNeeded(Timer timer) {
this.subscriptions.seekUnvalidated(tp, position);

log.info("Setting offset for partition {} to the committed offset {}", tp, position);
} else {
log.info("Ignoring the returned {} since its partition {} is no longer assigned",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd suggest "Ignoring the fetched committed offset"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally did that, but then I realize OffsetAndMetadata#toString contains this already so I decided to avoid duplicated wording.

offsetAndMetadata, tp);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@
public class RebalanceInProgressException extends ApiException {
private static final long serialVersionUID = 1L;

public RebalanceInProgressException() {
super();
}

public RebalanceInProgressException(String message, Throwable cause) {
super(message, cause);
}

public RebalanceInProgressException(String message) {
super(message);
}

public RebalanceInProgressException(Throwable cause) {
super(cause);
}
}