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

sql: error in cluster_logical_timestamp when not SERIALIZABLE #107090

Merged

Conversation

chrisseto
Copy link
Contributor

@chrisseto chrisseto commented Jul 18, 2023

Previously, running cluster_logical_timestamp within an isolation level that tolerated write skew would result in an unhandled panic.

This commit adds a gate at the SQL level that will instead return a FeatureNotSupported pgerror. This behavior may be permanent or may be removed once we determine how CommitTimestamp should function at these isolation levels.

Epic: CRDB-26546
Fixes: #103245
Release note (sql change): cluster_logical_timestamp now returns an error when called at isolation levels lower than SERIALIZABLE.

@chrisseto chrisseto requested a review from a team as a code owner July 18, 2023 17:39
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@chrisseto chrisseto requested a review from rafiss July 18, 2023 17:44
@chrisseto chrisseto force-pushed the cluster_logical_timestamp_read_committed branch from 31c798a to 218d71e Compare July 18, 2023 17:46
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

very nice! just some minor comments

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


pkg/sql/sem/eval/context.go line 543 at r2 (raw file):

	// a pgerror until we decide how this will officially behave. See #103245.
	if ec.TxnIsoLevel.ToleratesWriteSkew() {
		return nil, pgerror.Newf(pgcode.FeatureNotSupported, "unsupported in %s isolation", ec.TxnIsoLevel.String())

super nit: could you use kvTxnIsolationLevelToTree(ec.TxnIsoLevel).String(). we have this bit of translation to keep the user-facing grammar separate from the internals of KV, and it has slightly more familiar string formatting.


pkg/sql/logictest/testdata/logic_test/txn line 1536 at r2 (raw file):

statement error pq: cluster_logical_timestamp\(\): unsupported in ReadCommitted isolation
BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT cluster_logical_timestamp();

nit: this should have a

statement ok
ROLLBACK

after this

@chrisseto chrisseto force-pushed the cluster_logical_timestamp_read_committed branch from 218d71e to 738f426 Compare July 21, 2023 18:18
@chrisseto chrisseto requested a review from a team as a code owner July 21, 2023 18:18
@chrisseto chrisseto force-pushed the cluster_logical_timestamp_read_committed branch 2 times, most recently from f73f27b to b4f6ab9 Compare July 21, 2023 19:41
@chrisseto
Copy link
Contributor Author

@rafiss could you point me in the right direction WRT the failing logic test? Seems like the test might be flake depending on which node you're executing against? If there's a way to read back the actual isolation level, we could skip the test if it isn't running at READ COMMITTED or we could gate the functionality on a specific version?

[20:06:40] --- done: /home/roach/.cache/bazel/_bazel_roach/c5a4e7d36696d9cd970af2045211a7df/sandbox/processwrapper-sandbox/12659/execroot/com_github_cockroachdb_cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/logictest/tests/local-mixed-22.2-23.1/local-mixed-22_2-23_1_test_/local-mixed-22_2-23_1_test.runfiles/com_github_cockroachdb_cockroach/pkg/sql/logictest/testdata/logic_test/txn with config local-mixed-22.2-23.1: 371 tests, 0 failures
    logic.go:4068:
        /home/roach/.cache/bazel/_bazel_roach/c5a4e7d36696d9cd970af2045211a7df/sandbox/processwrapper-sandbox/12659/execroot/com_github_cockroachdb_cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/logictest/tests/local-mixed-22.2-23.1/local-mixed-22_2-23_1_test_/local-mixed-22_2-23_1_test.runfiles/com_github_cockroachdb_cockroach/pkg/sql/logictest/testdata/logic_test/txn:1534: error while processing
    logic.go:4068:
        /home/roach/.cache/bazel/_bazel_roach/c5a4e7d36696d9cd970af2045211a7df/sandbox/processwrapper-sandbox/12659/execroot/com_github_cockroachdb_cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/logictest/tests/local-mixed-22.2-23.1/local-mixed-22_2-23_1_test_/local-mixed-22_2-23_1_test.runfiles/com_github_cockroachdb_cockroach/pkg/sql/logictest/testdata/logic_test/txn:1534:
        expected "pq: cluster_logical_timestamp\\(\\): unsupported in READ COMMITTED isolation", but no error occurred
    panic.go:522: -- test log scope end --
test logs left over in: /artifacts/tmp/_tmp/c2c63d472fc75a33623ecf6091cebe9e/logTestLogic_txn879699003

@rafiss
Copy link
Collaborator

rafiss commented Jul 24, 2023

Yes I can help for sure. The issue with this failure is:

        /home/roach/.cache/bazel/_bazel_roach/c5a4e7d36696d9cd970af2045211a7df/sandbox/processwrapper-sandbox/12659/execroot/com_github_cockroachdb_cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/logictest/tests/local-mixed-22.2-23.1/local-mixed-22_2-23_1_test_/local-mixed-22_2-23_1_test.runfiles/com_github_cockroachdb_cockroach/pkg/sql/logictest/testdata/logic_test/txn:1534: error while processing
    logic.go:4068:
        /home/roach/.cache/bazel/_bazel_roach/c5a4e7d36696d9cd970af2045211a7df/sandbox/processwrapper-sandbox/12659/execroot/com_github_cockroachdb_cockroach/bazel-out/k8-fastbuild/bin/pkg/sql/logictest/tests/local-mixed-22.2-23.1/local-mixed-22_2-23_1_test_/local-mixed-22_2-23_1_test.runfiles/com_github_cockroachdb_cockroach/pkg/sql/logictest/testdata/logic_test/txn:1534:
        expected "pq: cluster_logical_timestamp\\(\\): unsupported in READ COMMITTED isolation", but no error occurred

To interpret that a bit, this is saying that the txn is failing under the local-mixed-22_2-23_1 logictest configuration. That logictest configuration is defined here:

{
Name: "local-mixed-22.2-23.1",
NumNodes: 1,
OverrideDistSQLMode: "off",
BootstrapVersion: clusterversion.V22_2,
DisableUpgrade: true,
DeclarativeCorpusCollection: true,
},

The test configuration uses a current binary, but a "logical cluster version" from the previous release. This is so that it tests the mixed-version state of a CRDB cluster, which occurs during the process of an online upgrade. One of the things that we did for the READ COMMITTED project is we added a version gate so that READ COMMITTED can only be used if the cluster upgrade was finalized, and the cluster is no longer in a mixed version state. Otherwise, it falls back to the old behavior of automatically promoting READ COMMITTED to the SERIALIZABLE level. That gate is in this function:

func (ex *connExecutor) txnIsolationLevelToKV(

To put this all together, the issue you are seeing where no error occurs is actually expected under the local-mixed-22_2-23_1 configuration. So the right thing to do in this case is to use the skipif config local-mixed-22_2-23_1 directive. Check out the logictest docs for more information on skipif:

// - skipif <mysql/mssql/postgresql/cockroachdb/config CONFIG [ISSUE]>
// Skips the following `statement` or `query` if the argument is
// postgresql, cockroachdb, or a config matching the currently
// running configuration.

Previously, running `cluster_logical_timestamp` within an isolation
level that tolerated write skew would result in an unhandled panic.

This commit adds a gate at the SQL level that will instead return a
FeatureNotSupported pgerror. This behavior may be permanent or may be
removed once we determine how CommitTimestamp should function at these
isolation levels.

Epic:  CRDB-26546
Part of: cockroachdb#103245
Release note (sql change): cluster_logical_timestamp now returns an
error when called at isolation levels lower than SERIALIZABLE.
@chrisseto chrisseto force-pushed the cluster_logical_timestamp_read_committed branch from b4f6ab9 to 55ed31f Compare July 25, 2023 19:58
@chrisseto
Copy link
Contributor Author

Thanks! This round of CI should pass now 🤞

@chrisseto chrisseto requested a review from rafiss July 25, 2023 21:11
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

nice!

@chrisseto
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 26, 2023

Build succeeded:

@craig craig bot merged commit c10ca05 into cockroachdb:master Jul 26, 2023
6 of 7 checks passed
@chrisseto chrisseto deleted the cluster_logical_timestamp_read_committed branch July 26, 2023 15:46
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.

kv: rationalize cluster_logical_timestamp in weak isolation transactions
3 participants