cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql: recycle name of a column/index that has been dropped as soon as possible

Open vivekmenezes opened this issue 9 years ago • 13 comments

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 avatar May 18 '17 14:05 vivekmenezes

@vivekmenezes I want to dig into the part of schema change, could I have a try for this?

a6802739 avatar Jun 01 '17 12:06 a6802739

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!

vivekmenezes avatar Jun 01 '17 15:06 vivekmenezes

@a6802739 any help needed here? Thanks

vivekmenezes avatar Jun 19 '17 15:06 vivekmenezes

Oh, Thank you very much. Sorry for late response, I will try to fix it as you say, Thanks for your remind.

a6802739 avatar Jun 19 '17 15:06 a6802739

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

a6802739 avatar Jun 20 '17 06:06 a6802739

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 avatar Jun 20 '17 14:06 vivekmenezes

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

a6802739 avatar Jun 20 '17 14:06 a6802739

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 .

vivekmenezes avatar Jun 20 '17 16:06 vivekmenezes

Thank you very much. 👍

a6802739 avatar Jun 21 '17 01:06 a6802739

@vivekmenezes I can't tell what happened here - is there still work to be done?

jordanlewis avatar Jan 22 '18 19:01 jordanlewis

Only the test showing the problem was written for this. It needs to be implemented and the test modified to match the implementation.

vivekmenezes avatar Jan 22 '18 21:01 vivekmenezes

potential starter project for lucy

vivekmenezes avatar Oct 29 '18 15:10 vivekmenezes

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.

thoszhang avatar Apr 30 '20 19:04 thoszhang