Skip to content

Commit

Permalink
rclone_client: delete file to return job it
Browse files Browse the repository at this point in the history
  • Loading branch information
karol-kokoszka committed Jul 12, 2024
1 parent e0ace3a commit 0b64056
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
12 changes: 8 additions & 4 deletions pkg/scyllaclient/client_rclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ func (c *Client) RcloneDeleteDir(ctx context.Context, host, remotePath string) e

// RcloneDeleteFile removes the single file pointed to by remotePath
// Remote path format is "name:bucket/path".
func (c *Client) RcloneDeleteFile(ctx context.Context, host, remotePath string) error {
func (c *Client) RcloneDeleteFile(ctx context.Context, host, remotePath string) (int64, error) {
fs, remote, err := rcloneSplitRemotePath(remotePath)
if err != nil {
return err
return 0, err
}
p := operations.OperationsDeletefileParams{
Context: forceHost(ctx, host),
Expand All @@ -336,8 +336,12 @@ func (c *Client) RcloneDeleteFile(ctx context.Context, host, remotePath string)
},
Async: false,
}
_, err = c.agentOps.OperationsDeletefile(&p) // nolint: errcheck
return err
resp, err := c.agentOps.OperationsDeletefile(&p) // nolint: errcheck
if err != nil {
return 0, err
}

return resp.Payload.Jobid, nil
}

// RcloneDiskUsage get disk space usage.
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/backup/purger.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (p purger) onDelete(ctx context.Context, total, success, missing int) {

func (p purger) deleteFile(ctx context.Context, path string) (bool, error) {
p.logger.Debug(ctx, "Deleting file", "path", path)
err := p.client.RcloneDeleteFile(ctx, p.host, path)
_, err := p.client.RcloneDeleteFile(ctx, p.host, path)
if scyllaclient.StatusCodeOf(err) == http.StatusNotFound {
return false, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/backup/worker_deduplicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (w *worker) basedOnUUIDGenerationAvailability(ctx context.Context, d snapsh
localSSTableFileNameWithPath := path.Join(d.Path, file)
w.Logger.Debug(ctx, "Removing local snapshot file (deduplication based on generation UUID)",
"host", h.IP, "file", localSSTableFileNameWithPath)
if err := w.Client.RcloneDeleteFile(ctx, h.IP, localSSTableFileNameWithPath); err != nil {
if _, err := w.Client.RcloneDeleteFile(ctx, h.IP, localSSTableFileNameWithPath); err != nil {
return errors.Wrapf(err, "cannot delete local snapshot's SSTable file %s", localSSTableFileNameWithPath)
}
}
Expand Down Expand Up @@ -170,7 +170,7 @@ func (w *worker) basedOnCrc32Content(ctx context.Context, d snapshotDir, h hostI
for _, fileToBeRemoved := range ssTableContent {
localSSTableFileNameWithPath := path.Join(d.Path, fileToBeRemoved)
w.Logger.Debug(ctx, "Removing local snapshot file (deduplication based on .crc32)", "host", h.IP, "file", localSSTableFileNameWithPath)
if err := w.Client.RcloneDeleteFile(ctx, h.IP, localSSTableFileNameWithPath); err != nil {
if _, err := w.Client.RcloneDeleteFile(ctx, h.IP, localSSTableFileNameWithPath); err != nil {
return errors.Wrapf(err, "cannot delete local snapshot's SSTable file %s", localSSTableFileNameWithPath)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/backup/worker_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ func (w *worker) indexSnapshotDirs(ctx context.Context, h hostInfo) ([]snapshotD
)

mp := path.Join(d.Path, ScyllaManifest)
if err := w.Client.RcloneDeleteFile(ctx, h.IP, mp); err != nil {
if _, err := w.Client.RcloneDeleteFile(ctx, h.IP, mp); err != nil {
if scyllaclient.StatusCodeOf(err) != http.StatusNotFound {
w.Logger.Error(ctx, "Failed to delete local manifest file", "error", err)
}
}
sp := path.Join(d.Path, ScyllaSchema)
if err := w.Client.RcloneDeleteFile(ctx, h.IP, sp); err != nil {
if _, err := w.Client.RcloneDeleteFile(ctx, h.IP, sp); err != nil {
if scyllaclient.StatusCodeOf(err) != http.StatusNotFound {
w.Logger.Error(ctx, "Failed to delete local schema file", "error", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/restore/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (w *worker) cleanUploadDir(ctx context.Context, host, dir string, excluded

for _, f := range toBeDeleted {
remotePath := path.Join(dir, f)
if err := w.client.RcloneDeleteFile(ctx, host, remotePath); err != nil {
if _, err := w.client.RcloneDeleteFile(ctx, host, remotePath); err != nil {
return errors.Wrapf(err, "delete file: %s on host: %s", remotePath, host)
}
}
Expand Down

0 comments on commit 0b64056

Please sign in to comment.