-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
ttl: disable ttl job when recover/flashback table/database/cluster #40268
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cbaf634
ttl: disable ttl job when recover/flashback table/database/cluster
lcwangchao 0ac9c3c
Merge branch 'master' into ttl_recover_flashback
lcwangchao 7f392d1
update
lcwangchao 5b6b0be
Merge branch 'ttl_recover_flashback' of github.com:lcwangchao/tidb in…
lcwangchao 784d227
Merge branch 'master' into ttl_recover_flashback
lcwangchao 8930ecd
update
lcwangchao f75f966
Merge branch 'master' into ttl_recover_flashback
ti-chi-bot cf360de
Merge branch 'master' into ttl_recover_flashback
ti-chi-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ const ( | |
totalLockedRegionsOffset | ||
startTSOffset | ||
commitTSOffset | ||
ttlJobEnableOffSet | ||
) | ||
|
||
func closePDSchedule() error { | ||
|
@@ -124,6 +125,18 @@ func ValidateFlashbackTS(ctx context.Context, sctx sessionctx.Context, flashBack | |
return gcutil.ValidateSnapshotWithGCSafePoint(flashBackTS, gcSafePoint) | ||
} | ||
|
||
func getTiDBTTLJobEnable(sess sessionctx.Context) (string, error) { | ||
val, err := sess.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBTTLJobEnable) | ||
if err != nil { | ||
return "", errors.Trace(err) | ||
} | ||
return val, nil | ||
} | ||
|
||
func setTiDBTTLJobEnable(ctx context.Context, sess sessionctx.Context, value string) error { | ||
return sess.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(ctx, variable.TiDBTTLJobEnable, value) | ||
} | ||
|
||
func setTiDBEnableAutoAnalyze(ctx context.Context, sess sessionctx.Context, value string) error { | ||
return sess.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(ctx, variable.TiDBEnableAutoAnalyze, value) | ||
} | ||
|
@@ -176,6 +189,9 @@ func checkAndSetFlashbackClusterInfo(sess sessionctx.Context, d *ddlCtx, t *meta | |
if err = setTiDBSuperReadOnly(d.ctx, sess, variable.On); err != nil { | ||
return err | ||
} | ||
if err = setTiDBTTLJobEnable(d.ctx, sess, variable.Off); err != nil { | ||
return err | ||
} | ||
|
||
nowSchemaVersion, err := t.GetSchemaVersion() | ||
if err != nil { | ||
|
@@ -553,9 +569,9 @@ func (w *worker) onFlashbackCluster(d *ddlCtx, t *meta.Meta, job *model.Job) (ve | |
|
||
var flashbackTS, lockedRegions, startTS, commitTS uint64 | ||
var pdScheduleValue map[string]interface{} | ||
var autoAnalyzeValue, readOnlyValue string | ||
var autoAnalyzeValue, readOnlyValue, ttlJobEnableValue string | ||
var gcEnabledValue bool | ||
if err := job.DecodeArgs(&flashbackTS, &pdScheduleValue, &gcEnabledValue, &autoAnalyzeValue, &readOnlyValue, &lockedRegions, &startTS, &commitTS); err != nil { | ||
if err := job.DecodeArgs(&flashbackTS, &pdScheduleValue, &gcEnabledValue, &autoAnalyzeValue, &readOnlyValue, &lockedRegions, &startTS, &commitTS, &ttlJobEnableValue); err != nil { | ||
job.State = model.JobStateCancelled | ||
return ver, errors.Trace(err) | ||
} | ||
|
@@ -595,6 +611,12 @@ func (w *worker) onFlashbackCluster(d *ddlCtx, t *meta.Meta, job *model.Job) (ve | |
return ver, errors.Trace(err) | ||
} | ||
job.Args[readOnlyOffset] = &readOnlyValue | ||
ttlJobEnableValue, err = getTiDBTTLJobEnable(sess) | ||
if err != nil { | ||
job.State = model.JobStateCancelled | ||
return ver, errors.Trace(err) | ||
} | ||
job.Args[ttlJobEnableOffSet] = &ttlJobEnableValue | ||
job.SchemaState = model.StateDeleteOnly | ||
return ver, nil | ||
// Stage 2, check flashbackTS, close GC and PD schedule. | ||
|
@@ -694,10 +716,10 @@ func finishFlashbackCluster(w *worker, job *model.Job) error { | |
|
||
var flashbackTS, lockedRegions, startTS, commitTS uint64 | ||
var pdScheduleValue map[string]interface{} | ||
var autoAnalyzeValue, readOnlyValue string | ||
var autoAnalyzeValue, readOnlyValue, ttlJobEnableValue string | ||
var gcEnabled bool | ||
|
||
if err := job.DecodeArgs(&flashbackTS, &pdScheduleValue, &gcEnabled, &autoAnalyzeValue, &readOnlyValue, &lockedRegions, &startTS, &commitTS); err != nil { | ||
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. Should store session variable in 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. done |
||
if err := job.DecodeArgs(&flashbackTS, &pdScheduleValue, &gcEnabled, &autoAnalyzeValue, &readOnlyValue, &lockedRegions, &startTS, &commitTS, &ttlJobEnableValue); err != nil { | ||
return errors.Trace(err) | ||
} | ||
sess, err := w.sessPool.get() | ||
|
@@ -718,6 +740,14 @@ func finishFlashbackCluster(w *worker, job *model.Job) error { | |
if err = setTiDBSuperReadOnly(w.ctx, sess, readOnlyValue); err != nil { | ||
return err | ||
} | ||
|
||
if job.IsCancelled() { | ||
// only restore `tidb_ttl_job_enable` when flashback failed | ||
if err = setTiDBTTLJobEnable(w.ctx, sess, ttlJobEnableValue); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return setTiDBEnableAutoAnalyze(w.ctx, sess, autoAnalyzeValue) | ||
}) | ||
if err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As we have turned off the
TTL_ENABLE
for every table, is it still necessary to turn off this variable?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.
for flashback cluster,we did not turn off any table's TTL_ENABLE and just set
tidb_ttl_job_enable='OFF'