Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(PITR): make error message more friendly to user (#1528)
h3n4l8b3667bc494a
diff --git a/plugin/restore/mysql/mysql.go b/plugin/restore/mysql/mysql.goindex be4b2169e3..816fba1f29 100644--- a/plugin/restore/mysql/mysql.go+++ b/plugin/restore/mysql/mysql.go@@ -101,7 +101,7 @@ func (r *Restore) replayBinlog(ctx context.Context, originalDatabase, pitrDataba// Start decoding the binary log at the log position, this option applies to the first log file named on the command line."--start-position", fmt.Sprintf("%d", startBinlogInfo.Position),// Stop reading the binary log at the first event having a timestamp equal to or later than the datetime argument.- "--stop-datetime", getDateTime(targetTs),+ "--stop-datetime", formatDateTime(targetTs),}mysqlbinlogArgs = append(mysqlbinlogArgs, replayBinlogPaths...)@@ -337,7 +337,7 @@ func (r *Restore) GetLatestBackupBeforeOrEqualTs(ctx context.Context, backupListvalidBackupList = append(validBackupList, b)eventTs, err := r.parseLocalBinlogEventTimestamp(ctx, b.Payload.BinlogInfo)if err != nil {- return nil, fmt.Errorf("failed to parse binlog event timestamp, error[%w]", err)+ return nil, fmt.Errorf("failed to parse binlog event timestamp, error: %w", err)}eventTsList = append(eventTsList, eventTs)}@@ -371,8 +371,17 @@ func getLatestBackupBeforeOrEqualTsImpl(backupList []*api.Backup, eventTsList []minEventTs = eventTs}}+if maxEventTsLETargetTs == 0 {- return nil, fmt.Errorf("the target restore timestamp[%d] is earlier than the oldest backup time[%d]", targetTs, minEventTs)+ targetDateTime := time.Unix(targetTs, 0).Format(time.RFC822)+ minEventDateTime := time.Unix(minEventTs, 0).Format(time.RFC822)+ log.Debug("the target restore time is earlier than the oldest backup time",+ zap.String("targetDatetime", targetDateTime),+ zap.Int64("targetTimestamp", targetTs),+ zap.String("minEventDateTime", minEventDateTime),+ zap.Int64("minEventTimestamp", minEventTs))++ return nil, fmt.Errorf("the target restore time %s is earlier than the oldest backup time %s", targetDateTime, minEventDateTime)}return backup, nil}@@ -834,8 +843,8 @@ func (r *Restore) CheckBinlogRowFormat(ctx context.Context) error {return nil}-// getDateTime returns converts the targetTs to the local date-time.-func getDateTime(targetTs int64) string {- t := time.Unix(targetTs, 0)+// formatDateTime formats the timestamp to the local time string.+func formatDateTime(ts int64) string {+ t := time.Unix(ts, 0)return fmt.Sprintf("%d-%d-%d %d:%d:%d", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())}diff --git a/server/task_executor_pitr_restore.go b/server/task_executor_pitr_restore.goindex 5768716937..30d0538d77 100644--- a/server/task_executor_pitr_restore.go+++ b/server/task_executor_pitr_restore.go@@ -36,7 +36,7 @@ func (exec *PITRRestoreTaskExecutor) RunOnce(ctx context.Context, server *Serverpayload := api.TaskDatabasePITRRestorePayload{}if err := json.Unmarshal([]byte(task.Payload), &payload); err != nil {- return true, nil, fmt.Errorf("invalid PITR restore payload[%s], error[%w]", task.Payload, err)+ return true, nil, fmt.Errorf("invalid PITR restore payload: %s, error: %w", task.Payload, err)}driver, err := getAdminDatabaseDriver(ctx, task.Instance, "", "" /* pgInstanceDir */)@@ -100,16 +100,18 @@ func (exec *PITRRestoreTaskExecutor) doPITRRestore(ctx context.Context, task *aplog.Debug("Getting latest backup before or equal to targetTs...", zap.Time("targetTs", time.Unix(targetTs, 0)))backup, err := mysqlRestore.GetLatestBackupBeforeOrEqualTs(ctx, backupList, targetTs)if err != nil {- log.Error("Failed to get backup before or equal to targetTs",+ dateTime := time.Unix(targetTs, 0).Format(time.RFC822)+ log.Error("Failed to get backup before or equal to time",+ zap.String("dateTime", dateTime),zap.Time("targetTs", time.Unix(targetTs, 0)),zap.Error(err))- return fmt.Errorf("failed to get latest backup before or equal to targetTs[%d], error[%w]", targetTs, err)+ return fmt.Errorf("failed to get latest backup before or equal to %s, error: %w", dateTime, err)}log.Debug("Got latest backup before or equal to targetTs", zap.String("backup", backup.Name))backupFileName := getBackupAbsFilePath(dataDir, backup.DatabaseID, backup.Name)backupFile, err := os.OpenFile(backupFileName, os.O_RDONLY, os.ModePerm)if err != nil {- return fmt.Errorf("failed to open backup file[%s], error[%w]", backupFileName, err)+ return fmt.Errorf("failed to open backup file: %s, error: %w", backupFileName, err)}defer backupFile.Close()log.Debug("Successfully opened backup file", zap.String("filename", backupFileName))@@ -127,7 +129,7 @@ func (exec *PITRRestoreTaskExecutor) doPITRRestore(ctx context.Context, task *apzap.Int("issueID", issue.ID),zap.String("database", database.Name),zap.Error(err))- return fmt.Errorf("failed to perform a PITR restore in the PITR database, error[%w]", err)+ return fmt.Errorf("failed to perform a PITR restore in the PITR database, error: %w", err)}return nil@@ -137,11 +139,11 @@ func getIssueByPipelineID(ctx context.Context, store *store.Store, pid int) (*apissue, err := store.GetIssueByPipelineID(ctx, pid)if err != nil {log.Error("failed to get issue by PipelineID", zap.Int("PipelineID", pid), zap.Error(err))- return nil, fmt.Errorf("failed to get issue by PipelineID[%d], error[%w]", pid, err)+ return nil, fmt.Errorf("failed to get issue by PipelineID: %d, error: %w", pid, err)}if issue == nil {log.Error("issue not found with PipelineID", zap.Int("PipelineID", pid))- return nil, fmt.Errorf("issue not found with PipelineID[%d]", pid)+ return nil, fmt.Errorf("issue not found with PipelineID: %d", pid)}return issue, nil}