Skip to content

Commit 0787d92

Browse files
committed
Merge branch '347-scheduler-context' into 'master'
fix (engine) : avoid panicking with an empty scheduler context (#347) Closes #347 See merge request postgres-ai/database-lab!546
2 parents 90840b9 + 626d50b commit 0787d92

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

engine/cmd/database-lab/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,8 @@ func setShutdownListener() chan os.Signal {
294294
func shutdownDatabaseLabEngine(ctx context.Context, dockerCLI *client.Client, engProps global.EngineProps, fsm pool.FSManager) {
295295
log.Msg("Stopping auxiliary containers")
296296

297-
if fsm != nil {
298-
if err := cont.StopControlContainers(ctx, dockerCLI, engProps.InstanceID, fsm.Pool().DataDir()); err != nil {
299-
log.Err("Failed to stop control containers", err)
300-
}
297+
if err := cont.StopControlContainers(ctx, dockerCLI, engProps.InstanceID, fsm); err != nil {
298+
log.Err("Failed to stop control containers", err)
301299
}
302300

303301
if err := cont.CleanUpSatelliteContainers(ctx, dockerCLI, engProps.InstanceID); err != nil {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,9 @@ func (p *PhysicalInitial) startScheduler(ctx context.Context) {
444444
}
445445

446446
func (p *PhysicalInitial) waitToStopScheduler() {
447-
<-p.schedulerCtx.Done()
447+
if p.schedulerCtx != nil {
448+
<-p.schedulerCtx.Done()
449+
}
448450

449451
if p.scheduler != nil {
450452
log.Msg("Stop snapshot scheduler")

engine/internal/retrieval/engine/postgres/tools/cont/container.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/docker/go-units"
1818
"github.com/pkg/errors"
1919

20+
"gitlab.com/postgres-ai/database-lab/v3/internal/provision/pool"
2021
"gitlab.com/postgres-ai/database-lab/v3/internal/retrieval/engine/postgres/tools"
2122
"gitlab.com/postgres-ai/database-lab/v3/internal/retrieval/options"
2223
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
@@ -63,7 +64,7 @@ const (
6364
// TODO(akartasov): Control container manager.
6465

6566
// StopControlContainers stops control containers run by Database Lab Engine.
66-
func StopControlContainers(ctx context.Context, dockerClient *client.Client, instanceID, dataDir string) error {
67+
func StopControlContainers(ctx context.Context, dockerClient *client.Client, instanceID string, fsm pool.FSManager) error {
6768
log.Msg("Stop control containers")
6869

6970
list, err := getContainerList(ctx, dockerClient, instanceID, getControlContainerFilters())
@@ -80,10 +81,10 @@ func StopControlContainers(ctx context.Context, dockerClient *client.Client, ins
8081
continue
8182
}
8283

83-
if shouldStopInternalProcess(controlLabel) {
84+
if shouldStopInternalProcess(controlLabel) && fsm != nil {
8485
log.Msg("Stopping control container: ", containerName)
8586

86-
if err := tools.StopPostgres(ctx, dockerClient, controlCont.ID, dataDir, tools.DefaultStopTimeout); err != nil {
87+
if err := tools.StopPostgres(ctx, dockerClient, controlCont.ID, fsm.Pool().DataDir(), tools.DefaultStopTimeout); err != nil {
8788
log.Msg("Failed to stop Postgres", err)
8889
tools.PrintContainerLogs(ctx, dockerClient, controlCont.ID)
8990

0 commit comments

Comments
 (0)