Skip to content

Commit

Permalink
cluster/store: recover node when peer is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Feb 28, 2024
1 parent d9afbb2 commit 49cc9fa
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/cluster/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package store
import (
"context"
"errors"
"fmt"
"log/slog"
"net"
"os"
Expand Down Expand Up @@ -272,6 +273,21 @@ func (s *Store) Open() error {
config := raft.DefaultConfig()
config.LocalID = raft.ServerID(s.config.NodeId)

// Request to recover node?
if pathExists(s.peersPath) {
s.logger.Info("attempting node recovery ", "peerPath", s.peersPath)
config, err := raft.ReadConfigJSON(s.peersPath)
if err != nil {
return fmt.Errorf("failed to read peers file: %s", err.Error())
}
if err = RecoverNode(s.raftDir, s.raftLog, s.boltStore, s.snapshotStore, s.raftTn, config); err != nil {
return fmt.Errorf("failed to recover node: %s", err.Error())
}
if err := os.Rename(s.peersPath, s.peersInfoPath); err != nil {
return fmt.Errorf("failed to move %s after recovery: %s", s.peersPath, err.Error())
}
s.logger.Info("node recovered successfully", "peerPath", s.peersPath)
}
return nil
}

Expand Down

0 comments on commit 49cc9fa

Please sign in to comment.