Skip to content

Commit

Permalink
Better wait for restore.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Sep 19, 2023
1 parent 9390f6f commit aa2cc72
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions cmd/internal/database/meilisearch/meilisearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/meilisearch/meilisearch-go"
"github.com/spf13/afero"
"golang.org/x/sync/errgroup"
"golang.org/x/sync/semaphore"

"github.com/metal-stack/backup-restore-sidecar/cmd/internal/utils"
"github.com/metal-stack/backup-restore-sidecar/pkg/constants"
Expand Down Expand Up @@ -209,21 +210,38 @@ func (db *Meilisearch) importDump(ctx context.Context, dump string) error {
return fmt.Errorf("unable to create prober")
}

for {
time.Sleep(3 * time.Second)

err = restoreDB.Probe(ctx)
if err != nil {
db.log.Errorw("meilisearch is still restoring, continue probing for readiness...", "error", err)

return err
} else {
db.log.Infow("meilisearch started after importing the dump, stopping it again for takeover from the database container")

break
waitForRestore := func() error {
ticker := time.NewTicker(3 * time.Second)
defer ticker.Stop()
sem := semaphore.NewWeighted(1)

for {
select {
case <-ticker.C:
if !sem.TryAcquire(1) {
continue
}

err = restoreDB.Probe(ctx)
sem.Release(1)
if err != nil {
db.log.Errorw("meilisearch is still restoring, continue probing for readiness...", "error", err)
continue
}

db.log.Infow("meilisearch started after importing the dump, stopping it again for takeover from the database container")

return nil
case <-ctx.Done():
return fmt.Errorf("context cancelled during meilisearch restore")
}
}
}

if err := waitForRestore(); err != nil {
return handleFailedRecovery(err)
}

if err := cmd.Process.Signal(syscall.SIGINT); err != nil {
return handleFailedRecovery(err)
}
Expand Down

0 comments on commit aa2cc72

Please sign in to comment.