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: squash add and drop mutations in same transaction #32066

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eriktrinh
Copy link

@eriktrinh eriktrinh commented Oct 31, 2018

Schema elements in an adding state can be dropped if the drop happens in
the same transaction as the one which initiated the add because
the rest of the cluster is not aware that the element ever existed. This
change uses the cluster version of the mutable table descriptor to
squash these new mutations.

Related to #16020.

Release note: None

@eriktrinh eriktrinh requested review from vivekmenezes and a team October 31, 2018 20:47
@cockroach-teamcity
Copy link
Member

This change is Reviewable

// ADD and DROP column squashed and works.
{`add-drop-column`, `ALTER TABLE t.kv ADD COLUMN i INT`, `ALTER TABLE t.kv DROP COLUMN i`, ``},
// CREATE and DROP index squashed and works.
{`add-drop-index`, `CREATE INDEX foobar ON t.kv (v)`, `DROP INDEX t.kv@foobar`, ``},
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these can be modeled in the logic tests. See the tests in logictest file schema_change_in_txn

You can also add the ADD, DROP, ADD cases there

and the ADD, DROP, RENAME (to the name used by the ADD) case

pkg/sql/table.go Outdated
// squashNewMutations rewrites the mutations list, removing
// mutations where schema elements are added and dropped in
// the same transaction, and marking the mutation jobs as
// succeeded.
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this should only care about DROP mutations in the DELETE_AND_WRITE_ONLY state that were not present in the ClusterVersion.

Copy link
Author

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


pkg/sql/table.go, line 782 at r1 (raw file):

Previously, vivekmenezes wrote…

I believe this should only care about DROP mutations in the DELETE_AND_WRITE_ONLY state that were not present in the ClusterVersion.

All DROP mutations not present in the cluster version should be in the DELETE_AND_WRITE_ONLY state, I don't think we need to do any checks on state here.


pkg/sql/schema_changer_test.go, line 2411 at r1 (raw file):

Previously, vivekmenezes wrote…

I think these can be modeled in the logic tests. See the tests in logictest file schema_change_in_txn

You can also add the ADD, DROP, ADD cases there

and the ADD, DROP, RENAME (to the name used by the ADD) case

Done.

Copy link
Contributor

@vivekmenezes vivekmenezes left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together! It could be nice to get the PR out that ensures that a transaction
uses only a single mutation id before we merge this one. Your call.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained


pkg/sql/table.go, line 783 at r2 (raw file):

// the same transaction, and marking the mutation jobs as
// succeeded.
func (p *planner) squashNewMutations(

perhaps rename this to maybeSquashNewMutations


pkg/sql/table.go, line 793 at r2 (raw file):

	addDroppedColumns := make(map[sqlbase.ColumnID]bool)
	addDroppedIndexes := make(map[sqlbase.IndexID]bool)
	for _, m := range desc.Mutations[origLen:] {

Can you add a comment here discussing what this code is doing?


pkg/sql/table.go, line 819 at r2 (raw file):

	var squashedIDs []sqlbase.MutationID

	for _, m := range desc.Mutations[origLen:] {

Can you add a column here as to what this code is doing.


pkg/sql/table.go, line 841 at r2 (raw file):

	var prev sqlbase.MutationID
	for _, id := range squashedIDs {

you should need to only squash a single mutation ID corresponding to the mutation ID of the transaction being processed.

How about adding a TODO to fix the issue of using a mutation ID for each transaction. Even better if you can fix that issue and then merge this PR after that one.


pkg/sql/logictest/testdata/logic_test/schema_change_in_txn, line 539 at r2 (raw file):


statement ok
COMMIT

Can you add a SHOW JOBS check to ensure the jobs are cleaned up properly

Schema elements in an adding state can be dropped if the drop happens in
the same transaction as the one which initiated the add because
the rest of the cluster is not aware that the element ever existed. This
change uses the cluster version of the mutable table descriptor to
squash these new mutations.

Related to cockroachdb#16020.

Release note: None
Copy link
Author

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


pkg/sql/table.go, line 783 at r2 (raw file):

Previously, vivekmenezes wrote…

perhaps rename this to maybeSquashNewMutations

Done.


pkg/sql/table.go, line 793 at r2 (raw file):

Previously, vivekmenezes wrote…

Can you add a comment here discussing what this code is doing?

Done.


pkg/sql/table.go, line 819 at r2 (raw file):

Previously, vivekmenezes wrote…

Can you add a column here as to what this code is doing.

Done.


pkg/sql/table.go, line 841 at r2 (raw file):

Previously, vivekmenezes wrote…

you should need to only squash a single mutation ID corresponding to the mutation ID of the transaction being processed.

How about adding a TODO to fix the issue of using a mutation ID for each transaction. Even better if you can fix that issue and then merge this PR after that one.

Rebased after merging that PR, PTAL.


pkg/sql/logictest/testdata/logic_test/schema_change_in_txn, line 539 at r2 (raw file):

Previously, vivekmenezes wrote…

Can you add a SHOW JOBS check to ensure the jobs are cleaned up properly

Done.

@tbg tbg added the X-noremind Bots won't notify about PRs with X-noremind label Jun 19, 2019
@cockroach-teamcity
Copy link
Member

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Erik Trinh seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
X-noremind Bots won't notify about PRs with X-noremind
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants