Skip to content

Commit

Permalink
APPS-963 Use array to store request's bin list (#44)
Browse files Browse the repository at this point in the history
* use array for bin list

* use array for nodes list

* use array for nodes list

* set node_list

* set node_list

* add annotations
  • Loading branch information
korotkov-aerospike authored Nov 5, 2023
1 parent 872df85 commit 3c9b5ea
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
21 changes: 19 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,10 @@
"type": "integer"
},
"bin_list": {
"type": "string"
"type": "array",
"items": {
"type": "string"
}
},
"file_limit": {
"type": "integer"
Expand Down Expand Up @@ -732,7 +735,10 @@
"type": "boolean"
},
"node_list": {
"type": "string"
"type": "array",
"items": {
"$ref": "#/definitions/model.Node"
}
},
"parallel": {
"type": "integer"
Expand Down Expand Up @@ -852,6 +858,17 @@
}
}
},
"model.Node": {
"type": "object",
"properties": {
"ip": {
"type": "string"
},
"port": {
"type": "integer"
}
}
},
"model.RateLimiterConfig": {
"type": "object",
"properties": {
Expand Down
15 changes: 13 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ definitions:
bandwidth:
type: integer
bin_list:
type: string
items:
type: string
type: array
file_limit:
type: integer
filter_exp:
Expand All @@ -60,7 +62,9 @@ definitions:
no_udfs:
type: boolean
node_list:
type: string
items:
$ref: '#/definitions/model.Node'
type: array
parallel:
type: integer
partition_list:
Expand Down Expand Up @@ -139,6 +143,13 @@ definitions:
rate:
$ref: '#/definitions/model.RateLimiterConfig'
type: object
model.Node:
properties:
ip:
type: string
port:
type: integer
type: object
model.RateLimiterConfig:
properties:
size:
Expand Down
11 changes: 8 additions & 3 deletions pkg/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ type BackupPolicy struct {
Storage *string `yaml:"storage,omitempty" json:"storage,omitempty"`
Namespace *string `yaml:"namespace,omitempty" json:"namespace,omitempty"`
Parallel *int32 `yaml:"parallel,omitempty" json:"parallel,omitempty"`
SetList *[]string `yaml:"set_list,omitempty" json:"set_list,omitempty"`
NodeList *string `yaml:"node_list,omitempty" json:"node_list,omitempty"`
BinList *string `yaml:"bin_list,omitempty" json:"bin_list,omitempty"`
SetList []string `yaml:"set_list,omitempty" json:"set_list,omitempty"`
BinList []string `yaml:"bin_list,omitempty" json:"bin_list,omitempty"`
NodeList []Node `yaml:"node_list,omitempty" json:"node_list,omitempty"`
SocketTimeout *uint32 `yaml:"socket_timeout,omitempty" json:"socket_timeout,omitempty"`
TotalTimeout *uint32 `yaml:"total_timeout,omitempty" json:"total_timeout,omitempty"`
MaxRetries *uint32 `yaml:"max_retries,omitempty" json:"max_retries,omitempty"`
Expand Down Expand Up @@ -154,6 +154,11 @@ func (p *BackupPolicy) Clone() *BackupPolicy {
return &clone
}

type Node struct {
IP string `yaml:"ip" json:"ip"`
Port int `yaml:"port" json:"port"`
}

// GetName returns the name of the BackupPolicy.
func (p *BackupPolicy) GetName() *string {
return p.Name
Expand Down
20 changes: 17 additions & 3 deletions pkg/shared/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"log/slog"

"github.com/aerospike/backup/pkg/model"
"github.com/aws/smithy-go/ptr"
)

// BackupShared implements the Backup interface.
Expand Down Expand Up @@ -61,9 +62,13 @@ func (b *BackupShared) BackupRun(backupPolicy *model.BackupPolicy, cluster *mode
setCString(&backupConfig.password, cluster.GetPassword())
setCString(&backupConfig.auth_mode, cluster.AuthMode)

parseSetList(&backupConfig.set_list, backupPolicy.SetList)
setCString(&backupConfig.bin_list, backupPolicy.BinList)

parseSetList(&backupConfig.set_list, &backupPolicy.SetList)
if backupPolicy.BinList != nil {
setCString(&backupConfig.bin_list, ptr.String(strings.Join(backupPolicy.BinList, ",")))
}
if backupPolicy.NodeList != nil {
setCString(&backupConfig.node_list, printNodes(backupPolicy.NodeList))
}
setCUint(&backupConfig.socket_timeout, backupPolicy.SocketTimeout)
setCUint(&backupConfig.total_timeout, backupPolicy.TotalTimeout)
setCUint(&backupConfig.max_retries, backupPolicy.MaxRetries)
Expand Down Expand Up @@ -146,3 +151,12 @@ func getIncrementalPath(storage *model.BackupStorage) *string {
func timeSuffix() string {
return strconv.FormatInt(time.Now().Unix(), 10)
}

func printNodes(nodes []model.Node) *string {
nodeStrings := make([]string, 0, len(nodes))
for _, node := range nodes {
nodeStrings = append(nodeStrings, fmt.Sprintf("%s:%d", node.IP, node.Port))
}
concatenated := strings.Join(nodeStrings, ",")
return &concatenated
}

0 comments on commit 3c9b5ea

Please sign in to comment.