Skip to content

Commit 192a828

Browse files
storage: s/replica.mu.proposals/replica.mu.localProposals/
Release note: None
1 parent 03b116f commit 192a828

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

pkg/storage/replica.go

+17-18
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,15 @@ type Replica struct {
373373
minLeaseProposedTS hlc.Timestamp
374374
// Max bytes before split.
375375
maxBytes int64
376-
// proposals stores the Raft in-flight commands which
377-
// originated at this Replica, i.e. all commands for which
378-
// propose has been called, but which have not yet
379-
// applied.
376+
// localProposals stores the Raft in-flight commands which originated at
377+
// this Replica, i.e. all commands for which propose has been called,
378+
// but which have not yet applied.
380379
//
381380
// The *ProposalData in the map are "owned" by it. Elements from the
382381
// map must only be referenced while Replica.mu is held, except if the
383382
// element is removed from the map first. The notable exception is the
384383
// contained RaftCommand, which we treat as immutable.
385-
proposals map[storagebase.CmdIDKey]*ProposalData
384+
localProposals map[storagebase.CmdIDKey]*ProposalData
386385
// remoteProposals is maintained by Raft leaders and stores in-flight
387386
// commands that were forwarded to the leader during its current term.
388387
// The set allows leaders to detect duplicate forwarded commands and
@@ -696,7 +695,7 @@ func (r *Replica) initRaftMuLockedReplicaMuLocked(
696695
r.cmdQMu.queues[spanset.SpanLocal] = NewCommandQueue(false /* optimizeOverlap */)
697696
r.cmdQMu.Unlock()
698697

699-
r.mu.proposals = map[storagebase.CmdIDKey]*ProposalData{}
698+
r.mu.localProposals = map[storagebase.CmdIDKey]*ProposalData{}
700699
r.mu.checksums = map[uuid.UUID]ReplicaChecksum{}
701700
// Clear the internal raft group in case we're being reset. Since we're
702701
// reloading the raft state below, it isn't safe to use the existing raft
@@ -852,7 +851,7 @@ func (r *Replica) cancelPendingCommandsLocked() {
852851
Err: roachpb.NewError(roachpb.NewAmbiguousResultError("removing replica")),
853852
ProposalRetry: proposalRangeNoLongerExists,
854853
}
855-
for _, p := range r.mu.proposals {
854+
for _, p := range r.mu.localProposals {
856855
r.cleanupFailedProposalLocked(p)
857856
p.finishApplication(pr)
858857
}
@@ -864,7 +863,7 @@ func (r *Replica) cancelPendingCommandsLocked() {
864863
func (r *Replica) cleanupFailedProposalLocked(p *ProposalData) {
865864
// Clear the proposal from the proposals map. May be a no-op if the
866865
// proposal has not yet been inserted into the map.
867-
delete(r.mu.proposals, p.idKey)
866+
delete(r.mu.localProposals, p.idKey)
868867
// Release associated quota pool resources if we have been tracking
869868
// this command.
870869
//
@@ -1866,7 +1865,7 @@ func (r *Replica) State() storagebase.RangeInfo {
18661865
var ri storagebase.RangeInfo
18671866
ri.ReplicaState = *(protoutil.Clone(&r.mu.state)).(*storagebase.ReplicaState)
18681867
ri.LastIndex = r.mu.lastIndex
1869-
ri.NumPending = uint64(len(r.mu.proposals))
1868+
ri.NumPending = uint64(len(r.mu.localProposals))
18701869
ri.RaftLogSize = r.mu.raftLogSize
18711870
ri.NumDropped = uint64(r.mu.droppedMessages)
18721871
if r.mu.proposalQuota != nil {
@@ -3344,11 +3343,11 @@ func (r *Replica) insertProposalLocked(
33443343
proposal.idKey, proposal.command.MaxLeaseIndex)
33453344
}
33463345

3347-
if _, ok := r.mu.proposals[proposal.idKey]; ok {
3346+
if _, ok := r.mu.localProposals[proposal.idKey]; ok {
33483347
ctx := r.AnnotateCtx(context.TODO())
33493348
log.Fatalf(ctx, "pending command already exists for %s", proposal.idKey)
33503349
}
3351-
r.mu.proposals[proposal.idKey] = proposal
3350+
r.mu.localProposals[proposal.idKey] = proposal
33523351
}
33533352

33543353
func makeIDKey() storagebase.CmdIDKey {
@@ -3556,7 +3555,7 @@ func (r *Replica) propose(
35563555
// range.
35573556
tryAbandon := func() bool {
35583557
r.mu.Lock()
3559-
p, ok := r.mu.proposals[idKey]
3558+
p, ok := r.mu.localProposals[idKey]
35603559
if ok {
35613560
// TODO(radu): Should this context be created via tracer.ForkCtxSpan?
35623561
// We'd need to make sure the span is finished eventually.
@@ -3683,9 +3682,9 @@ func (r *Replica) quiesce() bool {
36833682

36843683
func (r *Replica) quiesceLocked() bool {
36853684
ctx := r.AnnotateCtx(context.TODO())
3686-
if len(r.mu.proposals) != 0 {
3685+
if len(r.mu.localProposals) != 0 {
36873686
if log.V(3) {
3688-
log.Infof(ctx, "not quiescing: %d pending commands", len(r.mu.proposals))
3687+
log.Infof(ctx, "not quiescing: %d pending commands", len(r.mu.localProposals))
36893688
}
36903689
return false
36913690
}
@@ -4339,7 +4338,7 @@ func (r *Replica) tick(livenessMap map[roachpb.NodeID]bool) (bool, error) {
43394338
// correctness issues.
43404339
func (r *Replica) maybeQuiesceLocked(livenessMap map[roachpb.NodeID]bool) bool {
43414340
ctx := r.AnnotateCtx(context.TODO())
4342-
status, ok := shouldReplicaQuiesce(ctx, r, r.store.Clock().Now(), len(r.mu.proposals), livenessMap)
4341+
status, ok := shouldReplicaQuiesce(ctx, r, r.store.Clock().Now(), len(r.mu.localProposals), livenessMap)
43434342
if !ok {
43444343
return false
43454344
}
@@ -4600,7 +4599,7 @@ func (r *Replica) refreshProposalsLocked(refreshAtDelta int, reason refreshRaftR
46004599

46014600
numShouldRetry := 0
46024601
var reproposals pendingCmdSlice
4603-
for _, p := range r.mu.proposals {
4602+
for _, p := range r.mu.localProposals {
46044603
if p.command.MaxLeaseIndex == 0 {
46054604
// Commands without a MaxLeaseIndex cannot be reproposed, as they might
46064605
// apply twice. We also don't want to ask the proposer to retry these
@@ -5070,14 +5069,14 @@ func (r *Replica) processRaftCommand(
50705069
}
50715070

50725071
r.mu.Lock()
5073-
proposal, proposedLocally := r.mu.proposals[idKey]
5072+
proposal, proposedLocally := r.mu.localProposals[idKey]
50745073

50755074
// TODO(tschottdorf): consider the Trace situation here.
50765075
if proposedLocally {
50775076
// We initiated this command, so use the caller-supplied context.
50785077
ctx = proposal.ctx
50795078
proposal.ctx = nil // avoid confusion
5080-
delete(r.mu.proposals, idKey)
5079+
delete(r.mu.localProposals, idKey)
50815080
}
50825081

50835082
// Delete the entry for a forwarded proposal set.

pkg/storage/replica_sideload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (r *Replica) maybeSideloadEntriesRaftMuLocked(
7070
maybeRaftCommand := func(cmdID storagebase.CmdIDKey) (storagebase.RaftCommand, bool) {
7171
r.mu.Lock()
7272
defer r.mu.Unlock()
73-
cmd, ok := r.mu.proposals[cmdID]
73+
cmd, ok := r.mu.localProposals[cmdID]
7474
if ok {
7575
return *cmd.command, true
7676
}

pkg/storage/replica_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -7455,7 +7455,7 @@ func TestReplicaTryAbandon(t *testing.T) {
74557455
func() {
74567456
tc.repl.mu.Lock()
74577457
defer tc.repl.mu.Unlock()
7458-
if len(tc.repl.mu.proposals) == 0 {
7458+
if len(tc.repl.mu.localProposals) == 0 {
74597459
t.Fatal("expected non-empty proposals map")
74607460
}
74617461
}()
@@ -8010,7 +8010,7 @@ func TestReplicaBurstPendingCommandsAndRepropose(t *testing.T) {
80108010
}
80118011

80128012
tc.repl.mu.Lock()
8013-
for _, p := range tc.repl.mu.proposals {
8013+
for _, p := range tc.repl.mu.localProposals {
80148014
if v := p.ctx.Value(magicKey{}); v != nil {
80158015
origIndexes = append(origIndexes, int(p.command.MaxLeaseIndex))
80168016
}
@@ -8042,13 +8042,13 @@ func TestReplicaBurstPendingCommandsAndRepropose(t *testing.T) {
80428042

80438043
tc.repl.mu.Lock()
80448044
defer tc.repl.mu.Unlock()
8045-
nonePending := len(tc.repl.mu.proposals) == 0
8045+
nonePending := len(tc.repl.mu.localProposals) == 0
80468046
c := int(tc.repl.mu.lastAssignedLeaseIndex) - int(tc.repl.mu.state.LeaseAppliedIndex)
80478047
if nonePending && c > 0 {
80488048
t.Errorf("no pending cmds, but have required index offset %d", c)
80498049
}
80508050
if !nonePending {
8051-
t.Fatalf("still pending commands: %+v", tc.repl.mu.proposals)
8051+
t.Fatalf("still pending commands: %+v", tc.repl.mu.localProposals)
80528052
}
80538053
}
80548054

@@ -8206,7 +8206,7 @@ func TestReplicaRefreshPendingCommandsTicks(t *testing.T) {
82068206
}
82078207
// Build the map of expected reproposals at this stage.
82088208
m := map[storagebase.CmdIDKey]int{}
8209-
for id, p := range r.mu.proposals {
8209+
for id, p := range r.mu.localProposals {
82108210
m[id] = p.proposedAtTicks
82118211
}
82128212
r.mu.Unlock()

0 commit comments

Comments
 (0)