Use TSO instead of seconds in gc_delete_range table (#7610)
This commit is contained in:
committed by
zhangjinpeng1987
parent
4538bcd52c
commit
56f5ff8e09
@ -25,7 +25,6 @@ import (
|
||||
"github.com/pingcap/tidb/kv"
|
||||
"github.com/pingcap/tidb/model"
|
||||
"github.com/pingcap/tidb/sessionctx"
|
||||
"github.com/pingcap/tidb/store/tikv/oracle"
|
||||
"github.com/pingcap/tidb/tablecodec"
|
||||
"github.com/pingcap/tidb/terror"
|
||||
"github.com/pingcap/tidb/util/sqlexec"
|
||||
@ -208,7 +207,7 @@ func (dr *delRange) doTask(ctx sessionctx.Context, r util.DelRangeTask) error {
|
||||
// and inserts a new record into gc_delete_range table. The primary key is
|
||||
// job ID, so we ignore key conflict error.
|
||||
func insertJobIntoDeleteRangeTable(ctx sessionctx.Context, job *model.Job) error {
|
||||
now, err := getNowTS(ctx)
|
||||
now, err := getNowTSO(ctx)
|
||||
if err != nil {
|
||||
return errors.Trace(err)
|
||||
}
|
||||
@ -302,7 +301,7 @@ func insertJobIntoDeleteRangeTable(ctx sessionctx.Context, job *model.Job) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func doInsert(s sqlexec.SQLExecutor, jobID int64, elementID int64, startKey, endKey kv.Key, ts int64) error {
|
||||
func doInsert(s sqlexec.SQLExecutor, jobID int64, elementID int64, startKey, endKey kv.Key, ts uint64) error {
|
||||
log.Infof("[ddl] insert into delete-range table with key: (%d,%d)", jobID, elementID)
|
||||
startKeyEncoded := hex.EncodeToString(startKey)
|
||||
endKeyEncoded := hex.EncodeToString(endKey)
|
||||
@ -311,12 +310,11 @@ func doInsert(s sqlexec.SQLExecutor, jobID int64, elementID int64, startKey, end
|
||||
return errors.Trace(err)
|
||||
}
|
||||
|
||||
// getNowTS gets the current timestamp, in second.
|
||||
func getNowTS(ctx sessionctx.Context) (int64, error) {
|
||||
// getNowTS gets the current timestamp, in TSO.
|
||||
func getNowTSO(ctx sessionctx.Context) (uint64, error) {
|
||||
currVer, err := ctx.GetStore().CurrentVersion()
|
||||
if err != nil {
|
||||
return 0, errors.Trace(err)
|
||||
}
|
||||
physical := oracle.ExtractPhysical(currVer.Ver)
|
||||
return physical / 1e3, nil
|
||||
return currVer.Ver, nil
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ const (
|
||||
element_id BIGINT NOT NULL COMMENT "the schema element ID",
|
||||
start_key VARCHAR(255) NOT NULL COMMENT "encoded in hex",
|
||||
end_key VARCHAR(255) NOT NULL COMMENT "encoded in hex",
|
||||
ts BIGINT NOT NULL COMMENT "timestamp in int64",
|
||||
ts BIGINT NOT NULL COMMENT "timestamp in uint64",
|
||||
UNIQUE KEY delete_range_index (job_id, element_id)
|
||||
);`
|
||||
|
||||
@ -196,7 +196,7 @@ const (
|
||||
element_id BIGINT NOT NULL COMMENT "the schema element ID",
|
||||
start_key VARCHAR(255) NOT NULL COMMENT "encoded in hex",
|
||||
end_key VARCHAR(255) NOT NULL COMMENT "encoded in hex",
|
||||
ts BIGINT NOT NULL COMMENT "timestamp in int64",
|
||||
ts BIGINT NOT NULL COMMENT "timestamp in uint64",
|
||||
UNIQUE KEY delete_range_done_index (job_id, element_id)
|
||||
);`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user