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

store/gc_worker: Save gc_delete_range items that is done in another table instead of deleting them. #6512

Merged

Conversation

MyonKeminta
Copy link
Contributor

@MyonKeminta MyonKeminta commented May 9, 2018

Please refer to: tikv/tikv#3034
This pull request added a is_done field in mysql.gc_delete_range, and after deleting range, it marks the record in mysql.gc_delete_range as "Done" status rather than deleting it from the table.
Related pull request in TiKV: tikv/tikv#3046

At the same time this PR fix a bug that we incorrectly set element_id field unique in mysql.gc_delete_range. Element id of index is not globally unique.

Please be careful reviewing this PR

UPDATE: Save already-done gc_delete_range items in a new table.

@MyonKeminta
Copy link
Contributor Author

@zhangjinpeng1987 PTAL

@MyonKeminta MyonKeminta changed the title [WIP] store/gc_worker: Use is_done flag field instead of deleting entry from gc_delete_range table store/gc_worker: Use is_done flag field instead of deleting entry from gc_delete_range table May 9, 2018
@MyonKeminta MyonKeminta changed the title store/gc_worker: Use is_done flag field instead of deleting entry from gc_delete_range table [DNM] store/gc_worker: Use is_done flag field instead of deleting entry from gc_delete_range table May 9, 2018
@MyonKeminta MyonKeminta changed the title [DNM] store/gc_worker: Use is_done flag field instead of deleting entry from gc_delete_range table store/gc_worker: Use is_done flag field instead of deleting entry from gc_delete_range table May 10, 2018
@MyonKeminta
Copy link
Contributor Author

@tiancaiamao @coocood PTAL

@@ -35,7 +35,10 @@ import (
)

const (
insertDeleteRangeSQL = `INSERT IGNORE INTO mysql.gc_delete_range VALUES ("%d", "%d", "%s", "%s", "%d")`
// Use ON DUPLICATE KEY UPDATE to avoid already-processed records in the table breaking tests.
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 it is better to investigate why the test failed.

ddl/util/util.go Outdated
@@ -27,8 +27,8 @@ import (
)

const (
loadDeleteRangeSQL = `SELECT HIGH_PRIORITY job_id, element_id, start_key, end_key FROM mysql.gc_delete_range WHERE ts < %v ORDER BY ts`
completeDeleteRangeSQL = `DELETE FROM mysql.gc_delete_range WHERE job_id = %d AND element_id = %d`
loadDeleteRangeSQL = `SELECT HIGH_PRIORITY job_id, element_id, start_key, end_key FROM mysql.gc_delete_range WHERE ts < %v AND is_done = FALSE ORDER BY ts`
Copy link
Contributor

Choose a reason for hiding this comment

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

ORDER BY ts is not necessary.

@tiancaiamao
Copy link
Contributor

There is a currentBootstrapVersion , you should update its value to 21.
https://github.com/pingcap/tidb/pull/6512/files#diff-4a9e9120daccf5fc0d249b976f057938R306

@shenli
Copy link
Member

shenli commented May 10, 2018

In this case, the data in the gc_delete_range will increase forever?

it marks the record in mysql.gc_delete_range as "Done" status rather than deleting it from the table.

@shenli
Copy link
Member

shenli commented May 10, 2018

/run-all-tests

@MyonKeminta
Copy link
Contributor Author

@shenli We plan to change it back later, after apply bool is implemented. For detail please see tikv/tikv#3034

@siddontang
Copy link
Member

@shenli this is just a workaround, we will fix this problem later.

@tiancaiamao
Copy link
Contributor

LGTM

@tiancaiamao tiancaiamao added the status/LGT1 Indicates that a PR has LGTM 1. label May 11, 2018
@MyonKeminta
Copy link
Contributor Author

@zimulala @coocood PTAL

@zhangjinpeng87
Copy link
Contributor

@shenli PTAL

@MyonKeminta MyonKeminta changed the title [DNM] store/gc_worker: Use is_done flag field instead of deleting entry from gc_delete_range table [DNM] store/gc_worker: Save gc_delete_range items that is done in another table instead of deleting them. May 14, 2018
@MyonKeminta MyonKeminta changed the title [DNM] store/gc_worker: Save gc_delete_range items that is done in another table instead of deleting them. store/gc_worker: Save gc_delete_range items that is done in another table instead of deleting them. May 14, 2018
@shenli
Copy link
Member

shenli commented May 14, 2018

/run-all-tests


doReentrantDDL(s, "ALTER TABLE mysql.gc_delete_range DROP INDEX element_id", ddl.ErrCantDropFieldOrKey)
doReentrantDDL(s, "ALTER TABLE mysql.gc_delete_range DROP INDEX job_id", ddl.ErrCantDropFieldOrKey)
doReentrantDDL(s, "ALTER TABLE mysql.gc_delete_range ADD UNIQUE INDEX delete_range_index (job_id, element_id)", ddl.ErrDupKeyName)
Copy link
Member

Choose a reason for hiding this comment

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

Can we add index first?
If we drop the element id unique index, then two records inserted with the same element_id, then add unique index would fail.

ddl/util/util.go Outdated
@@ -89,8 +90,14 @@ func LoadDeleteRanges(ctx sessionctx.Context, safePoint uint64) (ranges []DelRan
// CompleteDeleteRange deletes a record from gc_delete_range table.
Copy link
Member

Choose a reason for hiding this comment

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

Please update the comment

@coocood
Copy link
Member

coocood commented May 14, 2018

LGTM

@MyonKeminta
Copy link
Contributor Author

@coocood @zimulala PTAL again..

@tiancaiamao
Copy link
Contributor

tiancaiamao commented May 14, 2018

LGTM @zimulala

@tiancaiamao tiancaiamao added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 14, 2018
completeDeleteRangeSQL = `DELETE FROM mysql.gc_delete_range WHERE job_id = %d AND element_id = %d`
updateDeleteRangeSQL = `UPDATE mysql.gc_delete_range SET start_key = "%s" WHERE job_id = %d AND element_id = %d AND start_key = "%s"`
loadDeleteRangeSQL = `SELECT HIGH_PRIORITY job_id, element_id, start_key, end_key FROM mysql.gc_delete_range WHERE ts < %v`
recordDoneDeletedRangeSQL = `INSERT IGNORE INTO mysql.gc_delete_range_done SELECT * FROM mysql.gc_delete_range WHERE job_id = %d AND element_id = %d`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why need "IGNORE" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The insert statement in ddl/delete_range.go has IGNORE too...
It's might considering that maybe multiple TiDBs are trying to insert the record

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala
Copy link
Contributor

/run-all-tests

@zimulala
Copy link
Contributor

/run-unit-test

@BusyJay
Copy link
Contributor

BusyJay commented May 14, 2018

Ping

@zimulala zimulala added all-tests-passed status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels May 14, 2018
@tiancaiamao tiancaiamao merged commit 10e57a5 into pingcap:master May 14, 2018
MyonKeminta added a commit to MyonKeminta/tidb that referenced this pull request May 15, 2018
disksing pushed a commit that referenced this pull request May 16, 2018
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra status/LGT3 The PR has already had 3 LGTM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants