Skip to content

spanconfig: improve use of commit ts validity intervals#80196

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
irfansharif:220419.kvaccessor-exp
Apr 20, 2022
Merged

spanconfig: improve use of commit ts validity intervals#80196
craig[bot] merged 1 commit intocockroachdb:masterfrom
irfansharif:220419.kvaccessor-exp

Conversation

@irfansharif
Copy link
Copy Markdown
Contributor

@irfansharif irfansharif commented Apr 19, 2022

  • Fix a bug where the sqlliveness session was incorrectly returning
    hlc.MinTimestamp when asking for the start timestamp of the underlying
    lease;
  • Drop the "lease" verbiage from KVAccessor, instead talk about the
    valid commit timestamp interval. Not all uses of the KVAccessor plumb
    in lease timestamps;
  • Check whether the max commit timestamp is non-empty (possible if the
    lease has already expired) before issuing the RPC, saves an extra
    round trip;
  • Unify handling of commit timestamp interval -- we were previously
    checking properties only in codepaths where the txn was not already
    scoped;
  • Move the retryable commit-timestamp-out-of-bounds error out to the
    base spanconfig package (breaking the dependency between
    spanconfigreconciler and spanconfigkvaccessor);
  • Re-write a test to use manual clocks, and use it to test the scenario
    where a txn's timestamp is bumped past the maximum commit timestamp
    (can happen for large kvaccessor batches, we should observe an
    internal retry);
  • Remove an extraneous goroutine from a test checking whether ctx
    cancellation is respected.

(re-) Fixes #73789.

Release note: None
Release justification: low risk, high benefit change

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@irfansharif irfansharif force-pushed the 220419.kvaccessor-exp branch 2 times, most recently from 854fd5f to 26466fc Compare April 20, 2022 17:40
@irfansharif irfansharif changed the title [wip] spanconfig: fix use of txn commit ts validity interval spanconfig: improve use of commit ts validity intervals Apr 20, 2022
@irfansharif irfansharif marked this pull request as ready for review April 20, 2022 17:41
@irfansharif irfansharif requested review from a team as code owners April 20, 2022 17:41
Copy link
Copy Markdown
Contributor

@ajwerner ajwerner 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 20 of 20 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @arulajmani and @irfansharif)


pkg/spanconfig/spanconfigkvaccessor/kvaccessor.go, line 289 at r1 (raw file):

	}

	if maxCommitTS.Less(txn.ReadTimestamp()) {

should this check ProvisionalCommitTimestamp instead of ReadTimestamp? I know that the below code does the check based on the ReadTimestamp. I guess I'm wondering whether that's correct.


pkg/spanconfig/errors.go, line 22 at r1 (raw file):

// CommitTimestampOutOfBoundsError is returned when it's not possible to commit
// an update within the specified time interval.
type CommitTimestampOutOfBoundsError struct{}

I'm 50/50 on exporting this. I don't know that it adds any value, but I don't feel strongly.

@irfansharif irfansharif force-pushed the 220419.kvaccessor-exp branch from 26466fc to 8882f75 Compare April 20, 2022 18:28
Copy link
Copy Markdown
Contributor Author

@irfansharif irfansharif left a comment

Choose a reason for hiding this comment

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

Thanks!

bors r+

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


pkg/spanconfig/spanconfigkvaccessor/kvaccessor.go, line 289 at r1 (raw file):

Previously, ajwerner wrote…

should this check ProvisionalCommitTimestamp instead of ReadTimestamp? I know that the below code does the check based on the ReadTimestamp. I guess I'm wondering whether that's correct.

Yea I was wondering the same. I also found #76727 earlier today which fires the assertion under txn.UpdateDeadline, but doesn't look directly relevant. Looks like the check below dates back to 6acbe92 and was pointing to the txn's (static?) original timestamp. I'm not sure what would break if we only allowed deadlines to be set if under the provisional timestamp.

Back to this PR: if we're comparing the maxCommitTS against ReadTimestamp here, and if that's different from the ProvisionalCommitTimestamp, we can have the following scenarios (given ReadTimestamp <= ProvisionalTimestamp <= FinalCommitTS):
a. maxCommitTS < ReadTimestamp implies maxCommitTS < ProvisionalTimestamp
b. maxCommitTS >= ReadTimestamp
i. maxCommitTS <= ProvisionalTimestamp
ii. maxCommitTS > ProvisionalTimestamp

For both (b.i) and (b.ii) we can set the deadline without error-ing and will retry if maxCommitTS > FinalCommitTS. I'll keep the patch as is for now.


pkg/spanconfig/errors.go, line 22 at r1 (raw file):

Previously, ajwerner wrote…

I'm 50/50 on exporting this. I don't know that it adds any value, but I don't feel strongly.

With NewCommitTimestampOutOfBoundsError, the linter'll complains if it's unexported; I also wanted to avoid the reconciler -> kvaccessor dependency. But most of all I wanted to refer to a public symbol in various comments (KVAccessor, the RPCs).

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Apr 20, 2022

Build failed (retrying...):

Copy link
Copy Markdown
Contributor

@ajwerner ajwerner 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 @ajwerner, @arulajmani, and @irfansharif)


pkg/spanconfig/errors.go, line 22 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

With NewCommitTimestampOutOfBoundsError, the linter'll complains if it's unexported; I also wanted to avoid the reconciler -> kvaccessor dependency. But most of all I wanted to refer to a public symbol in various comments (KVAccessor, the RPCs).

I don't follow. I'd just have NewCommitTimestampOutOfBoundsError return error

@irfansharif irfansharif force-pushed the 220419.kvaccessor-exp branch from 8882f75 to c8bb9a2 Compare April 20, 2022 19:21
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Apr 20, 2022

Canceled.

Copy link
Copy Markdown
Contributor Author

@irfansharif irfansharif 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 @ajwerner and @arulajmani)


pkg/spanconfig/errors.go, line 22 at r1 (raw file):

Previously, ajwerner wrote…

I don't follow. I'd just have NewCommitTimestampOutOfBoundsError return error

Doh, done.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Apr 20, 2022

🕐 Waiting for PR status (Github check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

- Fix a bug where the sqlliveness session was incorrectly returning
  hlc.MinTimestamp when asking for the start timestamp of the underlying
  lease;
- Drop the "lease" verbiage from KVAccessor, instead talk about the
  valid commit timestamp interval. Not all uses of the KVAccessor plumb
  in lease timestamps;
- Check whether the max commit timestamp is non-empty (possible if the
  lease has already expired) before issuing the RPC, saves an extra
  round trip.
- Unify handling of commit timestamp interval -- we were previously
  checking properties only in codepaths where the txn was not already
  scoped;
- Move the retryable commit-timestamp-out-of-bounds error out to the
  base spanconfig package (breaking the dependency between
  spanconfigreconciler and spanconfigkvaccessor);
- Re-write a test to use manual clocks, and use it to test the scenario
  where a txn's timestamp is bumped past the maximum commit timestamp
  (can happen for large kvaccessor batches, we should observe an
  internal retry);
- Remove an extraneous goroutine from a test checking whether ctx
  cancellation is respected.

Release note: None
Release justification: low risk, high benefit change
@irfansharif irfansharif force-pushed the 220419.kvaccessor-exp branch from c8bb9a2 to 064a43f Compare April 20, 2022 19:26
@irfansharif
Copy link
Copy Markdown
Contributor Author

Bouncing the CLA bot.

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Apr 20, 2022

Stopped waiting for PR status (Github check) without running due to duplicate requests to run. You may check Bors to see that this PR is included in a batch by one of the other requests.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Apr 20, 2022

Build succeeded:

@craig craig bot merged commit c50ffb4 into cockroachdb:master Apr 20, 2022
@irfansharif irfansharif deleted the 220419.kvaccessor-exp branch April 20, 2022 23:12
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.

spanconfig: ensure safety without mutual exclusion in the reconciliation job

3 participants