Skip to content

sql: add version gate to stop upgrade if interleaved tables exist#68074

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
fqazi:interleaveLockout
Aug 18, 2021
Merged

sql: add version gate to stop upgrade if interleaved tables exist#68074
craig[bot] merged 2 commits intocockroachdb:masterfrom
fqazi:interleaveLockout

Conversation

@fqazi
Copy link
Copy Markdown
Collaborator

@fqazi fqazi commented Jul 26, 2021

Fixes: #52009

Previously, interleaved tables were only deprecated so users
were allowed to create them after flipping an internal setting.
This was inadequate because we want to completely drop support
for this feature, as a part of the next release we will be
completely disabling support for them. To address this, this
patch will block upgrade to the next version if interleaved
tables exist.

Release note: Upgrade to the next version will be blocked if
interleaved tables/indexes exist. Users should convert existing
interleaved tables/indexes to non-interleaved ones or drop any
tables/indexes before upgrading to the next version.

@fqazi fqazi requested a review from a team July 26, 2021 18:37
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown

@postamar postamar left a comment

Choose a reason for hiding this comment

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

Welcome back!

Your commit message needs some editing:

  1. For a start there's a "mend" string that made its way in there by mistake.
  2. Next, your use of the word "migration" instead of "upgrade" is quite confusing. Clusters upgrade from one version to the next, and in so doing they might run migrations, but they're not the same thing.
  3. If we don't have an issue for this (which is possible) can you please create one and link it to the jira epic?
  4. Can you flesh out your release note some more? This is very terse considering the impact on our users, never mind our documentations team.

Unrelated but why are there changes to migrations.pb.go checked in this commit?

Reviewed 1 of 9 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @fqazi)


pkg/migration/migrations/interleaved_tables.go, line 36 at r1 (raw file):

	}
	return nil
}

What is the purpose of this migration? My understanding is you need to version-gate the creation of new interleaves, such that when the migration runs in the next version, we are guaranteed that there are no concurrent interleave creations. Such as it is, we're checking that there are no interleaves twice, which isn't cheap, for no apparent good reason (to me).


pkg/migration/migrations/interleaved_tables.go, line 47 at r1 (raw file):

	txn := d.DB.NewTxn(ctx, "interleaved-check")
	rows, err := d.InternalExecutor.QueryRowEx(ctx, "check-for-interleaved", txn, sessiondata.InternalExecutorOverride{User: security.RootUserName()},
		"select * from crdb_internal.interleaved")

I may be wrong, but the way this table is built, this query seems awfully expensive. The table generator follows the interleave references to get the interleaved table names, etc. Plus we don't actually care about all the rows in this table only whether there are none or not. Perhaps consider adding a LIMIT 1? Not sure if this helps. This is worth testing for.

Alternatively, and arguably preferably, consider bypassing the table and instead reimplement the logic from the table generator fn in this migration. It's simple enough. That way you don't need to change the semantics of the table by including dropped indexes like you did. Besides, it seems to me that we'll want to remove that table sooner rather than later. In fact, why not do so in this PR?


pkg/migration/migrations/interleaved_tables_external_test.go, line 122 at r1 (raw file):

	// Migration should succeed.
	tdb.ExecSucceedsSoon(t, "SET CLUSTER SETTING version = $1",
		clusterversion.ByKey(clusterversion.InterleavedTablesRemovedMigration).String())

perhaps also add an assertion on a CREATE TABLE ... INTERLEAVE IN PARENT expecting an interleavedTableDisabledMigrationError, post-upgrade?

Copy link
Copy Markdown
Collaborator Author

@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.

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


pkg/migration/migrations/interleaved_tables.go, line 36 at r1 (raw file):

Previously, postamar (Marius Posta) wrote…

What is the purpose of this migration? My understanding is you need to version-gate the creation of new interleaves, such that when the migration runs in the next version, we are guaranteed that there are no concurrent interleave creations. Such as it is, we're checking that there are no interleaves twice, which isn't cheap, for no apparent good reason (to me).

So, the first stage is sort of prone to race conditions it only validates no interleaves exist at the current point in time, without blocking CREATE TABLE / CREATE INDEXES or other operations. So, the first stage disables those operations only, the second once again validates no interleaved objects exist.


pkg/migration/migrations/interleaved_tables.go, line 47 at r1 (raw file):

ably preferably, consider bypassing the table and instead reimplement the logi
We can't drop the internal table yet? If you haven't gone past this migration you still need that function to figure out the source of your problem. I think once your past this point on the next release we can drop all the code right?

Let me dig into using the code from the CRDB function directly, or confirm if the limit clause is sufficient.


pkg/migration/migrations/interleaved_tables_external_test.go, line 122 at r1 (raw file):

Previously, postamar (Marius Posta) wrote…

perhaps also add an assertion on a CREATE TABLE ... INTERLEAVE IN PARENT expecting an interleavedTableDisabledMigrationError, post-upgrade?

Good point, let me confirm that new error shows up :)

@fqazi fqazi force-pushed the interleaveLockout branch 3 times, most recently from 36b8b73 to 57a70b2 Compare July 26, 2021 20:48
@fqazi fqazi changed the title sql: add version gate to stop migration if interleaved tables exist sql: add version gate to stop upgrade if interleaved tables exist Jul 26, 2021
@fqazi fqazi force-pushed the interleaveLockout branch from 57a70b2 to 3cfd6d4 Compare July 26, 2021 20:53
@fqazi
Copy link
Copy Markdown
Collaborator Author

fqazi commented Jul 26, 2021

Welcome back!

Your commit message needs some editing:

  1. For a start there's a "mend" string that made its way in there by mistake.
  2. Next, your use of the word "migration" instead of "upgrade" is quite confusing. Clusters upgrade from one version to the next, and in so doing they might run migrations, but they're not the same thing.
  3. If we don't have an issue for this (which is possible) can you please create one and link it to the jira epic?
  4. Can you flesh out your release note some more? This is very terse considering the impact on our users, never mind our documentations team.

Unrelated but why are there changes to migrations.pb.go checked in this commit?

Reviewed 1 of 9 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @fqazi)

pkg/migration/migrations/interleaved_tables.go, line 36 at r1 (raw file):

	}
	return nil
}

What is the purpose of this migration? My understanding is you need to version-gate the creation of new interleaves, such that when the migration runs in the next version, we are guaranteed that there are no concurrent interleave creations. Such as it is, we're checking that there are no interleaves twice, which isn't cheap, for no apparent good reason (to me).

pkg/migration/migrations/interleaved_tables.go, line 47 at r1 (raw file):

	txn := d.DB.NewTxn(ctx, "interleaved-check")
	rows, err := d.InternalExecutor.QueryRowEx(ctx, "check-for-interleaved", txn, sessiondata.InternalExecutorOverride{User: security.RootUserName()},
		"select * from crdb_internal.interleaved")

I may be wrong, but the way this table is built, this query seems awfully expensive. The table generator follows the interleave references to get the interleaved table names, etc. Plus we don't actually care about all the rows in this table only whether there are none or not. Perhaps consider adding a LIMIT 1? Not sure if this helps. This is worth testing for.

Alternatively, and arguably preferably, consider bypassing the table and instead reimplement the logic from the table generator fn in this migration. It's simple enough. That way you don't need to change the semantics of the table by including dropped indexes like you did. Besides, it seems to me that we'll want to remove that table sooner rather than later. In fact, why not do so in this PR?

pkg/migration/migrations/interleaved_tables_external_test.go, line 122 at r1 (raw file):

	// Migration should succeed.
	tdb.ExecSucceedsSoon(t, "SET CLUSTER SETTING version = $1",
		clusterversion.ByKey(clusterversion.InterleavedTablesRemovedMigration).String())

perhaps also add an assertion on a CREATE TABLE ... INTERLEAVE IN PARENT expecting an interleavedTableDisabledMigrationError, post-upgrade?

  1. Linked to the issue for this work in the commit message (I will open a separate one for code clean up after the next release to kill all code for interleaved tables).
  2. Sorry, I should have added more detail. Updated the language for release notes based on our documentation.

@fqazi fqazi force-pushed the interleaveLockout branch from 3cfd6d4 to 76dd5bb Compare July 26, 2021 20:55
@fqazi fqazi requested a review from postamar July 26, 2021 20:55
@fqazi fqazi force-pushed the interleaveLockout branch from 76dd5bb to cc73ffe Compare July 27, 2021 13:21
@fqazi fqazi requested a review from a team as a code owner July 27, 2021 13:21
@fqazi fqazi force-pushed the interleaveLockout branch 5 times, most recently from 2eecd67 to 81f1b45 Compare July 28, 2021 18:30
@fqazi fqazi requested review from a team and dt and removed request for a team July 28, 2021 18:30
@fqazi fqazi force-pushed the interleaveLockout branch 2 times, most recently from a9fd110 to 4ceb541 Compare July 28, 2021 19:34
@dt dt removed their request for review July 29, 2021 20:52
@fqazi fqazi force-pushed the interleaveLockout branch 3 times, most recently from 23c6ace to f1e8429 Compare August 3, 2021 20:11
@fqazi fqazi force-pushed the interleaveLockout branch from 0dde399 to 4e99b56 Compare August 17, 2021 13:35
@fqazi fqazi requested a review from ajwerner August 17, 2021 13:36
@fqazi fqazi force-pushed the interleaveLockout branch from 4e99b56 to d7cb6e5 Compare August 18, 2021 13:03
@fqazi fqazi requested a review from postamar August 18, 2021 13:46
Copy link
Copy Markdown
Collaborator Author

@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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @irfansharif, @otan, and @postamar)


pkg/migration/migrations/interleaved_tables.go, line 47 at r1 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

Done. Validated the limit clause works correctly, and stops execution instantly.

Done.


pkg/sql/crdb_internal.go, line 4538 at r15 (raw file):

Previously, ajwerner wrote…

Yeah, consider the case where you drop and index in a schema change that adds another index and then that gets reverted then the index comes back.

Done.

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.

:lgtm:

Another thing that came up was the possibility of silently ignoring INTERLEAVE statements at some point. We can do that as a follow-up but let's make sure we track it if that's the decision.

Did we track this?

Reviewed 1 of 34 files at r16, 40 of 76 files at r20, 4 of 14 files at r22, 1 of 8 files at r23, 1 of 8 files at r25.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajwerner, @fqazi, @irfansharif, @otan, and @postamar)


pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go, line 260 at r25 (raw file):

						if !cv.Version.Equal(v1) && !cv.Version.Equal(v2) {
							return nil, false
						}

nit: just make this the default case.


pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go, line 324 at r25 (raw file):

		// will fail on v1.
		initialTenantRunner.ExpectErr(t,
			".*(sql: database is closed)*(failed to connect)*.*",

This will match literally any string. What about sql: database is closed|failed to connect.


pkg/migration/migrations/interleaved_tables_external_test.go, line 84 at r25 (raw file):

	})
	// Check that creation of interleaved tables is fully disabled.
	tdb.ExecSucceedsSoon(t, "CREATE TABLE customers2 (id INT PRIMARY KEY, name STRING(50));")

Does this needs a succeeds soon?

Copy link
Copy Markdown
Collaborator Author

@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.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajwerner, @irfansharif, @otan, and @postamar)


pkg/ccl/kvccl/kvtenantccl/tenant_upgrade_test.go, line 324 at r25 (raw file):

Previously, ajwerner wrote…

This will match literally any string. What about sql: database is closed|failed to connect.

Done.


pkg/clusterversion/cockroach_versions.go, line 272 at r8 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

PreventNewInterleavedTables
Those are much better names, let me do that.

Done.

@fqazi
Copy link
Copy Markdown
Collaborator Author

fqazi commented Aug 18, 2021

Another thing that came up was the possibility of silently ignoring INTERLEAVE statements at some point. We can do that as a follow-up but let's make sure we track it if that's the decision.

Did we track this?
@ajwerner The issue #68344 tracks this

@fqazi fqazi force-pushed the interleaveLockout branch from d7cb6e5 to f357035 Compare August 18, 2021 16:15
@fqazi
Copy link
Copy Markdown
Collaborator Author

fqazi commented Aug 18, 2021

bors r+

@fqazi
Copy link
Copy Markdown
Collaborator Author

fqazi commented Aug 18, 2021

bors cancel

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 18, 2021

Canceled.

@fqazi fqazi force-pushed the interleaveLockout branch from f357035 to 1fbe0f4 Compare August 18, 2021 17:47
@fqazi
Copy link
Copy Markdown
Collaborator Author

fqazi commented Aug 18, 2021

bors r+

fqazi added 2 commits August 18, 2021 15:58
Fixes: cockroachdb#52009

Previously, interleaved tables were only deprecated so users
were allowed to create them after flipping an internal setting.
This was inadequate because we want to completely drop support
for this feature, as a part of the next release we will be
completely disabling support for them. To address this, this
patch will block upgrade to the next version if interleaved
tables exist. Additionally, test cases for interleaved table
/ index functionality are removed.

Release note: Upgrade to the next version will be blocked if
interleaved tables/indexes exist. Users should convert existing
interleaved tables/indexes to non-interleaved ones or drop any
interleaved tables/indexes before upgrading to the next version.
Fixes: cockroachdb#68116

Previously, for tenants we only updated the cluster version
once migration was fully complete. This was inadequate because,
there was a potential danger for the individual operations
version upgrades succeeding, but the version on disk not
changing. To address this, this patch updates the settings
table directly for tenants as we step through version numbers.

Release note: None
@fqazi fqazi force-pushed the interleaveLockout branch from 1fbe0f4 to 1f68d54 Compare August 18, 2021 19:58
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 18, 2021

Canceled.

@fqazi
Copy link
Copy Markdown
Collaborator Author

fqazi commented Aug 18, 2021

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 18, 2021

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: remove interleaved tables

5 participants