Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -463,6 +463,10 @@ void maybeUpdateSubscriptionMetadata() {
}
}

private boolean coordinatorUnknownAndUnready(Timer timer) {
return coordinatorUnknown() && !ensureCoordinatorReady(timer);
}

/**
* Poll for coordinator events. This ensures that the coordinator is known and that the consumer
* has joined the group (if it is using group management). This also handles periodic offset commits
Expand All @@ -488,7 +492,7 @@ public boolean poll(Timer timer, boolean waitForJoinGroup) {
// Always update the heartbeat last poll time so that the heartbeat thread does not leave the
// group proactively due to application inactivity even if (say) the coordinator cannot be found.
pollHeartbeat(timer.currentTimeMs());
if (coordinatorUnknown() && !ensureCoordinatorReady(timer)) {
if (coordinatorUnknownAndUnready(timer)) {
Comment on lines 492 to +495
Copy link
Copy Markdown
Member Author

@showuon showuon Feb 6, 2022

Choose a reason for hiding this comment

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

Could we move the whole block before the if-else block and also update the related comments?

We can't because we should always lookup the coordinator after heartbeat poll to avoid the heartbeat timeout in group management case.

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.

Makes sense.

return false;
}

Expand Down Expand Up @@ -525,15 +529,13 @@ public boolean poll(Timer timer, boolean waitForJoinGroup) {
}
}
} else {
// For manually assigned partitions, if there are no ready nodes, await metadata.
// For manually assigned partitions, if coordinator is unknown, make sure we lookup one and await metadata.
// If connections to all nodes fail, wakeups triggered while attempting to send fetch
// requests result in polls returning immediately, causing a tight loop of polls. Without
// the wakeup, poll() with no channels would block for the timeout, delaying re-connection.
// awaitMetadataUpdate() initiates new connections with configured backoff and avoids the busy loop.
// When group management is used, metadata wait is already performed for this scenario as
// coordinator is unknown, hence this check is not required.
if (metadata.updateRequested() && !client.hasReadyNodes(timer.currentTimeMs())) {
client.awaitMetadataUpdate(timer);
// awaitMetadataUpdate() in ensureCoordinatorReady initiates new connections with configured backoff and avoids the busy loop.
if (coordinatorUnknownAndUnready(timer)) {
return false;
}
}

Expand Down Expand Up @@ -1030,7 +1032,7 @@ public boolean commitOffsetsSync(Map<TopicPartition, OffsetAndMetadata> offsets,
return true;

do {
if (coordinatorUnknown() && !ensureCoordinatorReady(timer)) {
if (coordinatorUnknownAndUnready(timer)) {
return false;
}

Expand Down
Loading