Commit 94a98550 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0fdf4c40
...@@ -154,21 +154,16 @@ func (_ *_ΔStateCode) δClusterState() {} ...@@ -154,21 +154,16 @@ func (_ *_ΔStateCode) δClusterState() {}
// //
// Use Run to actually start running the node. // Use Run to actually start running the node.
func NewMaster(clusterName string, net xnet.Networker) *Master { func NewMaster(clusterName string, net xnet.Networker) *Master {
m := &Master{ return &Master{
node: xneo.NewNode(proto.MASTER, clusterName, net, ""), node: xneo.NewNode(proto.MASTER, clusterName, net, ""),
ctlStart: make(chan chan error), ctlStart: make(chan chan error),
ctlStop: make(chan chan struct{}), ctlStop: make(chan chan struct{}),
nodeComeq: make(chan nodeCome), nodeComeq: make(chan nodeCome),
nodeLeaveq: make(chan nodeLeave), nodeLeaveq: make(chan nodeLeave),
peerTab: make(map[proto.NodeID]*_MasteredPeer), peerTab: make(map[proto.NodeID]*_MasteredPeer),
monotime: xtime.Mono, monotime: xtime.Mono,
} }
return m
} }
var ErrStartNonOperational = errors.New("start: cluster is non-operational") var ErrStartNonOperational = errors.New("start: cluster is non-operational")
...@@ -1026,6 +1021,7 @@ func (m *Master) serveClient1(ctx context.Context, req proto.Msg) (resp proto.Ms ...@@ -1026,6 +1021,7 @@ func (m *Master) serveClient1(ctx context.Context, req proto.Msg) (resp proto.Ms
// other peers are notified with δnodeTab about it. // other peers are notified with δnodeTab about it.
func (m *Master) disconnectPeer(ctx context.Context, peer *_MasteredPeer) { func (m *Master) disconnectPeer(ctx context.Context, peer *_MasteredPeer) {
log.Infof(ctx, "disconnecting %s", peer.node.NID) log.Infof(ctx, "disconnecting %s", peer.node.NID)
peer.cancel()
peer.node.ResetLink(ctx) peer.node.ResetLink(ctx)
delete(m.peerTab, peer.node.NID) delete(m.peerTab, peer.node.NID)
m.updateNodeState(ctx, peer.node, proto.DOWN) m.updateNodeState(ctx, peer.node, proto.DOWN)
...@@ -1181,6 +1177,9 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (peer *_MasteredPeer, ...@@ -1181,6 +1177,9 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (peer *_MasteredPeer,
} }
}) })
// XXX compensate a bit for lack of ctx handling in Send/Recv
return xxcontext.WithCloseOnErrCancel(ctx, link, func() error {
// send accept and indicate to run that initial acceptance is done // send accept and indicate to run that initial acceptance is done
err := peer.accept(ctx) err := peer.accept(ctx)
if err != nil { if err != nil {
...@@ -1191,6 +1190,7 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (peer *_MasteredPeer, ...@@ -1191,6 +1190,7 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (peer *_MasteredPeer,
// proxy δnodeTab,δpartTab/δclusterState from main to the peer // proxy δnodeTab,δpartTab/δclusterState from main to the peer
return peer.notify(ctx) return peer.notify(ctx)
}) })
})
return peer, true return peer, true
} }
...@@ -1259,12 +1259,9 @@ func (m *Master) notifyAll(ctx context.Context, event _ΔClusterState) { ...@@ -1259,12 +1259,9 @@ func (m *Master) notifyAll(ctx context.Context, event _ΔClusterState) {
default: default:
} }
// XXX try to move logging into other place - so that we could remove ctx arg here
log.Warningf(ctx, "peer %s is slow -> detaching it", nid) log.Warningf(ctx, "peer %s is slow -> detaching it", nid)
close(peer.notifyqOverflow) close(peer.notifyqOverflow)
// TODO delete(m.peerTab, nid) -> p.cancel() delete(m.peerTab, nid)
// XXX what else?
panic("TODO")
} }
} }
...@@ -1273,10 +1270,9 @@ func (m *Master) notifyAll(ctx context.Context, event _ΔClusterState) { ...@@ -1273,10 +1270,9 @@ func (m *Master) notifyAll(ctx context.Context, event _ΔClusterState) {
func (p *_MasteredPeer) notify(ctx context.Context) (err error) { func (p *_MasteredPeer) notify(ctx context.Context) (err error) {
defer task.Runningf(&ctx, "notify %s", p.node.NID)(&err) defer task.Runningf(&ctx, "notify %s", p.node.NID)(&err)
link := p.node.Link()
stateCode := p.state0.Code stateCode := p.state0.Code
// XXX vvv right?
return xxcontext.WithCloseOnErrCancel(ctx, p.node.Link(), func() error {
for { for {
var δstate _ΔClusterState var δstate _ΔClusterState
...@@ -1285,17 +1281,16 @@ func (p *_MasteredPeer) notify(ctx context.Context) (err error) { ...@@ -1285,17 +1281,16 @@ func (p *_MasteredPeer) notify(ctx context.Context) (err error) {
return ctx.Err() return ctx.Err()
case <-p.notifyqOverflow: case <-p.notifyqOverflow:
// XXX err -> ?
return fmt.Errorf("detaching (peer is too slow to consume updates)") return fmt.Errorf("detaching (peer is too slow to consume updates)")
case δstate = <-p.notifyq: // XXX could be also closed? case δstate = <-p.notifyq:
} }
var msg proto.Msg var msg proto.Msg
switch δstate := δstate.(type) { switch δstate := δstate.(type) {
case *_ΔNodeTab: case *_ΔNodeTab:
msg = &proto.NotifyNodeInformation{ msg = &proto.NotifyNodeInformation{
IdTime: proto.IdTimeNone, // FIXME IdTime: proto.IdTimeNone, // XXX ok?
NodeList: []proto.NodeInfo{δstate.NodeInfo}, NodeList: []proto.NodeInfo{δstate.NodeInfo},
} }
...@@ -1322,14 +1317,11 @@ func (p *_MasteredPeer) notify(ctx context.Context) (err error) { ...@@ -1322,14 +1317,11 @@ func (p *_MasteredPeer) notify(ctx context.Context) (err error) {
panic("bug") panic("bug")
} }
err := p.node.Link().Send1(msg) err := link.Send1(msg)
if err != nil { if err != nil {
return err return err
} }
} }
})
return nil
} }
// allocNID allocates new node ID for a node of kind nodeType. // allocNID allocates new node ID for a node of kind nodeType.
......
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