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

metamorphic: add MVCC{CheckFor,}AcquireLock operations #113698

Merged
merged 1 commit into from
Nov 3, 2023

Conversation

itsbilal
Copy link
Member

@itsbilal itsbilal commented Nov 2, 2023

This change adds two new operations to the MVCC metamorphic testing package that were added in #110323. We check for determinism in the storage package by adding these operations to the metamorphic tests as well.

Fixes #109650.

Epic: none

Release note: None

@itsbilal itsbilal requested a review from a team as a code owner November 2, 2023 19:20
@itsbilal itsbilal requested a review from sumeerbhola November 2, 2023 19:20
Copy link

blathers-crl bot commented Nov 2, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

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


pkg/storage/metamorphic/operations.go line 271 at r1 (raw file):

	_, err := storage.MVCCInitPut(ctx, writer, m.key, txn.ReadTimestamp, m.value, false, storage.MVCCWriteOptions{Txn: txn})
	if err != nil {
		if writeTooOldErr := (*kvpb.WriteTooOldError)(nil); errors.As(err, &writeTooOldErr) {

[nit] It might make sense to separate this into a separate handleWriteError(txn, key, err) function (it's duplicated three times).

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.

Thanks @itsbilal! This is really great.

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @itsbilal and @sumeerbhola)


pkg/storage/metamorphic/operations.go line 294 at r1 (raw file):

func (m mvccCheckForAcquireLockOp) run(ctx context.Context) string {
	txn := m.m.getTxn(m.txn)
	txn.Sequence++

Here and below: we don't need to advance the write sequence for lock acquisition.


pkg/storage/metamorphic/operations.go line 297 at r1 (raw file):

	writer := m.m.getReadWriter(m.writer)

	err := storage.MVCCCheckForAcquireLock(ctx, writer, txn, m.strength, m.key, 64)

The maxLockConflicts value is interesting here. We set it to 64 for these two functions, but set it for other MVCC operations (hidden in MVCCGetOptions, MVCCScanOptions, and MVCCWriteOptions). Would it make sense to randomize this value for all users?


pkg/storage/metamorphic/operations.go line 302 at r1 (raw file):

	}

	// Update the txn's lock spans to account for this intent being written.

Stray comment.


pkg/storage/metamorphic/operations.go line 321 at r1 (raw file):

	err := storage.MVCCAcquireLock(ctx, writer, txn, m.strength, m.key, nil, 64)
	if err != nil {
		if writeTooOldErr := (*kvpb.WriteTooOldError)(nil); errors.As(err, &writeTooOldErr) {

I don't think this is needed for MVCCAcquireLock. It should never return a WriteTooOld error, because those are due to write-write version conflicts instead of locking conflicts.


pkg/storage/metamorphic/operations.go line 329 at r1 (raw file):

	}

	// Update the txn's lock spans to account for this intent being written.

s/intent being written/lock being acquired/.


pkg/storage/metamorphic/operations.go line 993 at r1 (raw file):

	},
	{
		name: "mvcc_acquire_lock",

nit: want to order these the same as the methods above?


pkg/storage/metamorphic/operations.go line 1004 at r1 (raw file):

			// Track this write in the txn generator. This ensures the batch will be
			// committed before the transaction is committed

nit: missing punctuation.

This change adds two new operations to the MVCC metamorphic
testing package that were added in cockroachdb#110323. We check for
determinism in the storage package by adding these operations
to the metamorphic tests as well.

Fixes cockroachdb#109650.

Epic: none

Release note: None
@itsbilal itsbilal force-pushed the metamorphic-add-lock-methods branch from 0573d37 to e16e705 Compare November 3, 2023 15:14
Copy link
Member Author

@itsbilal itsbilal left a comment

Choose a reason for hiding this comment

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

TFTR!

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


pkg/storage/metamorphic/operations.go line 271 at r1 (raw file):

Previously, RaduBerinde wrote…

[nit] It might make sense to separate this into a separate handleWriteError(txn, key, err) function (it's duplicated three times).

Done (not relevant anymore for this PR).


pkg/storage/metamorphic/operations.go line 294 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Here and below: we don't need to advance the write sequence for lock acquisition.

Done.


pkg/storage/metamorphic/operations.go line 297 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

The maxLockConflicts value is interesting here. We set it to 64 for these two functions, but set it for other MVCC operations (hidden in MVCCGetOptions, MVCCScanOptions, and MVCCWriteOptions). Would it make sense to randomize this value for all users?

I've randomized it for this method for now! but yes we might want to explore randomizing more options in those methods in general.


pkg/storage/metamorphic/operations.go line 321 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

I don't think this is needed for MVCCAcquireLock. It should never return a WriteTooOld error, because those are due to write-write version conflicts instead of locking conflicts.

Done.


pkg/storage/metamorphic/operations.go line 329 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

s/intent being written/lock being acquired/.

Done.


pkg/storage/metamorphic/operations.go line 993 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

nit: want to order these the same as the methods above?

Done.


pkg/storage/metamorphic/operations.go line 1004 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

nit: missing punctuation.

Done.

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

@itsbilal
Copy link
Member Author

itsbilal commented Nov 3, 2023

TFTR!

bors r=nvanbenschoten

@craig
Copy link
Contributor

craig bot commented Nov 3, 2023

Build succeeded:

@craig craig bot merged commit 17e08f8 into cockroachdb:master Nov 3, 2023
3 checks passed
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.

storage: add replicated locks to storage metamorphic testing
4 participants