Skip to content

Commit a22c931

Browse files
authored
feat(1-1-restore): add unpin-agent-cpu flag (#4380)
* feat(1-1-restore): add unpin-agent-cpu flag This adds support of unpin-agent-cpu flag to 1-1-restore command. Unpinning agent CPU should help with agent download speed. Refs: #4375 * fix: remove misleading sentence from `unpin-agent-cpu` flag description
1 parent 8563306 commit a22c931

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

docs/source/sctool/partials/sctool_restore_1-1-restore.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ options:
117117
usage: |
118118
Timezone of --cron and --window flag values.
119119
The default value is taken from this system, namely 'TZ' envvar or '/etc/localtime' file.
120+
- name: unpin-agent-cpu
121+
default_value: "false"
122+
usage: |
123+
Defines if ScyllaDB Manager Agent should be unpinned from CPUs during restore.
120124
- name: window
121125
default_value: '[]'
122126
usage: |

docs/source/sctool/partials/sctool_restore_1-1-restore_update.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ options:
118118
usage: |
119119
Timezone of --cron and --window flag values.
120120
The default value is taken from this system, namely 'TZ' envvar or '/etc/localtime' file.
121+
- name: unpin-agent-cpu
122+
default_value: "false"
123+
usage: |
124+
Defines if ScyllaDB Manager Agent should be unpinned from CPUs during restore.
121125
- name: window
122126
default_value: '[]'
123127
usage: |

pkg/command/one2onerestore/cmd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type command struct {
3232
keyspace []string
3333
snapshotTag string
3434
nodesMapping nodesMapping
35+
unpinAgentCPU bool
3536
dryRun bool
3637
}
3738

@@ -83,6 +84,7 @@ func (cmd *command) init() {
8384

8485
// Common configuration for restore procedures
8586
w.Unwrap().BoolVar(&cmd.dryRun, "dry-run", false, "")
87+
w.Unwrap().BoolVar(&cmd.unpinAgentCPU, "unpin-agent-cpu", false, "")
8688
}
8789

8890
func (cmd *command) run(args []string) error {
@@ -205,6 +207,11 @@ func flagsToTaskProperties(cmd *command, task *models.Task) (updated bool, err e
205207
flagName: "nodes-mapping",
206208
value: cmd.nodesMapping,
207209
},
210+
{
211+
flagName: "unpin-agent-cpu",
212+
value: cmd.unpinAgentCPU,
213+
canBeUpdated: true,
214+
},
208215
}
209216

210217
props := task.Properties.(map[string]interface{})

pkg/command/one2onerestore/res.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ nodes-mapping:
2828
dry-run: |
2929
Validates and displays restore information without actually running the restore.
3030
This allows you to display what will happen should the restore run with the parameters you set.
31+
32+
unpin-agent-cpu: |
33+
Defines if ScyllaDB Manager Agent should be unpinned from CPUs during restore.

pkg/service/one2onerestore/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Target struct {
1919
SourceClusterID uuid.UUID `json:"source_cluster_id"`
2020
SnapshotTag string `json:"snapshot_tag"`
2121
NodesMapping []nodeMapping `json:"nodes_mapping"`
22+
UnpinAgentCPU bool `json:"unpin_agent_cpu"`
2223
}
2324

2425
func defaultTarget() Target {

pkg/service/one2onerestore/worker.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ func (w *worker) restore(ctx context.Context, workload []hostWorkload, target Ta
7979
return errors.Wrap(err, "disable auto compaction")
8080
}
8181

82+
// We always want to pin agent to CPUs outside the 1-1-restore.
83+
defer func() {
84+
if err := w.pinAgentCPU(context.Background(), workload, true); err != nil {
85+
w.logger.Error(ctx, "Can't pin agent to CPU", "error", err)
86+
}
87+
}()
88+
if target.UnpinAgentCPU {
89+
if err := w.pinAgentCPU(ctx, workload, false); err != nil {
90+
return errors.Wrap(err, "unpin agent from CPU")
91+
}
92+
}
93+
8294
if err := w.setTombstoneGCModeRepair(ctx, workload); err != nil {
8395
return errors.Wrap(err, "tombstone_gc mode")
8496
}
@@ -209,6 +221,22 @@ func (w *worker) setAutoCompaction(ctx context.Context, workload []hostWorkload,
209221
return nil
210222
}
211223

224+
func (w *worker) pinAgentCPU(ctx context.Context, workload []hostWorkload, pin bool) error {
225+
setPinFunc := w.client.PinCPU
226+
if !pin {
227+
setPinFunc = w.client.UnpinFromCPU
228+
}
229+
return parallel.Run(len(workload), len(workload), func(i int) error {
230+
host := workload[i].host
231+
return errors.Wrapf(setPinFunc(ctx, host.Addr), "set CPU pinning on %s", host.Addr)
232+
}, func(i int, err error) {
233+
w.logger.Error(ctx, "Failed to change agent CPU pinning",
234+
"host", workload[i].host.Addr,
235+
"pinned", pin,
236+
"error", err)
237+
})
238+
}
239+
212240
// alterSchemaRetryWrapper is useful when executing many statements altering schema,
213241
// as it might take more time for Scylla to process them one after another.
214242
// This wrapper exits on: success, context cancel, op returned non-timeout error or after maxTotalTime has passed.

0 commit comments

Comments
 (0)