Commit b2f0b1c6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 62117b70
...@@ -43,7 +43,7 @@ import ( ...@@ -43,7 +43,7 @@ import (
// Client talks to NEO cluster and exposes access to it via ZODB interfaces. // Client talks to NEO cluster and exposes access to it via ZODB interfaces.
type Client struct { type Client struct {
node neo.NodeCommon node neo.NodeApp
talkMasterCancel func() talkMasterCancel func()
...@@ -62,7 +62,7 @@ type Client struct { ...@@ -62,7 +62,7 @@ type Client struct {
// - .ClusterState = RUNNING <- XXX needed? // - .ClusterState = RUNNING <- XXX needed?
// //
// however master link is accessed separately (see ^^^ and masterLink) // however master link is accessed separately (see ^^^ and masterLink)
operational bool // XXX <- somehow move to NodeCommon? operational bool // XXX <- somehow move to NodeApp?
opReady chan struct{} // reinitialized each time state becomes non-operational opReady chan struct{} // reinitialized each time state becomes non-operational
} }
...@@ -77,7 +77,7 @@ func (c *Client) StorageName() string { ...@@ -77,7 +77,7 @@ func (c *Client) StorageName() string {
// It will connect to master @masterAddr and identify with sepcified cluster name. // It will connect to master @masterAddr and identify with sepcified cluster name.
func NewClient(clusterName, masterAddr string, net xnet.Networker) *Client { func NewClient(clusterName, masterAddr string, net xnet.Networker) *Client {
cli := &Client{ cli := &Client{
node: neo.NodeCommon{ node: neo.NodeApp{
MyInfo: neo.NodeInfo{Type: neo.CLIENT, Addr: neo.Address{}}, MyInfo: neo.NodeInfo{Type: neo.CLIENT, Addr: neo.Address{}},
ClusterName: clusterName, ClusterName: clusterName,
Net: net, Net: net,
...@@ -368,15 +368,14 @@ func (c *Client) LastOid(ctx context.Context) (zodb.Oid, error) { ...@@ -368,15 +368,14 @@ func (c *Client) LastOid(ctx context.Context) (zodb.Oid, error) {
} }
func (c *Client) Load(ctx context.Context, xid zodb.Xid) (data []byte, serial zodb.Tid, err error) { func (c *Client) Load(ctx context.Context, xid zodb.Xid) (data []byte, serial zodb.Tid, err error) {
// XXX err context (but keep zodb errors intact ?) defer xerr.Contextf(&err, "client: load %v", xid) // XXX keep zodb errors intact?
defer xerr.Contextf(&err, "client: load %v", xid)
err = c.withOperational(ctx) err = c.withOperational(ctx)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
// Here we have cluster state operational and rlocked. Retrieve // here we have cluster state operational and rlocked. Retrieve
// storages we might need to access and release the lock. // storages we might need to access and release the lock.
storv := make([]*neo.Node, 0) storv := make([]*neo.Node, 0)
for _, cell := range c.node.PartTab.Get(xid.Oid) { for _, cell := range c.node.PartTab.Get(xid.Oid) {
......
...@@ -49,10 +49,10 @@ const ( ...@@ -49,10 +49,10 @@ const (
) )
// NodeCommon is common data in all NEO nodes: Master, Storage & Client XXX text // NodeApp is base for implementing NEO node applications.
// XXX naming -> Node ? //
// XXX -> internal? // XXX -> internal?
type NodeCommon struct { type NodeApp struct {
MyInfo NodeInfo MyInfo NodeInfo
ClusterName string ClusterName string
...@@ -70,7 +70,7 @@ type NodeCommon struct { ...@@ -70,7 +70,7 @@ type NodeCommon struct {
// It handshakes, requests identification and checks peer type. If successful returned are: // It handshakes, requests identification and checks peer type. If successful returned are:
// - primary link connection which carried identification // - primary link connection which carried identification
// - accept identification reply // - accept identification reply
func (n *NodeCommon) Dial(ctx context.Context, peerType NodeType, addr string) (_ *Conn, _ *AcceptIdentification, err error) { func (n *NodeApp) Dial(ctx context.Context, peerType NodeType, addr string) (_ *Conn, _ *AcceptIdentification, err error) {
link, err := DialLink(ctx, n.Net, addr) link, err := DialLink(ctx, n.Net, addr)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
...@@ -117,9 +117,10 @@ func (n *NodeCommon) Dial(ctx context.Context, peerType NodeType, addr string) ( ...@@ -117,9 +117,10 @@ func (n *NodeCommon) Dial(ctx context.Context, peerType NodeType, addr string) (
// Listen starts listening at node's listening address. // Listen starts listening at node's listening address.
//
// If the address is empty one new free is automatically selected. // If the address is empty one new free is automatically selected.
// The node information about where it listens at is appropriately updated. // The node information about where it listens at is appropriately updated.
func (n *NodeCommon) Listen() (Listener, error) { func (n *NodeApp) Listen() (Listener, error) {
// start listening // start listening
ll, err := ListenLink(n.Net, n.MyInfo.Addr.String()) ll, err := ListenLink(n.Net, n.MyInfo.Addr.String())
if err != nil { if err != nil {
......
...@@ -69,6 +69,7 @@ type NodeTable struct { ...@@ -69,6 +69,7 @@ type NodeTable struct {
//trace:event traceNodeChanged(nt *NodeTable, n *Node) //trace:event traceNodeChanged(nt *NodeTable, n *Node)
// Node represents a peer node in the cluster. // Node represents a peer node in the cluster.
//
// XXX name as Peer? // XXX name as Peer?
type Node struct { type Node struct {
nodeTab *NodeTable // this node is part of nodeTab *NodeTable // this node is part of
...@@ -336,7 +337,7 @@ type dialed struct { ...@@ -336,7 +337,7 @@ type dialed struct {
ready chan struct{} ready chan struct{}
} }
// Dial returns link to peer node. // Dial establishes link to peer node.
// //
// If the link was not yet established Dial dials the peer appropriately, // If the link was not yet established Dial dials the peer appropriately,
// handshakes, requests identification and checks that identification reply is // handshakes, requests identification and checks that identification reply is
...@@ -470,7 +471,7 @@ func (p *Peer) PutConn(c *Conn) { ...@@ -470,7 +471,7 @@ func (p *Peer) PutConn(c *Conn) {
// dial does low-level work to dial peer // dial does low-level work to dial peer
// XXX p.* reading without lock - ok? // XXX p.* reading without lock - ok?
func (p *Node) dial(ctx context.Context) (*NodeLink, error) { func (p *Node) dial(ctx context.Context) (*NodeLink, error) {
var me *NodeCommon // XXX temp stub var me *NodeApp // XXX bad -> crashes
conn0, accept, err := me.Dial(ctx, p.Type, p.Addr.String()) conn0, accept, err := me.Dial(ctx, p.Type, p.Addr.String())
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -211,7 +211,7 @@ func TestMasterStorage(t *testing.T) { ...@@ -211,7 +211,7 @@ func TestMasterStorage(t *testing.T) {
} }
// shortcut for nodetab change // shortcut for nodetab change
node := func(x *neo.NodeCommon, laddr string, typ neo.NodeType, num int32, state neo.NodeState, idtstamp float64) *traceNode { node := func(x *neo.NodeApp, laddr string, typ neo.NodeType, num int32, state neo.NodeState, idtstamp float64) *traceNode {
return &traceNode{ return &traceNode{
NodeTab: unsafe.Pointer(x.NodeTab), NodeTab: unsafe.Pointer(x.NodeTab),
NodeInfo: nodei(laddr, typ, num, state, idtstamp), NodeInfo: nodei(laddr, typ, num, state, idtstamp),
...@@ -394,7 +394,7 @@ func TestMasterStorage(t *testing.T) { ...@@ -394,7 +394,7 @@ func TestMasterStorage(t *testing.T) {
}, },
})) }))
Cnode := (*neo.NodeCommon)(unsafe.Pointer(C)) // XXX hack Cnode := (*neo.NodeApp)(unsafe.Pointer(C)) // XXX hack
tc.Expect(node(Cnode, "m:1", neo.MASTER, 1, neo.RUNNING, 0.00)) 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, "s:1", neo.STORAGE, 1, neo.RUNNING, 0.01))
tc.Expect(node(Cnode, "", neo.CLIENT, 1, neo.RUNNING, 0.02)) tc.Expect(node(Cnode, "", neo.CLIENT, 1, neo.RUNNING, 0.02))
......
...@@ -44,7 +44,7 @@ import ( ...@@ -44,7 +44,7 @@ import (
// Master is a node overseeing and managing how whole NEO cluster works // Master is a node overseeing and managing how whole NEO cluster works
type Master struct { type Master struct {
node neo.NodeCommon node neo.NodeApp
// master manages node and partition tables and broadcast their updates // master manages node and partition tables and broadcast their updates
// to all nodes in cluster // to all nodes in cluster
...@@ -90,7 +90,7 @@ func NewMaster(clusterName, serveAddr string, net xnet.Networker) *Master { ...@@ -90,7 +90,7 @@ func NewMaster(clusterName, serveAddr string, net xnet.Networker) *Master {
} }
m := &Master{ m := &Master{
node: neo.NodeCommon{ node: neo.NodeApp{
MyInfo: neo.NodeInfo{Type: neo.MASTER, Addr: addr}, MyInfo: neo.NodeInfo{Type: neo.MASTER, Addr: addr},
ClusterName: clusterName, ClusterName: clusterName,
Net: net, Net: net,
......
...@@ -39,7 +39,7 @@ import ( ...@@ -39,7 +39,7 @@ import (
// Storage is NEO node that keeps data and provides read/write access to it // Storage is NEO node that keeps data and provides read/write access to it
type Storage struct { type Storage struct {
node neo.NodeCommon node neo.NodeApp
// context for providing operational service // context for providing operational service
// it is renewed every time master tells us StartOpertion, so users // it is renewed every time master tells us StartOpertion, so users
...@@ -68,7 +68,7 @@ func NewStorage(cluster, masterAddr, serveAddr string, net xnet.Networker, zstor ...@@ -68,7 +68,7 @@ func NewStorage(cluster, masterAddr, serveAddr string, net xnet.Networker, zstor
} }
stor := &Storage{ stor := &Storage{
node: neo.NodeCommon{ node: neo.NodeApp{
MyInfo: neo.NodeInfo{Type: neo.STORAGE, Addr: addr}, MyInfo: neo.NodeInfo{Type: neo.STORAGE, Addr: addr},
ClusterName: cluster, ClusterName: cluster,
Net: net, Net: net,
......
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