Skip to content

Commit 8f5e645

Browse files
authored
Remote restores should only be eligible on uninitialized clusters (#249)
1 parent f923434 commit 8f5e645

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

internal/flypg/node.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,25 @@ func (n *Node) Init(ctx context.Context) error {
133133
return fmt.Errorf("failed initialize cluster state store: %s", err)
134134
}
135135

136+
// Check to see if cluster has already been initialized.
137+
clusterInitialized, err := store.IsInitializationFlagSet()
138+
if err != nil {
139+
return fmt.Errorf("failed to verify cluster state %s", err)
140+
}
141+
136142
// Ensure we have the required s3 credentials set.
137143
if os.Getenv("S3_ARCHIVE_CONFIG") != "" || os.Getenv("S3_ARCHIVE_REMOTE_RESTORE_CONFIG") != "" {
138144
if err := writeS3Credentials(ctx, s3AuthDir); err != nil {
139145
return fmt.Errorf("failed to write s3 credentials: %s", err)
140146
}
141147
}
142148

143-
// Determine if we are performing a remote restore.
144-
if err := n.handleRemoteRestore(ctx, store); err != nil {
145-
return fmt.Errorf("failed to handle remote restore: %s", err)
149+
// Remote restores are only eligible on uninitialized clusters.
150+
if !clusterInitialized {
151+
// Determine if we are performing a remote restore.
152+
if err := n.handleRemoteRestore(ctx, store); err != nil {
153+
return fmt.Errorf("failed to handle remote restore: %s", err)
154+
}
146155
}
147156

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

163172
if !n.PGConfig.isInitialized() {
164-
// Check to see if cluster has already been initialized.
165-
clusterInitialized, err := store.IsInitializationFlagSet()
166-
if err != nil {
167-
return fmt.Errorf("failed to verify cluster state %s", err)
168-
}
169-
170173
if clusterInitialized {
171174
if n.RepMgr.Witness {
172175
log.Println("Provisioning witness")

0 commit comments

Comments
 (0)