-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kv,migration: rm code handling legacy raft truncated state #69887
kv,migration: rm code handling legacy raft truncated state #69887
Conversation
d4a3208
to
ea3f25a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The various legacy keys that were removed were removed in their entirety. Our CLI to scan over store keys will no longer recognize these keys. Is that ok?
It doesn't seem that important to me to delete all of these keys. I could see deleting all of the kvserver code and some of the constructors but leaving the keys around for debugging. I'm curious what others think about that.
Reviewed 32 of 41 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @irfansharif, @nvanbenschoten, and @tbg)
pkg/cli/debug_check_store.go, line 255 at r1 (raw file):
} getReplicaInfo(rangeID).committedIndex = hs.Commit case bytes.Equal(suffix, keys.LocalRaftTruncatedStateLegacySuffix):
I think you could leave this code in perpetuity if you wanted.
pkg/kv/kvserver/raft.proto, line 195 at r1 (raw file):
// // TODO(irfansharif): Remove this in v22.1. bool legacy_unreplicated_truncated_state = 8;
nit: I'd call this Deprecated
rather than Legacy
as it made me think the state was legacy rather than the field. Maybe that's just me.
ea3f25a
to
b212c37
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 10 files at r4.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @irfansharif, @nvanbenschoten, and @tbg)
pkg/kv/kvserver/stateloader/stateloader.go, line 166 at r4 (raw file):
) (enginepb.RangeAppliedState, error) { var as enginepb.RangeAppliedState _, err := storage.MVCCGetProto(ctx, reader, rsl.RangeAppliedStateKey(), hlc.Timestamp{}, &as,
Is it good to return a zero value here silently? before we would check for nil at least and do something. Now we might get a zero value and no error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @irfansharif, @nvanbenschoten, and @tbg)
pkg/kv/kvserver/stateloader/stateloader.go, line 166 at r4 (raw file):
Previously, ajwerner wrote…
Is it good to return a zero value here silently? before we would check for nil at least and do something. Now we might get a zero value and no error.
If I'm reading it all correctly, this is exactly what we're doing today. StateLoader.Load would previously read from LoadRangeAppliedState, and if the key (RangeAppliedStateKey) was not found, fall back to using LoadAppliedIndex + LoadMVCCStats. Each of those helpers would in turn first read from the RangeAppliedStateKey first, and if nothing is found, fall back to reading from the legacy keys. If those legacy keys were not found we would return the zero values.
Given that things have been fully migrated, we're not expecting to find anything under the legacy keys; if nothing exists under RangeAppliedStateKey, we'd then already be returning the zero values.
Does that seem sound? I'm not sure what else to do if the the key is not found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious if we feel this is worth getting in during stability
Thanks for getting this out!
I think we should consinder merging this only after we have a beta out (looks like we're inching closer there). Let me know if that has any downside I'm not considering. The changes look good, very satisfying. I have requested some additional clarifications to bad comments (I can say that, I wrote them originally), but there's nothing in this PR that I'd consider problematic.
The various legacy keys that were removed were removed in their
entirety. Our CLI to scan over store keys will no longer recognize these
keys. Is that ok?
I think that's ok. I can also see Andrew's argument (it's cheap to keep them so we should just in case) but also a <=21.1 cli is easy to come by if you need one. We have so many keys and it's an area of confusion to many, so if we can strip down the list we should. Also, this is already what this PR does so adding it back in and rearranging seems like busy-work for you that I'd like to avoid.
I don't think we need any checks to make sure we're not re-using some
of these keys in the future -- but I'd like other opinions.
Agreed.
Reviewed 33 of 41 files at r1, 10 of 10 files at r4, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @irfansharif, and @nvanbenschoten)
pkg/kv/kvserver/replica_command.go, line 2443 at r1 (raw file):
} canAvoidSendingLog := snap.State.TruncatedState.Index < snap.State.RaftAppliedIndex
Let's make this true
(which also allows us to close #66843 if you also remove the actual ability to send the log). If it is false
, we have a way worse problem.
It's fine if you want to postpone this, but it's so tempting.
pkg/kv/kvserver/replica_raft.go, line 1794 at r1 (raw file):
// truncated state. This isn't 100% trivial. The truncated state is // unreplicated, and effectively determines the first index of the log. We make // use of this fact by not sending the raft log in snapshots. Updates to the
nit: now "this fact" seems to refer to the truncated state determining where the log starts. But it should refer to the "unreplicated" bit. How about
// The truncated state of a replica determines where its Raft log starts (by giving the last index that already deleted). It is unreplicated, i.e. can differ between replicas despite being at the same applied index. The main way in which this happens is through snapshots, which contain no log (i.e. the truncated index will equal the applied index).
pkg/kv/kvserver/replica_raft.go, line 1791 at r4 (raw file):
} // handleTruncatedStateBelowRaft is called when a Raft command updates the
Can you rename this to handleTruncatedStateBelowRaftPreApply
? Took me a minute to remember that this is pre-apply. I was also confused about what's in the incoming ReadWriter. This is called from runPreApplyTriggersAfterStagingWriteBatch
, so for a bit I thought that the ReadWriter would already have a TruncatedState write applied to it, and we may have to undo it (if it's incompatible with the local log). But that is not the case; the truncation is a purely replicated side effect (i.e. it doesn't write to the truncated state key, which makes sense, since that is an unreplicated key). If this confused me it's a good idea to write it down explicitly that this is how it works.
pkg/kv/kvserver/replica_raft.go, line 1840 at r4 (raw file):
} if truncStatePostApply.Index < newTruncatedState.Index {
Doesn't this method need to be simplified further? We have in scope:
- oldTruncatedState (receives
b.state.TruncatedState
) - newTruncatedState (receives
res.State.TruncatedState
, i.e. what the raft leader intends to truncate to) - truncStatePostApply (loaded from the batch, but since a truncation doesn't write to the batch, this should equal oldTruncatedState?)
Let's rename newTruncatedState
to suggestedTruncatedState
and I think we should also be able to eliminate truncStatePostApply
and the corresponding LoadRaftTruncatedState
(though we could keep it for an assertion for a while)
pkg/kv/kvserver/stateloader/stateloader.go, line 166 at r4 (raw file):
Previously, irfansharif (irfan sharif) wrote…
If I'm reading it all correctly, this is exactly what we're doing today. StateLoader.Load would previously read from LoadRangeAppliedState, and if the key (RangeAppliedStateKey) was not found, fall back to using LoadAppliedIndex + LoadMVCCStats. Each of those helpers would in turn first read from the RangeAppliedStateKey first, and if nothing is found, fall back to reading from the legacy keys. If those legacy keys were not found we would return the zero values.
Given that things have been fully migrated, we're not expecting to find anything under the legacy keys; if nothing exists under RangeAppliedStateKey, we'd then already be returning the zero values.
Does that seem sound? I'm not sure what else to do if the the key is not found.
This seems consistent with what we do elsewhere, but I think it always needs to exist, so we might want to make this return an error if it does not.
pkg/kv/kvserver/stateloader/stateloader.go, line 172 at r4 (raw file):
// LoadAppliedIndex returns the Raft applied index and the lease applied index. func (rsl StateLoader) LoadAppliedIndex(
nit: can't this method be removed? Why not go through the AppliedState? I think there are only two callers here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm cool with removing the keys.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @irfansharif, and @nvanbenschoten)
b212c37
to
b5f74e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just remove the keys -- it's super unlikely we'd ever run into them in practice, and yea, older binaries are easy to come about. Thanks for reviewing!
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @nvanbenschoten, and @tbg)
pkg/cli/debug_check_store.go, line 255 at r1 (raw file):
Previously, ajwerner wrote…
I think you could leave this code in perpetuity if you wanted.
Leaving it as is per discussion above.
pkg/kv/kvserver/replica_command.go, line 2443 at r1 (raw file):
Previously, tbg (Tobias Grieger) wrote…
Let's make this
true
(which also allows us to close #66843 if you also remove the actual ability to send the log). If it isfalse
, we have a way worse problem.It's fine if you want to postpone this, but it's so tempting.
Done.
pkg/kv/kvserver/replica_raft.go, line 1794 at r1 (raw file):
Previously, tbg (Tobias Grieger) wrote…
nit: now "this fact" seems to refer to the truncated state determining where the log starts. But it should refer to the "unreplicated" bit. How about
// The truncated state of a replica determines where its Raft log starts (by giving the last index that already deleted). It is unreplicated, i.e. can differ between replicas despite being at the same applied index. The main way in which this happens is through snapshots, which contain no log (i.e. the truncated index will equal the applied index).
Done.
pkg/kv/kvserver/replica_raft.go, line 1791 at r4 (raw file):
Can you rename this to handleTruncatedStateBelowRaftPreApply
Done.
I'm not entirely sure I followed the second part of your review. I've tried rewording this comment block to something that makes a bit more sense to me. PTAL.
pkg/kv/kvserver/replica_raft.go, line 1840 at r4 (raw file):
Previously, tbg (Tobias Grieger) wrote…
Doesn't this method need to be simplified further? We have in scope:
- oldTruncatedState (receives
b.state.TruncatedState
)- newTruncatedState (receives
res.State.TruncatedState
, i.e. what the raft leader intends to truncate to)- truncStatePostApply (loaded from the batch, but since a truncation doesn't write to the batch, this should equal oldTruncatedState?)
Let's rename
newTruncatedState
tosuggestedTruncatedState
and I think we should also be able to eliminatetruncStatePostApply
and the correspondingLoadRaftTruncatedState
(though we could keep it for an assertion for a while)
Done.
pkg/kv/kvserver/stateloader/stateloader.go, line 166 at r4 (raw file):
Previously, tbg (Tobias Grieger) wrote…
This seems consistent with what we do elsewhere, but I think it always needs to exist, so we might want to make this return an error if it does not.
I was actually seeing in CI that it was possible for the key to not exist, and that we were relying on the zero values (and no errors). I could work through where exactly that happens now and improve this signature, but it seems relatively non-important. (Also like Tobi mentioned, we use this pattern elsewhere).
pkg/kv/kvserver/stateloader/stateloader.go, line 172 at r4 (raw file):
Previously, tbg (Tobias Grieger) wrote…
nit: can't this method be removed? Why not go through the AppliedState? I think there are only two callers here.
Good catch, done.
b5f74e3
to
b487ae7
Compare
b487ae7
to
259eff7
Compare
Added the GA-blocker + backport-21.2 labels. I think they're correct but could be wrong. It'd be nice to get this into 21.2, that'll let us clean up a few of these hold-over proto fields early next cycle. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this to master only and not target 21.2. I'm all for removing proto fields, but whether we do that in a month or in seven months is relatively unimportant. The change here isn't trivial, and they also make any problems in the migrations a lot more dicey.
I think there might be a place or two where you need to adjust when we can remove the fields.
Reviewed 10 of 10 files at r5, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @irfansharif and @nvanbenschoten)
pkg/kv/kvserver/replica_command.go, line 2443 at r1 (raw file):
Previously, irfansharif (irfan sharif) wrote…
Done.
Oops, meant #66834 in my last comment.
pkg/kv/kvserver/replica_raft.go, line 1793 at r5 (raw file):
, i.e. a command that includes a suggested truncated state.
I want to make sure that we understand from the comment that the truncation is not "mandated" by the command. We could just do nothing and everything would be correct. The raft command is basically just saying "hey, I (the raft leader) am suggesting this truncation, see if you like it".
pkg/kv/kvserver/replica_raft.go, line 1808 at r5 (raw file):
Add this (bonus points if you can say it more elegantly):
Note also that we crucially rely on truncations happening in the apply loop. This makes sure that a truncation can not remove log entries yet to be applied to the Replica state machine. Since a truncation only ever removes committed log indexes, and after chosing the index gets proposed, it will itself be assigned an index ahead of the highest index it could possibly remove. By the time the truncation is then handled, the state machine has thus applied all entries the truncation could possibly affect.
This was the source of my confusion in #70109, and it's an invariant we are likely to accidentally break if we ever do a decoupled apply loop or improve raft log truncations.
pkg/kv/kvserver/replica_raft.go, line 1838 at r5 (raw file):
unsafeKey := prefixBuf.RaftLogKey(idx) if err := readWriter.ClearUnversioned(unsafeKey); err != nil { return false, errors.Wrapf(err, "unable to clear truncated Raft entries for %+v", suggestedTruncatedState)
mention the idx here.
pkg/kv/kvserver/replica_raft_truncation_test.go, line 39 at r5 (raw file):
ctx := context.Background() var prevTruncatedState roachpb.RaftTruncatedState
Oops, this should be declared inside of Walk
, right? Also, can we "just" load the proto from eng
right before handleTruncatedStateBelowRaftPreApply
and avoid this out-of-band tracking?
Fixes cockroachdb#66544. Fixes cockroachdb#66834. We fully migrated away from the replicated truncated state and the old range applied state keys (RaftAppliedIndexLegacyKey, LeaseAppliedIndexLegacyKey, and RangeStatsLegacyKey) in cockroachdb#58088. We're now guaranteed to never see the legacy truncated+applied state representations, making this code (finally) safe to delete. Release justification: cluster version cleanup Release note: None --- This turned out to be pretty hairy and invasive. I'll wait for a few CI runs and inspect the diffs here a bit more closely. Given the surface area here, I'm curious if we feel this is worth getting in during stability. Some questions to consider: - The various legacy keys that were removed were removed in their entirety. Our CLI to scan over store keys will no longer recognize these keys. Is that ok? - I don't think we need any checks to make sure we're not re-using some of these keys in the future -- but I'd like other opinions. - Looks like we re-purposed the LocalRaftTruncatedStateLegacySuffix for the unreplicated truncated key as well, so just renamed it more appropriately. - v21.1 nodes have to interop with v20.2 nodes where the legacy representation was possible, and it identified such cases through booleans in proto messages (SnapshotRequest.Header.UseUnreplicatedTruncatedState for example). This means that we still need to explicitly set them in v21.2 code. Crucially we'll stop reading these fields in v21.2 code, letting us remove these fields entirely in v22.1. - The treatment above does not extend to ReplicaState.UsingAppliedStateKey; that field was only being used to trigger an idempotent migration to start using the newer applied state key representation, not as a way to express that the replica should expect the legacy representation. Since cockroachdb#58088 has already migrated every range in the system, we no longer need to trigger anything, and this field can be removed.
259eff7
to
6464de2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Begone replicated truncated state!
bors r+
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten and @tbg)
Build succeeded: |
This reverts commit 6464de2. That PR broke few of our roachtests since we haven't release the 21.2 beta yet. For our roachtests that exercised the upgrade path, we were effectively upgrading from 21.1 to 22.1 code (as of that PR) that asserted on the completion of the long running migration removing the legacy raft truncated state -- something that would only happen when going through 21.2. Given that, we temporarily revert cockroachdb#69887 while our beta gets prepared. cockroachdb#69887 (or rather, the revert of this commit) will be re-introduced to master once cockroachdb#69826 lands. Fixes cockroachdb#70244. Fixes cockroachdb#70252. Fixes cockroachdb#70253. Fixes cockroachdb#70283. Fixes cockroachdb#70350. Fixes cockroachdb#70390. Release note: None
This reverts commit 6464de2. That PR broke few of our roachtests since we haven't release the 21.2 beta yet. For our roachtests that exercised the upgrade path, we were effectively upgrading from 21.1 to 22.1 code (as of that PR) that asserted on the completion of the long running migration removing the legacy raft truncated state -- something that would only happen when going through 21.2. Given that, we temporarily revert cockroachdb#69887 while our beta gets prepared. cockroachdb#69887 (or rather, the revert of this commit) will be re-introduced to master once cockroachdb#69826 lands. Fixes cockroachdb#70244. Fixes cockroachdb#70252. Fixes cockroachdb#70253. Fixes cockroachdb#70283. Fixes cockroachdb#70350. Fixes cockroachdb#70390. Release note: None
70325: vendor: Add dependency on prometheus r=dhartunian a=rimadeodhar This PR adds an external dependency on prometheus. We need the promql library in order to enforce validity of promql expressions which will be contained in upcoming alerting and aggregation rules. These rule implementations are upcoming as a part of the new metrics upgrade. Resolves #69796 Release note: None 70347: pgcode: use XC instead of CDB r=knz a=otan Release note (sql change): Change the pgerror code XC instead of CD for CockroachDB specific errors. This is because the "C" class is reserved for the SQL standard. The pgcode `CDB00` used for unsatisfiable bounded staleness is now `XCUBS`. 70374: ui: updates the jobs table styling r=maryliag a=maryliag This commit updates the style of the table on the Jobs page and adds tooltips to its columns. Resolves #70149 Before <img width="924" alt="Screen Shot 2021-09-17 at 3 35 04 PM" src="https://user-images.githubusercontent.com/1017486/133844066-3168bec7-db52-4194-9f97-c7b10628d98e.png"> After <img width="880" alt="Screen Shot 2021-09-17 at 3 35 52 PM" src="https://user-images.githubusercontent.com/1017486/133844146-86e94611-ca99-4764-a97e-c8ca4e09f269.png"> Release note (ui change): Updating job table style to match all other tables on the console. 70432: Revert "kv,migration: rm code handling legacy raft truncated state" r=irfansharif a=irfansharif This reverts commit 6464de2. That PR broke few of our roachtests since we haven't release the 21.2 beta yet. For our roachtests that exercised the upgrade path, we were effectively upgrading from 21.1 to 22.1 code (as of that PR) that asserted on the completion of the long running migration removing the legacy raft truncated state -- something that would only happen when going through 21.2. Given that, we temporarily revert #69887 while our beta gets prepared. #69887 (or rather, the revert of _this_ commit) will be re-introduced to master once #69826 lands. Fixes #70244. Fixes #70252. Fixes #70253. Fixes #70283. Fixes #70350. Fixes #70390. Release note: None 70436: spanconfig: fix an erroneous usage of timeutil.Timer r=irfansharif a=irfansharif The contract for timeutil.Timer indicates that we should only be setting .Read when reading from the timer channel, not unconditionally before a call to .Reset(). Release note: None Co-authored-by: rimadeodhar <[email protected]> Co-authored-by: Oliver Tan <[email protected]> Co-authored-by: Marylia Gutierrez <[email protected]> Co-authored-by: irfan sharif <[email protected]>
…ate" This reverts commit ef1dd6f. cockroachdb#70432 reverted cockroachdb#69887, as temporary stop-gap until we release the first 21.2 beta. See the discussion over on cockroachdb#70432 for why we want to queue up this revert to the original revert; this should only be merged after cockroachdb#69826 lands. Release note: None
…ate" This reverts commit ef1dd6f. cockroachdb#70432 reverted cockroachdb#69887, as temporary stop-gap until we release the first 21.2 beta. See the discussion over on cockroachdb#70432 for why we want to queue up this revert to the original revert; this should only be merged after cockroachdb#69826 lands. Release note: None
70464: Re-introduce "kv,migration: rm code handling legacy raft truncated st… r=irfansharif a=irfansharif …ate" This reverts commit ef1dd6f. #70432 reverted #69887, as temporary stop-gap until we release the first 21.2 beta. See the discussion over on #70432 for why we want to queue up this revert to the original revert; this should only be merged after #69826 lands. Release note: None 71962: backup: mark some settings public r=dt a=dt This marks some of BACKUP's cluster settings as public as they are intended for user-tuning to match their desired workload / requirements, such as the delay before invoking priority reads or the target file size. Release note (ops change): Some existing settings related to BACKUP execution are now listed by SHOW CLUSTER SETTINGS. Fixes #71786. Co-authored-by: irfan sharif <[email protected]> Co-authored-by: David Taylor <[email protected]>
Fixes #66544.
Fixes #66834.
We fully migrated away from the replicated truncated state
and the old range applied state keys (RaftAppliedIndexLegacyKey,
LeaseAppliedIndexLegacyKey, and RangeStatsLegacyKey) in #58088. We're
now guaranteed to never see the legacy truncated+applied state
representations, making this code (finally) safe to delete.
Release justification: cluster version cleanup
Release note: None
This turned out to be pretty hairy and invasive. I'll wait for a few CI
runs and inspect the diffs here a bit more closely. Given the surface
area here, I'm curious if we feel this is worth getting in during
stability. Some questions to consider:
entirety. Our CLI to scan over store keys will no longer recognize these
keys. Is that ok?
of these keys in the future -- but I'd like other opinions.
the unreplicated truncated key as well, so just renamed it more
appropriately.
representation was possible, and it identified such cases through
booleans in proto messages (SnapshotRequest.Header.UseUnreplicatedTruncatedState
for example). This means that we still need to explicitly set them in
v21.2 code. Crucially we'll stop reading these fields in v21.2 code,
letting us remove these fields entirely in v22.1.
that field was only being used to trigger an idempotent migration to
start using the newer applied state key representation, not as a way
to express that the replica should expect the legacy representation.
Since #58088 has already migrated every range in the system, we no
longer need to trigger anything, and this field can be removed.