Skip to content

Commit 57c7aa3

Browse files
committed
Merge branch '187-skip-start-snapshot' into 'v2.0'
fix: keep taking snapshots by schedule (#187) See merge request postgres-ai/database-lab!205
2 parents 592c882 + 69b4d40 commit 57c7aa3

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

pkg/retrieval/engine/postgres/snapshot/physical.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ type PhysicalInitial struct {
7676
dbMark *dbmarker.Config
7777
dockerClient *client.Client
7878
scheduler *cron.Cron
79-
scheduleOnce sync.Once
8079
promotionMutex sync.Mutex
8180
}
8281

@@ -188,10 +187,18 @@ func (p *PhysicalInitial) Name() string {
188187
// Run starts the job.
189188
func (p *PhysicalInitial) Run(ctx context.Context) (err error) {
190189
// Start scheduling after initial snapshot.
191-
defer func() {
192-
p.scheduleOnce.Do(p.startScheduler(ctx))
193-
}()
190+
defer p.startScheduler(ctx)()
191+
192+
if p.options.SkipStartSnapshot {
193+
log.Msg("Skip taking a snapshot at the start")
194+
195+
return nil
196+
}
194197

198+
return p.run(ctx)
199+
}
200+
201+
func (p *PhysicalInitial) run(ctx context.Context) (err error) {
195202
select {
196203
case <-ctx.Done():
197204
if p.scheduler != nil {
@@ -204,12 +211,6 @@ func (p *PhysicalInitial) Run(ctx context.Context) (err error) {
204211
default:
205212
}
206213

207-
if p.options.SkipStartSnapshot {
208-
log.Msg("Skip taking a snapshot at the start")
209-
210-
return nil
211-
}
212-
213214
p.dbMark.DataStateAt = extractDataStateAt(p.dbMarker)
214215

215216
// Snapshot data.
@@ -304,7 +305,7 @@ func (p *PhysicalInitial) startScheduler(ctx context.Context) func() {
304305

305306
func (p *PhysicalInitial) runAutoSnapshot(ctx context.Context) func() {
306307
return func() {
307-
if err := p.Run(ctx); err != nil {
308+
if err := p.run(ctx); err != nil {
308309
log.Err(errors.Wrap(err, "failed to take a snapshot automatically"))
309310

310311
log.Msg("Interrupt automatic snapshots")

0 commit comments

Comments
 (0)