Skip to content

Commit

Permalink
add other small change
Browse files Browse the repository at this point in the history
  • Loading branch information
mattisonchao committed Jan 24, 2025
1 parent 1be8c62 commit cd4c171
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions server/follower_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,29 +268,30 @@ func (fc *followerController) NewTerm(req *proto.NewTermRequest) (*proto.NewTerm
)
return nil, common.ErrorInvalidTerm
}
if req.Term == fc.term && fc.status != proto.ServingStatus_FENCED {
// It's OK to receive a duplicate Fence request, for the same term, as long as we haven't moved
// out of the Fenced state for that term
fc.log.Warn(
"Failed to fence with same term in invalid state",
slog.Int64("follower-term", fc.term),
slog.Int64("new-term", req.Term),
slog.Any("status", fc.status),
)
return nil, common.ErrorInvalidStatus
}
if req.Term == fc.term && fc.status == proto.ServingStatus_FENCED {
lastEntryId, err := getLastEntryIdInWal(fc.wal)
if err != nil {
if req.Term == fc.term {
if fc.status == proto.ServingStatus_FENCED {
lastEntryId, err := getLastEntryIdInWal(fc.wal)
if err != nil {
fc.log.Warn(
"Failed to get last",
slog.Any("error", err),
slog.Int64("follower-term", fc.term),
slog.Int64("new-term", req.Term),
)
return nil, err
}
return &proto.NewTermResponse{HeadEntryId: lastEntryId}, nil
} else {
// It's OK to receive a duplicate Fence request, for the same term, as long as we haven't moved
// out of the Fenced state for that term
fc.log.Warn(
"Failed to get last",
slog.Any("error", err),
"Failed to fence with same term in invalid state",
slog.Int64("follower-term", fc.term),
slog.Int64("new-term", req.Term),
slog.Any("status", fc.status),
)
return nil, err
return nil, common.ErrorInvalidStatus
}
return &proto.NewTermResponse{HeadEntryId: lastEntryId}, nil
}

if fc.db == nil {
Expand Down

0 comments on commit cd4c171

Please sign in to comment.