Skip to content

roachpb: make range/replica descriptor fields non-nullable#85120

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
erikgrinaker:rangedescriptor-non-nullable
Aug 1, 2022
Merged

roachpb: make range/replica descriptor fields non-nullable#85120
craig[bot] merged 1 commit intocockroachdb:masterfrom
erikgrinaker:rangedescriptor-non-nullable

Conversation

@erikgrinaker
Copy link
Copy Markdown
Contributor

@erikgrinaker erikgrinaker commented Jul 27, 2022

This patch makes all fields in range/replica descriptors non-nullable,
fixing a long-standing TODO.

Additionally, this fixes a set of bugs where code would use regular
comparison operators (e.g. ==) to compare replica descriptors, which
with nullable pointer fields would compare the memory locations rather
than the values. One practical consequence of this was that the
DistSender would fail to use a new leaseholder with a non-VOTER type
(e.g. VOTER_INCOMING), instead continuing to try other replicas
before backing off. However, there are further issues surrounding this
bug and it will be addressed separately in a way that is more amenable
to backporting.

The preparatory work for this was done in ea720e3.

Touches #85060.
Touches #38308.
Touches #38465.

Release note: None

@erikgrinaker erikgrinaker requested a review from a team July 27, 2022 11:53
@erikgrinaker erikgrinaker requested review from a team as code owners July 27, 2022 11:53
@erikgrinaker erikgrinaker requested a review from a team July 27, 2022 11:53
@erikgrinaker erikgrinaker self-assigned this Jul 27, 2022
@erikgrinaker erikgrinaker requested a review from a team July 27, 2022 11:53
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@erikgrinaker erikgrinaker force-pushed the rangedescriptor-non-nullable branch from 871a307 to 38b8002 Compare July 27, 2022 11:54
@erikgrinaker erikgrinaker requested review from pav-kv and removed request for a team July 27, 2022 11:54
@erikgrinaker erikgrinaker force-pushed the rangedescriptor-non-nullable branch 4 times, most recently from c91cfc4 to 7ec5794 Compare July 27, 2022 15:44
@erikgrinaker
Copy link
Copy Markdown
Contributor Author

erikgrinaker commented Jul 27, 2022

I've submitted a separate DistSender fix in #85140, since there are additional issues around these replica descriptor comparisons.

@erikgrinaker erikgrinaker force-pushed the rangedescriptor-non-nullable branch from 7ec5794 to 2a07859 Compare July 27, 2022 15:50
Copy link
Copy Markdown
Collaborator

@pav-kv pav-kv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % comments.

Also, it looks like, for ease/speed of review, this PR could be split in 2, one per proto field modified? Ok to leave as is.


func predVoterFull(rDesc ReplicaDescriptor) bool {
switch rDesc.GetType() {
switch rDesc.Type {
Copy link
Copy Markdown
Collaborator

@pav-kv pav-kv Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has making Type non-nullable eliminated this getter?

If I remember correctly, proto is converging towards GetBlah()+builders kind of APIs, so that they can make an assumption of immutability to enable optimizations. Is gogoproto different in this sense?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, its only purpose was to convert nil to VOTER. gogoproto doesn't generate getters by default, this was a custom one. We're still stuck on the old Protobuf library and gogoproto for reasons that escape me right now.

// l.Replica.Type, newL.Replica.Type = 0, 0
l.Replica.Type, newL.Replica.Type = nil, nil
// replica, but that also shouldn't prevent it from extending its lease.
l.Replica.Type, newL.Replica.Type = 0, 0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do zeroes mean here? Is there a named constant for what they represent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zero value is VOTER, but I think 0 better expresses the intent: we're clearing these fields because we don't care about them for comparison purposes.

return false
}

switch typ := repDesc.GetType(); typ {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: Personally, I would leave this assignment to avoid retyping repDesc.Type below (here and in a few other cases in this PR), but it seems just a taste thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, left it like this in a few places where we reuse the value quite a lot, but I didn't see much point in it here.

@erikgrinaker
Copy link
Copy Markdown
Contributor Author

Also, it looks like, for ease/speed of review, this PR could be split in 2, one per proto field modified? Ok to leave as is.

Yeah, I agree. Not sure if it's worth the effort to go back and split it up, but it would've been better to submit them separately.

@erikgrinaker erikgrinaker force-pushed the rangedescriptor-non-nullable branch 2 times, most recently from b567e0c to bee3fbd Compare August 1, 2022 10:35
This patch makes all fields in range/replica descriptors non-nullable,
fixing a long-standing TODO.

Additionally, this fixes a set of bugs where code would use regular
comparison operators (e.g. `==`) to compare replica descriptors, which
with nullable pointer fields would compare the memory locations rather
than the values. One practical consequence of this was that the
DistSender would fail to use a new leaseholder with a non-`VOTER` type
(e.g.  `VOTER_INCOMING`), instead continuing to try other replicas
before backing off. However, there are further issues surrounding this
bug and it will be addressed separately in a way that is more amenable
to backporting.

The preparatory work for this was done in ea720e3.

Release note: None
@erikgrinaker erikgrinaker force-pushed the rangedescriptor-non-nullable branch from bee3fbd to acdf42a Compare August 1, 2022 11:31
@erikgrinaker
Copy link
Copy Markdown
Contributor Author

Spun up a mixed-version cluster with this PR and master, didn't see any issues with range descriptor incompatibilities like we did previously. Going to push this through and see if the nightlies pick up anything.

TFTR!

bors r=pavelkalinnikov

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 1, 2022

Build succeeded:

@craig craig bot merged commit 590049f into cockroachdb:master Aug 1, 2022
@erikgrinaker erikgrinaker deleted the rangedescriptor-non-nullable branch August 1, 2022 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants