Commit 17a95c4f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 4e33b5f7
......@@ -82,8 +82,9 @@ func NewClient(clusterName, masterAddr string, net xnet.Networker) *Client {
Net: net,
MasterAddr: masterAddr,
//NodeTab: &neo.NodeTable{},
//PartTab: &neo.PartitionTable{},
NodeTab: &neo.NodeTable{},
PartTab: &neo.PartitionTable{},
ClusterState: -1, // invalid
},
mlinkReady: make(chan struct{}),
......@@ -270,9 +271,13 @@ func (c *Client) recvMaster(ctx context.Context, mlink *neo.NodeLink) error {
case *neo.NotifyNodeInformation:
// XXX msg.IdTimestamp ?
for _, nodeInfo := range msg.NodeList {
log.Infof(ctx, "rx peer update: %v", nodeInfo)
c.node.NodeTab.Update(nodeInfo, /*XXX conn should not be here*/nil)
}
// FIXME logging under lock
log.Infof(ctx, "full nodetab:\n%s", c.node.NodeTab)
case *neo.NotifyClusterState:
c.node.ClusterState.Set(msg.State)
}
......
//go:generate stringer -output zproto-str.go -type ErrorCode,NodeType proto.go
//go:generate stringer -output zproto-str.go -type ErrorCode,NodeType,NodeState proto.go
package neo
// supporting code for types defined in proto.go
......
......@@ -199,31 +199,25 @@ func TestMasterStorage(t *testing.T) {
return &traceNeoSend{Src: xaddr(src), Dst: xaddr(dst), ConnID: connid, Msg: msg}
}
// shortcut for nodetab change
node := func(x *neo.NodeCommon, laddr string, typ neo.NodeType, num int32, state neo.NodeState, idtstamp float64) *traceNode {
return &traceNode{
NodeTab: unsafe.Pointer(x.NodeTab),
NodeInfo: neo.NodeInfo{
Type: typ,
Addr: xnaddr(laddr),
UUID: neo.UUID(typ, num),
State: state,
IdTimestamp: idtstamp,
},
}
}
// shortcut for NodeInfo
nodei := func(typ neo.NodeType, addr string, uuid neo.NodeUUID, state neo.NodeState, idtstamp float64) neo.NodeInfo {
nodei := func(laddr string, typ neo.NodeType, num int32, state neo.NodeState, idtstamp float64) neo.NodeInfo {
return neo.NodeInfo{
Type: typ,
Addr: xnaddr(addr),
UUID: uuid,
Addr: xnaddr(laddr),
UUID: neo.UUID(typ, num),
State: state,
IdTimestamp: idtstamp,
}
}
// shortcut for nodetab change
node := func(x *neo.NodeCommon, laddr string, typ neo.NodeType, num int32, state neo.NodeState, idtstamp float64) *traceNode {
return &traceNode{
NodeTab: unsafe.Pointer(x.NodeTab),
NodeInfo: nodei(laddr, typ, num, state, idtstamp),
}
}
Mhost := xnet.NetTrace(net.Host("m"), tracer)
Shost := xnet.NetTrace(net.Host("s"), tracer)
......@@ -380,16 +374,6 @@ func TestMasterStorage(t *testing.T) {
YourUUID: neo.UUID(neo.CLIENT, 1),
}))
// C <- M NotifyNodeInformation C1,M1,S1
tc.Expect(conntx("m:3", "c:1", 2, &neo.NotifyNodeInformation{
IdTimestamp: 0, // XXX ?
NodeList: []neo.NodeInfo{
nodei(neo.MASTER, "m:1", neo.UUID(neo.MASTER, 1), neo.RUNNING, 0.00),
nodei(neo.STORAGE, "s:1", neo.UUID(neo.STORAGE, 1), neo.RUNNING, 0.01),
nodei(neo.STORAGE, "", neo.UUID(neo.CLIENT, 1), neo.RUNNING, 0.02),
},
}))
// C asks M about PT
tc.Expect(conntx("c:1", "m:3", 3, &neo.AskPartitionTable{}))
tc.Expect(conntx("m:3", "c:1", 3, &neo.AnswerPartitionTable{
......@@ -399,6 +383,21 @@ func TestMasterStorage(t *testing.T) {
},
}))
// C <- M NotifyNodeInformation C1,M1,S1
tc.Expect(conntx("m:3", "c:1", 0, &neo.NotifyNodeInformation{
IdTimestamp: 0, // XXX ?
NodeList: []neo.NodeInfo{
nodei("m:1", neo.MASTER, 1, neo.RUNNING, 0.00),
nodei("s:1", neo.STORAGE, 1, neo.RUNNING, 0.01),
nodei("", neo.CLIENT, 1, neo.RUNNING, 0.02),
},
}))
Cnode := (*neo.NodeCommon)(unsafe.Pointer(C)) // XXX hack
tc.Expect(node(Cnode, "m:1", neo.MASTER, 1, neo.RUNNING, 0.00))
tc.Expect(node(Cnode, "s:1", neo.STORAGE, 1, neo.RUNNING, 0.01))
tc.Expect(node(Cnode, "", neo.CLIENT, 1, neo.RUNNING, 0.02))
// C asks M about last tid XXX better master sends it itself on new client connected
wg = &xsync.WorkGroup{}
......
// Code generated by "stringer -output zproto-str.go -type ErrorCode,NodeType proto.go"; DO NOT EDIT.
// Code generated by "stringer -output zproto-str.go -type ErrorCode,NodeType,NodeState proto.go"; DO NOT EDIT.
package neo
......@@ -25,3 +25,14 @@ func (i NodeType) String() string {
}
return _NodeType_name[_NodeType_index[i]:_NodeType_index[i+1]]
}
const _NodeState_name = "UNKNOWNDOWNRUNNINGPENDING"
var _NodeState_index = [...]uint8{0, 7, 11, 18, 25}
func (i NodeState) String() string {
if i < 0 || i >= NodeState(len(_NodeState_index)-1) {
return fmt.Sprintf("NodeState(%d)", i)
}
return _NodeState_name[_NodeState_index[i]:_NodeState_index[i+1]]
}
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