MCPcopy
hub / github.com/pingcap/tidb / progressFileWriterRoutine

Function progressFileWriterRoutine

br/pkg/task/common.go:991–1012  ·  view source on GitHub ↗

write progress in tmp file for tidb-operator, so tidb-operator can retrieve the progress of ebs backup. and user can get the progress through `kubectl get job` todo: maybe change to http api later

(ctx context.Context, progress glue.Progress, total int64, progressFile string)

Source from the content-addressed store, hash-verified

989// progress of ebs backup. and user can get the progress through `kubectl get job`
990// todo: maybe change to http api later
991func progressFileWriterRoutine(ctx context.Context, progress glue.Progress, total int64, progressFile string) {
992 // remove tmp file
993 defer func() {
994 _ = os.Remove(progressFile)
995 }()
996
997 for progress.GetCurrent() < total {
998 select {
999 case <-ctx.Done():
1000 return
1001 case <-time.After(500 * time.Millisecond):
1002 break
1003 }
1004 cur := progress.GetCurrent()
1005 p := float64(cur) / float64(total)
1006 p *= 100
1007 err := os.WriteFile(progressFile, []byte(fmt.Sprintf("%.2f", p)), 0600)
1008 if err != nil {
1009 log.Warn("failed to update tmp progress file", zap.Error(err))
1010 }
1011 }
1012}
1013
1014func WriteStringToConsole(g glue.Glue, msg string) error {
1015 b := []byte(msg)

Callers 3

restoreMethod · 0.85
RunResolveKvDataFunction · 0.85
RunBackupEBSFunction · 0.85

Calls 6

WarnMethod · 0.80
RemoveMethod · 0.65
GetCurrentMethod · 0.65
DoneMethod · 0.65
WriteFileMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected