Skip to content

Commit

Permalink
shards: fix shards assign missing updated value (#172)
Browse files Browse the repository at this point in the history
* shards: fix shards assign missing updated value

In the old logic, we didn't return the newest shards for reassigned
collection. which causes client can't connect to expected leader.
  • Loading branch information
mattisonchao authored Aug 2, 2024
1 parent 3df43a9 commit ce4ddc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ static ShardAssignmentChanges computeShardLeaderChanges(
oldAssignments.values().stream()
.filter(s -> newAssignments.containsKey(s.id()))
.filter(s -> !newAssignments.get(s.id()).leader().equals(s.leader()))
.map(s -> newAssignments.get(s.id())) // return reassigned leader
.collect(toSet());
return new ShardAssignmentChanges(
unmodifiableSet(added), unmodifiableSet(removed), unmodifiableSet(changed));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ void recomputeShardHashBoundariesWithSameValue() {
assertThat(a).isUnmodifiable();
});
}

@Test
void recomputeAssignmentsWithSameBoundariesAndDiffLeader() {
final var existing = Map.of(1L, new Shard(1L, "leader 1", new HashRange(0, 4294967295L)));
final var updates = Set.of(new Shard(1L, "leader 2", new HashRange(0, 4294967295L)));
final var updatedMap = ShardManager.recomputeShardHashBoundaries(existing, updates);
final var changes = ShardManager.computeShardLeaderChanges(existing, updatedMap);
assertThat(changes.reassigned()).isEqualTo(updates);
}
}

@Nested
Expand Down

0 comments on commit ce4ddc2

Please sign in to comment.