Commit c8565988 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b254a74d
......@@ -20,20 +20,23 @@
package xneo
// transactional log of states
// XXX ...
// State represents state of a cluster.
type State struct {
// XXX +transaction ID?
NodeTab *NodeTable // nodes in the cluster
PartTab *PartitionTable // on which nodes which data is located
ClusterState proto.ClusterState // code for cluster state
}
type StateSnapshot interface {
NodeTab() RONodeTable
PartTab() ROPartitionTable
// StateRO provides read-only access to a State.
type StateRO interface {
NodeTab() NodeTableRO
PartTab() PartitionTableRO
ClusterState() proto.ClusterState
}
// XXX transactional journal ...
// StateLog is transactional journal of State changes.
type StateLog struct {
mu sync.Mutex
head *State
......@@ -41,7 +44,7 @@ type StateLog struct {
// ReadHead returns state from head of the log.
func (l *StateLog) ReadHead() StateSnapshot {
func (l *StateLog) ReadHead() StateRO {
l.mu.Lock()
defer l.mu.Unlock()
return l.head
......@@ -55,3 +58,13 @@ func (l *StateLog) CommitUpdate(δf func(*State)) {
δf(s)
l.head = s
}
// Clone creates new instance of State initialized with previous content.
func (s *State) Clone() *State {
return &State{
NodeTab: s.NodeTab.Clone(),
PartTab: s.PartTab.Clone(),
ClusterState: s.ClusterState,
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment