Skip to content

Commit

Permalink
Remote restores should only be eligible on uninitialized clusters (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
davissp14 authored Jul 26, 2024
1 parent f923434 commit 8f5e645
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions internal/flypg/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,25 @@ func (n *Node) Init(ctx context.Context) error {
return fmt.Errorf("failed initialize cluster state store: %s", err)
}

// Check to see if cluster has already been initialized.
clusterInitialized, err := store.IsInitializationFlagSet()
if err != nil {
return fmt.Errorf("failed to verify cluster state %s", err)
}

// Ensure we have the required s3 credentials set.
if os.Getenv("S3_ARCHIVE_CONFIG") != "" || os.Getenv("S3_ARCHIVE_REMOTE_RESTORE_CONFIG") != "" {
if err := writeS3Credentials(ctx, s3AuthDir); err != nil {
return fmt.Errorf("failed to write s3 credentials: %s", err)
}
}

// Determine if we are performing a remote restore.
if err := n.handleRemoteRestore(ctx, store); err != nil {
return fmt.Errorf("failed to handle remote restore: %s", err)
// Remote restores are only eligible on uninitialized clusters.
if !clusterInitialized {
// Determine if we are performing a remote restore.
if err := n.handleRemoteRestore(ctx, store); err != nil {
return fmt.Errorf("failed to handle remote restore: %s", err)
}
}

// Verify whether we are a booting zombie.
Expand All @@ -161,12 +170,6 @@ func (n *Node) Init(ctx context.Context) error {
}

if !n.PGConfig.isInitialized() {
// Check to see if cluster has already been initialized.
clusterInitialized, err := store.IsInitializationFlagSet()
if err != nil {
return fmt.Errorf("failed to verify cluster state %s", err)
}

if clusterInitialized {
if n.RepMgr.Witness {
log.Println("Provisioning witness")
Expand Down

0 comments on commit 8f5e645

Please sign in to comment.