Skip to content

Commit

Permalink
Revert "Extract utility method from HandleRaftRequest."
Browse files Browse the repository at this point in the history
This reverts commit 57f0c98.
  • Loading branch information
tamird committed Sep 3, 2016
1 parent 13c55a8 commit d985d23
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2175,24 +2175,6 @@ func (s *Store) maybeUpdateTransaction(txn *roachpb.Transaction, now hlc.Timesta
return txn, nil
}

// checkReplicaTooOld checks to see if the replica id of the sender of a Raft
// message is too old and no longer exists.
func checkReplicaTooOld(r *Replica, fromReplicaID roachpb.ReplicaID) *roachpb.Error {
found := false
desc := r.Desc()
for _, rep := range desc.Replicas {
if rep.ReplicaID == fromReplicaID {
found = true
break
}
}
// It's not a current member of the group. Is it from the past?
if !found && fromReplicaID < desc.NextReplicaID {
return roachpb.NewError(&roachpb.ReplicaTooOldError{})
}
return nil
}

// HandleRaftRequest dispatches a raft message to the appropriate Replica. It
// requires that s.processRaftMu and s.mu are not held.
func (s *Store) HandleRaftRequest(ctx context.Context, req *RaftMessageRequest) *roachpb.Error {
Expand All @@ -2207,8 +2189,17 @@ func (s *Store) HandleRaftRequest(ctx context.Context, req *RaftMessageRequest)
r, ok := s.mu.replicas[req.RangeID]
s.mu.Unlock()
if ok {
if err := checkReplicaTooOld(r, req.FromReplica.ReplicaID); err != nil {
return err
found := false
desc := r.Desc()
for _, rep := range desc.Replicas {
if rep.ReplicaID == req.FromReplica.ReplicaID {
found = true
break
}
}
// It's not a current member of the group. Is it from the past?
if !found && req.FromReplica.ReplicaID < desc.NextReplicaID {
return roachpb.NewError(&roachpb.ReplicaTooOldError{})
}
}

Expand Down

0 comments on commit d985d23

Please sign in to comment.