Skip to content

Commit

Permalink
make restore policy optional
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Jan 28, 2025
1 parent 4f531b6 commit 682e6b1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 37 deletions.
4 changes: 1 addition & 3 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2515,8 +2515,7 @@ const docTemplate = `{
"description": "RestoreRequest represents a restore operation request.",
"type": "object",
"required": [
"backup-data-path",
"policy"
"backup-data-path"
],
"properties": {
"backup-data-path": {
Expand Down Expand Up @@ -2573,7 +2572,6 @@ const docTemplate = `{
"description": "RestoreTimestampRequest represents a restore by timestamp operation request.",
"type": "object",
"required": [
"policy",
"routine",
"time"
],
Expand Down
4 changes: 2 additions & 2 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2691,7 +2691,7 @@
"type" : "string"
}
},
"required" : [ "backup-data-path", "policy" ],
"required" : [ "backup-data-path" ],
"type" : "object"
},
"dto.RestoreTimestampRequest" : {
Expand Down Expand Up @@ -2749,7 +2749,7 @@
"type" : "integer"
}
},
"required" : [ "policy", "routine", "time" ],
"required" : [ "routine", "time" ],
"type" : "object"
},
"dto.RetentionPolicy" : {
Expand Down
2 changes: 0 additions & 2 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,6 @@ components:
type: string
required:
- backup-data-path
- policy
type: object
dto.RestoreTimestampRequest:
description: RestoreTimestampRequest represents a restore by timestamp operation
Expand Down Expand Up @@ -2283,7 +2282,6 @@ components:
format: int64
type: integer
required:
- policy
- routine
- time
type: object
Expand Down
4 changes: 2 additions & 2 deletions pkg/dto/restore_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type RestorePolicy struct {
// Validate validates the restore policy.
func (p *RestorePolicy) Validate() error {
if p == nil {
return fmt.Errorf("restore policy is not specified")
return nil
}
if p.Parallel != nil && *p.Parallel <= 0 {
return fmt.Errorf("parallel %d invalid, should be positive number", *p.Parallel)
Expand Down Expand Up @@ -123,7 +123,7 @@ func (p *RestorePolicy) Validate() error {

func (p *RestorePolicy) ToModel() *model.RestorePolicy {
if p == nil {
return nil
return &model.RestorePolicy{}
}

return &model.RestorePolicy{
Expand Down
18 changes: 9 additions & 9 deletions pkg/dto/restore_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import (
// RestoreRequest represents a restore operation request from custom storage
// @Description RestoreRequest represents a restore operation request.
type RestoreRequest struct {
DestinationClusterConfig `yaml:",inline"`
*SecretAgentConfig `yaml:",inline"`
StorageConfig `yaml:",inline"`
DestinationClusterConfig
*SecretAgentConfig
StorageConfig
// Restore policy to use in the operation.
Policy *RestorePolicy `json:"policy,omitempty" validate:"required"`
Policy *RestorePolicy `json:"policy"`
// Path to the data from storage root.
BackupDataPath string `json:"backup-data-path" validate:"required"`
}

// RestoreTimestampRequest represents a restore by timestamp operation request.
// @Description RestoreTimestampRequest represents a restore by timestamp operation request.
type RestoreTimestampRequest struct {
DestinationClusterConfig `yaml:",inline"`
*SecretAgentConfig `yaml:",inline"`
StorageConfig `yaml:",inline"`
DestinationClusterConfig
*SecretAgentConfig
StorageConfig
// Restore policy to use in the operation.
Policy *RestorePolicy `json:"policy,omitempty" validate:"required"`
Policy *RestorePolicy `json:"policy"`
// Required epoch time for recovery. The closest backup before the timestamp will be applied.
Time int64 `json:"time,omitempty" format:"int64" example:"1739538000000" validate:"required"`
// The backup routine name.
Expand Down Expand Up @@ -67,7 +67,7 @@ func (r *RestoreTimestampRequest) Validate() error {
return errors.New("restore point in time should be positive")
}
if r.Routine == "" {
return errValidationEmptyField(r.Routine)
return errValidationEmptyField("routine")
}

return nil
Expand Down
19 changes: 0 additions & 19 deletions pkg/model/restore_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,3 @@ func (p *RestorePolicy) GetBatchSizeOrDefault() int {
}
return *defaultConfig.restorePolicy.MaxAsyncBatches
}

func (p *RestorePolicy) GetTotalTimeoutOrDefault() time.Duration {
if p.TotalTimeout != nil {
return *p.TotalTimeout
}
return *defaultConfig.restorePolicy.TotalTimeout
}

func (p *RestorePolicy) GetSocketTimeoutOrDefault() time.Duration {
if p.SocketTimeout == nil {
return *defaultConfig.restorePolicy.SocketTimeout
}
// If this value is 0, its set to total-timeout.
if *p.SocketTimeout == 0 {
return p.GetTotalTimeoutOrDefault()
}

return *p.SocketTimeout
}

0 comments on commit 682e6b1

Please sign in to comment.