Skip to content

kvserver: remove ability to send log entries in raft snaps #66834

@tbg

Description

@tbg

This is mostly dead code and has been for multiple releases - we don't send any log entries with the snapshots any more:

usesReplicatedTruncatedState, err := storage.MVCCGetProto(
ctx, snap.EngineSnap, keys.RaftTruncatedStateLegacyKey(r.RangeID), hlc.Timestamp{}, nil, storage.MVCCGetOptions{},
)
if err != nil {
return errors.Wrap(err, "loading legacy truncated state")
}
canAvoidSendingLog := !usesReplicatedTruncatedState &&
snap.State.TruncatedState.Index < snap.State.RaftAppliedIndex

Also, as of 21.2 (i.e. master now), we actually know for sure it is dead code:

// TruncatedAndRangeAppliedStateMigration is part of the migration to stop
// using the legacy truncated state within KV. After the migration, we'll be
// using the unreplicated truncated state and the RangeAppliedState on all
// ranges. Callers that wish to assert on there no longer being any legacy
// will be able to do so after PostTruncatedAndRangeAppliedStateMigration is
// active. This lets remove any holdover code handling the possibility of
// replicated truncated state in 21.2.
//
// TODO(irfansharif): Do the above in 21.2.
TruncatedAndRangeAppliedStateMigration

This will let us significantly simplify kvBatchSnapshotStrategy.Send, which can always assume that the truncated index for the snapshot matches the applied index because this branch becomes unconditional:

if canAvoidSendingLog {
// If we're not using a legacy (replicated) truncated state, we avoid
// sending the (past) Raft log in the snapshot in the first place and
// send only those entries that are actually useful to the follower.
// This is done by changing the truncated state, which we're allowed
// to do since it is not a replicated key (and thus not subject to
// matching across replicas). The actual sending happens here:
_ = (*kvBatchSnapshotStrategy)(nil).Send
// and results in no log entries being sent at all. Note that
// Metadata.Index is really the applied index of the replica.
snap.State.TruncatedState = &roachpb.RaftTruncatedState{
Index: snap.RaftSnap.Metadata.Index,
Term: snap.RaftSnap.Metadata.Term,
}
}

The one weird little thing is this line,

snap.State.TruncatedState.Index < snap.State.RaftAppliedIndex

and whether it can ever be false. I don't think it can, as truncations only become visible when they are applied (at least that's how we're doing it today). So this can be turned into an errors.AssertionFailedf.

Metadata

Metadata

Assignees

Labels

C-cleanupTech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior.T-kvKV Team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions