Skip to content

Commit 421cc69

Browse files
craig[bot]pav-kv
craig[bot]
andcommitted
Merge #147218
147218: kvserver: rm unnecessary ReplicaID write r=arulajmani,tbg a=pav-kv In `splitPreApply`, the common case is that the replica exists because it was created by `acquireSplitLock` which calls `getOrCreateReplica`, which ultimately writes the `ReplicaID`. Alternatively, this replica could have been brought to existence by an earlier `getOrCreateReplica`. We don't need to duplicate the `ReplicaID` write in this case. Another way to understand this: a replica **always** goes through the uninitialized state before being initialized. We already write `ReplicaID` when going through the uninitialized state. Epic: CRDB-46488 Co-authored-by: Pavel Kalinnikov <[email protected]>
2 parents 1a504b8 + 1a91db6 commit 421cc69

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

pkg/kv/kvserver/store_split.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func splitPreApply(
3838
//
3939
// The exception to that is if the DisableEagerReplicaRemoval testing flag is
4040
// enabled.
41-
rightDesc, hasRightDesc := split.RightDesc.GetReplicaDescriptor(r.StoreID())
41+
_, hasRightDesc := split.RightDesc.GetReplicaDescriptor(r.StoreID())
4242
_, hasLeftDesc := split.LeftDesc.GetReplicaDescriptor(r.StoreID())
4343
if !hasRightDesc || !hasLeftDesc {
4444
log.Fatalf(ctx, "cannot process split on s%s which does not exist in the split: %+v",
@@ -130,21 +130,14 @@ func splitPreApply(
130130
return
131131
}
132132

133-
// Update the raft HardState with the new Commit value now that the
134-
// replica is initialized (combining it with existing or default
135-
// Term and Vote). This is the common case.
133+
// The RHS replica exists and is uninitialized. We are initializing it here.
134+
// Update the raft HardState with the new Commit index (taken from the applied
135+
// state in the write batch), and use existing or default Term and Vote. This
136+
// is the common case.
136137
rsl := stateloader.Make(split.RightDesc.RangeID)
137138
if err := rsl.SynthesizeRaftState(ctx, readWriter); err != nil {
138139
log.Fatalf(ctx, "%v", err)
139140
}
140-
// Write the RaftReplicaID for the RHS to maintain the invariant that any
141-
// replica (uninitialized or initialized), with persistent state, has a
142-
// RaftReplicaID. NB: this invariant will not be universally true until we
143-
// introduce node startup code that will write this value for existing
144-
// ranges.
145-
if err := rsl.SetRaftReplicaID(ctx, readWriter, rightDesc.ReplicaID); err != nil {
146-
log.Fatalf(ctx, "%v", err)
147-
}
148141
// Persist the closed timestamp.
149142
//
150143
// In order to tolerate a nil initClosedTS input, let's forward to

0 commit comments

Comments
 (0)