Skip to content

Commit

Permalink
chore: review
Browse files Browse the repository at this point in the history
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
  • Loading branch information
armru committed Jan 29, 2024
1 parent 606560f commit 94730af
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
20 changes: 10 additions & 10 deletions pkg/management/postgres/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (instance *Instance) RefreshPGIdent(cluster *apiv1.Cluster) (postgresIdentC
// of PostgreSQL, using the specified connection string to connect to the primary server
func UpdateReplicaConfiguration(pgData, primaryConnInfo, slotName string) (changed bool, err error) {
changed, err = configurePostgresOverrideConfFile(pgData, primaryConnInfo, slotName)
if err != nil {
if err != nil {
return changed, err
}

Expand Down Expand Up @@ -290,7 +290,7 @@ func configurePostgresOverrideConfFile(pgData, primaryConnInfo, slotName string)
return false, err
}

var options map[string]string
options := make(map[string]string)

if major >= 12 {
options = map[string]string{
Expand All @@ -299,9 +299,7 @@ func configurePostgresOverrideConfFile(pgData, primaryConnInfo, slotName string)
postgres.LogPath, postgres.LogFileName),
"recovery_target_timeline": "latest",
"primary_slot_name": slotName,
}
if primaryConnInfo != "" {
options["primary_conninfo"] = primaryConnInfo
"primary_conninfo": primaryConnInfo,
}
}

Expand Down Expand Up @@ -453,13 +451,14 @@ func createPostgresqlConfiguration(cluster *apiv1.Cluster, preserveUserSettings

// configurePostgresForImport configures Postgres to be optimized for the firt import
// process, by writing dedicated options the override.conf file just for this phase
func configurePostgresForImport(pgData string) (changed bool, err error) {
func configurePostgresForImport(ctx context.Context, pgData string) (changed bool, err error) {
contextLogger := log.FromContext(ctx)
targetFile := path.Join(pgData, constants.PostgresqlOverrideConfigurationFile)

options := map[string]string{
"archive_mode": "off",
"fsync": "off",
"wal_level": "minimal",
"archive_mode": "off",
"fsync": "off",
"wal_level": "minimal",
"full_page_writes": "off",
}

Expand All @@ -469,7 +468,8 @@ func configurePostgresForImport(pgData string) (changed bool, err error) {
}

if changed {
log.Info("Updated replication settings", "filename", constants.PostgresqlOverrideConfigurationFile)
contextLogger.Info("Configuration optimized for import",
"filename", constants.PostgresqlOverrideConfigurationFile)
}

return changed, nil
Expand Down
12 changes: 6 additions & 6 deletions pkg/management/postgres/initdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (info InitInfo) Bootstrap(ctx context.Context) error {
slotName := cluster.GetSlotNameFromInstanceName(info.PodName)
// Write a special configuration for the import phase
if isImportBootstrap {
if _, err := configurePostgresForImport(info.PgData); err != nil {
if _, err := configurePostgresForImport(ctx, info.PgData); err != nil {
return fmt.Errorf("while configuring Postgres for import: %w", err)
}
} else {
Expand All @@ -392,7 +392,7 @@ func (info InitInfo) Bootstrap(ctx context.Context) error {
return fmt.Errorf("while removing Postgres configuration for import: %w", err)
}
// Run fsync
if err := info.initdbSyncOnly(); err != nil {
if err := info.initdbSyncOnly(ctx); err != nil {
return err
}
}
Expand Down Expand Up @@ -455,19 +455,19 @@ func getConnectionPoolerForExternalCluster(
}

// initdbSyncOnly Run initdb with --sync-only option after a database import
func (info InitInfo) initdbSyncOnly() error {
func (info InitInfo) initdbSyncOnly(ctx context.Context) error {
contextLogger := log.FromContext(ctx)

// Invoke initdb to generate a data directory
options := []string{
"-D",
info.PgData,
"--sync-only",
}
log.Info("Running initdb --sync-only",
"pgdata", info.PgData)
contextLogger.Info("Running initdb --sync-only", "pgdata", info.PgData)
initdbCmd := exec.Command(constants.InitdbName, options...) // #nosec
if err := execlog.RunBuffering(initdbCmd, constants.InitdbName); err != nil {
return fmt.Errorf("error while running initdb --sync-only: %w", err)
}
return nil
}

6 changes: 2 additions & 4 deletions pkg/management/postgres/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,7 @@ func (info InitInfo) ConfigureInstanceAfterRestore(ctx context.Context, cluster

primaryConnInfo := info.GetPrimaryConnInfo()
slotName := cluster.GetSlotNameFromInstanceName(info.PodName)
_, err := configurePostgresOverrideConfFile(info.PgData, primaryConnInfo, slotName)
if err != nil {
if _, err := configurePostgresOverrideConfFile(info.PgData, primaryConnInfo, slotName); err != nil {
return fmt.Errorf("while configuring replica: %w", err)
}

Expand All @@ -816,8 +815,7 @@ func (info InitInfo) ConfigureInstanceAfterRestore(ctx context.Context, cluster

// Configure the application database information for restored instance
return instance.WithActiveInstance(func() error {
err = info.ConfigureNewInstance(instance)
if err != nil {
if err := info.ConfigureNewInstance(instance); err != nil {
return fmt.Errorf("while configuring restored instance: %w", err)
}

Expand Down

0 comments on commit 94730af

Please sign in to comment.