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: scan only intents during rts scan #71295

Merged
merged 1 commit into from
Oct 16, 2021

Conversation

stevendanna
Copy link
Collaborator

@stevendanna stevendanna commented Oct 7, 2021

In 21.2, seperated intents are the default. Once migrated, we can then
use this to iterate over substantially less data to find all intents
for a given keyspan. The hope is that this will make rangefeed
start-up substantially cheaper.

Informs #70920
Fixes #69697

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.

Exciting! Just left some drive-by comments. I'd be interested to hear what kind of impact you are seeing this have on changefeed restart latency.

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @stevendanna)


pkg/kv/kvserver/replica_rangefeed.go, line 380 at r1 (raw file):

	p = rangefeed.NewProcessor(cfg)

	onlySeperatedIntents := r.store.cfg.Settings.Version.ActiveVersionOrEmpty(ctx).IsActive(clusterversion.PostSeparatedIntentsMigration)

I don't think you need the ActiveVersionOrEmpty(ctx) part.


pkg/kv/kvserver/replica_rangefeed.go, line 385 at r1 (raw file):

	if onlySeperatedIntents {
		rtsIter = func() rangefeed.IntentScanner {
			lowerBound := keys.LockTableSingleKeyStart

If we're providing a lower bound (which itself shouldn't be necessary), shouldn't it be keys.LockTableSingleKey(desc.Key.AsRawKey(), nil)?


pkg/kv/kvserver/rangefeed/task.go, line 104 at r1 (raw file):

	ltStart, _ := keys.LockTableSingleKey(startKey, nil)
	var meta enginepb.MVCCMetadata
	for valid, err := s.iter.SeekEngineKeyGE(storage.EngineKey{Key: ltStart}); ; valid, err = s.iter.NextEngineKey() {

This is relying on the iterator's upper bound to terminate the iteration. That's not necessarily a problem, but we should make that clear both here and in the SeperatedIntentScanner contract.


pkg/kv/kvserver/rangefeed/task.go, line 113 at r1 (raw file):

		engineKey, err := s.iter.EngineKey()
		if err != nil {
			// TODO(ssd): should this return or continue?

I assume you're asking the question because of the corresponding logic in computeMinIntentTimestamp. That logic looks wrong. We were continuing on all error cases at one point during the review process, and we switched it over, but must have missed that case. Do you mind fixing that over there as well?


pkg/kv/kvserver/rangefeed/task.go, line 125 at r1 (raw file):

		}

		if meta.Txn != nil {

meta.Txn == nil is an error case, so we should treat it as such.

@stevendanna stevendanna force-pushed the rangefeed-rts-scan branch 2 times, most recently from 8867cd1 to c6789af Compare October 8, 2021 17:45
Copy link
Collaborator Author

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

I'd be interested to hear what kind of impact you are seeing this have on changefeed restart latency.

Me too! Haven't been able to test this well yet.

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


pkg/kv/kvserver/replica_rangefeed.go, line 380 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

I don't think you need the ActiveVersionOrEmpty(ctx) part.

Done. Thanks!


pkg/kv/kvserver/replica_rangefeed.go, line 385 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

If we're providing a lower bound (which itself shouldn't be necessary), shouldn't it be keys.LockTableSingleKey(desc.Key.AsRawKey(), nil)?

Done. Thanks!


pkg/kv/kvserver/rangefeed/task.go, line 113 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

I assume you're asking the question because of the corresponding logic in computeMinIntentTimestamp. That logic looks wrong. We were continuing on all error cases at one point during the review process, and we switched it over, but must have missed that case. Do you mind fixing that over there as well?

Done -- your are exactly right about why I was asking, thanks for confirming!


pkg/kv/kvserver/rangefeed/task.go, line 125 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

meta.Txn == nil is an error case, so we should treat it as such.

Done.

@stevendanna stevendanna changed the title DNM: kvserver: scan only intents during rts scan kvserver: scan only intents during rts scan Oct 8, 2021
@stevendanna stevendanna marked this pull request as ready for review October 8, 2021 17:49
@stevendanna stevendanna requested a review from a team as a code owner October 8, 2021 17:49
@stevendanna
Copy link
Collaborator Author

I'd still like to write a benchmark here, but I think the general shape of this should be ready for review.

@erikgrinaker
Copy link
Contributor

erikgrinaker commented Oct 8, 2021

Drive-by comment: we may want to use storage APIs to access the separated intents rather than directly using the engine and keys all over the place. I wrote a small utility function for this a while ago:

func ScanSeparatedIntents(

Although it'd be even nicer if we had an intent iterator or something in there. Not sure if we have something like that laying around already, otherwise it might be easy to whip one up (i.e. adapt what you have here).

Don't let this block the PR though, just a thought.

@stevendanna
Copy link
Collaborator Author

stevendanna commented Oct 8, 2021 via email

@erikgrinaker
Copy link
Contributor

I agree, we should use an iterator here. Feel free to punt it for now though.

@stevendanna
Copy link
Collaborator Author

More to do here:

=== RUN   TestRegistryLifecycle/pause_reverting
panic: negative refcount -1 for txn &{txnID:[161 116 255 222 31 77 69 178 164 172 37 223 11 77 109 164] txnKey:[] txnMinTimestamp:{WallTime:0 Logical:0 Synthetic:false} timestamp:{WallTime:1633944999852953000 Logical:0 Synthetic:false} refCount:-1 index:0} [recovered]
	panic: negative refcount -1 for txn &{txnID:[161 116 255 222 31 77 69 178 164 172 37 223 11 77 109 164] txnKey:[] txnMinTimestamp:{WallTime:0 Logical:0 Synthetic:false} timestamp:{WallTime:1633944999852953000 Logical:0 Synthetic:false} refCount:-1 index:0}

goroutine 4387 [running]:
github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).Recover(0xc0048ec180, 0x9523798, 0xc0020fd9b0)
	/Users/ssd/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:231 +0x126
panic(0x79256e0, 0xc0039c4000)
	/usr/local/Cellar/go/1.16.5/libexec/src/runtime/panic.go:965 +0x1b9
github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed.(*unresolvedIntentQueue).assertOnlyPositiveRefCounts(0xc000f2a248)
	/Users/ssd/go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed/resolved_timestamp.go:524 +0x165
github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed.(*unresolvedIntentQueue).AllowNegRefCount(...)
	/Users/ssd/go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed/resolved_timestamp.go:516
github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed.(*resolvedTimestamp).Init(0xc000f2a220, 0x8)
	/Users/ssd/go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed/resolved_timestamp.go:107 +0x32
github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed.(*Processor).initResolvedTS(0xc000f2a160, 0x95236f0, 0xc0023dd540)
	/Users/ssd/go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed/processor.go:620 +0x34
github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed.(*Processor).consumeEvent(0xc000f2a160, 0x95236f0, 0xc0023dd540, 0xc00319b0a0)
	/Users/ssd/go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed/processor.go:560 +0x258
github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed.(*Processor).run(0xc000f2a160, 0x9523798, 0xc0020fd9b0, 0x6, 0xc001220ea0, 0xc0048ec180)
	/Users/ssd/go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed/processor.go:302 +0x1054
github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed.(*Processor).Start.func1(0x9523798, 0xc0020fd9b0)
	/Users/ssd/go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/rangefeed/processor.go:204 +0x59
github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).RunAsyncTaskEx.func2(0xc0048ec180, 0x9523798, 0xc0020fd9b0, 0x0, 0x0, 0xc001220ee0)
	/Users/ssd/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:442 +0xf3
created by github.com/cockroachdb/cockroach/pkg/util/stop.(*Stopper).RunAsyncTaskEx
	/Users/ssd/go/src/github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:434 +0x22b

@stevendanna
Copy link
Collaborator Author

That error was a result of me accidentally misusing the scratch buffer provided by keys.LockSingleKey. Should be resolved now, let's see what CI says.

Copy link
Contributor

@miretskiy miretskiy 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 @miretskiy, @nvanbenschoten, and @stevendanna)


pkg/kv/kvserver/rangefeed/task.go, line 90 at r6 (raw file):

// separated intents are in use.
//
// EngineIterator Contract:

Any way to enforce this contract?

@miretskiy miretskiy self-requested a review October 11, 2021 13:18
@stevendanna
Copy link
Collaborator Author

stevendanna commented Oct 14, 2021

@nvanbenschoten I've run some ad-hoc tests. While running the tpcc workload (w=100) against a 4 node local cluster, the impact on changefeed startup (without a backfill) is pretty substantial. You can see it pretty dramatically in p99 sql latency:

Screenshot 2021-10-14 at 11 24 47

I would take the scale there with a grain of salt, but I've run this a few times in different orders and get the same shape of difference each time.

@miretskiy
Copy link
Contributor

miretskiy commented Oct 14, 2021 via email

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_strong:

Reviewed 3 of 5 files at r2, 1 of 1 files at r3, 1 of 1 files at r5, 1 of 1 files at r6, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @miretskiy and @stevendanna)


pkg/kv/kvserver/replica_rangefeed.go, line 380 at r6 (raw file):

	p = rangefeed.NewProcessor(cfg)

	onlySeparatedIntents := r.store.cfg.Settings.Version.IsActive(ctx, clusterversion.PostSeparatedIntentsMigration)

nit: any reason not to push this into the rtsIter closure?


pkg/kv/kvserver/replica_rangefeed.go, line 402 at r6 (raw file):

		iter := r.Engine().NewMVCCIterator(storage.MVCCKeyAndIntentsIterKind, storage.IterOptions{
			UpperBound: desc.EndKey.AsRawKey(),
			// TODO(nvanbenschoten): To facilitate fast restarts of rangefeed

I think we can get rid of this TODO now 🥳


pkg/kv/kvserver/rangefeed/task.go, line 43 at r6 (raw file):

type initResolvedTSScan struct {
	p              *Processor
	intentConsumer IntentScanner

nit: the naming here is a little off. We have a type named IntentScanner and we call it c in some contexts and intentConsumer in others. And we also have a type named eventConsumer. Can I suggest using is in all contexts?


pkg/kv/kvserver/rangefeed/task.go, line 114 at r6 (raw file):

			return err
		} else if !valid {
			// We assume the iterator has an UpperBound

s/assume the iterator has/depend on the iterator having/

In 21.2, seperated intents are the default. Once migrated, we can then
use this to iterate over substantially less data to find all intents
for a given keyspan. The hope is that this will make rangefeed
start-up substantially cheaper.

Release note: None
@stevendanna
Copy link
Collaborator Author

bors r=nvanbenschoten

@craig
Copy link
Contributor

craig bot commented Oct 16, 2021

Build succeeded:

@craig craig bot merged commit 5d972a6 into cockroachdb:master Oct 16, 2021
stevendanna added a commit to stevendanna/cockroach that referenced this pull request Mar 22, 2022
This setting was added in a 21.2 backport

cockroachdb#72315

but was never added to master:

cockroachdb#71295

So from the perspective of someone who upgrades from 21.2, it is now a
retired setting.

Release justification: Low-risk bug fix

Release note: None
craig bot pushed a commit that referenced this pull request Mar 22, 2022
78186: ui: improve UI for statuses on the jobs page r=jocrl a=jocrl

Addresses #71963

Previously the `cancel-requested`, `pause-requested`, and `revert-failed` had
blue badges.
![image](https://user-images.githubusercontent.com/91907326/138773770-84aa4637-d87c-47a2-bd07-7d02c2322982.png) 

Now, `cancel-requested` and `pause-requested` have gray badges and
`revert-failed` has a red badge.
![image](https://user-images.githubusercontent.com/91907326/159310950-9742cc1b-9350-4c6d-990b-3e7e2197e681.png)

Release note (ui): Improved colors for status badges on the Jobs page. Three
status on the Jobs page, `cancel-requested`, `pause-requested`, and
`revert-failed`, previously had blue status badge colors that were
uninformative of their meaning. This commit modifies the badge colors to
reflect their meaning. Now `cancel-requested` and `pause-requested` have gray
badges and `revert-failed` has a red badge.

78213: distsql: simple projection in experimental distsql planner panics r=msirek a=msirek

Previously, selecting a given column from a table more than once could
cause an `index out of range` panic when experimental_distsql_planning
is set to always, for example:
```
CREATE TABLE kv (k INT PRIMARY KEY, v INT);
INSERT INTO kv VALUES (1, 1), (2, 1), (3, 2);
SET experimental_distsql_planning = always;
SELECT v, k, k, v FROM kv;
```
This commit fixes the issue, which is due to incorrect mapping of
selected columns to source column ordinals in
`ConstructSimpleProject`.

Release note: none

78243: backupccl: fix paper cut in latest files directory structure r=DarrylWong a=adityamaru

Prior to this change, the LATEST files of a backup were written to
`metadatalatest/` instead of `metadata/latest/`, this patch fixes
that.

Release note (bug fix): The LATEST file that points to the latest full
backup in a collection was written to a directory path with the wrong
structure.

78246: settings: retire kv.rangefeed.separated_intent_scan.enabled  r=nvanbenschoten a=stevendanna

This setting was added in a 21.2 backport

#72315

but was never added to master:

#71295

So from the perspective of someone who upgrades from 21.2, it is now a
retired setting.

Release justification: Low-risk bug fix

Release note: None

Co-authored-by: Josephine Lee <josephine@cockroachlabs.com>
Co-authored-by: Mark Sirek <sirek@cockroachlabs.com>
Co-authored-by: Aditya Maru <adityamaru@gmail.com>
Co-authored-by: Steven Danna <danna@cockroachlabs.com>
blathers-crl bot pushed a commit that referenced this pull request Mar 22, 2022
This setting was added in a 21.2 backport

#72315

but was never added to master:

#71295

So from the perspective of someone who upgrades from 21.2, it is now a
retired setting.

Release justification: Low-risk bug fix

Release note: None
stevendanna added a commit that referenced this pull request Jun 6, 2022
This setting was added in a 21.2 backport

#72315

but was never added to master:

#71295

So from the perspective of someone who upgrades from 21.2, it is now a
retired setting.

Release justification: Low-risk bug fix

Release note: None
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.

kvserver/rangefeed: only scan separated intents span to bootstrap resolved timestamp
5 participants