Commit d9882191 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b3e86791
...@@ -23,7 +23,7 @@ package xneo ...@@ -23,7 +23,7 @@ package xneo
//go:generate gotrace gen . //go:generate gotrace gen .
import ( import (
// "sync" "sync"
"lab.nexedi.com/kirr/go123/xnet" "lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/neo/go/neo/proto" "lab.nexedi.com/kirr/neo/go/neo/proto"
...@@ -33,6 +33,7 @@ import ( ...@@ -33,6 +33,7 @@ import (
// //
// XXX text about imaginary transactional log of state changes originated from master. // XXX text about imaginary transactional log of state changes originated from master.
// XXX naming: review (struct and field names) // XXX naming: review (struct and field names)
type State = NodeState // XXX temp
type NodeState struct { type NodeState struct {
MyNID proto.NodeID // nid received by node from M XXX -> MasteredState ? (because .mlink is there ?) MyNID proto.NodeID // nid received by node from M XXX -> MasteredState ? (because .mlink is there ?)
IdTime proto.IdTime // when this node last identified to master IdTime proto.IdTime // when this node last identified to master
...@@ -110,8 +111,10 @@ type Node struct { ...@@ -110,8 +111,10 @@ type Node struct {
// MyInfo proto.NodeInfo // type, laddr, nid, state, idtime XXX nid is managed by M // MyInfo proto.NodeInfo // type, laddr, nid, state, idtime XXX nid is managed by M
Type proto.NodeType Type proto.NodeType
Addr proto.Address // listening address XXX -> LAddr ? Addr proto.Address // listening address XXX -> LAddr ?
State NodeState
// XXX type, laddr stateLogMu sync.Mutex
state *NodeState
ClusterName string ClusterName string
Net xnet.Networker // network AP we are sending/receiving on Net xnet.Networker // network AP we are sending/receiving on
MasterAddr string // address of current master TODO -> masterRegistry MasterAddr string // address of current master TODO -> masterRegistry
...@@ -128,7 +131,7 @@ type Node struct { ...@@ -128,7 +131,7 @@ type Node struct {
func NewNode(typ proto.NodeType, clusterName string, net xnet.Networker, masterAddr string) *Node { func NewNode(typ proto.NodeType, clusterName string, net xnet.Networker, masterAddr string) *Node {
node := &Node{ node := &Node{
Type: typ, Type: typ,
State: NodeState{ state: &NodeState{
MyNID: proto.NID(typ, 0), // temp, e.g. S? TODO use "temp" bit in NodeID MyNID: proto.NID(typ, 0), // temp, e.g. S? TODO use "temp" bit in NodeID
IdTime: proto.IdTimeNone, IdTime: proto.IdTimeNone,
...@@ -143,6 +146,25 @@ func NewNode(typ proto.NodeType, clusterName string, net xnet.Networker, masterA ...@@ -143,6 +146,25 @@ func NewNode(typ proto.NodeType, clusterName string, net xnet.Networker, masterA
MasterAddr: masterAddr, MasterAddr: masterAddr,
} }
node.State.NodeTab.localNode = node node.state.NodeTab.localNode = node
return node return node
} }
// XXX doc, naming
func (node *Node) WithState(f func(*/*readonly*/State)) {
node.stateLogMu.Lock()
s := node.state
node.stateLogMu.Unlock()
f(s)
}
// XXX doc
func (node *Node) ModifyState(δf func(*State)) {
node.stateLogMu.Lock()
defer node.stateLogMu.Unlock()
s := node.state.Clone()
δf(s)
node.state = s
}
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