-
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: Use strict types for common fields #100181
kv: Use strict types for common fields #100181
Conversation
2ae342b
to
d607489
Compare
This was a 95% mechanical change and seemed pretty useful. There are three things that I don't love about this PR but couldn't easily change:
Let me know if you have any thoughts on this. Finally I put a few reviewers on here, but I don't expect everyone to look at every line. I'm not sure the best way to tag it. |
Also if we decide to make this change should be backported? It feels pretty low risk and could avoid some merge conflicts on backports. However, it probably isn't that important to do as the conflicts would be trivial to resolve. There are no serialization format changes to any protobufs. |
Let's move
Since we're doing all of this work anyway, let's just flip it to
I'd prefer not to. There's only downside to users, if we get something wrong. |
9c0f8ec
to
6e3a111
Compare
I was able to move them into kvserverpb at least, but it would have taken a fair bit more rearranging to move then into the more specific packages. This would probably be a good thing to do as a follow-on PR later.
I couldn't do this without breaking
Sounds good - I won't plan it for backport. The only risk I saw was making some PRs harder to backport, but I think that is not overly important. |
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 was able to move them into kvserverpb at least, but it would have taken a fair bit more rearranging to move then into the more specific packages. This would probably be a good thing to do as a follow-on PR later.
That's fine, we can clean it up later. I take it we were forced to move the index/term types into roachpb
for similar dependency reasons?
I couldn't do this without breaking
TestBelowRaftProtosDontChange
. I tried a couple of variations of this, but it wasn't possible to make it a uint64 but serialize as a int64 either since it hit a negative check.
I think that's just because the test uses Protobuf-generated Populate*
functions that randomly populate messages using a fixed seed. When we change a field from int64 to uint64 it can both change the randomly chosen values, and possibly also inject additional calls to the RNG such as if r.Intn(2) == 0 { this.Sequence *= -1 }
. It can therefore change both the randomly generated values and the sequence, but that doesn't mean that the messages aren't wire-compatible.
However, when I tried changing it to uint64 and running TestBelowRaftProtosDontChange
it passed. 🤷♀️
Reviewed 40 of 119 files at r2, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @andrewbaptist, @nvanbenschoten, @pavelkalinnikov, @RaduBerinde, and @tbg)
-- commits
line 4 at r2:
Needs updating.
pkg/kv/kvpb/api.proto
line 2102 at r2 (raw file):
// applied index of the CPut that left an intent on the local copy of the // right-hand range descriptor. int64 lease_applied_index = 4 [(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.LeaseSequence"];
The lease applied index is not a lease sequence number, so this type isn't appropriate. Didn't we already have a separate type for it?
The lease sequence number distinguishes different leases from each other. It is incremented when we acquire a new lease.
The lease applied index is used to order individual Raft proposals, for replay protection. It is incremented for every Raft proposal:
b.assignedLAI++ |
pkg/kv/kvserver/kvserverpb/state.proto
line 40 at r2 (raw file):
uint64 raft_applied_index = 1 [(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.RaftIndex"]; // The highest (and last) lease index applied to the state machine. int64 lease_applied_index = 2 [(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.LeaseSequence"];
As mentioned elsewhere, this and other instances should be a LeaseAppliedIndex not a LeaseSequence.
a89d330
to
caa73c2
Compare
f88b416
to
0d49b3a
Compare
Thanks! I didn't realize the difference between LeaseSequence and LeaseAppliedIndex until now. This makes more sense. I updated to use uint64 everywhere and it is passing the tests now. I must have been doing something strange before, but it seems like you were right that we can do this. Finally, I wanted to move all these fields into kv so I looked at what was necessary to do that. It turned out that only the |
ec12863
to
16e5036
Compare
Thanks! I won't have time for another pass before OOO and breather week, but I suppose we'd want to let this sit until the 23.1 backport bonanza calms down anyway. |
Yep, we can let this sit a little. There isn't a rush to get this in. It shouldn't be too hard to keep this up-to-date with master. At least it is now all green. |
9d1269a
to
d5a9005
Compare
@erikgrinaker if you get a chance next week can you review this again? Would be nice to merge to master now that backports to 23.1 have slowed down. |
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.
LGTM
Don't bother addressing the import nits in this PR if it's green, can be done as a follow-up PR.
pkg/kv/kvpb/data.go
Outdated
type RaftIndex uint64 | ||
|
||
// SafeValue implements the redact.SafeValue interface. | ||
func (s RaftTerm) SafeValue() {} |
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.
nit: it's unusual to implement this "not next to" the receiver.
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/util/timeutil" | ||
) | ||
|
||
// Used within the RangeUpdate method. | ||
var _ kvpb.LeaseAppliedIndex |
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.
Why not remove this? This is a no-op.
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.
If you need kvpb
imported, use a _ "github.com/cockroachdb/cockroach/pkg/kv/kvpb"
import instead.
// mvcc stats. These are all persisted on each transition of the Raft | ||
// state machine (i.e. on each Raft application), so they are stored | ||
// in the same RocksDB key for efficiency. | ||
message RangeAppliedState { |
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.
Moved from elsewhere with just casttype adjustments, right?
@@ -25,6 +26,9 @@ import ( | |||
// representation outside of tests. | |||
type RecoveryKey roachpb.RKey | |||
|
|||
// Needed for recovery.proto. | |||
var _ kvpb.RaftIndex |
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.
Ditto
d5a9005
to
a8f676b
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.
No problem - all easy to address. TFTY
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @erikgrinaker, @nvanbenschoten, @pavelkalinnikov, @RaduBerinde, and @tbg)
Previously, erikgrinaker (Erik Grinaker) wrote…
Needs updating.
Updated - thanks.
pkg/kv/kvpb/api.proto
line 2102 at r2 (raw file):
Previously, erikgrinaker (Erik Grinaker) wrote…
The lease applied index is not a lease sequence number, so this type isn't appropriate. Didn't we already have a separate type for it?
The lease sequence number distinguishes different leases from each other. It is incremented when we acquire a new lease.
The lease applied index is used to order individual Raft proposals, for replay protection. It is incremented for every Raft proposal:
b.assignedLAI++
Fixed. I changed to separate these back out.
pkg/kv/kvpb/data.go
line 174 at r6 (raw file):
Previously, tbg (Tobias Grieger) wrote…
nit: it's unusual to implement this "not next to" the receiver.
Fixed, moved next to the definitions.
pkg/kv/kvserver/closedts/ctpb/service.go
line 25 at r6 (raw file):
Previously, tbg (Tobias Grieger) wrote…
If you need
kvpb
imported, use a_ "github.com/cockroachdb/cockroach/pkg/kv/kvpb"
import instead.
Done. Thanks for the tip!
pkg/kv/kvserver/kvserverpb/state.proto
line 40 at r2 (raw file):
Previously, erikgrinaker (Erik Grinaker) wrote…
As mentioned elsewhere, this and other instances should be a LeaseAppliedIndex not a LeaseSequence.
Changed
pkg/kv/kvserver/kvserverpb/state.proto
line 218 at r6 (raw file):
Previously, tbg (Tobias Grieger) wrote…
Moved from elsewhere with just casttype adjustments, right?
Correct. This was in roachpb before, but more appropriate here.
pkg/kv/kvserver/loqrecovery/loqrecoverypb/recovery.go
line 30 at r6 (raw file):
Previously, tbg (Tobias Grieger) wrote…
Ditto
Fixed
This PR introduces 3 new typed fields to the kvpb package: RaftTerm, RaftIndex and LeaseAppliedIndex. These fields were previously just unit64 throughout the code and this made the code harder to read and risked incorrect conversions. It also moves internal_raft.proto into the kvserver package as it is no longer accessed outside of kv. Epic: none Release note: None
a8f676b
to
a9989a8
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.
Thanks for the cleanup! Reviewed all of the Protobuf changes, LGTM.
For next time, it'd be nice to split this out into a few commits (e.g. file reorganization and Protobuf message changes), to more easily identify the changes that need particular scrutiny. But don't spend time on that now.
bors r=erikgrinaker TFTR - I'll split it out any future cleanups. |
Build failed (retrying...): |
Build succeeded: |
This PR introduces 3 new typed fields in mvcc.go:
RaftTerm, RaftIndex and LeaseSequence. These fields were previously just unit64 throughout the code and this made the code harder to read and risked incorrect conversions.
Epic: none
Release note: None