-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make table deletion a schema change so that truncation doesn't race with other people still using the table #5907
Conversation
// called multiple times if retries occur: make sure it does not have side | ||
// effects. | ||
// Publish updates a table descriptor. It also maintains the invariant that | ||
// there's at most two versions of the descriptor out in the wild at any time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are
Review status: 0 of 31 files reviewed at latest revision, 8 unresolved discussions, some commit checks failed. sql/structured.proto, line 259 [r5] (raw file): Can you just delete all mutations and mark the table descriptor as deleted? That will disable all the mutation related work going on the table, and get it ready for deletion. sql/parser/expr.go, line 536 [r5] (raw file): Comments from Reviewable |
66f06cd
to
3aa1afc
Compare
@vivekmenezes I've removed the mutation. I've also added some other utility commits. PTAL when you can. Review status: 0 of 35 files reviewed at latest revision, 8 unresolved discussions, some commit checks failed. sql/structured.proto, line 259 [r5] (raw file): Comments from Reviewable |
Thanks for making this change. I do like it but there is one more improvement worth making here or creating an issue over. Once the table descriptor has been marked deleted and there are no more leases on the previous version, it would be nice to rename the table to GC (or equivalent) so that going forward all schema change commands and other commands like creating a table with the same name behave nicely. If you have a very large table you need not have to wait until the table is completely GC-ed before you can reuse the name. The above change will also make the thinking around everything else a lot easier. You don't have to worry about new schema change mutations being added for instance to the old descriptor. Review status: 0 of 35 files reviewed at latest revision, 30 unresolved discussions, some commit checks failed. roachpb/errors.go, line 556 [r13] (raw file): roachpb/errors.proto, line 193 [r13] (raw file): sql/alter_table.go, line 182 [r13] (raw file): sql/descriptor.go, line 133 [r13] (raw file): sql/drop.go, line 172 [r13] (raw file): sql/drop.go, line 228 [r13] (raw file): sql/lease.go, line 493 [r13] (raw file): sql/lease.go, line 571 [r13] (raw file): sql/lease.go, line 667 [r13] (raw file): sql/lease_test.go, line 348 [r13] (raw file): sql/lease_test.go, line 393 [r13] (raw file): sql/lease_test.go, line 405 [r13] (raw file): sql/lease_test.go, line 407 [r13] (raw file): sql/lease_test.go, line 418 [r13] (raw file): sql/plan.go, line 389 [r13] (raw file): sql/schema_changer.go, line 65 [r13] (raw file): sql/schema_changer.go, line 90 [r13] (raw file): sql/schema_changer.go, line 142 [r13] (raw file): sql/schema_changer.go, line 246 [r13] (raw file): From this point forward it is guaranteed that no node will change the underlying data on the table with the exception of the backfill. It is important to grab a schema change lease on the table now to prevent some backfill operation from adding more data. Schema change commands can continue executing on the table descriptor. That's fine, but we don't want any backfill being triggered. I suppose that's protected by the fact that the backfill checks whether the descriptor has been deleted. sql/schema_changer.go, line 652 [r13] (raw file): sql/structured.proto, line 257 [r13] (raw file): sql/parser/expr.go, line 540 [r13] (raw file):
Comments from Reviewable |
The more i think about this, lets make drop table super fast and decouple I'm happy to chat about this before you proceed On Fri, Apr 8, 2016, 1:29 PM Andrei Matei notifications@github.com wrote:
|
We even have an issue filed to optimize DROP/TRUNCATE: On Fri, Apr 8, 2016 at 4:01 PM, vivekmenezes notifications@github.com
|
3aa1afc
to
2387ddd
Compare
Review status: 0 of 35 files reviewed at latest revision, 30 unresolved discussions, some commit checks failed. roachpb/errors.go, line 556 [r13] (raw file): roachpb/errors.proto, line 193 [r13] (raw file): sql/descriptor.go, line 133 [r13] (raw file): sql/drop.go, line 172 [r13] (raw file): sql/drop.go, line 228 [r13] (raw file): sql/lease.go, line 217 [r2] (raw file): sql/lease.go, line 220 [r2] (raw file): sql/lease.go, line 493 [r13] (raw file): sql/lease_test.go, line 348 [r13] (raw file): sql/lease_test.go, line 393 [r13] (raw file): sql/lease_test.go, line 405 [r13] (raw file): sql/lease_test.go, line 407 [r13] (raw file): sql/lease_test.go, line 418 [r13] (raw file): sql/plan.go, line 389 [r13] (raw file): sql/schema_changer.go, line 65 [r13] (raw file): sql/schema_changer.go, line 90 [r13] (raw file): sql/schema_changer.go, line 142 [r13] (raw file): sql/schema_changer.go, line 246 [r13] (raw file): sql/schema_changer.go, line 652 [r13] (raw file): sql/structured.proto, line 257 [r13] (raw file): sql/table.go, line 46 [r2] (raw file): sql/table.go, line 47 [r2] (raw file): sql/table.go, line 217 [r2] (raw file): Why do you like sql/table.go, line 263 [r2] (raw file): sql/parser/expr.go, line 536 [r5] (raw file): sql/parser/expr.go, line 540 [r13] (raw file): Comments from Reviewable |
@vivekmenezes as we discussed, let's do async truncate in a future PR Review status: 0 of 35 files reviewed at latest revision, 30 unresolved discussions. Comments from Reviewable |
Review status: 0 of 35 files reviewed at latest revision, 37 unresolved discussions, some commit checks failed. sql/backfill.go, line 104 [r22] (raw file): sql/config.go, line 67 [r22] (raw file): sql/lease.go, line 493 [r13] (raw file): sql/lease.go, line 130 [r22] (raw file): sql/lease_test.go, line 411 [r22] (raw file): sql/schema_changer.go, line 142 [r13] (raw file): sql/schema_changer.go, line 191 [r22] (raw file): sql/schema_changer.go, line 549 [r22] (raw file): sql/structured.go, line 642 [r22] (raw file): setUpVersion() // only sets upversion newMutationID() // gets new mutation id and sets upversion. Add a TODO to eliminate newMutationID() in favor of appendMutation() or something more sensible. Comments from Reviewable |
2387ddd
to
ed338c3
Compare
Review status: 0 of 35 files reviewed at latest revision, 37 unresolved discussions, some commit checks failed. sql/backfill.go, line 104 [r22] (raw file): sql/config.go, line 67 [r22] (raw file): sql/lease.go, line 493 [r13] (raw file): sql/lease.go, line 130 [r22] (raw file): sql/lease_test.go, line 411 [r22] (raw file): sql/schema_changer.go, line 142 [r13] (raw file): sql/schema_changer.go, line 191 [r22] (raw file): sql/schema_changer.go, line 549 [r22] (raw file): sql/structured.go, line 642 [r22] (raw file): Comments from Reviewable |
ed338c3
to
7e1487a
Compare
I've taken another pass at this. Most of the comments are in the lease and schema change area, and very little is in the rest of the refactoring. It would make me very happy if you can take lease and schema changer out of this change and do the basic refactoring stuff in a separate PR, or consolidate this entire PR into three commits
Thanks! Review status: 0 of 35 files reviewed at latest revision, 49 unresolved discussions, some commit checks failed. sql/drop_test.go, line 284 [r30] (raw file): sql/lease.go, line 492 [r30] (raw file): sql/lease.go, line 496 [r30] (raw file): sql/lease.go, line 522 [r30] (raw file): sql/lease.go, line 590 [r30] (raw file): sql/lease.go, line 598 [r30] (raw file): sql/lease.go, line 613 [r30] (raw file): sql/lease.go, line 626 [r30] (raw file): sql/lease.go, line 636 [r30] (raw file): sql/schema_changer.go, line 171 [r30] (raw file): Perhaps what you want is to not run the truncate and delete code through exec() and instead call its own method deleteTable(). See purgeMutations(). sql/schema_changer.go, line 178 [r30] (raw file): sql/schema_changer.go, line 598 [r30] (raw file): Comments from Reviewable |
7e1487a
to
cc9baac
Compare
On DROP TABLE, we now synchronously mark the table as DELETED and set up_version. The schema changer will then publish this change. This ensures (in conjunction with the next commit) that leases will not be handed out any more. Then, we asynchronously truncate and delete the table, now that nobody's writing on it any more.
Fixes cockroachdb#5483 Fixes cockroachdb#5484 Also eliminates a race in leasing: LeaseManager.RefreshLease() was reading tableState.active without locking.
Before this we have DisableSyncSchemaChanges, but that guy can only be called before the server is created (otherwise it races with schema changers). I need to be able to let schema changes run in the beginning of the test, and block them later on. This will be used in the next commit.
cc9baac
to
cedd8e7
Compare
@vivekmenezes the other refactoring PR has gone in. Mind taking another look? Review status: 0 of 26 files reviewed at latest revision, 49 unresolved discussions, some commit checks pending. sql/drop_test.go, line 284 [r30] (raw file): sql/lease.go, line 492 [r30] (raw file): sql/lease.go, line 496 [r30] (raw file): sql/lease.go, line 522 [r30] (raw file): sql/lease.go, line 590 [r30] (raw file): sql/lease.go, line 598 [r30] (raw file): sql/lease.go, line 613 [r30] (raw file): sql/lease.go, line 626 [r30] (raw file): sql/lease.go, line 636 [r30] (raw file): sql/schema_changer.go, line 171 [r30] (raw file): sql/schema_changer.go, line 178 [r30] (raw file): sql/schema_changer.go, line 598 [r30] (raw file): Comments from Reviewable |
I'd like you to split this into four PRs: "sql: add delete bit to table descriptor; schema change commands error on seeing the delete bit" and another PR called "sql: added TestingSchemaChangerCollection for ..." and another "sql: ensure that a lease is not taken on a deleted table" and "sql: delete table safely after all leases have expired" I know this is more work but 1. you'll see these PRs getting checked in, and 2. I wont be sweating each time I have to review this. Thanks Review status: 0 of 26 files reviewed at latest revision, 45 unresolved discussions, some commit checks failed. Comments from Reviewable |
This change is