-
Notifications
You must be signed in to change notification settings - Fork 4.1k
kvserver: remove ability to send log entries in raft snaps #66834
Description
This is mostly dead code and has been for multiple releases - we don't send any log entries with the snapshots any more:
cockroach/pkg/kv/kvserver/replica_command.go
Lines 2438 to 2446 in 1ac67a1
| 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:
cockroach/pkg/clusterversion/cockroach_versions.go
Lines 233 to 242 in d546be9
| // 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:
cockroach/pkg/kv/kvserver/replica_command.go
Lines 2448 to 2462 in 1ac67a1
| 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,
cockroach/pkg/kv/kvserver/replica_command.go
Line 2446 in 1ac67a1
| 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.