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
store/gc_worker: Save gc_delete_range items that is done in another table instead of deleting them. #6512
Conversation
@zhangjinpeng1987 PTAL |
@tiancaiamao @coocood PTAL |
ddl/delete_range.go
Outdated
@@ -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. |
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.
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` |
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.
ORDER BY ts
is not necessary.
There is a |
In this case, the data in the gc_delete_range will increase forever?
|
/run-all-tests |
@shenli We plan to change it back later, after apply bool is implemented. For detail please see tikv/tikv#3034 |
…b.com/MyonKeminta/tidb into misono/deleterange-workaround-speedup
@shenli this is just a workaround, we will fix this problem later. |
LGTM |
@shenli PTAL |
/run-all-tests |
session/bootstrap.go
Outdated
|
||
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) |
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.
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. |
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.
Please update the comment
…b.com/MyonKeminta/tidb into misono/deleterange-workaround-speedup
LGTM |
LGTM @zimulala |
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` |
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.
Why need "IGNORE" ?
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.
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
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.
LGTM
/run-all-tests |
/run-unit-test |
Ping |
Please refer to: tikv/tikv#3034
This pull request added a
is_done
field inmysql.gc_delete_range
, and after deleting range, it marks the record inmysql.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 inmysql.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.