2020-08-21 21:16:42 +00:00
|
|
|
package rafttools
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-02-23 20:43:59 +00:00
|
|
|
raftboltdb "github.com/hashicorp/raft-boltdb/v2"
|
2020-08-21 21:16:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func RaftState(p string) (store *raftboltdb.BoltStore, firstIdx uint64, lastIdx uint64, err error) {
|
|
|
|
s, err := raftboltdb.NewBoltStore(p)
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, 0, fmt.Errorf("failed to open raft logs: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
firstIdx, err = s.FirstIndex()
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, 0, fmt.Errorf("failed to fetch first index: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
lastIdx, err = s.LastIndex()
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, 0, fmt.Errorf("failed to fetch last index: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return s, firstIdx, lastIdx, nil
|
|
|
|
}
|