Skip to content

Commit

Permalink
feat(restore): disable compaction during restore
Browse files Browse the repository at this point in the history
Fixes #3956
  • Loading branch information
Michal-Leszczynski committed Oct 3, 2024
1 parent a3dc0ad commit a939782
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/service/restore/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import (

// Target specifies what data should be restored and from which locations.
type Target struct {
Location []Location `json:"location"`
Keyspace []string `json:"keyspace,omitempty"`
SnapshotTag string `json:"snapshot_tag"`
BatchSize int `json:"batch_size,omitempty"`
Parallel int `json:"parallel,omitempty"`
RestoreSchema bool `json:"restore_schema,omitempty"`
RestoreTables bool `json:"restore_tables,omitempty"`
Continue bool `json:"continue"`
Location []Location `json:"location"`
Keyspace []string `json:"keyspace,omitempty"`
SnapshotTag string `json:"snapshot_tag"`
BatchSize int `json:"batch_size,omitempty"`
Parallel int `json:"parallel,omitempty"`
AllowCompaction bool `json:"allow_compaction,omitempty"`
RestoreSchema bool `json:"restore_schema,omitempty"`
RestoreTables bool `json:"restore_tables,omitempty"`
Continue bool `json:"continue"`

// Cache for host with access to remote location
locationHosts map[Location][]string `json:"-"`
Expand Down
29 changes: 29 additions & 0 deletions pkg/service/restore/tables_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ func (w *tablesWorker) stageRestoreData(ctx context.Context) error {
}
hosts := hostsS.List()

if !w.target.AllowCompaction {
defer func() {
if err := w.setAutoCompaction(ctx, hosts, true); err != nil {
w.logger.Error(ctx, "Couldn't enable auto compaction", "error", err)
}
}()
if err := w.setAutoCompaction(ctx, hosts, false); err != nil {
return errors.Wrapf(err, "disable auto compaction")
}
}

f := func(n int) (err error) {
h := hosts[n]
for {
Expand Down Expand Up @@ -304,3 +315,21 @@ func (w *tablesWorker) initRestoreMetrics(ctx context.Context) {
}
}
}

// Disables auto compaction on all provided hosts and units.
func (w *tablesWorker) setAutoCompaction(ctx context.Context, hosts []string, enabled bool) error {
f := w.client.EnableAutoCompaction
if !enabled {
f = w.client.DisableAutoCompaction
}
for _, h := range hosts {
for _, u := range w.run.Units {
for _, t := range u.Tables {
if err := f(ctx, h, u.Keyspace, t.Table); err != nil {
return errors.Wrapf(err, "set autocompaction on %s to %v", h, enabled)
}
}
}
}
return nil
}

0 comments on commit a939782

Please sign in to comment.