Skip to content

ptstorage: change Protect and GetRecord to work with target column#74297

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
adityamaru:pts-storage-v2
Jan 17, 2022
Merged

ptstorage: change Protect and GetRecord to work with target column#74297
craig[bot] merged 1 commit intocockroachdb:masterfrom
adityamaru:pts-storage-v2

Conversation

@adityamaru
Copy link
Copy Markdown
Contributor

@adityamaru adityamaru commented Dec 28, 2021

Protected timestamp records now apply on a ptpb.Target instead
of roachpb.Spans. This change modifies the Protect and GetRecord
methods of the ptstorage interface. Protect will persist the
ptpb.Target specified on the passed in ptpb.Record as an encoded
protocol buffer in the target column, and GetRecord will read the
target column when constructing a ptpb.Record to return to the caller.

If we are running in a mixed version state where the migration that adds
the target column to the system.pts_records table has not run,
we use the existing logic to protect Spans. This logic has wholesale
been moved to deprecatedProtect method.

Once the migration has run, all calls to protect must
have a non-nil ptpb.Target field on the record, as we will no longer
be persisting the DeprecatedSpans field in the underlying system table.
Post migration, we do not use the kv.protectedts.max_spans to enforce
any limits, but continue to use kv.protectedts.max_bytes to enforce a
ceiling on the total size of encoded targets we can store in the subsystem.

Most tests in ptstorage_test continue to run in both a pre and post migration
state to ensure that Storage is handling both span backed and target backed
records correctly. This can be cleaned up in a future version when we get
rid of spans from the pts record entirely. All other PTS tests in the kvserver
package run on a version prior to the pts migration since the remainder of the
new pts system is yet to be implemented. These tests will be revisited as and
when we develop those pieces of the subsystem.

Informs: #73727

Release note: None

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@adityamaru
Copy link
Copy Markdown
Contributor Author

First three commits from #74248.

@adityamaru adityamaru force-pushed the pts-storage-v2 branch 4 times, most recently from 935fc5d to 46106ca Compare January 6, 2022 19:30
@adityamaru adityamaru marked this pull request as ready for review January 6, 2022 19:32
@adityamaru adityamaru requested a review from a team January 6, 2022 19:32
@adityamaru adityamaru requested review from a team as code owners January 6, 2022 19:32
@adityamaru adityamaru requested review from ajwerner, arulajmani, irfansharif and shermanCRL and removed request for a team and shermanCRL January 6, 2022 19:32
@adityamaru
Copy link
Copy Markdown
Contributor Author

adityamaru commented Jan 6, 2022

First commit is from #74248.

edit: rebased

@adityamaru adityamaru force-pushed the pts-storage-v2 branch 2 times, most recently from b0ac63e to 3f16f9e Compare January 7, 2022 19:31
@adityamaru adityamaru requested review from a team and msbutler and removed request for a team January 7, 2022 19:33
@adityamaru
Copy link
Copy Markdown
Contributor Author

@ajwerner @arulajmani friendly ping for a review on this!

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.

cursory pass this looks fine

Reviewed 6 of 19 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @arulajmani, @irfansharif, and @msbutler)


pkg/kv/kvserver/protectedts/ptstorage/storage.go, line 146 at r1 (raw file):

	}

	// TODO(during review): To avoid breaking protected timestamps before the

How hard is it to put in a cluster setting or testing knob that we pair with the version gate in all the places we check it that we default to false? With that, we wouldn't break anything and we can test the new logic by enabling that cluster setting. Then, before we release, we get rid of the cluster setting or testing knob.

Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 19 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @ajwerner, @irfansharif, and @msbutler)


pkg/kv/kvserver/protectedts/ptstorage/sql.go, line 126 at r1 (raw file):

`

	getRecordsWithoutTargetQueryBase = `

nit: might be worth commenting that the Target column was added in a migration which necessitates these with and without target versions of queries.


pkg/kv/kvserver/protectedts/ptstorage/storage.go, line 83 at r1 (raw file):

		return errors.Wrap(err, "failed to marshal spans")
	}
	it, err := p.ex.QueryIteratorEx(ctx, "protectedts-protect", txn,

nit: s/protectedts-protected/protectedts-deprecated-protect/


pkg/kv/kvserver/protectedts/ptstorage/storage.go, line 142 at r1 (raw file):

		meta = []byte{}
	}
	if !p.settings.Version.IsActive(ctx, clusterversion.AlterSystemProtectedTimestampAddColumn) {

Might be worth adding a comment about this here as well and a TODO to remove this in v22.2.


pkg/kv/kvserver/protectedts/ptstorage/storage.go, line 146 at r1 (raw file):

Previously, ajwerner wrote…

How hard is it to put in a cluster setting or testing knob that we pair with the version gate in all the places we check it that we default to false? With that, we wouldn't break anything and we can test the new logic by enabling that cluster setting. Then, before we release, we get rid of the cluster setting or testing knob.

We could also run some of the tests that are supposed to work before and after theAlterSystemProtectedTimestampAddColumn migration with the testing knob set to both values for 22.2.


pkg/kv/kvserver/protectedts/ptstorage/storage.go, line 213 at r1 (raw file):

		}
	} else {
		row, err = p.ex.QueryRowEx(ctx, "protectedts-GetRecord", txn,

nit: Similar to how you did for Protect, you could pull this logic out in a deprecated method as well. That way, when we come back to this to cleanup, it'll be easier.

Copy link
Copy Markdown
Contributor Author

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


pkg/kv/kvserver/protectedts/ptstorage/storage.go, line 142 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Might be worth adding a comment about this here as well and a TODO to remove this in v22.2.

Done.


pkg/kv/kvserver/protectedts/ptstorage/storage.go, line 146 at r1 (raw file):

Done.
Adding a testing knob that currently defaults to false. All tests that want to run with the new system have to override this knob. Prior to the release, we will default this knob to true or rename it to DisablePTSForMultiTenant and have all the tests that want to run with the old system override it.

@adityamaru
Copy link
Copy Markdown
Contributor Author

I'm not sure what happened to reviewable, but I have addressed all the comments so this if RFAL.

@adityamaru adityamaru requested review from ajwerner and arulajmani and removed request for a team January 13, 2022 21:23
it, err := p.ex.QueryIteratorEx(ctx, "protectedts-GetRecords", txn,
sessiondata.InternalExecutorOverride{User: security.NodeUserName()},
getRecordsQuery)
getRecordsWithoutTargetQuery)
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.

this is wrong, it should be getRecordsQuery. I'm just waiting for CI to shake out all failures before repushing.

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.

done.

Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

Couple of minor comments, but otherwise :lgtm:

Reviewed 1 of 19 files at r1, 15 of 24 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @adityamaru, @ajwerner, @arulajmani, @irfansharif, and @msbutler)


pkg/kv/kvserver/protectedts/ptprovider/provider.go, line 47 at r3 (raw file):

// New creates a new protectedts.Provider.
func New(cfg Config, knobs *protectedts.TestingKnobs) (protectedts.Provider, error) {

Any reason to not put these on the Config struct itself?


pkg/kv/kvserver/protectedts/ptstorage/storage.go, line 156 at r3 (raw file):

	// TODO(adityamaru): Delete in 22.2 once we exclusively protect `target`s.
	if !p.settings.Version.IsActive(ctx, clusterversion.AlterSystemProtectedTimestampAddColumn) ||
		!p.knobs.EnableProtectedTimestampForMultiTenant {

nit: maybe pull this logic into a useDeprecatedProtectedTSStorage or something -- we use it in a couple of places and it's slightly more readable than this disjunction.


pkg/ccl/backupccl/backup_test.go, line 6759 at r3 (raw file):

	dir, dirCleanupFn := testutils.TempDir(t)
	defer dirCleanupFn()
	clusterArgs := base.TestClusterArgs{}

revert?


pkg/kv/kvserver/protectedts/ptstorage/storage_test.go, line 324 at r3 (raw file):

	// If set to true, the test will be run on a cluster version prior to
	// AlterSystemProtectedTimestampAddColumn, thereby testing the "old" protected

Maybe reference the testing knob instead?

Protected timestamp records now apply on a `ptpb.Target` instead
of `roachpb.Spans`. This change modifies the `Protect` and `GetRecord`
methods of the ptstorage interface. Protect will persist the
`ptpb.Target` specified on the passed in `ptpb.Record` as an encoded
protocol buffer in the `target` column, and `GetRecord` will read the
`target` column when constructing a `ptpb.Record` to return to the caller.

If we are running in a mixed version state where the migration that adds
the `target` column to the system.pts_records table has not run,
we use the existing logic to protect Spans. This logic has wholesale
been moved to `deprecatedProtect` method.

Once the migration has run, all calls to protect must
have a non-nil `ptpb.Target` field on the record, as we will no longer
be persisting the `DeprecatedSpans` field in the underlying system table.
Post migration, we do not use the `kv.protectedts.max_spans` to enforce
any limits, but continue to use `kv.protectedts.max_bytes` to enforce a
ceiling on the total size of encoded targets we can store in the subsystem.

Most tests in `ptstorage_test` continue to run in both a pre and post migration
state to ensure that `Storage` is handling both span backed and target backed
records correctly. This can be cleaned up in a future version when we get
rid of spans from the pts record entirely. All other PTS tests in the `kvserver`
package run on a version prior to the pts migration since the remainder of the
new pts system is yet to be implemented. These tests will be revisited as and
when we develop those pieces of the subsystem.

Informs: cockroachdb#73727

Release note: None
Copy link
Copy Markdown
Contributor Author

@adityamaru adityamaru 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, @irfansharif, and @msbutler)


pkg/kv/kvserver/protectedts/ptprovider/provider.go, line 47 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Any reason to not put these on the Config struct itself?

good point, done.


pkg/kv/kvserver/protectedts/ptstorage/storage.go, line 156 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: maybe pull this logic into a useDeprecatedProtectedTSStorage or something -- we use it in a couple of places and it's slightly more readable than this disjunction.

i like it, thanks!


pkg/ccl/backupccl/backup_test.go, line 6759 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

revert?

Done.


pkg/kv/kvserver/protectedts/ptstorage/storage_test.go, line 324 at r3 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Maybe reference the testing knob instead?

yup stale comment, done.

@adityamaru
Copy link
Copy Markdown
Contributor Author

@ajwerner let me know if you'd like to take another pass at this, thanks!

Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner, @arulajmani, @irfansharif, and @msbutler)

@adityamaru
Copy link
Copy Markdown
Contributor Author

borsing to cleanup some of the PRs on top of this will keep a lookout for additional comments

TFTR!

bors r=arulajmani

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 17, 2022

Build succeeded:

@craig craig bot merged commit 4e50204 into cockroachdb:master Jan 17, 2022
@adityamaru adityamaru deleted the pts-storage-v2 branch January 17, 2022 19:27
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.

4 participants