@@ -90,20 +90,16 @@ func (s *Store) tryGetReplica(
90
90
if ! found {
91
91
return nil , nil
92
92
}
93
-
94
93
repl .raftMu .Lock () // not unlocked on success
95
- repl .mu .RLock ()
96
94
97
95
// The current replica is removed, go back around.
98
96
if repl .shMu .destroyStatus .Removed () {
99
- repl .mu .RUnlock ()
100
97
repl .raftMu .Unlock ()
101
98
return nil , errRetry
102
99
}
103
100
104
101
// Drop messages from replicas we know to be too old.
105
- if fromReplicaIsTooOldRLocked (repl , creatingReplica ) {
106
- repl .mu .RUnlock ()
102
+ if fromReplicaIsTooOldRaftMuLocked (repl , creatingReplica ) {
107
103
repl .raftMu .Unlock ()
108
104
return nil , kvpb .NewReplicaTooOldError (creatingReplica .ReplicaID )
109
105
}
@@ -115,7 +111,6 @@ func (s *Store) tryGetReplica(
115
111
id .ReplicaID , repl )
116
112
}
117
113
118
- repl .mu .RUnlock ()
119
114
if err := s .removeReplicaRaftMuLocked (
120
115
ctx , repl , id .ReplicaID , "superseded by newer Replica" ,
121
116
); err != nil {
@@ -124,7 +119,6 @@ func (s *Store) tryGetReplica(
124
119
repl .raftMu .Unlock ()
125
120
return nil , errRetry
126
121
}
127
- defer repl .mu .RUnlock ()
128
122
129
123
if repl .replicaID > id .ReplicaID {
130
124
// The sender is behind and is sending to an old replica.
@@ -224,11 +218,15 @@ func (s *Store) tryGetOrCreateReplica(
224
218
return repl , true , nil
225
219
}
226
220
227
- // fromReplicaIsTooOldRLocked returns true if the creatingReplica is deemed to
228
- // be a member of the range which has been removed.
229
- // Assumes toReplica.mu is locked for (at least) reading.
230
- func fromReplicaIsTooOldRLocked (toReplica * Replica , fromReplica * roachpb.ReplicaDescriptor ) bool {
231
- toReplica .mu .AssertRHeld ()
221
+ // fromReplicaIsTooOldRaftMuLocked returns true if the creatingReplica is deemed
222
+ // to be a member of the range which has been removed.
223
+ //
224
+ // Assumes toReplica.raftMu is locked. This could be relaxed to Replica.mu
225
+ // locked for reads, but the only user of it holds raftMu.
226
+ func fromReplicaIsTooOldRaftMuLocked (
227
+ toReplica * Replica , fromReplica * roachpb.ReplicaDescriptor ,
228
+ ) bool {
229
+ toReplica .raftMu .AssertHeld ()
232
230
if fromReplica == nil {
233
231
return false
234
232
}
0 commit comments