-
Notifications
You must be signed in to change notification settings - Fork 26
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
[close #138] br return backup ts #156
Changes from 3 commits
62ea74e
27492ac
4fccc8b
c723339
c44c022
bd06c9f
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 | ||||
---|---|---|---|---|---|---|
|
@@ -27,6 +27,8 @@ const ( | |||||
flagStartKey = "start" | ||||||
flagEndKey = "end" | ||||||
flagDstAPIVersion = "dst-api-version" | ||||||
flagSafeInterval = "safe-interval" | ||||||
flagGCTTL = "gcttl" | ||||||
) | ||||||
|
||||||
// DefineRawBackupFlags defines common flags for the backup command. | ||||||
|
@@ -49,6 +51,10 @@ func DefineRawBackupFlags(command *cobra.Command) { | |||||
command.Flags().Bool(flagRemoveSchedulers, false, | ||||||
"disable the balance, shuffle and region-merge schedulers in PD to speed up backup.") | ||||||
|
||||||
command.Flags().Duration(flagSafeInterval, utils.DefaultBRSafeInterval, | ||||||
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. Suggest to hide safe interval. It's difficult for common users to set this argument. 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 |
||||||
"The interval between backup-ts and current tso.") | ||||||
command.Flags().Int64(flagGCTTL, utils.DefaultBRGCSafePointTTL, "the TTL (in seconds) that PD holds for BR's GC safepoint") | ||||||
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. Suggest to be a
Suggested change
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 |
||||||
|
||||||
// This flag can impact the online cluster, so hide it in case of abuse. | ||||||
_ = command.Flags().MarkHidden(flagCompressionType) | ||||||
_ = command.Flags().MarkHidden(flagRemoveSchedulers) | ||||||
|
@@ -114,6 +120,15 @@ func RunBackupRaw(c context.Context, g glue.Glue, cmdName string, cfg *RawKvConf | |||||
if err = client.SetStorage(ctx, u, &opts); err != nil { | ||||||
return errors.Trace(err) | ||||||
} | ||||||
client.SetGCTTL(cfg.GCTTL) | ||||||
if curAPIVersion == kvrpcpb.APIVersion_V2 { | ||||||
// set safepoint to avoid the logical deletion data to gc. | ||||||
backupTs, err := client.UpdateBRGCSafePoint(ctx, cfg.SafeInterval) | ||||||
if err != nil { | ||||||
return errors.Trace(err) | ||||||
} | ||||||
g.Record("BackupTS", backupTs) | ||||||
} | ||||||
|
||||||
backupRange := rtree.Range{StartKey: cfg.StartKey, EndKey: cfg.EndKey} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,9 @@ const ( | |
brServiceSafePointIDFormat = "br-%s" | ||
preUpdateServiceSafePointFactor = 3 | ||
checkGCSafePointGapTime = 5 * time.Second | ||
// DefaultBRGCSafePointTTL means PD keep safePoint limit at least 5min. | ||
DefaultBRGCSafePointTTL = 5 * 60 | ||
// DefaultBRGCSafePointTTL means PD keep safePoint limit at least 72h. | ||
DefaultBRGCSafePointTTL = 72 * 60 * 60 // 72h | ||
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. Defaults to 72 hours may be too long, and waste disk space if there is no following CDC. 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 |
||
DefaultBRSafeInterval = time.Minute // safe interval is used to calc the backup-ts. | ||
) | ||
|
||
// BRServiceSafePoint is metadata of service safe point from a BR 'instance'. | ||
|
@@ -74,7 +75,7 @@ func CheckGCSafePoint(ctx context.Context, pdClient pd.Client, ts uint64) error | |
} | ||
|
||
// updateServiceSafePoint register BackupTS to PD, to lock down BackupTS as safePoint with TTL seconds. | ||
func updateServiceSafePoint(ctx context.Context, pdClient pd.Client, sp BRServiceSafePoint) error { | ||
func UpdateServiceSafePoint(ctx context.Context, pdClient pd.Client, sp BRServiceSafePoint) error { | ||
log.Debug("update PD safePoint limit with TTL", zap.Object("safePoint", sp)) | ||
|
||
lastSafePoint, err := pdClient.UpdateServiceGCSafePoint(ctx, sp.ID, sp.TTL, sp.BackupTS-1) | ||
|
@@ -102,7 +103,7 @@ func StartServiceSafePointKeeper( | |
} | ||
// Update service safe point immediately to cover the gap between starting | ||
// update goroutine and updating service safe point. | ||
if err := updateServiceSafePoint(ctx, pdClient, sp); err != nil { | ||
if err := UpdateServiceSafePoint(ctx, pdClient, sp); err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
||
|
@@ -119,7 +120,7 @@ func StartServiceSafePointKeeper( | |
log.Debug("service safe point keeper exited") | ||
return | ||
case <-updateTick.C: | ||
if err := updateServiceSafePoint(ctx, pdClient, sp); err != nil { | ||
if err := UpdateServiceSafePoint(ctx, pdClient, sp); err != nil { | ||
log.Warn("failed to update service safe point, backup may fail if gc triggered", | ||
zap.Error(err), | ||
) | ||
|
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.
"enable-ttl: true" would be reasonable when api-version is 2.
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.
done