Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
0b4cf8c7
Commit
0b4cf8c7
authored
Feb 03, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
641b1326
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
38 deletions
+38
-38
go/neo/master.go
go/neo/master.go
+2
-2
go/neo/storage.go
go/neo/storage.go
+4
-4
go/neo/xneo/nodetab.go
go/neo/xneo/nodetab.go
+6
-6
go/neo/xneo/xneo.go
go/neo/xneo/xneo.go
+26
-26
No files found.
go/neo/master.go
View file @
0b4cf8c7
...
...
@@ -44,7 +44,7 @@ import (
// Master is a node overseeing and managing how whole NEO cluster works.
type
Master
struct
{
node
*
xneo
.
Node
App
node
*
xneo
.
Node
// master manages node and partition tables and broadcast their updates
// to all nodes in cluster
...
...
@@ -74,7 +74,7 @@ type Master struct {
// Use Run to actually start running the node.
func
NewMaster
(
clusterName
string
,
net
xnet
.
Networker
)
*
Master
{
m
:=
&
Master
{
node
:
xneo
.
NewNode
App
(
net
,
proto
.
MASTER
,
clusterName
,
""
),
node
:
xneo
.
NewNode
(
net
,
proto
.
MASTER
,
clusterName
,
""
),
ctlStart
:
make
(
chan
chan
error
),
ctlStop
:
make
(
chan
chan
struct
{}),
...
...
go/neo/storage.go
View file @
0b4cf8c7
...
...
@@ -48,7 +48,7 @@ import (
//
// Storage implements only NEO protocol logic with data being persisted via provided storage.Backend.
type
Storage
struct
{
node
*
xneo
.
Node
App
node
*
xneo
.
Node
// context for providing operational service
// it is renewed every time master tells us StartOpertion, so users
...
...
@@ -67,7 +67,7 @@ type Storage struct {
// Use Run to actually start running the node.
func
NewStorage
(
clusterName
,
masterAddr
string
,
net
xnet
.
Networker
,
back
storage
.
Backend
)
*
Storage
{
stor
:=
&
Storage
{
node
:
xneo
.
NewNode
App
(
net
,
proto
.
STORAGE
,
clusterName
,
masterAddr
),
node
:
xneo
.
NewNode
(
net
,
proto
.
STORAGE
,
clusterName
,
masterAddr
),
back
:
back
,
}
...
...
@@ -316,7 +316,7 @@ func (stor *Storage) m1initialize1(ctx context.Context, req neonet.Request) erro
err
=
req
.
Reply
(
&
proto
.
AnswerLastIDs
{
LastTid
:
lastTid
,
LastOid
:
lastOid
})
// XXX -> somehow to common part in Node
App
?
// XXX -> somehow to common part in Node ?
case
*
proto
.
SendPartitionTable
:
// TODO M sends us whole PT -> save locally
stor
.
node
.
UpdatePartTab
(
ctx
,
msg
)
// XXX lock? XXX handle msg.NumReplicas
...
...
@@ -388,7 +388,7 @@ func (stor *Storage) m1serve1(ctx context.Context, req neonet.Request) error {
case
*
proto
.
StopOperation
:
return
fmt
.
Errorf
(
"stop requested"
)
// should be served by Node
App
.commonRecv1
// should be served by Node.commonRecv1
// ---- 8< ----
// XXX SendPartitionTable?
// XXX NotifyPartitionChanges?
...
...
go/neo/xneo/nodetab.go
View file @
0b4cf8c7
...
...
@@ -73,7 +73,7 @@ import (
type
NodeTable
struct
{
// XXX for PeerNode.Dial to work. see also comments vvv near "peer link"
// XXX move pointer to local node to PeerNode instead?
nodeApp
*
NodeApp
localNode
*
Node
nodev
[]
*
PeerNode
// all nodes
notifyv
[]
chan
proto
.
NodeInfo
// subscribers
...
...
@@ -326,21 +326,21 @@ func (p *PeerNode) ResetLink(ctx context.Context) {
func
(
p
*
PeerNode
)
dial
(
ctx
context
.
Context
)
(
_
*
neonet
.
NodeLink
,
err
error
)
{
defer
task
.
Runningf
(
&
ctx
,
"connect %s"
,
p
.
NID
)(
&
err
)
// XXX "connect" good word here?
app
:=
p
.
nodeTab
.
nodeApp
link
,
accept
,
err
:=
app
.
Dial
(
ctx
,
p
.
Type
,
p
.
Addr
.
String
())
node
:=
p
.
nodeTab
.
localNode
link
,
accept
,
err
:=
node
.
Dial
(
ctx
,
p
.
Type
,
p
.
Addr
.
String
())
if
err
!=
nil
{
return
nil
,
err
}
// verify peer identifies as what we expect
switch
{
// type is already checked by
app
.Dial
// type is already checked by
node
.Dial
case
accept
.
MyNID
!=
p
.
NID
:
err
=
fmt
.
Errorf
(
"connected, but peer's nid is not %v (identifies as %v)"
,
p
.
NID
,
accept
.
MyNID
)
case
accept
.
YourNID
!=
app
.
MyInfo
.
NID
:
err
=
fmt
.
Errorf
(
"connected, but peer gives us nid %v (our is %v)"
,
accept
.
YourNID
,
app
.
MyInfo
.
NID
)
case
accept
.
YourNID
!=
node
.
MyInfo
.
NID
:
err
=
fmt
.
Errorf
(
"connected, but peer gives us nid %v (our is %v)"
,
accept
.
YourNID
,
node
.
MyInfo
.
NID
)
// XXX PeerNode.Dial is currently used by Client only.
// XXX For Client it would be not correct to check #partition only at
...
...
go/neo/xneo/xneo.go
View file @
0b4cf8c7
...
...
@@ -52,14 +52,14 @@ func (cs *ClusterState) IsOperational() bool {
return
/* cs.Code == proto.ClusterRunning && */
cs
.
PartTab
.
OperationalWith
(
cs
.
NodeTab
)
}
// Node
App provides base functionality underlying any NEO node. XXX -> NodeBase? NodeSrv? NodeInstance?
// Node
provides base functionality underlying any NEO node.
//
// Every node knows how to talk to master and receives master idea about:
//
// - current node table (all nodes in the cluster),
// - current partition table (how data is split around storage nodes),
// - current cluster state.
type
Node
App
struct
{
type
Node
struct
{
MyInfo
proto
.
NodeInfo
ClusterName
string
...
...
@@ -71,13 +71,13 @@ type NodeApp struct {
PartTab
*
PartitionTable
// information about data distribution in the cluster
ClusterState
proto
.
ClusterState
// master idea about cluster state
// should be set by user so Node
App
can notify when master tells this node to shutdown
// should be set by user so Node can notify when master tells this node to shutdown
OnShutdown
func
()
}
// NewNode
App creates new node application
func
NewNode
App
(
net
xnet
.
Networker
,
typ
proto
.
NodeType
,
clusterName
,
masterAddr
string
)
*
NodeApp
{
app
:=
&
NodeApp
{
// NewNode
creates new node.
func
NewNode
(
net
xnet
.
Networker
,
typ
proto
.
NodeType
,
clusterName
,
masterAddr
string
)
*
Node
{
node
:=
&
Node
{
MyInfo
:
proto
.
NodeInfo
{
Type
:
typ
,
Addr
:
proto
.
Address
{},
NID
:
0
,
IdTime
:
proto
.
IdTimeNone
},
ClusterName
:
clusterName
,
Net
:
net
,
...
...
@@ -88,8 +88,8 @@ func NewNodeApp(net xnet.Networker, typ proto.NodeType, clusterName, masterAddr
ClusterState
:
-
1
,
// invalid
}
app
.
NodeTab
.
nodeApp
=
app
return
app
node
.
NodeTab
.
localNode
=
node
return
node
}
// Dial connects to another node in the cluster.
...
...
@@ -102,14 +102,14 @@ func NewNodeApp(net xnet.Networker, typ proto.NodeType, clusterName, masterAddr
// Dial does not update .NodeTab or its node entries in any way.
// For establishing links to peers present in .NodeTab use Node.Dial.
//
// XXX unexport after Node
App
+= talkMaster <- used only to dial to M
// XXX unexport after Node += talkMaster <- used only to dial to M
// <- dialing to other nodes always go through node.Dial
//
// XXX <- use dialNode instead
func
(
app
*
NodeApp
)
Dial
(
ctx
context
.
Context
,
peerType
proto
.
NodeType
,
addr
string
)
(
_
*
neonet
.
NodeLink
,
_
*
proto
.
AcceptIdentification
,
err
error
)
{
func
(
node
*
Node
)
Dial
(
ctx
context
.
Context
,
peerType
proto
.
NodeType
,
addr
string
)
(
_
*
neonet
.
NodeLink
,
_
*
proto
.
AcceptIdentification
,
err
error
)
{
defer
task
.
Runningf
(
&
ctx
,
"dial %v (%v)"
,
addr
,
peerType
)(
&
err
)
link
,
err
:=
neonet
.
DialLink
(
ctx
,
app
.
Net
,
addr
)
link
,
err
:=
neonet
.
DialLink
(
ctx
,
node
.
Net
,
addr
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
...
...
@@ -129,11 +129,11 @@ func (app *NodeApp) Dial(ctx context.Context, peerType proto.NodeType, addr stri
}()
req
:=
&
proto
.
RequestIdentification
{
NodeType
:
app
.
MyInfo
.
Type
,
NID
:
app
.
MyInfo
.
NID
,
Address
:
app
.
MyInfo
.
Addr
,
ClusterName
:
app
.
ClusterName
,
IdTime
:
app
.
MyInfo
.
IdTime
,
// XXX ok?
NodeType
:
node
.
MyInfo
.
Type
,
NID
:
node
.
MyInfo
.
NID
,
Address
:
node
.
MyInfo
.
Addr
,
ClusterName
:
node
.
ClusterName
,
IdTime
:
node
.
MyInfo
.
IdTime
,
// XXX ok?
DevPath
:
nil
,
// XXX stub
NewNID
:
nil
,
// XXX stub
}
...
...
@@ -237,24 +237,24 @@ func (l *listener) Addr() net.Addr { return l.l.Addr() }
// ----------------------------------------
// UpdateNodeTab applies updates to .NodeTab from message and logs changes appropriately.
func
(
app
*
NodeApp
)
UpdateNodeTab
(
ctx
context
.
Context
,
msg
*
proto
.
NotifyNodeInformation
)
{
func
(
node
*
Node
)
UpdateNodeTab
(
ctx
context
.
Context
,
msg
*
proto
.
NotifyNodeInformation
)
{
// XXX msg.IdTime ?
for
_
,
nodeInfo
:=
range
msg
.
NodeList
{
log
.
Infof
(
ctx
,
"node update: %v"
,
nodeInfo
)
app
.
NodeTab
.
Update
(
nodeInfo
)
node
.
NodeTab
.
Update
(
nodeInfo
)
// XXX we have to provide IdTime when requesting identification to other peers
// (e.g. Spy checks this is what master broadcast them and if not replies "unknown by master")
if
nodeInfo
.
NID
==
app
.
MyInfo
.
NID
{
if
nodeInfo
.
NID
==
node
.
MyInfo
.
NID
{
// XXX recheck locking
// XXX do .MyInfo = nodeInfo ?
app
.
MyInfo
.
IdTime
=
nodeInfo
.
IdTime
node
.
MyInfo
.
IdTime
=
nodeInfo
.
IdTime
// FIXME hack - better it be separate command and handled cleanly
if
nodeInfo
.
State
==
proto
.
DOWN
{
log
.
Info
(
ctx
,
"master told us to shutdown"
)
log
.
Flush
()
app
.
OnShutdown
()
node
.
OnShutdown
()
// os.Exit(1)
return
}
...
...
@@ -262,20 +262,20 @@ func (app *NodeApp) UpdateNodeTab(ctx context.Context, msg *proto.NotifyNodeInfo
}
// FIXME logging under lock (if caller took e.g. .StateMu before applying updates)
log
.
Infof
(
ctx
,
"full nodetab:
\n
%s"
,
app
.
NodeTab
)
log
.
Infof
(
ctx
,
"full nodetab:
\n
%s"
,
node
.
NodeTab
)
}
// UpdatePartTab applies updates to .PartTab from message and logs changes appropriately.
func
(
app
*
NodeApp
)
UpdatePartTab
(
ctx
context
.
Context
,
msg
*
proto
.
SendPartitionTable
)
{
func
(
node
*
Node
)
UpdatePartTab
(
ctx
context
.
Context
,
msg
*
proto
.
SendPartitionTable
)
{
pt
:=
PartTabFromDump
(
msg
.
PTid
,
msg
.
RowList
)
// FIXME handle msg.NumReplicas
// XXX logging under lock
log
.
Infof
(
ctx
,
"parttab update: %v"
,
pt
)
app
.
PartTab
=
pt
node
.
PartTab
=
pt
}
// UpdateClusterState applies update to .ClusterState from message and logs change appropriately.
func
(
app
*
NodeApp
)
UpdateClusterState
(
ctx
context
.
Context
,
msg
*
proto
.
NotifyClusterState
)
{
func
(
node
*
Node
)
UpdateClusterState
(
ctx
context
.
Context
,
msg
*
proto
.
NotifyClusterState
)
{
// XXX loging under lock
log
.
Infof
(
ctx
,
"state update: %v"
,
msg
.
State
)
app
.
ClusterState
.
Set
(
msg
.
State
)
node
.
ClusterState
.
Set
(
msg
.
State
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment