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 Aug 19, 2024
1 parent 19ba220 commit 3e423d3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
13 changes: 12 additions & 1 deletion controller/backup_target_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
v1core "k8s.io/client-go/kubernetes/typed/core/v1"

systembackupstore "github.com/longhorn/backupstore/systembackup"
lhtypes "github.com/longhorn/go-common-libs/types"

"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/engineapi"
Expand Down Expand Up @@ -276,7 +277,17 @@ 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
if executeTimeout <= 0 {
timeout = lhtypes.ExecuteNoTimeout
}

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

func newBackupTargetClientFromDefaultEngineImage(ds *datastore.DataStore, backupTarget *longhorn.BackupTarget) (*engineapi.BackupTargetClient, error) {
Expand Down
29 changes: 20 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,16 @@ 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
if executeTimeout <= 0 {
timeout = lhtypes.ExecuteNoTimeout
}

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

func (btc *BackupTargetClient) LonghornEngineBinary() string {
Expand Down Expand Up @@ -130,7 +141,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 @@ -135,6 +135,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 @@ -227,6 +228,7 @@ var (
SettingNameFreezeFilesystemForSnapshot,
SettingNameAutoCleanupSnapshotWhenDeleteBackup,
SettingNameDefaultMinNumberOfBackingImageCopies,
SettingNameBackupExecutionTimeout,
SettingNameRWXVolumeFastFailover,
}
)
Expand Down Expand Up @@ -347,6 +349,7 @@ var (
SettingNameFreezeFilesystemForSnapshot: SettingDefinitionFreezeFilesystemForSnapshot,
SettingNameAutoCleanupSnapshotWhenDeleteBackup: SettingDefinitionAutoCleanupSnapshotWhenDeleteBackup,
SettingNameDefaultMinNumberOfBackingImageCopies: SettingDefinitionDefaultMinNumberOfBackingImageCopies,
SettingNameBackupExecutionTimeout: SettingDefinitionBackupExecutionTimeout,
SettingNameRWXVolumeFastFailover: SettingDefinitionRWXVolumeFastFailover,
}

Expand Down Expand Up @@ -409,6 +412,19 @@ var (
},
}

SettingDefinitionBackupExecutionTimeout = SettingDefinition{
DisplayName: "Backup Execution Timeout",
Description: "In minutes. This setting determines the timeout for the backup engine execution. If timeout is set to 0, it will wait indefinitely until the execution returns.",
Category: SettingCategoryBackup,
Type: SettingTypeInt,
Required: true,
ReadOnly: false,
Default: "1",
ValueIntRange: map[string]int{
ValueIntRangeMinimum: 0,
},
}

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 3e423d3

Please sign in to comment.