nomad: adding immutable radix, snapshot support

This commit is contained in:
Armon Dadgar
2015-06-03 11:21:59 +02:00
parent adc98c1a24
commit 790ef5d528
2 changed files with 14 additions and 6 deletions

View File

@@ -77,10 +77,6 @@ func (n *nomadFSM) Apply(log *raft.Log) interface{} {
}
}
func (n *nomadFSM) Snapshot() (raft.FSMSnapshot, error) {
defer func(start time.Time) {
n.logger.Printf("[INFO] nomad.fsm: snapshot created in %v", time.Now().Sub(start))
}(time.Now())
// Create a new snapshot
snap, err := n.state.Snapshot()
if err != nil {

View File

@@ -3,6 +3,8 @@ package nomad
import (
"io"
"log"
"github.com/hashicorp/go-immutable-radix"
)
// The StateStore is responsible for maintaining all the Consul
@@ -12,6 +14,7 @@ import (
// to provide write availability in the face of reads.
type StateStore struct {
logger *log.Logger
root *iradix.Tree
}
// StateSnapshot is used to provide a point-in-time snapshot
@@ -28,6 +31,7 @@ func (s *StateSnapshot) Close() error {
func NewStateStore(logOutput io.Writer) (*StateStore, error) {
s := &StateStore{
logger: log.New(logOutput, "", log.LstdFlags),
root: iradix.New(),
}
return s, nil
}
@@ -37,7 +41,15 @@ func (s *StateStore) Close() error {
return nil
}
// Snapshot is used to create a point in time snapshot
// Snapshot is used to create a point in time snapshot. Because
// we use an immutable radix tree, we just need to preserve the
// pointer to the root, and we are done.
func (s *StateStore) Snapshot() (*StateSnapshot, error) {
return nil, nil
snap := &StateSnapshot{
store: &StateStore{
logger: s.logger,
root: s.root,
},
}
return snap, nil
}