Lucas Brutschy created KAFKA-21697:
--------------------------------------
Summary: Streams group: reverting to a snapshot does not restore
which processes hold standby and warm-up tasks
Key: KAFKA-21697
URL: https://issues.apache.org/jira/browse/KAFKA-21697
Project: Kafka
Issue Type: Bug
Components: group-coordinator
Affects Versions: 4.2.0, 4.1.0, 4.3.0, 4.4.0
Reporter: Lucas Brutschy
{{StreamsGroup}} indexes the processes that hold each standby and warm-up task
in {{currentStandbyTaskToProcessIds}} and {{currentWarmupTaskToProcessIds}}:
timeline maps from subtopology to a {{TimelineHashMap<Integer, Set<String>>}}.
{{addTaskProcessIdToSet}} and {{removeTaskProcessIdsFromSet}} change the
{{Set<String>}} values in place ({{computeIfAbsent(partitionId, ___ -> new
HashSet<>()).add(processId)}} and {{remove(processId)}}). The snapshot registry
only tracks the map entries, so reverting to a snapshot restores the entries
but not the contents of the sets.
The coordinator runtime reverts to the snapshot of the batch when an append
fails. After a failed append of a streams group heartbeat that moved a standby
or warm-up task, the task can stay attributed to a process that no longer holds
it, or lose a process that still holds it.
h3. Impact
The coordinator does not grant a task to a member while its process holds that
task in another role ({{currentStandbyTaskProcessIds}} /
{{currentWarmupTaskProcessIds}} are consulted when reconciling). A member of a
process that is wrongly recorded as holding a standby can therefore wait in
{{UNRELEASED_TASKS}} for the active task until the membership changes. A
process that is wrongly not recorded can get the same task twice (active and
standby).
h3. Steps to reproduce (unit level)
{code:java}
SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
StreamsGroup group = new StreamsGroup(new LogContext(), snapshotRegistry,
"group");
group.updateMember(member("first", "process-1", standby("bar", 0)));
snapshotRegistry.idempotentCreateSnapshot(1);
group.updateMember(member("second", "process-2", standby("bar", 0)));
group.updateMember(member("first", "process-1", noTasks()));
// currentStandbyTaskProcessIds("bar", 0) == {process-2}
snapshotRegistry.revertToSnapshot(1);
// expected {process-1}, actual {process-2}
{code}
h3. Proposed fix
Replace the sets instead of changing them in place (copy, add/remove, put), or
use an immutable set per entry. Found by a deterministic simulation of the
coordinator with append failures.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)