sql: recycle name of a column/index that has been dropped as soon as possible
When a schema element gets into the DELETE_ONLY state during a DROP schema change, it stays that way until all the schema related data has been dropped with the name for the schema element still in use by the schema element. This can take many hours/days. We should recycle the name sooner.
During a DROP once the entire cluster sees the schema element in WRITE_ONLY, the schema changer during the process of changing the state to DELETE_ONLY can also rename the schema element to some illegal system internal name.
related to #16018
@vivekmenezes I want to dig into the part of schema change, could I have a try for this?
I appreciate you taking a look at this! I think it will be valuable for you to first add a test in schema_changer_test.go that tests for the particular condition. What you need to do is create a table with enough data (1000 rows), use the TestingKnob notification for when the backfill starts for deleting the index and check if you can insert a column/index into the table when the backfill starts using the same name. The current code should disallow it.
Once you have the test merged, you can work on another PR that allows the use of the name before the backfill and you should see the above test break. Fix the breakage in this new PR.
Thanks!
@a6802739 any help needed here? Thanks
Oh, Thank you very much. Sorry for late response, I will try to fix it as you say, Thanks for your remind.
@vivekmenezes, how to use TestingKnob notification, any reference? Thank you very much.
Any doc or reference for TestingKnob, I'm not quite familiar with this.
Here is my thought. We should define RunBeforeBackfill, use a notify channel to asynchronous notify us call a function to add a column/index, and see if the error is as our expected?
So the key point is make sure the backfill is running, right?
That's correct. The notification lets you know when the backfill is running. TestSchemaChangeRetryOnVersionChange is a good example of how RunBeforeBackfill is called to keep track of the number of retries and RunBeforeBackfillChunk is called which in turn calls the upTableVersion(). You can define a function that creates an index/column and call it from RunBeforeBackfill . This is done while running a schema change that drops the index/column.
Hope that is helpful.
@vivekmenezes Thank you very much, So what kind of error will occur if we try to add the same index/column during we drop the index/column?
you will see an error: "duplicate column name". You should be able to check the returned error and log it using t.Fatal(err). Since this is a test we want to merge you will need to use testutil.IsError() to test for the error. Thanks
On Tue, Jun 20, 2017 at 10:58 AM songhao [email protected] wrote:
@vivekmenezes https://github.com/vivekmenezes Thank you very much, So what kind of error will occur if we try to add the same index/column during we drop the index/column?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cockroachdb/cockroach/issues/16020#issuecomment-309785383, or mute the thread https://github.com/notifications/unsubscribe-auth/ALOpBAwzPANYrlJKAo3fmeJDU_NQTD-bks5sF94fgaJpZM4NfUI5 .
Thank you very much. 👍
@vivekmenezes I can't tell what happened here - is there still work to be done?
Only the test showing the problem was written for this. It needs to be implemented and the test modified to match the implementation.
potential starter project for lucy
I don't think this is a problem for indexes; we should be able to reuse the old name before we GC the actual index data. And I'm not convinced that it is a problem for columns currently - even if it's slow, we wait to return results to the client until after the cleanup backfill is done, so there's not a correctness issue. We could consider reopening if people raise concerns about it.