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

19.2: sql: TRUNCATE prevents later ALTER TABLE ... RENAME TO ... #50587

Closed
2 tasks done
ajwerner opened this issue Jun 23, 2020 · 4 comments
Closed
2 tasks done

19.2: sql: TRUNCATE prevents later ALTER TABLE ... RENAME TO ... #50587

ajwerner opened this issue Jun 23, 2020 · 4 comments
Assignees
Labels
A-schema-changes C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. C-technical-advisory Caused a technical advisory

Comments

@ajwerner
Copy link
Contributor

ajwerner commented Jun 23, 2020

Describe the problem

The implementation of TRUNCATE is to create a new table with a new descriptor ID and replace an old table which we'll drop. When we drop the old table, we create a drop job to asynchronously clean up its data. In 19.2 and prior, we'd assign this job ID to the old table prior to copying it for the new table. This means that the new table descriptor will have a populated drop job ID. This populated drop job ID then later prevents renames.

Here's the crazy assignment:

tableDesc.DropJobID = dropJobID
newTableDesc := sqlbase.NewMutableCreatedTableDescriptor(tableDesc.TableDescriptor)

The problem ends up being here:

W200622 19:46:55.858884 359674971 sql/exec_util.go:1140 [n5,client=10.0.32.19:38956,user=root] error executing schema change: job with ID 559393931270488069 does not exist

To Reproduce

Using 19.2.7 or prior: TRUNCATE a table, set the default GC ttl to 1s, wait for the drop of the old table to succeed, then try to rename the table.

root@localhost:26257/defaultdb> ALTER  TABLE bar RENAME TO foo;                          
pq: cannot update progress on succeeded job (id 566502454837379073)
-- it'd be a different error if this happened after the job record had been GC'd
root@localhost:26257/defaultdb> ALTER  TABLE bar RENAME TO foo;
pq: relation "bar" does not exist

Expected behavior

We won't write that DropJobID and we remain robust to schema changes which try to operate on public tables which have it.

Additional context

At this point, we need to do a couple of things:

  • Remove the bogus DropJobID in the new table
  • Make the rename, and schema changes in general, robust to table which have such drop jobs IDs but are not dropped.
@ajwerner ajwerner added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-schema-changes labels Jun 23, 2020
ajwerner added a commit to ajwerner/cockroach that referenced this issue Jun 26, 2020
Prior to this commit, we'd populate the DropJobID in both the new and old
tables when truncating a table. This causes problems later. Note that this
commit does not add robustness to clusters which have table descriptors with
a DropJobID due to this bug. That will come in a follow-up.

Touches cockroachdb#50587.

Release note (bug fix): Fixed a bug in TRUNCATE which could later leave
tables in a state where they cannot be renamed.
ajwerner added a commit to ajwerner/cockroach that referenced this issue Jun 29, 2020
In cockroachdb#50587 we discovered that TRUNCATE would leave a DropJobID on both the new
and old tables. This situation was rectified in cockroachdb#50714. In most cases that job
ID is ignored. However, in release-19.2 and earlier, it would prevent RENAME
operations from completing. To deal with this, we repair the descriptor by
removing the DropJobID. We also, for additional protection, prevent the
failure to update the job from preventing progress.

Release note (bug fix): Fixed a bug which could prevent previously TRUNCATED
tables from being renamed.
ajwerner added a commit to ajwerner/cockroach that referenced this issue Jun 29, 2020
In cockroachdb#50587 we discovered that TRUNCATE would leave a DropJobID on both the new
and old tables. This situation was rectified in cockroachdb#50714. In most cases that job
ID is ignored. However, in release-19.2 and earlier, it would prevent RENAME
operations from completing. To deal with this, we repair the descriptor by
removing the DropJobID. We also, for additional protection, prevent the
failure to update the job from preventing progress.

Release note (bug fix): Fixed a bug which could prevent previously TRUNCATED
tables from being renamed.
@ajwerner
Copy link
Contributor Author

I have some lingering concerns about the job upgrade migration that I'm working through. I'm curious to what extent this bug relates to #49876 which I'm still investigating.

@ajwerner ajwerner self-assigned this Jun 29, 2020
ajwerner added a commit to ajwerner/cockroach that referenced this issue Jun 29, 2020
Prior to this commit, we'd populate the DropJobID in both the new and old
tables when truncating a table. This causes problems later. Note that this
commit does not add robustness to clusters which have table descriptors with
a DropJobID due to this bug. That will come in a follow-up.

Touches cockroachdb#50587.

Release note (bug fix): Fixed a bug in TRUNCATE which could later leave
tables in a state where they cannot be renamed.
ajwerner added a commit to ajwerner/cockroach that referenced this issue Jun 29, 2020
In cockroachdb#50587 we discovered that TRUNCATE would leave a DropJobID on both the new
and old tables. This situation was rectified in cockroachdb#50714. In most cases that job
ID is ignored. However, in release-19.2 and earlier, it would prevent RENAME
operations from completing. To deal with this, we repair the descriptor by
removing the DropJobID. We also, for additional protection, prevent the
failure to update the job from preventing progress.

Release note (bug fix): Fixed a bug which could prevent previously TRUNCATED
tables from being renamed.
@thoszhang
Copy link
Contributor

I have some lingering concerns about the job upgrade migration that I'm working through.

I'm interested in this, say more when you have time?

@dbist
Copy link
Contributor

dbist commented Jun 30, 2020

#50766

@ajwerner
Copy link
Contributor Author

I have some lingering concerns about the job upgrade migration that I'm working through.

I'm interested in this, say more when you have time?

I just wanted to make sure that these DropJobIDs wouldn't cause problems when upgrading. They don't. Nothing to see here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-schema-changes C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. C-technical-advisory Caused a technical advisory
Projects
None yet
Development

No branches or pull requests

4 participants