Fix multi-bootstrap RQLite cluster setup

- Primary bootstrap (57.129.81.31): starts new cluster (no join address)
- Secondary bootstrap (38.242.250.186): joins primary bootstrap cluster
- Regular nodes: join primary bootstrap cluster

This allows both VPS servers to be bootstrap nodes while forming a
proper RQLite cluster where the secondary bootstrap joins the primary
instead of trying to start its own independent cluster.

Should resolve the leadership establishment timeout on the second VPS.
This commit is contained in:
johnysigma 2025-08-06 08:21:21 +03:00
parent 37bf582932
commit dfa4de33b4
2 changed files with 25 additions and 4 deletions

View File

@ -85,9 +85,30 @@ func main() {
cfg.Database.RQLiteRaftPort = 4002 cfg.Database.RQLiteRaftPort = 4002
if isBootstrap { if isBootstrap {
// Bootstrap node doesn't join anyone - it starts the cluster // Check if this is the primary bootstrap node (first in list) or secondary
cfg.Database.RQLiteJoinAddress = "" bootstrapPeers := constants.GetBootstrapPeers()
logger.Printf("Bootstrap node - starting new RQLite cluster") isSecondaryBootstrap := false
if len(bootstrapPeers) > 1 {
// Check if this machine matches any bootstrap peer other than the first
for i := 1; i < len(bootstrapPeers); i++ {
host := parseHostFromMultiaddr(bootstrapPeers[i])
if host != "" && isLocalIP(host) {
isSecondaryBootstrap = true
break
}
}
}
if isSecondaryBootstrap {
// Secondary bootstrap nodes join the primary bootstrap
primaryBootstrapHost := parseHostFromMultiaddr(bootstrapPeers[0])
cfg.Database.RQLiteJoinAddress = fmt.Sprintf("http://%s:4001", primaryBootstrapHost)
logger.Printf("Secondary bootstrap node - joining primary bootstrap at: %s", cfg.Database.RQLiteJoinAddress)
} else {
// Primary bootstrap node doesn't join anyone - it starts the cluster
cfg.Database.RQLiteJoinAddress = ""
logger.Printf("Primary bootstrap node - starting new RQLite cluster")
}
} else { } else {
// Configure bootstrap peers for P2P discovery // Configure bootstrap peers for P2P discovery
var rqliteJoinAddr string var rqliteJoinAddr string

View File

@ -47,7 +47,7 @@ func (r *RQLiteManager) Start(ctx context.Context) error {
"-raft-addr", fmt.Sprintf("localhost:%d", r.config.RQLiteRaftPort), "-raft-addr", fmt.Sprintf("localhost:%d", r.config.RQLiteRaftPort),
} }
// Add join address if specified (for non-bootstrap nodes) // Add join address if specified (for non-bootstrap or secondary bootstrap nodes)
if r.config.RQLiteJoinAddress != "" { if r.config.RQLiteJoinAddress != "" {
args = append(args, "-join", r.config.RQLiteJoinAddress) args = append(args, "-join", r.config.RQLiteJoinAddress)
} }