Skip to content

Commit 5a32ea3

Browse files
committed
kvserver: clean up postDestroyRaftMuLocked
Epic: none Release note: none
1 parent 19a8a6e commit 5a32ea3

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

pkg/kv/kvserver/replica_application_result.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ func (r *Replica) handleChangeReplicasResult(
698698
// NB: postDestroyRaftMuLocked requires that the batch which removed the data
699699
// be durably synced to disk, which we have.
700700
// See replicaAppBatch.ApplyToStateMachine().
701-
if err := r.postDestroyRaftMuLocked(ctx, r.GetMVCCStats()); err != nil {
701+
if err := r.postDestroyRaftMuLocked(ctx); err != nil {
702702
log.Fatalf(ctx, "failed to run Replica postDestroy: %v", err)
703703
}
704704

pkg/kv/kvserver/replica_destroy.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/apply"
1515
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvstorage"
1616
"github.com/cockroachdb/cockroach/pkg/roachpb"
17-
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
1817
"github.com/cockroachdb/cockroach/pkg/util/log"
1918
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
2019
)
@@ -65,20 +64,12 @@ func (s destroyStatus) Removed() bool {
6564
// don't know the current replica ID.
6665
const mergedTombstoneReplicaID roachpb.ReplicaID = math.MaxInt32
6766

68-
func (r *Replica) postDestroyRaftMuLocked(ctx context.Context, ms enginepb.MVCCStats) error {
69-
// TODO(tschottdorf): at node startup, we should remove all on-disk
70-
// directories belonging to replicas which aren't present. A crash before a
71-
// call to postDestroyRaftMuLocked will currently leave the files around
72-
// forever.
73-
//
74-
// TODO(tbg): coming back in 2021, the above should be outdated. The ReplicaID
75-
// is set on creation and never changes over the lifetime of a Replica. Also,
76-
// the replica is always contained in its descriptor. So this code below should
77-
// be removable.
78-
//
79-
// TODO(pavelkalinnikov): coming back in 2023, the above may still happen if:
80-
// (1) state machine syncs, (2) OS crashes before (3) sideloaded was able to
81-
// sync the files removal. The files should be cleaned up on restart.
67+
// postDestroyRaftMuLocked is called after the replica destruction is durably
68+
// written to Pebble.
69+
func (r *Replica) postDestroyRaftMuLocked(ctx context.Context) error {
70+
// TODO(#136416): at node startup, we should remove all on-disk directories
71+
// belonging to replicas which aren't present. A crash before a call to
72+
// postDestroyRaftMuLocked will currently leave the files around forever.
8273
if err := r.logStorage.ls.Sideload.Clear(ctx); err != nil {
8374
return err
8475
}
@@ -135,7 +126,7 @@ func (r *Replica) destroyRaftMuLocked(ctx context.Context, nextReplicaID roachpb
135126
}
136127
commitTime := timeutil.Now()
137128

138-
if err := r.postDestroyRaftMuLocked(ctx, ms); err != nil {
129+
if err := r.postDestroyRaftMuLocked(ctx); err != nil {
139130
return err
140131
}
141132
if r.IsInitialized() {

pkg/kv/kvserver/replica_raftstorage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ func (r *Replica) clearSubsumedReplicaInMemoryData(
815815
phs = append(phs, ph)
816816
// We removed sr's data when we committed the batch. Finish subsumption by
817817
// updating the in-memory bookkeping.
818-
if err := sr.postDestroyRaftMuLocked(ctx, sr.GetMVCCStats()); err != nil {
818+
if err := sr.postDestroyRaftMuLocked(ctx); err != nil {
819819
return nil, err
820820
}
821821
}

pkg/kv/kvserver/store_merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (s *Store) MergeRange(
138138
return errors.Wrap(err, "cannot remove range")
139139
}
140140

141-
if err := rightRepl.postDestroyRaftMuLocked(ctx, rightRepl.GetMVCCStats()); err != nil {
141+
if err := rightRepl.postDestroyRaftMuLocked(ctx); err != nil {
142142
return err
143143
}
144144

0 commit comments

Comments
 (0)