Skip to content
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

kvserver: reorder leasePostApply on snapshot application #60634

Merged

Conversation

andreimatei
Copy link
Contributor

The snapshot application code was weird - it called
leasePostApplyLocked() before doing r.mu.state = snapshot.state. This
is different from the way it's called when a lease applies regularly
through a raft command, where most of the command's effects on the
replica state have already been applied (hence the "Post" in the name).
This patch reorders things on snapshot application such that r.mu.state
is updated before the leasePostApplyLocked call.

Besides being sane, this comes in anticipation of leasePostApplyLocked
using more elements of the replica state, and needing those to be up to
date.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 4 files at r1, 4 of 4 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andreimatei)


pkg/kv/kvserver/replica_proposal.go, line 295 at r1 (raw file):

}

type leaseJumpOption bool

Could you give this a comment?


pkg/kv/kvserver/replica_proposal.go, line 315 at r2 (raw file):

// not be aware of other lease changes that happened before the snapshot was
// generated. This method thus tolerates prevLease being "stale" when
// allowLeaseJump is passed. It's also

Sentence was cut off.


pkg/kv/kvserver/replica_proposal.go, line 320 at r2 (raw file):

// newLease is the same as prevLease. This allows leasePostApplyLocked to be
// called for some of its side-effects even if the lease in question has
// otherwise already been applied to the range.

Do you think this is better than just saying that the method supports prevLease == newLease and that such situations are idempotent? We still rely on this behavior in applySnapshot, because the lease may not have changed.

My vote would be to get rid of the newLease == nil handling.


pkg/kv/kvserver/replica_proposal.go, line 324 at r2 (raw file):

	ctx context.Context, prevLease *roachpb.Lease, newLease *roachpb.Lease, jumpOpt leaseJumpOption,
) {
	if newLease == nil {

If you want to keep this, give this a comment as well.


pkg/kv/kvserver/replica_raftstorage.go, line 986 at r2 (raw file):

	r.store.mu.Unlock()

	// Inform the concurrency manager that this replica just applied a snapshot.

Pull this down below leasePostApplyLocked as well.

@andreimatei andreimatei force-pushed the closedts.lease-post-apply-refactor branch from c0ae546 to 19d212c Compare February 17, 2021 18:25
Copy link
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andreimatei and @nvanbenschoten)


pkg/kv/kvserver/replica_proposal.go, line 295 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Could you give this a comment?

done


pkg/kv/kvserver/replica_proposal.go, line 315 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Sentence was cut off.

done


pkg/kv/kvserver/replica_proposal.go, line 320 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Do you think this is better than just saying that the method supports prevLease == newLease and that such situations are idempotent? We still rely on this behavior in applySnapshot, because the lease may not have changed.

My vote would be to get rid of the newLease == nil handling.

done


pkg/kv/kvserver/replica_proposal.go, line 324 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

If you want to keep this, give this a comment as well.

gone

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 4 of 4 files at r4.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @andreimatei)


pkg/kv/kvserver/replica_proposal.go, line 323 at r4 (raw file):

// allowLeaseJump is passed. prevLease can also be the same as newLease; see below.
//
// newLease represents the lease being applied. Can be the same as prevLease

nit: missing period.

The snapshot application code was weird - it called
leasePostApplyLocked() *before* doing r.mu.state = snapshot.state. This
is different from the way it's called when a lease applies regularly
through a raft command, where most of the command's effects on the
replica state have already been applied (hence the "Post" in the name).
This patch reorders things on snapshot application such that r.mu.state
is updated before the leasePostApplyLocked call.

Besides being sane, this comes in anticipation of leasePostApplyLocked
using more elements of the replica state, and needing those to be up to
date.

Release note: None
@andreimatei andreimatei force-pushed the closedts.lease-post-apply-refactor branch from 19d212c to 4a22463 Compare February 18, 2021 00:19
Copy link
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @nvanbenschoten)


pkg/kv/kvserver/replica_proposal.go, line 323 at r4 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

nit: missing period.

done


pkg/kv/kvserver/replica_raftstorage.go, line 986 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Pull this down below leasePostApplyLocked as well.

done

Copy link
Contributor Author

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

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

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @nvanbenschoten)

@craig
Copy link
Contributor

craig bot commented Feb 18, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Feb 18, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Feb 18, 2021

Build succeeded:

@craig craig bot merged commit 3c223f5 into cockroachdb:master Feb 18, 2021
@andreimatei andreimatei deleted the closedts.lease-post-apply-refactor branch February 18, 2021 19:19
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