@@ -33,6 +33,7 @@ import (
33
33
"gitlab.com/postgres-ai/database-lab/pkg/retrieval/config"
34
34
"gitlab.com/postgres-ai/database-lab/pkg/retrieval/dbmarker"
35
35
"gitlab.com/postgres-ai/database-lab/pkg/retrieval/engine/postgres/tools"
36
+ "gitlab.com/postgres-ai/database-lab/pkg/retrieval/engine/postgres/tools/cont"
36
37
"gitlab.com/postgres-ai/database-lab/pkg/retrieval/engine/postgres/tools/defaults"
37
38
"gitlab.com/postgres-ai/database-lab/pkg/retrieval/engine/postgres/tools/health"
38
39
"gitlab.com/postgres-ai/database-lab/pkg/retrieval/options"
@@ -169,7 +170,7 @@ func (p *PhysicalInitial) validateConfig() error {
169
170
}
170
171
171
172
func (p * PhysicalInitial ) syncInstanceName () string {
172
- return tools .SyncInstanceContainerPrefix + p .globalCfg .InstanceID
173
+ return cont .SyncInstanceContainerPrefix + p .globalCfg .InstanceID
173
174
}
174
175
175
176
// Name returns a name of the job.
@@ -381,7 +382,7 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string)
381
382
}
382
383
383
384
// Run promotion container.
384
- cont , err := p .dockerClient .ContainerCreate (ctx ,
385
+ promoteCont , err := p .dockerClient .ContainerCreate (ctx ,
385
386
p .buildContainerConfig (clonePath , promoteImage , pwd ),
386
387
hostConfig ,
387
388
& network.NetworkingConfig {},
@@ -392,30 +393,30 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string)
392
393
return errors .Wrap (err , "failed to create container" )
393
394
}
394
395
395
- defer tools .RemoveContainer (ctx , p .dockerClient , cont .ID , tools .StopTimeout )
396
+ defer tools .RemoveContainer (ctx , p .dockerClient , promoteCont .ID , cont .StopTimeout )
396
397
397
398
defer func () {
398
399
if err != nil {
399
400
tools .PrintContainerLogs (ctx , p .dockerClient , p .promoteContainerName ())
400
401
}
401
402
}()
402
403
403
- if err := p .dockerClient .ContainerStart (ctx , cont .ID , types.ContainerStartOptions {}); err != nil {
404
+ if err := p .dockerClient .ContainerStart (ctx , promoteCont .ID , types.ContainerStartOptions {}); err != nil {
404
405
return errors .Wrap (err , "failed to start container" )
405
406
}
406
407
407
- log .Msg (fmt .Sprintf ("Running container: %s. ID: %v" , p .promoteContainerName (), cont .ID ))
408
+ log .Msg (fmt .Sprintf ("Running container: %s. ID: %v" , p .promoteContainerName (), promoteCont .ID ))
408
409
409
410
// Start PostgreSQL instance.
410
- if err := tools .RunPostgres (ctx , p .dockerClient , cont .ID , clonePath ); err != nil {
411
+ if err := tools .RunPostgres (ctx , p .dockerClient , promoteCont .ID , clonePath ); err != nil {
411
412
return errors .Wrap (err , "failed to start PostgreSQL instance" )
412
413
}
413
414
414
- if err := tools .CheckContainerReadiness (ctx , p .dockerClient , cont .ID ); err != nil {
415
+ if err := tools .CheckContainerReadiness (ctx , p .dockerClient , promoteCont .ID ); err != nil {
415
416
return errors .Wrap (err , "failed to readiness check" )
416
417
}
417
418
418
- shouldBePromoted , err := p .checkRecovery (ctx , cont .ID )
419
+ shouldBePromoted , err := p .checkRecovery (ctx , promoteCont .ID )
419
420
if err != nil {
420
421
return errors .Wrap (err , "failed to read response of the exec command" )
421
422
}
@@ -424,7 +425,7 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string)
424
425
425
426
// Detect dataStateAt.
426
427
if shouldBePromoted == "t" {
427
- extractedDataStateAt , err := p .extractDataStateAt (ctx , cont .ID )
428
+ extractedDataStateAt , err := p .extractDataStateAt (ctx , promoteCont .ID )
428
429
if err != nil {
429
430
return errors .Wrap (err ,
430
431
`Failed to get data_state_at: PGDATA should be promoted, but pg_last_xact_replay_timestamp() returns empty result.
@@ -444,13 +445,13 @@ func (p *PhysicalInitial) promoteInstance(ctx context.Context, clonePath string)
444
445
log .Msg ("Data state at: " , p .dbMark .DataStateAt )
445
446
446
447
// Promote PGDATA.
447
- if err := p .runPromoteCommand (ctx , cont .ID , clonePath ); err != nil {
448
+ if err := p .runPromoteCommand (ctx , promoteCont .ID , clonePath ); err != nil {
448
449
return errors .Wrapf (err , "failed to promote PGDATA: %s" , clonePath )
449
450
}
450
451
}
451
452
452
453
// Checkpoint.
453
- if err := p .checkpoint (ctx , cont .ID ); err != nil {
454
+ if err := p .checkpoint (ctx , promoteCont .ID ); err != nil {
454
455
return err
455
456
}
456
457
@@ -500,7 +501,10 @@ func (p *PhysicalInitial) adjustRecoveryConfiguration(pgVersion, clonePGDataDir
500
501
501
502
func (p * PhysicalInitial ) buildContainerConfig (clonePath , promoteImage , password string ) * container.Config {
502
503
return & container.Config {
503
- Labels : map [string ]string {tools .DBLabControlLabel : tools .DBLabPromoteLabel },
504
+ Labels : map [string ]string {
505
+ cont .DBLabControlLabel : cont .DBLabPromoteLabel ,
506
+ cont .DBLabInstanceIDLabel : p .globalCfg .InstanceID ,
507
+ },
504
508
Env : []string {
505
509
"PGDATA=" + clonePath ,
506
510
"POSTGRES_PASSWORD=" + password ,
0 commit comments