-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: Add backfill job related tables and operations #38978
Changes from 6 commits
677f72e
1cd415a
757f0e1
31c4db1
d7c6bc7
02b1de9
a011179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,20 +32,24 @@ import ( | |
"github.com/pingcap/tidb/kv" | ||
"github.com/pingcap/tidb/metrics" | ||
"github.com/pingcap/tidb/parser/model" | ||
"github.com/pingcap/tidb/parser/mysql" | ||
"github.com/pingcap/tidb/parser/terror" | ||
"github.com/pingcap/tidb/sessionctx" | ||
"github.com/pingcap/tidb/sessionctx/variable" | ||
"github.com/pingcap/tidb/store/copr" | ||
"github.com/pingcap/tidb/store/driver/backoff" | ||
"github.com/pingcap/tidb/table" | ||
"github.com/pingcap/tidb/tablecodec" | ||
"github.com/pingcap/tidb/types" | ||
"github.com/pingcap/tidb/util" | ||
"github.com/pingcap/tidb/util/dbterror" | ||
"github.com/pingcap/tidb/util/logutil" | ||
decoder "github.com/pingcap/tidb/util/rowDecoder" | ||
"github.com/pingcap/tidb/util/timeutil" | ||
"github.com/pingcap/tidb/util/topsql" | ||
"github.com/tikv/client-go/v2/oracle" | ||
"github.com/tikv/client-go/v2/tikv" | ||
atomicutil "go.uber.org/atomic" | ||
"go.uber.org/zap" | ||
) | ||
|
||
|
@@ -56,8 +60,65 @@ const ( | |
typeUpdateColumnWorker backfillWorkerType = 1 | ||
typeCleanUpIndexWorker backfillWorkerType = 2 | ||
typeAddIndexMergeTmpWorker backfillWorkerType = 3 | ||
|
||
// InstanceLease is the instance lease. | ||
InstanceLease = 1 * time.Minute | ||
) | ||
|
||
// enableDistReorg means whether to enable dist reorg. The default is enable. | ||
// TODO: control the behavior | ||
var enableDistReorg = atomicutil.NewBool(false) | ||
Benjamin2037 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default is enable, I think this should be ture |
||
|
||
// DistReorgEnable enables dist reorg. It exports for testing. | ||
func DistReorgEnable() { | ||
enableDistReorg.Store(true) | ||
} | ||
|
||
// DistReorgDisable disables dist reorg. It exports for testing. | ||
func DistReorgDisable() { | ||
enableDistReorg.Store(false) | ||
} | ||
|
||
// IsDistReorgEnable indicates whether dist reorg enabled. It exports for testing. | ||
func IsDistReorgEnable() bool { | ||
return enableDistReorg.Load() | ||
} | ||
|
||
// BackfillJob is for a tidb_ddl_backfill table's record. | ||
type BackfillJob struct { | ||
ID int64 | ||
JobID int64 | ||
EleID int64 | ||
EleKey []byte | ||
Tp model.BackfillType | ||
State model.JobState | ||
StoreID int64 | ||
InstanceID string | ||
InstanceLease types.Time | ||
Mate *model.BackfillMeta | ||
} | ||
|
||
// AbbrStr returns the BackfillJob's info without the Mate info. | ||
func (bj *BackfillJob) AbbrStr() string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. directly name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this function only shows some ID related info, we don't use |
||
return fmt.Sprintf("ID:%d, JobID:%d, EleID:%d, Type:%s, State:%s, InstanceID:%s, InstanceLease:%s", | ||
bj.ID, bj.JobID, bj.EleID, bj.Tp, bj.State, bj.InstanceID, bj.InstanceLease) | ||
} | ||
|
||
// GetOracleTime returns the current time from TS. | ||
func GetOracleTime(store kv.Storage) (time.Time, error) { | ||
currentVer, err := store.CurrentVersion(kv.GlobalTxnScope) | ||
if err != nil { | ||
return time.Time{}, errors.Trace(err) | ||
} | ||
return oracle.GetTimeFromTS(currentVer.Ver), nil | ||
} | ||
|
||
// GetLeaseGoTime returns a types.Time by adding a lease. | ||
func GetLeaseGoTime(currTime time.Time, lease time.Duration) types.Time { | ||
leaseTime := currTime.Add(lease) | ||
return types.NewTime(types.FromGoTime(leaseTime.In(time.UTC)), mysql.TypeTimestamp, types.MaxFsp) | ||
} | ||
|
||
// By now the DDL jobs that need backfilling include: | ||
// 1: add-index | ||
// 2: modify-column-type | ||
|
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.
We have feature tag in the
sessionctx/variable/featuretag
. We can test feature when it enables and disables by controlling the feature tag. I think it may be useful for you.