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: adding version gates for changes related to JSON forward indexes #101932

Merged
merged 1 commit into from
May 22, 2023

Conversation

Shivs11
Copy link
Contributor

@Shivs11 Shivs11 commented Apr 20, 2023

Previously, #99275 and #97928 were responsible for laying the
foundations of a JSON lexicographical order as well as enabling JSON
forward indexes in CRDB. However, these commits did not account for
version gates. In a given cluster, all of its nodes are required to be
at a certain version number for creating JSON forward indexes as well as
for ordering JSON columns. Thus, this PR aims to enable version gates
for ensuring all nodes in a given cluster meet this requirement.

Epic: CRDB-24501

Fixes: #35706

Release note (sql change): This PR adds version gates which requires all
nodes in a given cluster to have a minimum binary version number which
in turn is required for creating forward indexes on JSON columns and for
ordering JSON columns.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@Shivs11 Shivs11 force-pushed the adding_cluster_version_number branch 3 times, most recently from b52df42 to e2f02db Compare April 20, 2023 18:03
@Shivs11 Shivs11 requested review from mgartner, fqazi and a team April 20, 2023 18:05
@Shivs11 Shivs11 marked this pull request as ready for review April 20, 2023 18:05
@Shivs11 Shivs11 requested a review from a team April 20, 2023 18:05
@Shivs11 Shivs11 marked this pull request as draft April 20, 2023 18:57
@Shivs11 Shivs11 force-pushed the adding_cluster_version_number branch 4 times, most recently from 3671e0b to 5e32b80 Compare April 21, 2023 17:45
@@ -23,7 +23,7 @@ upgrade 1
query B
SELECT crdb_internal.node_executable_version() SIMILAR TO '1000023.1-%'
----
true
false
Copy link
Collaborator

@rafiss rafiss Apr 24, 2023

Choose a reason for hiding this comment

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

we shouldn't just rewrite these to false. instead, change the assertion so it's SIMILAR TO 1000023.2-%

@Shivs11 Shivs11 force-pushed the adding_cluster_version_number branch 2 times, most recently from b3790b9 to a9401c3 Compare April 24, 2023 16:24
Copy link
Contributor Author

@Shivs11 Shivs11 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 @fqazi, @mgartner, and @rafiss)


pkg/sql/logictest/testdata/logic_test/mixed_version_can_login line 26 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

we shouldn't just rewrite these to false. instead, change the assertion so it's SIMILAR TO 1000023.2-%

I don't think this is required anymore since the new version to be added still has the minor number to be set to 1. Thus, running this test with 1000023.1 worked unless this itself is wrong.

@Shivs11 Shivs11 force-pushed the adding_cluster_version_number branch 2 times, most recently from 1e16696 to 107903c Compare April 24, 2023 16:58
@Shivs11 Shivs11 marked this pull request as ready for review April 24, 2023 16:58
@Shivs11 Shivs11 force-pushed the adding_cluster_version_number branch 3 times, most recently from f342320 to e287ba9 Compare April 24, 2023 19:36
@Shivs11 Shivs11 requested a review from rafiss April 24, 2023 20:14
"enable JSON forward indexes and ORDER BY on JSON columns",
toCV(clusterversion.V23_2_JSONForwardIndexes),
upgrade.NoPrecondition,
NoTenantUpgradeFunc,
Copy link
Member

Choose a reason for hiding this comment

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

why do we need an upgrade at all?

Copy link
Contributor Author

@Shivs11 Shivs11 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 @dt, @fqazi, @mgartner, and @rafiss)


pkg/upgrade/upgrades/upgrades.go line 317 at r2 (raw file):

Previously, dt (David Taylor) wrote…

why do we need an upgrade at all?

Not sure if I understand your question to the fullest, but do you mean why we need an upgrade to this version? I believe this is required since each node in a given cluster has to be at this specific cluster version before it can start ordering/creating forward indexes on JSON columns. Thus, I wanted to add some checks in the code based on the cluster version number.

@Shivs11 Shivs11 requested a review from dt April 26, 2023 14:40
Copy link
Member

@dt dt left a comment

Choose a reason for hiding this comment

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

It isn't clear to me that this needs a new version minted versus just having the usage gates be on IsActive(V23_1) ?

Either way, even if it does need to mint a new version, then I don't think you need the no-op upgrade.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @fqazi, @mgartner, and @rafiss)

Copy link
Collaborator

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

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

@dt We haven't backported Shiv's JSON forward index support to 23.1 and only plan to have it available on 23.2. Please correct me if I'm wrong, but my understanding is that gating on IsActive(V23_1) would allow usage on 23.1, which is not what we want. I could see gating on IsActive(V23_2), except it seems we're at a point in this release cycle where that version hasn't been created yet.

Gating this feature, which doesn't require any upgrade steps, correctly has been confusing, so we're happy to get input on the best way to do it.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @fqazi, @mgartner, and @rafiss)

Copy link
Collaborator

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

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

TIL Thank you!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @fqazi, @mgartner, and @rafiss)

@Shivs11 Shivs11 force-pushed the adding_cluster_version_number branch 2 times, most recently from 5ee49ff to 676c402 Compare April 26, 2023 20:25
Copy link
Contributor Author

@Shivs11 Shivs11 left a comment

Choose a reason for hiding this comment

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

Thank for the great pointers everyone! The changes have been made and it is RFAL!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @fqazi, @mgartner, and @rafiss)

@Shivs11 Shivs11 requested review from dt and rharding6373 April 27, 2023 17:47
// Setting an older cluster version and expecting an error when creating
// forward indexes on JSON columns.
_, err = tc.Conns[0].ExecContext(ctx, `SET CLUSTER SETTING version = $1`,
clusterversion.ByKey(clusterversion.V23_1WebSessionsTableHasUserIDColumn).String())
Copy link
Member

Choose a reason for hiding this comment

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

can this just be V23_1?

Copy link
Collaborator

@rharding6373 rharding6373 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 @dt, @fqazi, @mgartner, @rafiss, and @Shivs11)


pkg/upgrade/upgrades/json_forward_indexes_test.go line 27 at r4 (raw file):

)

func TestJSONForwardingIndexes(t *testing.T) {

I was thinking about how what is really desirable to test is mixed versions -- which the version upgrade tests do, and happened to see Renato's fix for the version upgrade test that was failing with json forward indexes: https://github.com/cockroachdb/cockroach/pull/101638/files

There's a small bug there, which is that we should check for V23_2, not V23_1, for json forwarding indexes. If you have time do you mind adding a fix in this PR or a new one?


pkg/upgrade/upgrades/json_forward_indexes_test.go line 83 at r4 (raw file):

	)`)
	require.Error(t, err)

Can we also upgrade to 23.2 here and check that the previous commands succeed?

@rharding6373 rharding6373 force-pushed the adding_cluster_version_number branch from 676c402 to a7ecb81 Compare May 15, 2023 22:00
@rharding6373 rharding6373 requested a review from a team as a code owner May 15, 2023 22:00
@rharding6373 rharding6373 force-pushed the adding_cluster_version_number branch 2 times, most recently from 1f534a6 to 30fc318 Compare May 15, 2023 22:28
@rharding6373 rharding6373 requested a review from a team as a code owner May 15, 2023 22:28
@rharding6373 rharding6373 requested review from srosenberg and smg260 and removed request for a team May 15, 2023 22:28
Copy link
Collaborator

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

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

I'm picking up Shiv's PR to bring it over the finish line. I added the version gate for JSON forward indexes to the declarative schema changer (which supports CREATE INDEX as of 23.1) and a minor fix to operation_generator since JSON forward indexes are enabled in a different version than ARRAY. PTAL!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @fqazi, @mgartner, @rafiss, @smg260, and @srosenberg)


pkg/upgrade/upgrades/json_forward_indexes_test.go line 27 at r4 (raw file):

Previously, rharding6373 (Rachael Harding) wrote…

I was thinking about how what is really desirable to test is mixed versions -- which the version upgrade tests do, and happened to see Renato's fix for the version upgrade test that was failing with json forward indexes: https://github.com/cockroachdb/cockroach/pull/101638/files

There's a small bug there, which is that we should check for V23_2, not V23_1, for json forwarding indexes. If you have time do you mind adding a fix in this PR or a new one?

Done.


pkg/upgrade/upgrades/json_forward_indexes_test.go line 58 at r4 (raw file):

Previously, dt (David Taylor) wrote…

can this just be V23_1?

Thanks for the suggestion. We found that it couldn't, and it took us a long time to realize it was because create index uses the declarative schema changer in 23.1 and therefore a different path to create the index that we hadn't protected with the version gate. We now have tests for V22_2 and V23_1 to cover both possible paths.


pkg/upgrade/upgrades/json_forward_indexes_test.go line 83 at r4 (raw file):

Previously, rharding6373 (Rachael Harding) wrote…

Can we also upgrade to 23.2 here and check that the previous commands succeed?

Done.

Previously, cockroachdb#99275 and cockroachdb#97928 were responsible for laying the
foundations of a JSON lexicographical order as well as enabling JSON
forward indexes in CRDB. However, these commits did not account for
version gates. In a given cluster, all of its nodes are required to be
at a certain version number for creating JSON forward indexes as well as
for ordering JSON columns.  Thus, this PR aims to enable version gates
for ensuring all nodes in a given cluster meet this requirement.

Epic: CRDB-24501

Fixes: cockroachdb#35706

Release note (sql change): This PR adds version gates which requires all
nodes in a given cluster to have a minimum binary version number which
in turn is required for creating forward indexes on JSON columns and for
ordering JSON columns.
@rharding6373 rharding6373 force-pushed the adding_cluster_version_number branch from 30fc318 to 33a903e Compare May 15, 2023 22:37
Copy link
Collaborator

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

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

Turns out someone already fixed operation_generator since I last reviewed this :-) RFAL!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @fqazi, @mgartner, @rafiss, @smg260, and @srosenberg)

@rharding6373 rharding6373 requested review from dt and removed request for srosenberg and smg260 May 15, 2023 22:40
Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 19 files at r1, 1 of 2 files at r6, 6 of 6 files at r8, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @mgartner, and @rafiss)

@rharding6373
Copy link
Collaborator

Last call for comments! If there are no objections I will try to merge this EOD.

@rharding6373
Copy link
Collaborator

bors r=fqazi

@craig
Copy link
Contributor

craig bot commented May 22, 2023

Build succeeded:

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.

sql: support ordering by JSON (pq: unable to encode table key: *tree.DJSON)
6 participants