You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
824 B
Go
41 lines
824 B
Go
4 years ago
|
package store
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"path/filepath"
|
||
|
|
||
|
"github.com/hashicorp/raft-boltdb"
|
||
|
)
|
||
|
|
||
|
type Log struct {
|
||
|
path string
|
||
|
}
|
||
|
|
||
|
// NewLog returns an object that can return information about the
|
||
|
// Raft log.
|
||
|
func NewLog(dir string) *Log {
|
||
|
return &Log{
|
||
|
path: filepath.Join(dir, raftDBPath),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// FirstIndex returns the first index written. 0 for no entries
|
||
|
func (l *Log) FirstIndex() (uint64, error) {
|
||
|
bs, err := raftboltdb.NewBoltStore(l.path)
|
||
|
if err != nil {
|
||
|
return 0, fmt.Errorf("new bolt store: %s", err)
|
||
|
}
|
||
|
defer bs.Close()
|
||
|
return bs.FirstIndex()
|
||
|
}
|
||
|
|
||
|
// LastIndex returns the last index written. 0 for no entries.
|
||
|
func (l *Log) LastIndex() (uint64, error) {
|
||
|
bs, err := raftboltdb.NewBoltStore(l.path)
|
||
|
if err != nil {
|
||
|
return 0, fmt.Errorf("new bolt store: %s", err)
|
||
|
}
|
||
|
defer bs.Close()
|
||
|
return bs.LastIndex()
|
||
|
}
|