-
Notifications
You must be signed in to change notification settings - Fork 14.7k
KAFKA-19661: Streams groups sometimes describe as NOT_READY when STABLE #20600
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,9 +250,9 @@ | |
import static org.apache.kafka.coordinator.group.streams.StreamsCoordinatorRecordHelpers.convertToStreamsGroupTopologyRecord; | ||
import static org.apache.kafka.coordinator.group.streams.StreamsCoordinatorRecordHelpers.newStreamsGroupCurrentAssignmentRecord; | ||
import static org.apache.kafka.coordinator.group.streams.StreamsCoordinatorRecordHelpers.newStreamsGroupCurrentAssignmentTombstoneRecord; | ||
import static org.apache.kafka.coordinator.group.streams.StreamsCoordinatorRecordHelpers.newStreamsGroupEpochRecord; | ||
import static org.apache.kafka.coordinator.group.streams.StreamsCoordinatorRecordHelpers.newStreamsGroupMemberRecord; | ||
import static org.apache.kafka.coordinator.group.streams.StreamsCoordinatorRecordHelpers.newStreamsGroupMemberTombstoneRecord; | ||
import static org.apache.kafka.coordinator.group.streams.StreamsCoordinatorRecordHelpers.newStreamsGroupMetadataRecord; | ||
import static org.apache.kafka.coordinator.group.streams.StreamsCoordinatorRecordHelpers.newStreamsGroupTargetAssignmentTombstoneRecord; | ||
import static org.apache.kafka.coordinator.group.streams.StreamsCoordinatorRecordHelpers.newStreamsGroupTopologyRecord; | ||
import static org.apache.kafka.coordinator.group.streams.StreamsGroupMember.hasAssignedTasksChanged; | ||
|
@@ -1960,19 +1960,26 @@ private CoordinatorResult<StreamsGroupHeartbeatResult, CoordinatorRecord> stream | |
updatedConfiguredTopology = group.configuredTopology().get(); | ||
} | ||
|
||
// 3b. If the topology is validated, persist the fact that it is validated. | ||
int validatedTopologyEpoch = -1; | ||
if (updatedConfiguredTopology.isReady()) { | ||
validatedTopologyEpoch = updatedTopology.topologyEpoch(); | ||
SortedMap<String, ConfiguredSubtopology> subtopologySortedMap = updatedConfiguredTopology.subtopologies().get(); | ||
throwIfRequestContainsInvalidTasks(subtopologySortedMap, ownedActiveTasks); | ||
throwIfRequestContainsInvalidTasks(subtopologySortedMap, ownedStandbyTasks); | ||
throwIfRequestContainsInvalidTasks(subtopologySortedMap, ownedWarmupTasks); | ||
} | ||
// We validated a topology that was not validated before, so bump the group epoch as we may have to reassign tasks. | ||
if (validatedTopologyEpoch != group.validatedTopologyEpoch()) { | ||
bumpGroupEpoch = true; | ||
} | ||
|
||
// Actually bump the group epoch | ||
int groupEpoch = group.groupEpoch(); | ||
if (bumpGroupEpoch) { | ||
groupEpoch += 1; | ||
records.add(newStreamsGroupEpochRecord(groupId, groupEpoch, metadataHash)); | ||
log.info("[GroupId {}][MemberId {}] Bumped streams group epoch to {} with metadata hash {}.", groupId, memberId, groupEpoch, metadataHash); | ||
records.add(newStreamsGroupMetadataRecord(groupId, groupEpoch, metadataHash, validatedTopologyEpoch)); | ||
log.info("[GroupId {}][MemberId {}] Bumped streams group epoch to {} with metadata hash {} and validated topic epoch {}.", groupId, memberId, groupEpoch, metadataHash, validatedTopologyEpoch); | ||
metrics.record(STREAMS_GROUP_REBALANCES_SENSOR_NAME); | ||
group.setMetadataRefreshDeadline(currentTimeMs + METADATA_REFRESH_INTERVAL_MS, groupEpoch); | ||
} | ||
|
@@ -4245,7 +4252,7 @@ private <T> CoordinatorResult<T, CoordinatorRecord> streamsGroupFenceMember( | |
|
||
// We bump the group epoch. | ||
int groupEpoch = group.groupEpoch() + 1; | ||
records.add(newStreamsGroupEpochRecord(group.groupId(), groupEpoch, 0)); | ||
records.add(newStreamsGroupMetadataRecord(group.groupId(), groupEpoch, group.metadataHash(), group.validatedTopologyEpoch())); | ||
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. There was a bug here - every time we'd fence a member, we'd reset the metadata hash to 0. We don't need to do that, otherwise we'll need to recompute the metadata hash on the next heartbeat and bump the group epoch again. |
||
|
||
cancelTimers(group.groupId(), member.memberId()); | ||
|
||
|
@@ -5365,6 +5372,7 @@ public void replay( | |
StreamsGroup streamsGroup = getOrMaybeCreatePersistedStreamsGroup(groupId, true); | ||
streamsGroup.setGroupEpoch(value.epoch()); | ||
streamsGroup.setMetadataHash(value.metadataHash()); | ||
streamsGroup.setValidatedTopologyEpoch(value.validatedTopologyEpoch()); | ||
} else { | ||
StreamsGroup streamsGroup; | ||
try { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,9 +148,9 @@ public static class DeadlineAndEpoch { | |
private final TimelineHashMap<String, String> staticMembers; | ||
|
||
/** | ||
* The metadata associated with each subscribed topic name. | ||
* The topology epoch for which the subscribed topics identified by metadataHash are validated. | ||
*/ | ||
private final TimelineHashMap<String, TopicMetadata> partitionMetadata; | ||
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. the partition metadata field was not used anymore and wasn't removed in a previous PR |
||
protected final TimelineInteger validatedTopologyEpoch; | ||
|
||
/** | ||
* The metadata hash which is computed based on the all subscribed topics. | ||
|
@@ -224,7 +224,7 @@ public StreamsGroup( | |
this.groupEpoch = new TimelineInteger(snapshotRegistry); | ||
this.members = new TimelineHashMap<>(snapshotRegistry, 0); | ||
this.staticMembers = new TimelineHashMap<>(snapshotRegistry, 0); | ||
this.partitionMetadata = new TimelineHashMap<>(snapshotRegistry, 0); | ||
this.validatedTopologyEpoch = new TimelineInteger(snapshotRegistry); | ||
this.metadataHash = new TimelineLong(snapshotRegistry); | ||
this.targetAssignmentEpoch = new TimelineInteger(snapshotRegistry); | ||
this.targetAssignment = new TimelineHashMap<>(snapshotRegistry, 0); | ||
|
@@ -284,7 +284,6 @@ public void setTopology(StreamsTopology topology) { | |
|
||
public void setConfiguredTopology(ConfiguredTopology configuredTopology) { | ||
this.configuredTopology.set(Optional.ofNullable(configuredTopology)); | ||
maybeUpdateGroupState(); | ||
} | ||
|
||
/** | ||
|
@@ -600,6 +599,23 @@ public void setMetadataHash(long metadataHash) { | |
this.metadataHash.set(metadataHash); | ||
} | ||
|
||
/** | ||
* @return The validated topology epoch. | ||
*/ | ||
public int validatedTopologyEpoch() { | ||
return validatedTopologyEpoch.get(); | ||
} | ||
|
||
/** | ||
* Updates the validated topology epoch. | ||
* | ||
* @param validatedTopologyEpoch The validated topology epoch | ||
*/ | ||
public void setValidatedTopologyEpoch(int validatedTopologyEpoch) { | ||
this.validatedTopologyEpoch.set(validatedTopologyEpoch); | ||
maybeUpdateGroupState(); | ||
} | ||
|
||
/** | ||
* Computes the metadata hash based on the current topology and the current metadata image. | ||
* | ||
|
@@ -837,7 +853,7 @@ private void maybeUpdateGroupState() { | |
if (members.isEmpty()) { | ||
newState = EMPTY; | ||
clearShutdownRequestMemberId(); | ||
} else if (topology().isEmpty() || configuredTopology().isEmpty() || !configuredTopology().get().isReady()) { | ||
} else if (topology().filter(x -> x.topologyEpoch() == validatedTopologyEpoch.get()).isEmpty()) { | ||
newState = NOT_READY; | ||
} else if (groupEpoch.get() > targetAssignmentEpoch.get()) { | ||
newState = ASSIGNING; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
{ "name": "Epoch", "versions": "0+", "type": "int32", | ||
"about": "The group epoch." }, | ||
{ "name": "MetadataHash", "versions": "0+", "type": "int64", | ||
"about": "The hash of all topics in the group." } | ||
"about": "The hash of all topics in the group." }, | ||
{ "name": "ValidatedTopologyEpoch", "versions": "0+", "taggedVersions": "0+", "tag": 0, "default": -1, "type": "int32", | ||
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. We add the field as a tagged field, so if we are compatible without bumping the version. If a new kafka reads a record without ValidatedTopologyEpoch, it will assume the default -1 and revalidate the topology. If an old kafka reads a record with ValidatedTopologyEpoch, it will be ignored. |
||
"about": "The topology epoch whose topics where validated to be present in a valid configuration in the metadata." } | ||
] | ||
} |
Uh oh!
There was an error while loading. Please reload this page.