Skip to content

Commit

Permalink
microcluster: Return recovery tarball path during recovery
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Hershberger <[email protected]>
  • Loading branch information
MggMuggins committed Jun 25, 2024
1 parent 94c91a5 commit dd657a5
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions microcluster/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,26 @@ func (m *MicroCluster) GetLocalClusterMembers() ([]cluster.LocalMember, error) {
//
// On start, Microcluster will automatically check for & load the recovery
// tarball. A database backup will be taken before the load.
func (m *MicroCluster) RecoverFromQuorumLoss(members []cluster.LocalMember) error {
//
// RecoverFromQuorumLoss returns the path to the recovery tarball.
func (m *MicroCluster) RecoverFromQuorumLoss(members []cluster.LocalMember) (string, error) {
// Double check to make sure the cluster configuration has actually changed
oldMembers, err := m.GetLocalClusterMembers()
if err != nil {
return err
return "", err
}

err = recover.ValidateMemberChanges(oldMembers, members)
if err != nil {
return err
return "", err
}

// Set up our new cluster configuration
nodeInfo := make([]dqlite.NodeInfo, 0, len(members))
for _, member := range members {
info, err := member.NodeInfo()
if err != nil {
return err
return "", err
}
nodeInfo = append(nodeInfo, *info)
}
Expand All @@ -260,27 +262,27 @@ func (m *MicroCluster) RecoverFromQuorumLoss(members []cluster.LocalMember) erro
// that's still partially up.
remotes, err := recover.ReadTrustStore(m.FileSystem.TrustDir)
if err != nil {
return err
return "", err
}

serverCert, err := m.FileSystem.ServerCert()
if err != nil {
return err
return "", err
}

clusterCert, err := m.FileSystem.ClusterCert()
if err != nil {
return err
return "", err
}

clusterKey, err := clusterCert.PublicKeyX509()
if err != nil {
return err
return "", err
}

cluster, err := remotes.Cluster(false, serverCert, clusterKey)
if err != nil {
return err
return "", err
}

err = cluster.Query(context.Background(), true, func(ctx context.Context, client *client.Client) error {
Expand All @@ -292,33 +294,33 @@ func (m *MicroCluster) RecoverFromQuorumLoss(members []cluster.LocalMember) erro
return nil
})
if err != nil {
return err
return "", err
}

// Ensure that the daemon is not running
isSocketPresent, err := m.FileSystem.IsControlSocketPresent()
if err != nil {
return err
return "", err
}

if isSocketPresent {
return fmt.Errorf("daemon is running (socket path exists: %q)", m.FileSystem.ControlSocketPath())
return "", fmt.Errorf("daemon is running (socket path exists: %q)", m.FileSystem.ControlSocketPath())
}

// FIXME: Take a DB backup

err = dqlite.ReconfigureMembershipExt(m.FileSystem.DatabaseDir, nodeInfo)
if err != nil {
return fmt.Errorf("dqlite recovery: %w", err)
return "", fmt.Errorf("dqlite recovery: %w", err)
}

// Tar up the m.FileSystem.DatabaseDir and write to `dbExportPath`
err = recover.CreateRecoveryTarball(m.FileSystem)
recoveryTarballPath, err := recover.CreateRecoveryTarball(m.FileSystem)
if err != nil {
return err
return "", err
}

return nil
return recoveryTarballPath, nil
}

// NewJoinToken creates and records a new join token containing all the necessary credentials for joining a cluster.
Expand Down

0 comments on commit dd657a5

Please sign in to comment.