Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: don't parse binlog event timestamp of backup which binlogInfo field is empty (#1514)

h3n4l9fa147774127
diff --git a/api/backup.go b/api/backup.go
index ae004bb8e4..7a78b78812 100644
--- a/api/backup.go
+++ b/api/backup.go
@@ -85,6 +85,11 @@ type BinlogInfo struct {
Position int64 `json:"position"`
}
+// IsEmpty return true if the BinlogInfo is empty.
+func (b BinlogInfo) IsEmpty() bool {
+ return b == BinlogInfo{}
+}
+
// BackupPayload contains backup related database specific info, it differs for different database types.
// It is encoded in JSON and stored in the backup table.
type BackupPayload struct {
diff --git a/plugin/restore/mysql/mysql.go b/plugin/restore/mysql/mysql.go
index 4b8a6de702..f389724d9b 100644
--- a/plugin/restore/mysql/mysql.go
+++ b/plugin/restore/mysql/mysql.go
@@ -310,7 +310,13 @@ func (r *Restore) GetLatestBackupBeforeOrEqualTs(ctx context.Context, backupList
}
var eventTsList []int64
+ var validBackupList []*api.Backup
for _, b := range backupList {
+ if b.Payload.BinlogInfo.IsEmpty() {
+ log.Debug("Skip parsing binlog event timestamp of the backup where BinlogInfo is empty", zap.Int("backupId", b.ID), zap.String("backupName", b.Name))
+ continue
+ }
+ validBackupList = append(validBackupList, b)
eventTs, err := r.parseBinlogEventTimestamp(ctx, b.Payload.BinlogInfo)
if err != nil {
return nil, fmt.Errorf("failed to parse binlog event timestamp, error[%w]", err)
@@ -319,7 +325,7 @@ func (r *Restore) GetLatestBackupBeforeOrEqualTs(ctx context.Context, backupList
}
log.Debug("Binlog event ts list of backups", zap.Int64s("eventTsList", eventTsList))
- backup, err := getLatestBackupBeforeOrEqualTsImpl(backupList, eventTsList, targetTs)
+ backup, err := getLatestBackupBeforeOrEqualTsImpl(validBackupList, eventTsList, targetTs)
if err != nil {
return nil, err
}
@@ -332,10 +338,9 @@ func getLatestBackupBeforeOrEqualTsImpl(backupList []*api.Backup, eventTsList []
var maxEventTsLETargetTs int64
var minEventTs int64 = math.MaxInt64
var backup *api.Backup
- emptyBinlogInfo := api.BinlogInfo{}
for i, b := range backupList {
// Parse the binlog files and convert binlog positions into MySQL server timestamps.
- if b.Payload.BinlogInfo == emptyBinlogInfo {
+ if b.Payload.BinlogInfo.IsEmpty() {
continue
}
eventTs := eventTsList[i]
diff --git a/server/task_executor_pitr_restore.go b/server/task_executor_pitr_restore.go
index c1eb5414df..5768716937 100644
--- a/server/task_executor_pitr_restore.go
+++ b/server/task_executor_pitr_restore.go
@@ -66,7 +66,8 @@ func (exec *PITRRestoreTaskExecutor) doPITRRestore(ctx context.Context, task *ap
return err
}
- backupList, err := store.FindBackup(ctx, &api.BackupFind{DatabaseID: task.DatabaseID})
+ backupStatus := api.BackupStatusDone
+ backupList, err := store.FindBackup(ctx, &api.BackupFind{DatabaseID: task.DatabaseID, Status: &backupStatus})
if err != nil {
return err
}