Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add resilience in case the cluster falls bellow 1 node #53

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions cluster/consensus/consensus.go
Expand Up @@ -2,6 +2,7 @@ package consensus

import (
"errors"
"fmt"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/raft"
"github.com/hashicorp/raft-boltdb/v2"
Expand Down Expand Up @@ -267,12 +268,27 @@ func (n *Node) waitForClusterReadiness() error {
if currentTry > maxRetryCount {
return errors.New("quorum retry max reached")
}

if n.IsQuorumPossible(true) {
n.logger.Info("quorum possible.")
break
}
n.logger.Error("it is not possible to reach Quorum due to lack of nodes. Retrying...")
time.Sleep(sleepTime)

_, errLeader := discover.SearchLeader(n.ID)
if errLeader != nil {
msg := fmt.Sprintf("it isn't possible to reach Quorum due to lack of nodes. "+
"Tried to search for a leader to join an existent consensus. "+
"Leader not found: %v",
errLeader.Error(),
)
n.logger.Error(msg)
n.logger.Error("it isn't possible to reach Quorum due to lack of nodes and leader not available. Retrying...")
time.Sleep(sleepTime)
continue
}

n.logger.Warn("existent leader found, reinstalling....")
n.ReinstallNode()
}
return nil
}