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),
monotime: xtime.Mono,
peerTab: make(map[proto.NodeID]*_MasteredPeer),
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,15 +1177,19 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (peer *_MasteredPeer, ...@@ -1181,15 +1177,19 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (peer *_MasteredPeer,
} }
}) })
// send accept and indicate to run that initial acceptance is done // XXX compensate a bit for lack of ctx handling in Send/Recv
err := peer.accept(ctx) return xxcontext.WithCloseOnErrCancel(ctx, link, func() error {
if err != nil {
return nil
}
close(peer.acceptSent)
// proxy δnodeTab,δpartTab/δclusterState from main to the peer // send accept and indicate to run that initial acceptance is done
return peer.notify(ctx) err := peer.accept(ctx)
if err != nil {
return nil
}
close(peer.acceptSent)
// proxy δnodeTab,δpartTab/δclusterState from main to the peer
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,63 +1270,58 @@ func (m *Master) notifyAll(ctx context.Context, event _ΔClusterState) { ...@@ -1273,63 +1270,58 @@ 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? for {
return xxcontext.WithCloseOnErrCancel(ctx, p.node.Link(), func() error { var δstate _ΔClusterState
for {
var δstate _ΔClusterState
select {
case <-ctx.Done():
return ctx.Err()
case <-p.notifyqOverflow:
// XXX err -> ?
return fmt.Errorf("detaching (peer is too slow to consume updates)")
case δstate = <-p.notifyq: // XXX could be also closed? select {
} case <-ctx.Done():
return ctx.Err()
var msg proto.Msg case <-p.notifyqOverflow:
switch δstate := δstate.(type) { return fmt.Errorf("detaching (peer is too slow to consume updates)")
case *_ΔNodeTab:
msg = &proto.NotifyNodeInformation{
IdTime: proto.IdTimeNone, // FIXME
NodeList: []proto.NodeInfo{δstate.NodeInfo},
}
case *_ΔPartTab: case δstate = <-p.notifyq:
// don't send δpartTab to S unless cluster is RUNNING }
if p.node.Type == proto.STORAGE && stateCode != proto.ClusterRunning {
continue
}
msg = &proto.NotifyPartitionChanges{
// XXX
// PTid: ...,
// NumReplicas: ...,
// CellList: ...,
}
panic("TODO") // ^^^
case *_ΔStateCode: var msg proto.Msg
stateCode = δstate.ClusterState switch δstate := δstate.(type) {
msg = &proto.NotifyClusterState{ case *_ΔNodeTab:
State: stateCode, msg = &proto.NotifyNodeInformation{
} IdTime: proto.IdTimeNone, // XXX ok?
NodeList: []proto.NodeInfo{δstate.NodeInfo},
}
default: case *_ΔPartTab:
panic("bug") // don't send δpartTab to S unless cluster is RUNNING
if p.node.Type == proto.STORAGE && stateCode != proto.ClusterRunning {
continue
}
msg = &proto.NotifyPartitionChanges{
// XXX
// PTid: ...,
// NumReplicas: ...,
// CellList: ...,
} }
panic("TODO") // ^^^
err := p.node.Link().Send1(msg) case *_ΔStateCode:
if err != nil { stateCode = δstate.ClusterState
return err msg = &proto.NotifyClusterState{
State: stateCode,
} }
default:
panic("bug")
} }
})
return nil err := link.Send1(msg)
if err != nil {
return err
}
}
} }
// 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