Skip to content

Commit

Permalink
fix(backup): customize the timeout of backup binary execution
Browse files Browse the repository at this point in the history
Add a default setting `backupExecutionTimeout`

ref: longhorn/longhorn 8954,8319

Signed-off-by: James Lu <james.lu@suse.com>
  • Loading branch information
mantissahz committed Sep 2, 2024
1 parent 5b1557d commit 40f498a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
9 changes: 8 additions & 1 deletion controller/backup_target_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,14 @@ func newBackupTargetClient(ds *datastore.DataStore, backupTarget *longhorn.Backu
return nil, err
}
}
return engineapi.NewBackupTargetClient(engineImage, backupTarget.Spec.BackupTargetURL, credential), nil

executeTimeout, err := ds.GetSettingAsInt(types.SettingNameBackupExecutionTimeout)
if err != nil {
return nil, err
}
timeout := time.Duration(executeTimeout) * time.Minute

return engineapi.NewBackupTargetClient(engineImage, backupTarget.Spec.BackupTargetURL, credential, timeout), nil
}

func newBackupTargetClientFromDefaultEngineImage(ds *datastore.DataStore, backupTarget *longhorn.BackupTarget) (*engineapi.BackupTargetClient, error) {
Expand Down
26 changes: 17 additions & 9 deletions engineapi/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ const (
)

type BackupTargetClient struct {
Image string
URL string
Credential map[string]string
Image string
URL string
Credential map[string]string
ExecuteTimeout time.Duration
}

// NewBackupTargetClient returns the backup target client
func NewBackupTargetClient(engineImage, url string, credential map[string]string) *BackupTargetClient {
func NewBackupTargetClient(engineImage, url string, credential map[string]string, executeTimeout time.Duration) *BackupTargetClient {
return &BackupTargetClient{
Image: engineImage,
URL: url,
Credential: credential,
Image: engineImage,
URL: url,
Credential: credential,
ExecuteTimeout: executeTimeout,
}
}

Expand All @@ -68,7 +70,13 @@ func NewBackupTargetClientFromBackupTarget(backupTarget *longhorn.BackupTarget,
}
}

return NewBackupTargetClient(defaultEngineImage, backupTarget.Spec.BackupTargetURL, credential), nil
executeTimeout, err := ds.GetSettingAsInt(types.SettingNameBackupExecutionTimeout)
if err != nil {
return nil, err
}
timeout := time.Duration(executeTimeout) * time.Minute

return NewBackupTargetClient(defaultEngineImage, backupTarget.Spec.BackupTargetURL, credential, timeout), nil
}

func (btc *BackupTargetClient) LonghornEngineBinary() string {
Expand Down Expand Up @@ -130,7 +138,7 @@ func (btc *BackupTargetClient) ExecuteEngineBinary(args ...string) (string, erro
if err != nil {
return "", err
}
return lhexec.NewExecutor().Execute(envs, btc.LonghornEngineBinary(), args, lhtypes.ExecuteDefaultTimeout)
return lhexec.NewExecutor().Execute(envs, btc.LonghornEngineBinary(), args, btc.ExecuteTimeout)
}

func (btc *BackupTargetClient) ExecuteEngineBinaryWithTimeout(timeout time.Duration, args ...string) (string, error) {
Expand Down
16 changes: 16 additions & 0 deletions types/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const (
SettingNameFreezeFilesystemForSnapshot = SettingName("freeze-filesystem-for-snapshot")
SettingNameAutoCleanupSnapshotWhenDeleteBackup = SettingName("auto-cleanup-when-delete-backup")
SettingNameDefaultMinNumberOfBackingImageCopies = SettingName("default-min-number-of-backing-image-copies")
SettingNameBackupExecutionTimeout = SettingName("backup-execution-timeout")
SettingNameRWXVolumeFastFailover = SettingName("rwx-volume-fast-failover")
)

Expand Down Expand Up @@ -229,6 +230,7 @@ var (
SettingNameFreezeFilesystemForSnapshot,
SettingNameAutoCleanupSnapshotWhenDeleteBackup,
SettingNameDefaultMinNumberOfBackingImageCopies,
SettingNameBackupExecutionTimeout,
SettingNameRWXVolumeFastFailover,
}
)
Expand Down Expand Up @@ -349,6 +351,7 @@ var (
SettingNameFreezeFilesystemForSnapshot: SettingDefinitionFreezeFilesystemForSnapshot,
SettingNameAutoCleanupSnapshotWhenDeleteBackup: SettingDefinitionAutoCleanupSnapshotWhenDeleteBackup,
SettingNameDefaultMinNumberOfBackingImageCopies: SettingDefinitionDefaultMinNumberOfBackingImageCopies,
SettingNameBackupExecutionTimeout: SettingDefinitionBackupExecutionTimeout,
SettingNameRWXVolumeFastFailover: SettingDefinitionRWXVolumeFastFailover,
}

Expand Down Expand Up @@ -411,6 +414,19 @@ var (
},
}

SettingDefinitionBackupExecutionTimeout = SettingDefinition{
DisplayName: "Backup Execution Timeout",
Description: "In minutes. This setting determines the timeout for the backup engine execution. The default value is 1.",
Category: SettingCategoryBackup,
Type: SettingTypeInt,
Required: true,
ReadOnly: false,
Default: "1",
ValueIntRange: map[string]int{
ValueIntRangeMinimum: 1,
},
}

SettingDefinitionRestoreVolumeRecurringJobs = SettingDefinition{
DisplayName: "Restore Volume Recurring Jobs",
Description: "Restore recurring jobs from the backup volume on the backup target and create recurring jobs if not exist during a backup restoration.\n\n" +
Expand Down

0 comments on commit 40f498a

Please sign in to comment.