Skip to content

Commit

Permalink
fix(server): allow higher term shard deleting (#559)
Browse files Browse the repository at this point in the history
### Motivation

The coordinator will replace the ensemble when swapping the node.
Therefore, the old node can't receive new term requests, and the actual
shard term will be greater than the old server. and then the old server
will keep printing

```
Invalid term when deleting shard
```

### Modification

- Allow higher term shard deleting.

### Alternatives

- save the deleting term before the new ensemble is elected.
  • Loading branch information
mattisonchao authored Nov 5, 2024
1 parent c74352c commit be8cef5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/follower_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ func (fc *followerController) DeleteShard(request *proto.DeleteShardRequest) (*p
fc.Lock()
defer fc.Unlock()

if request.Term != fc.term {
if request.Term < fc.term {
fc.log.Warn("Invalid term when deleting shard",
slog.Int64("follower-term", fc.term),
slog.Int64("new-term", request.Term))
Expand Down
4 changes: 2 additions & 2 deletions server/follower_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,12 +824,12 @@ func TestFollowerController_DeleteShard_WrongTerm(t *testing.T) {
walFactory := newTestWalFactory(t)

fc, _ := NewFollowerController(Config{}, common.DefaultNamespace, shardId, walFactory, kvFactory)
_, _ = fc.NewTerm(&proto.NewTermRequest{Term: 1})
_, _ = fc.NewTerm(&proto.NewTermRequest{Term: 2})

_, err := fc.DeleteShard(&proto.DeleteShardRequest{
Namespace: common.DefaultNamespace,
Shard: shardId,
Term: 2,
Term: 1,
})

assert.ErrorIs(t, err, common.ErrorInvalidTerm)
Expand Down
2 changes: 1 addition & 1 deletion server/leader_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ func (lc *leaderController) DeleteShard(request *proto.DeleteShardRequest) (*pro
lc.Lock()
defer lc.Unlock()

if request.Term != lc.term {
if request.Term < lc.term {
lc.log.Warn("Invalid term when deleting shard",
slog.Int64("follower-term", lc.term),
slog.Int64("new-term", request.Term))
Expand Down

0 comments on commit be8cef5

Please sign in to comment.