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
5d5a4372
Commit
5d5a4372
authored
Jan 25, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X UUID -> NID (NodeID)
parent
ce27f975
Changes
15
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
243 additions
and
243 deletions
+243
-243
go/neo/client.go
go/neo/client.go
+4
-4
go/neo/master.go
go/neo/master.go
+21
-21
go/neo/neo_test.go
go/neo/neo_test.go
+9
-9
go/neo/proto/proto-misc.go
go/neo/proto/proto-misc.go
+11
-11
go/neo/proto/proto.go
go/neo/proto/proto.go
+24
-24
go/neo/proto/proto_test.go
go/neo/proto/proto_test.go
+16
-16
go/neo/proto/zproto-marshal.go
go/neo/proto/zproto-marshal.go
+107
-107
go/neo/storage.go
go/neo/storage.go
+9
-9
go/neo/storage/sqlite/sqlite.go
go/neo/storage/sqlite/sqlite.go
+2
-2
go/neo/t_cluster_test.go
go/neo/t_cluster_test.go
+3
-3
go/neo/t_events_test.go
go/neo/t_events_test.go
+1
-1
go/neo/xneo/nodetab.go
go/neo/xneo/nodetab.go
+15
-15
go/neo/xneo/parttab.go
go/neo/xneo/parttab.go
+7
-7
go/neo/xneo/parttab_test.go
go/neo/xneo/parttab_test.go
+9
-9
go/neo/xneo/xneo.go
go/neo/xneo/xneo.go
+5
-5
No files found.
go/neo/client.go
View file @
5d5a4372
...
@@ -265,9 +265,9 @@ func (c *Client) talkMaster1(ctx context.Context) (err error) {
...
@@ -265,9 +265,9 @@ func (c *Client) talkMaster1(ctx context.Context) (err error) {
// FIXME vvv dup from Storage.talkMaster1
// FIXME vvv dup from Storage.talkMaster1
// XXX -> node.Dial / node.DialMaster ?
// XXX -> node.Dial / node.DialMaster ?
if
accept
.
Your
UUID
!=
c
.
node
.
MyInfo
.
UU
ID
{
if
accept
.
Your
NID
!=
c
.
node
.
MyInfo
.
N
ID
{
log
.
Infof
(
ctx
,
"master told us to have
uuid=%v"
,
accept
.
YourUU
ID
)
log
.
Infof
(
ctx
,
"master told us to have
nid=%v"
,
accept
.
YourN
ID
)
c
.
node
.
MyInfo
.
UUID
=
accept
.
YourUU
ID
c
.
node
.
MyInfo
.
NID
=
accept
.
YourN
ID
}
}
wg
,
ctx
:=
errgroup
.
WithContext
(
ctx
)
// XXX -> xsync.WorkGroup
wg
,
ctx
:=
errgroup
.
WithContext
(
ctx
)
// XXX -> xsync.WorkGroup
...
@@ -530,7 +530,7 @@ func (c *Client) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial z
...
@@ -530,7 +530,7 @@ func (c *Client) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial z
storv
:=
make
([]
*
xneo
.
Node
,
0
,
1
)
storv
:=
make
([]
*
xneo
.
Node
,
0
,
1
)
for
_
,
cell
:=
range
c
.
node
.
PartTab
.
Get
(
xid
.
Oid
)
{
for
_
,
cell
:=
range
c
.
node
.
PartTab
.
Get
(
xid
.
Oid
)
{
if
cell
.
Readable
()
{
if
cell
.
Readable
()
{
stor
:=
c
.
node
.
NodeTab
.
Get
(
cell
.
UU
ID
)
stor
:=
c
.
node
.
NodeTab
.
Get
(
cell
.
N
ID
)
// this storage might not yet come up
// this storage might not yet come up
if
stor
!=
nil
&&
stor
.
State
==
proto
.
RUNNING
{
if
stor
!=
nil
&&
stor
.
State
==
proto
.
RUNNING
{
storv
=
append
(
storv
,
stor
)
storv
=
append
(
storv
,
stor
)
...
...
go/neo/master.go
View file @
5d5a4372
...
@@ -142,7 +142,7 @@ func (m *Master) Run(ctx context.Context, l xnet.Listener) (err error) {
...
@@ -142,7 +142,7 @@ func (m *Master) Run(ctx context.Context, l xnet.Listener) (err error) {
m
.
node
.
MyInfo
=
proto
.
NodeInfo
{
m
.
node
.
MyInfo
=
proto
.
NodeInfo
{
Type
:
proto
.
MASTER
,
Type
:
proto
.
MASTER
,
Addr
:
naddr
,
Addr
:
naddr
,
UUID
:
m
.
allocUU
ID
(
proto
.
MASTER
),
NID
:
m
.
allocN
ID
(
proto
.
MASTER
),
State
:
proto
.
RUNNING
,
State
:
proto
.
RUNNING
,
IdTime
:
proto
.
IdTimeNone
,
// XXX ok?
IdTime
:
proto
.
IdTimeNone
,
// XXX ok?
}
}
...
@@ -1038,7 +1038,7 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *xneo.Node, res
...
@@ -1038,7 +1038,7 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *xneo.Node, res
// - NodeType valid
// - NodeType valid
// - IdTime ?
// - IdTime ?
uuid
:=
n
.
idReq
.
UU
ID
nid
:=
n
.
idReq
.
N
ID
nodeType
:=
n
.
idReq
.
NodeType
nodeType
:=
n
.
idReq
.
NodeType
err
:=
func
()
*
proto
.
Error
{
err
:=
func
()
*
proto
.
Error
{
...
@@ -1046,18 +1046,18 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *xneo.Node, res
...
@@ -1046,18 +1046,18 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *xneo.Node, res
return
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
"cluster name mismatch"
}
return
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
"cluster name mismatch"
}
}
}
if
uu
id
==
0
{
if
n
id
==
0
{
uuid
=
m
.
allocUU
ID
(
nodeType
)
nid
=
m
.
allocN
ID
(
nodeType
)
}
}
// XXX
uu
id < 0 (temporary) -> reallocate if conflict ?
// XXX
n
id < 0 (temporary) -> reallocate if conflict ?
// XXX check
uu
id matches NodeType
// XXX check
n
id matches NodeType
node
=
m
.
node
.
NodeTab
.
Get
(
uu
id
)
node
=
m
.
node
.
NodeTab
.
Get
(
n
id
)
if
node
!=
nil
{
if
node
!=
nil
{
// reject -
uu
id is already occupied by someone else
// reject -
n
id is already occupied by someone else
// XXX check also for down state - it could be the same node reconnecting
// XXX check also for down state - it could be the same node reconnecting
return
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
fmt
.
Sprintf
(
"
uuid %v already used by another node"
,
uu
id
)}
return
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
fmt
.
Sprintf
(
"
nid %v already used by another node"
,
n
id
)}
}
}
// accept only certain kind of nodes depending on .clusterState, e.g.
// accept only certain kind of nodes depending on .clusterState, e.g.
...
@@ -1079,18 +1079,18 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *xneo.Node, res
...
@@ -1079,18 +1079,18 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *xneo.Node, res
return
nil
return
nil
}()
}()
subj
:=
fmt
.
Sprintf
(
"identify: %s (%s)"
,
n
.
req
.
Link
()
.
RemoteAddr
(),
n
.
idReq
.
UU
ID
)
subj
:=
fmt
.
Sprintf
(
"identify: %s (%s)"
,
n
.
req
.
Link
()
.
RemoteAddr
(),
n
.
idReq
.
N
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Infof
(
ctx
,
"%s: rejecting: %s"
,
subj
,
err
)
log
.
Infof
(
ctx
,
"%s: rejecting: %s"
,
subj
,
err
)
return
nil
,
err
return
nil
,
err
}
}
log
.
Infof
(
ctx
,
"%s: accepting as %s"
,
subj
,
uu
id
)
log
.
Infof
(
ctx
,
"%s: accepting as %s"
,
subj
,
n
id
)
accept
:=
&
proto
.
AcceptIdentification
{
accept
:=
&
proto
.
AcceptIdentification
{
NodeType
:
proto
.
MASTER
,
NodeType
:
proto
.
MASTER
,
My
UUID
:
m
.
node
.
MyInfo
.
UU
ID
,
My
NID
:
m
.
node
.
MyInfo
.
N
ID
,
Your
UUID
:
uu
id
,
Your
NID
:
n
id
,
}
}
// update nodeTab
// update nodeTab
...
@@ -1107,7 +1107,7 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *xneo.Node, res
...
@@ -1107,7 +1107,7 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *xneo.Node, res
nodeInfo
:=
proto
.
NodeInfo
{
nodeInfo
:=
proto
.
NodeInfo
{
Type
:
nodeType
,
Type
:
nodeType
,
Addr
:
n
.
idReq
.
Address
,
Addr
:
n
.
idReq
.
Address
,
UUID
:
uu
id
,
NID
:
n
id
,
State
:
nodeState
,
State
:
nodeState
,
IdTime
:
proto
.
IdTime
(
m
.
monotime
()),
IdTime
:
proto
.
IdTime
(
m
.
monotime
()),
}
}
...
@@ -1117,16 +1117,16 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *xneo.Node, res
...
@@ -1117,16 +1117,16 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *xneo.Node, res
return
node
,
accept
return
node
,
accept
}
}
// alloc
UUID allocates new node uuid
for a node of kind nodeType
// alloc
NID allocates new node ID
for a node of kind nodeType
// XXX it is bad idea for master to assign
uuid
to coming node
// XXX it is bad idea for master to assign
node ID
to coming node
// -> better nodes generate really unique UUID themselves and always show with them
// -> better nodes generate really unique UUID themselves and always show with them
func
(
m
*
Master
)
alloc
UUID
(
nodeType
proto
.
NodeType
)
proto
.
NodeUU
ID
{
func
(
m
*
Master
)
alloc
NID
(
nodeType
proto
.
NodeType
)
proto
.
Node
ID
{
for
num
:=
int32
(
1
);
num
<
1
<<
24
;
num
++
{
for
num
:=
int32
(
1
);
num
<
1
<<
24
;
num
++
{
uuid
:=
proto
.
UU
ID
(
nodeType
,
num
)
nid
:=
proto
.
N
ID
(
nodeType
,
num
)
if
m
.
node
.
NodeTab
.
Get
(
uu
id
)
==
nil
{
if
m
.
node
.
NodeTab
.
Get
(
n
id
)
==
nil
{
return
uu
id
return
n
id
}
}
}
}
panic
(
"all
uu
id allocated ???"
)
// XXX more robust ?
panic
(
"all
n
id allocated ???"
)
// XXX more robust ?
}
}
go/neo/neo_test.go
View file @
5d5a4372
...
@@ -74,7 +74,7 @@ func _TestMasterStorage(t0 *tEnv) {
...
@@ -74,7 +74,7 @@ func _TestMasterStorage(t0 *tEnv) {
// TODO create C; C tries connect to master - rejected ("not yet operational")
// TODO create C; C tries connect to master - rejected ("not yet operational")
// TODO test ID rejects (
uu
id already registered, ...)
// TODO test ID rejects (
n
id already registered, ...)
// M <- start cmd
// M <- start cmd
wg
:=
xsync
.
NewWorkGroup
(
bg
)
wg
:=
xsync
.
NewWorkGroup
(
bg
)
...
@@ -96,7 +96,7 @@ func _TestMasterStorage(t0 *tEnv) {
...
@@ -96,7 +96,7 @@ func _TestMasterStorage(t0 *tEnv) {
PTid
:
1
,
PTid
:
1
,
NumReplicas
:
0
,
NumReplicas
:
0
,
RowList
:
[]
proto
.
RowInfo
{
RowList
:
[]
proto
.
RowInfo
{
{[]
proto
.
CellInfo
{{
proto
.
UU
ID
(
proto
.
STORAGE
,
1
),
proto
.
UP_TO_DATE
}}},
{[]
proto
.
CellInfo
{{
proto
.
N
ID
(
proto
.
STORAGE
,
1
),
proto
.
UP_TO_DATE
}}},
},
},
}))
}))
...
@@ -139,7 +139,7 @@ func _TestMasterStorage(t0 *tEnv) {
...
@@ -139,7 +139,7 @@ func _TestMasterStorage(t0 *tEnv) {
tCM
.
Expect
(
netconnect
(
"c:1"
,
"m:3"
,
"m:1"
))
tCM
.
Expect
(
netconnect
(
"c:1"
,
"m:3"
,
"m:1"
))
tCM
.
Expect
(
conntx
(
"c:1"
,
"m:3"
,
1
,
&
proto
.
RequestIdentification
{
tCM
.
Expect
(
conntx
(
"c:1"
,
"m:3"
,
1
,
&
proto
.
RequestIdentification
{
NodeType
:
proto
.
CLIENT
,
NodeType
:
proto
.
CLIENT
,
UU
ID
:
0
,
N
ID
:
0
,
Address
:
xnaddr
(
""
),
Address
:
xnaddr
(
""
),
ClusterName
:
"abc1"
,
ClusterName
:
"abc1"
,
IdTime
:
proto
.
IdTimeNone
,
IdTime
:
proto
.
IdTimeNone
,
...
@@ -151,8 +151,8 @@ func _TestMasterStorage(t0 *tEnv) {
...
@@ -151,8 +151,8 @@ func _TestMasterStorage(t0 *tEnv) {
tCM
.
Expect
(
conntx
(
"m:3"
,
"c:1"
,
1
,
&
proto
.
AcceptIdentification
{
tCM
.
Expect
(
conntx
(
"m:3"
,
"c:1"
,
1
,
&
proto
.
AcceptIdentification
{
NodeType
:
proto
.
MASTER
,
NodeType
:
proto
.
MASTER
,
My
UUID
:
proto
.
UU
ID
(
proto
.
MASTER
,
1
),
My
NID
:
proto
.
N
ID
(
proto
.
MASTER
,
1
),
Your
UUID
:
proto
.
UU
ID
(
proto
.
CLIENT
,
1
),
Your
NID
:
proto
.
N
ID
(
proto
.
CLIENT
,
1
),
}))
}))
// C <- M NotifyNodeInformation C1,M1,S1
// C <- M NotifyNodeInformation C1,M1,S1
...
@@ -169,7 +169,7 @@ func _TestMasterStorage(t0 *tEnv) {
...
@@ -169,7 +169,7 @@ func _TestMasterStorage(t0 *tEnv) {
PTid
:
1
,
PTid
:
1
,
NumReplicas
:
0
,
NumReplicas
:
0
,
RowList
:
[]
proto
.
RowInfo
{
RowList
:
[]
proto
.
RowInfo
{
{[]
proto
.
CellInfo
{{
proto
.
UU
ID
(
proto
.
STORAGE
,
1
),
proto
.
UP_TO_DATE
}}},
{[]
proto
.
CellInfo
{{
proto
.
N
ID
(
proto
.
STORAGE
,
1
),
proto
.
UP_TO_DATE
}}},
},
},
}))
}))
...
@@ -220,7 +220,7 @@ func _TestMasterStorage(t0 *tEnv) {
...
@@ -220,7 +220,7 @@ func _TestMasterStorage(t0 *tEnv) {
tCS
.
Expect
(
netconnect
(
"c:2"
,
"s:3"
,
"s:1"
))
tCS
.
Expect
(
netconnect
(
"c:2"
,
"s:3"
,
"s:1"
))
tCS
.
Expect
(
conntx
(
"c:2"
,
"s:3"
,
1
,
&
proto
.
RequestIdentification
{
tCS
.
Expect
(
conntx
(
"c:2"
,
"s:3"
,
1
,
&
proto
.
RequestIdentification
{
NodeType
:
proto
.
CLIENT
,
NodeType
:
proto
.
CLIENT
,
UUID
:
proto
.
UU
ID
(
proto
.
CLIENT
,
1
),
NID
:
proto
.
N
ID
(
proto
.
CLIENT
,
1
),
Address
:
xnaddr
(
""
),
Address
:
xnaddr
(
""
),
ClusterName
:
"abc1"
,
ClusterName
:
"abc1"
,
IdTime
:
0.02
,
IdTime
:
0.02
,
...
@@ -230,8 +230,8 @@ func _TestMasterStorage(t0 *tEnv) {
...
@@ -230,8 +230,8 @@ func _TestMasterStorage(t0 *tEnv) {
tCS
.
Expect
(
conntx
(
"s:3"
,
"c:2"
,
1
,
&
proto
.
AcceptIdentification
{
tCS
.
Expect
(
conntx
(
"s:3"
,
"c:2"
,
1
,
&
proto
.
AcceptIdentification
{
NodeType
:
proto
.
STORAGE
,
NodeType
:
proto
.
STORAGE
,
My
UUID
:
proto
.
UU
ID
(
proto
.
STORAGE
,
1
),
My
NID
:
proto
.
N
ID
(
proto
.
STORAGE
,
1
),
Your
UUID
:
proto
.
UU
ID
(
proto
.
CLIENT
,
1
),
Your
NID
:
proto
.
N
ID
(
proto
.
CLIENT
,
1
),
}))
}))
// ... -> GetObject(xid1)
// ... -> GetObject(xid1)
...
...
go/neo/proto/proto-misc.go
View file @
5d5a4372
...
@@ -69,22 +69,22 @@ func (cs *ClusterState) Set(v ClusterState) {
...
@@ -69,22 +69,22 @@ func (cs *ClusterState) Set(v ClusterState) {
// node type -> character representing it.
// node type -> character representing it.
const
nodeTypeChar
=
"SMCA"
// NOTE neo/py does this out of sync with NodeType constants.
const
nodeTypeChar
=
"SMCA"
// NOTE neo/py does this out of sync with NodeType constants.
// String returns string representation of a node
uuid
.
// String returns string representation of a node
ID
.
//
//
// It returns ex 'S1', 'M2', ...
// It returns ex 'S1', 'M2', ...
func
(
n
odeUUID
NodeUU
ID
)
String
()
string
{
func
(
n
id
Node
ID
)
String
()
string
{
if
n
odeUUID
==
0
{
if
n
id
==
0
{
return
"?(0)0"
return
"?(0)0"
}
}
num
:=
n
odeUUID
&
(
1
<<
24
-
1
)
num
:=
n
id
&
(
1
<<
24
-
1
)
// XXX UUID_NAMESPACES description does not match neo/py code
// XXX UUID_NAMESPACES description does not match neo/py code
//typ := n
odeUUID
>> 24
//typ := n
id
>> 24
//temp := typ&(1 << 7) != 0
//temp := typ&(1 << 7) != 0
//typ &= 1<<7 - 1
//typ &= 1<<7 - 1
//nodeType := typ >> 4
//nodeType := typ >> 4
typ
:=
uint8
(
-
int8
(
n
odeUUID
>>
24
))
>>
4
typ
:=
uint8
(
-
int8
(
n
id
>>
24
))
>>
4
if
typ
<
4
{
if
typ
<
4
{
return
fmt
.
Sprintf
(
"%c%d"
,
nodeTypeChar
[
typ
],
num
)
return
fmt
.
Sprintf
(
"%c%d"
,
nodeTypeChar
[
typ
],
num
)
...
@@ -110,8 +110,8 @@ var nodeTypeNum = [...]int8{
...
@@ -110,8 +110,8 @@ var nodeTypeNum = [...]int8{
CLIENT
:
-
0x20
,
CLIENT
:
-
0x20
,
ADMIN
:
-
0x30
,
ADMIN
:
-
0x30
,
}
}
//
UUID creates node uuid
from node type and number.
//
NID creates node ID
from node type and number.
func
UUID
(
typ
NodeType
,
num
int32
)
NodeUU
ID
{
func
NID
(
typ
NodeType
,
num
int32
)
Node
ID
{
// XXX neo/py does not what UUID_NAMESPACES describes
// XXX neo/py does not what UUID_NAMESPACES describes
/*
/*
temp := uint32(0)
temp := uint32(0)
...
@@ -131,9 +131,9 @@ func UUID(typ NodeType, num int32) NodeUUID {
...
@@ -131,9 +131,9 @@ func UUID(typ NodeType, num int32) NodeUUID {
panic
(
"node number out of range"
)
panic
(
"node number out of range"
)
}
}
//
uu
id := temp << (7 + 3*8) | uint32(typ) << (4 + 3*8) | uint32(num)
//
n
id := temp << (7 + 3*8) | uint32(typ) << (4 + 3*8) | uint32(num)
uu
id
:=
uint32
(
uint8
(
typn
))
<<
(
3
*
8
)
|
uint32
(
num
)
n
id
:=
uint32
(
uint8
(
typn
))
<<
(
3
*
8
)
|
uint32
(
num
)
return
Node
UUID
(
uu
id
)
return
Node
ID
(
n
id
)
}
}
// ----------------------------------------
// ----------------------------------------
...
...
go/neo/proto/proto.go
View file @
5d5a4372
...
@@ -89,7 +89,7 @@ const (
...
@@ -89,7 +89,7 @@ const (
// answerBit is set in message code in answer messages for compatibility with neo/py
// answerBit is set in message code in answer messages for compatibility with neo/py
answerBit
=
0x8000
answerBit
=
0x8000
//INVALID_
UUID UU
ID = 0
//INVALID_
NID N
ID = 0
INVALID_TID
zodb
.
Tid
=
1
<<
64
-
1
// 0xffffffffffffffff
INVALID_TID
zodb
.
Tid
=
1
<<
64
-
1
// 0xffffffffffffffff
INVALID_OID
zodb
.
Oid
=
1
<<
64
-
1
INVALID_OID
zodb
.
Oid
=
1
<<
64
-
1
...
@@ -267,7 +267,7 @@ const (
...
@@ -267,7 +267,7 @@ const (
DISCARDED
//short: D
DISCARDED
//short: D
)
)
// Node
UU
ID is a node identifier, 4-bytes signed integer
// NodeID is a node identifier, 4-bytes signed integer
//
//
// High-order byte:
// High-order byte:
//
//
...
@@ -276,17 +276,17 @@ const (
...
@@ -276,17 +276,17 @@ const (
// | +-+-+---------- node type
// | +-+-+---------- node type
// +---------------- temporary if negative
// +---------------- temporary if negative
//
//
//
UU
ID namespaces are required to prevent conflicts when the master generate
//
N
ID namespaces are required to prevent conflicts when the master generate
// new
uuid before it knows uu
id of existing storage nodes. So only the high
// new
nid before it knows n
id of existing storage nodes. So only the high
// order bit is really important and the 31 other bits could be random.
// order bit is really important and the 31 other bits could be random.
// Extra namespace information and non-randomness of 3 LOB help to read logs.
// Extra namespace information and non-randomness of 3 LOB help to read logs.
//
//
// 0 is invalid Node
UU
ID XXX correct?
// 0 is invalid NodeID XXX correct?
//
//
// TODO -> back to 16-bytes randomly generated
UUID
// TODO -> back to 16-bytes randomly generated
node IDs
type
Node
UU
ID
int32
type
NodeID
int32
// TODO NodeType -> base Node
UU
ID
// TODO NodeType -> base NodeID
// Address represents host:port network endpoint.
// Address represents host:port network endpoint.
...
@@ -377,14 +377,14 @@ func (t *IdTime) neoDecodeN(data []byte) (uint64, bool) {
...
@@ -377,14 +377,14 @@ func (t *IdTime) neoDecodeN(data []byte) (uint64, bool) {
type
NodeInfo
struct
{
type
NodeInfo
struct
{
Type
NodeType
Type
NodeType
Addr
Address
// serving address
Addr
Address
// serving address
UUID
NodeUU
ID
NID
Node
ID
State
NodeState
State
NodeState
IdTime
IdTime
// XXX clarify semantic where it is used
IdTime
IdTime
// XXX clarify semantic where it is used
}
}
//neo:proto typeonly
//neo:proto typeonly
type
CellInfo
struct
{
type
CellInfo
struct
{
UUID
NodeUU
ID
NID
Node
ID
State
CellState
State
CellState
}
}
...
@@ -412,7 +412,7 @@ type Error struct {
...
@@ -412,7 +412,7 @@ type Error struct {
//neo:nodes * -> *
//neo:nodes * -> *
type
RequestIdentification
struct
{
type
RequestIdentification
struct
{
NodeType
NodeType
// XXX name
NodeType
NodeType
// XXX name
UUID
NodeUU
ID
NID
Node
ID
Address
Address
// where requesting node is also accepting connections
Address
Address
// where requesting node is also accepting connections
ClusterName
string
ClusterName
string
IdTime
IdTime
IdTime
IdTime
...
@@ -424,8 +424,8 @@ type RequestIdentification struct {
...
@@ -424,8 +424,8 @@ type RequestIdentification struct {
//neo:proto answer
//neo:proto answer
type
AcceptIdentification
struct
{
type
AcceptIdentification
struct
{
NodeType
NodeType
// XXX name
NodeType
NodeType
// XXX name
My
UUID
NodeUU
ID
My
NID
Node
ID
Your
UUID
NodeUU
ID
Your
NID
Node
ID
}
}
// Empty request used as network barrier.
// Empty request used as network barrier.
...
@@ -449,7 +449,7 @@ type PrimaryMaster struct {
...
@@ -449,7 +449,7 @@ type PrimaryMaster struct {
}
}
type
AnswerPrimary
struct
{
type
AnswerPrimary
struct
{
PrimaryNode
UUID
NodeUU
ID
PrimaryNode
ID
Node
ID
}
}
// Notify peer that I'm not the primary master. Attach any extra information
// Notify peer that I'm not the primary master. Attach any extra information
...
@@ -457,7 +457,7 @@ type AnswerPrimary struct {
...
@@ -457,7 +457,7 @@ type AnswerPrimary struct {
//
//
//neo:nodes SM -> *
//neo:nodes SM -> *
type
NotPrimaryMaster
struct
{
type
NotPrimaryMaster
struct
{
Primary
Node
UU
ID
// XXX PSignedNull in py
Primary
NodeID
// XXX PSignedNull in py
KnownMasterList
[]
struct
{
KnownMasterList
[]
struct
{
Address
Address
}
}
...
@@ -613,7 +613,7 @@ type AnswerBeginTransaction struct {
...
@@ -613,7 +613,7 @@ type AnswerBeginTransaction struct {
//neo:nodes C -> M
//neo:nodes C -> M
type
FailedVote
struct
{
type
FailedVote
struct
{
Tid
zodb
.
Tid
Tid
zodb
.
Tid
NodeList
[]
Node
UU
ID
NodeList
[]
NodeID
// answer = Error
// answer = Error
}
}
...
@@ -745,7 +745,7 @@ type AnswerStoreObject struct {
...
@@ -745,7 +745,7 @@ type AnswerStoreObject struct {
//neo:nodes C -> S; C -> M -> S
//neo:nodes C -> S; C -> M -> S
type
AbortTransaction
struct
{
type
AbortTransaction
struct
{
Tid
zodb
.
Tid
Tid
zodb
.
Tid
NodeList
[]
Node
UU
ID
// unused for * -> S
NodeList
[]
NodeID
// unused for * -> S
}
}
// Ask to store a transaction. Implies vote.
// Ask to store a transaction. Implies vote.
...
@@ -844,7 +844,7 @@ type AnswerObjectHistory struct {
...
@@ -844,7 +844,7 @@ type AnswerObjectHistory struct {
type
PartitionList
struct
{
type
PartitionList
struct
{
MinOffset
uint32
// PNumber
MinOffset
uint32
// PNumber
MaxOffset
uint32
// PNumber
MaxOffset
uint32
// PNumber
Node
UUID
NodeUU
ID
Node
ID
Node
ID
}
}
type
AnswerPartitionList
struct
{
type
AnswerPartitionList
struct
{
...
@@ -868,7 +868,7 @@ type AnswerNodeList struct {
...
@@ -868,7 +868,7 @@ type AnswerNodeList struct {
//
//
//neo:nodes ctl -> A -> M
//neo:nodes ctl -> A -> M
type
SetNodeState
struct
{
type
SetNodeState
struct
{
Node
UU
ID
NodeID
NodeState
NodeState
// answer = Error
// answer = Error
...
@@ -879,7 +879,7 @@ type SetNodeState struct {
...
@@ -879,7 +879,7 @@ type SetNodeState struct {
//
//
//neo:nodes ctl -> A -> M
//neo:nodes ctl -> A -> M
type
AddPendingNodes
struct
{
type
AddPendingNodes
struct
{
NodeList
[]
Node
UU
ID
NodeList
[]
NodeID
// answer = Error
// answer = Error
}
}
...
@@ -890,7 +890,7 @@ type AddPendingNodes struct {
...
@@ -890,7 +890,7 @@ type AddPendingNodes struct {
//neo:nodes ctl -> A -> M
//neo:nodes ctl -> A -> M
type
TweakPartitionTable
struct
{
type
TweakPartitionTable
struct
{
DryRun
bool
DryRun
bool
NodeList
[]
Node
UU
ID
NodeList
[]
NodeID
// answer = Error
// answer = Error
}
}
...
@@ -928,7 +928,7 @@ type repairFlags struct {
...
@@ -928,7 +928,7 @@ type repairFlags struct {
//
//
//neo:nodes ctl -> A -> M
//neo:nodes ctl -> A -> M
type
Repair
struct
{
type
Repair
struct
{
NodeList
[]
Node
UU
ID
NodeList
[]
NodeID
repairFlags
repairFlags
}
}
...
@@ -1020,7 +1020,7 @@ type AnswerPack struct {
...
@@ -1020,7 +1020,7 @@ type AnswerPack struct {
//
//
//neo:nodes ctl -> A -> M
//neo:nodes ctl -> A -> M
type
CheckReplicas
struct
{
type
CheckReplicas
struct
{
PartitionDict
map
[
uint32
]
Node
UU
ID
// partition -> source (PNumber)
PartitionDict
map
[
uint32
]
NodeID
// partition -> source (PNumber)
MinTID
zodb
.
Tid
MinTID
zodb
.
Tid
MaxTID
zodb
.
Tid
MaxTID
zodb
.
Tid
...
@@ -1087,7 +1087,7 @@ type AnswerCheckSerialRange struct {
...
@@ -1087,7 +1087,7 @@ type AnswerCheckSerialRange struct {
//neo:nodes S -> M
//neo:nodes S -> M
type
PartitionCorrupted
struct
{
type
PartitionCorrupted
struct
{
Partition
uint32
// PNumber
Partition
uint32
// PNumber
CellList
[]
Node
UU
ID
CellList
[]
NodeID
}
}
// Notify that node is ready to serve requests.
// Notify that node is ready to serve requests.
...
...
go/neo/proto/proto_test.go
View file @
5d5a4372
...
@@ -205,7 +205,7 @@ func TestMsgMarshal(t *testing.T) {
...
@@ -205,7 +205,7 @@ func TestMsgMarshal(t *testing.T) {
hex
(
"c408"
)
+
hex
(
"0a0b0c0d0e0f0104"
),
hex
(
"c408"
)
+
hex
(
"0a0b0c0d0e0f0104"
),
},
},
// PTid, [] (of [] of {
UU
ID, CellState})
// PTid, [] (of [] of {
Node
ID, CellState})
{
&
AnswerPartitionTable
{
{
&
AnswerPartitionTable
{
PTid
:
0x0102030405060708
,
PTid
:
0x0102030405060708
,
NumReplicas
:
34
,
NumReplicas
:
34
,
...
@@ -263,9 +263,9 @@ func TestMsgMarshal(t *testing.T) {
...
@@ -263,9 +263,9 @@ func TestMsgMarshal(t *testing.T) {
hex
(
"c408"
)
+
u64
(
8
)
+
hex
(
"93"
)
+
hex
(
"c408"
)
+
u64
(
7
)
+
hex
(
"c408"
)
+
u64
(
1
)
+
hex
(
"c2"
),
hex
(
"c408"
)
+
u64
(
8
)
+
hex
(
"93"
)
+
hex
(
"c408"
)
+
u64
(
7
)
+
hex
(
"c408"
)
+
u64
(
1
)
+
hex
(
"c2"
),
},
},
// map[uint32]
UU
ID + trailing ...
// map[uint32]
Node
ID + trailing ...
{
&
CheckReplicas
{
{
&
CheckReplicas
{
PartitionDict
:
map
[
uint32
]
Node
UU
ID
{
PartitionDict
:
map
[
uint32
]
NodeID
{
1
:
7
,
1
:
7
,
2
:
9
,
2
:
9
,
7
:
3
,
7
:
3
,
...
@@ -295,7 +295,7 @@ func TestMsgMarshal(t *testing.T) {
...
@@ -295,7 +295,7 @@ func TestMsgMarshal(t *testing.T) {
},
},
// uint32, []uint32
// uint32, []uint32
{
&
PartitionCorrupted
{
7
,
[]
Node
UU
ID
{
1
,
3
,
9
,
4
}},
{
&
PartitionCorrupted
{
7
,
[]
NodeID
{
1
,
3
,
9
,
4
}},
// N
// N
u32
(
7
)
+
u32
(
4
)
+
u32
(
1
)
+
u32
(
3
)
+
u32
(
9
)
+
u32
(
4
),
u32
(
7
)
+
u32
(
4
)
+
u32
(
1
)
+
u32
(
3
)
+
u32
(
9
)
+
u32
(
4
),
...
@@ -329,7 +329,7 @@ func TestMsgMarshal(t *testing.T) {
...
@@ -329,7 +329,7 @@ func TestMsgMarshal(t *testing.T) {
// IdTime, empty Address, int32
// IdTime, empty Address, int32
{
&
NotifyNodeInformation
{
1504466245.926185
,
[]
NodeInfo
{
{
&
NotifyNodeInformation
{
1504466245.926185
,
[]
NodeInfo
{
{
CLIENT
,
Address
{},
UU
ID
(
CLIENT
,
1
),
RUNNING
,
1504466245.925599
}}},
{
CLIENT
,
Address
{},
N
ID
(
CLIENT
,
1
),
RUNNING
,
1504466245.925599
}}},
// N
// N
hex
(
"41d66b15517b469d"
)
+
u32
(
1
)
+
hex
(
"41d66b15517b469d"
)
+
u32
(
1
)
+
u8
(
2
)
+
u32
(
0
)
/* <- ø Address */
+
hex
(
"e0000001"
)
+
u8
(
2
)
+
u8
(
2
)
+
u32
(
0
)
/* <- ø Address */
+
hex
(
"e0000001"
)
+
u8
(
2
)
+
...
@@ -425,8 +425,8 @@ func TestMsgDecodeLenOverflowN(t *testing.T) {
...
@@ -425,8 +425,8 @@ func TestMsgDecodeLenOverflowN(t *testing.T) {
}
}
}
}
func
Test
UU
ID
(
t
*
testing
.
T
)
{
func
Test
N
ID
(
t
*
testing
.
T
)
{
var
testv
=
[]
struct
{
typ
NodeType
;
num
int32
;
uu
id
uint32
;
str
string
}{
var
testv
=
[]
struct
{
typ
NodeType
;
num
int32
;
n
id
uint32
;
str
string
}{
{
STORAGE
,
1
,
0x00000001
,
"S1"
},
{
STORAGE
,
1
,
0x00000001
,
"S1"
},
{
MASTER
,
2
,
0xf0000002
,
"M2"
},
{
MASTER
,
2
,
0xf0000002
,
"M2"
},
{
CLIENT
,
3
,
0xe0000003
,
"C3"
},
{
CLIENT
,
3
,
0xe0000003
,
"C3"
},
...
@@ -434,18 +434,18 @@ func TestUUID(t *testing.T) {
...
@@ -434,18 +434,18 @@ func TestUUID(t *testing.T) {
}
}
for
_
,
tt
:=
range
testv
{
for
_
,
tt
:=
range
testv
{
uuid
:=
UU
ID
(
tt
.
typ
,
tt
.
num
)
nid
:=
N
ID
(
tt
.
typ
,
tt
.
num
)
if
uint32
(
uuid
)
!=
tt
.
uu
id
{
if
uint32
(
nid
)
!=
tt
.
n
id
{
t
.
Errorf
(
"%v:
uuid=%08x ; want %08x"
,
tt
,
uuid
,
tt
.
uu
id
)
t
.
Errorf
(
"%v:
nid=%08x ; want %08x"
,
tt
,
nid
,
tt
.
n
id
)
}
}
if
uuids
:=
uuid
.
String
();
uu
ids
!=
tt
.
str
{
if
nids
:=
nid
.
String
();
n
ids
!=
tt
.
str
{
t
.
Errorf
(
"%v: str(
uuid): %q ; want %q"
,
tt
,
uu
ids
,
tt
.
str
)
t
.
Errorf
(
"%v: str(
nid): %q ; want %q"
,
tt
,
n
ids
,
tt
.
str
)
}
}
}
}
}
}
func
Test
UU
IDDecode
(
t
*
testing
.
T
)
{
func
Test
N
IDDecode
(
t
*
testing
.
T
)
{
var
testv
=
[]
struct
{
uu
id
uint32
;
str
string
}{
var
testv
=
[]
struct
{
n
id
uint32
;
str
string
}{
{
0
,
"?(0)0"
},
{
0
,
"?(0)0"
},
{
0x00000001
,
"S1"
},
{
0x00000001
,
"S1"
},
{
0xf0000002
,
"M2"
},
{
0xf0000002
,
"M2"
},
...
@@ -467,9 +467,9 @@ func TestUUIDDecode(t *testing.T) {
...
@@ -467,9 +467,9 @@ func TestUUIDDecode(t *testing.T) {
}
}
for
_
,
tt
:=
range
testv
{
for
_
,
tt
:=
range
testv
{
str
:=
Node
UUID
(
tt
.
uu
id
)
.
String
()
str
:=
Node
ID
(
tt
.
n
id
)
.
String
()
if
str
!=
tt
.
str
{
if
str
!=
tt
.
str
{
t
.
Errorf
(
"%08x -> %q ; want %q"
,
tt
.
uu
id
,
str
,
tt
.
str
)
t
.
Errorf
(
"%08x -> %q ; want %q"
,
tt
.
n
id
,
str
,
tt
.
str
)
}
}
}
}
}
}
go/neo/proto/zproto-marshal.go
View file @
5d5a4372
This diff is collapsed.
Click to expand it.
go/neo/storage.go
View file @
5d5a4372
...
@@ -208,7 +208,7 @@ func (stor *Storage) talkMaster1(ctx context.Context) (err error) {
...
@@ -208,7 +208,7 @@ func (stor *Storage) talkMaster1(ctx context.Context) (err error) {
defer
xio
.
CloseWhenDone
(
ctx
,
mlink
)()
defer
xio
.
CloseWhenDone
(
ctx
,
mlink
)()
// XXX add master
UU
ID -> nodeTab ? or master will notify us with it himself ?
// XXX add master
N
ID -> nodeTab ? or master will notify us with it himself ?
// XXX move -> SetNumReplicas handler
// XXX move -> SetNumReplicas handler
/*
/*
...
@@ -219,9 +219,9 @@ func (stor *Storage) talkMaster1(ctx context.Context) (err error) {
...
@@ -219,9 +219,9 @@ func (stor *Storage) talkMaster1(ctx context.Context) (err error) {
*/
*/
// XXX -> node.Dial ?
// XXX -> node.Dial ?
if
accept
.
Your
UUID
!=
stor
.
node
.
MyInfo
.
UU
ID
{
if
accept
.
Your
NID
!=
stor
.
node
.
MyInfo
.
N
ID
{
log
.
Infof
(
ctx
,
"master told us to have
uuid=%v"
,
accept
.
YourUU
ID
)
log
.
Infof
(
ctx
,
"master told us to have
nid=%v"
,
accept
.
YourN
ID
)
stor
.
node
.
MyInfo
.
UUID
=
accept
.
YourUU
ID
stor
.
node
.
MyInfo
.
NID
=
accept
.
YourN
ID
}
}
// XXX the first packet M sends always is NotifyNodeInformation (with us)
// XXX the first packet M sends always is NotifyNodeInformation (with us)
...
@@ -325,7 +325,7 @@ func (stor *Storage) m1initialize1(ctx context.Context, req neonet.Request) erro
...
@@ -325,7 +325,7 @@ func (stor *Storage) m1initialize1(ctx context.Context, req neonet.Request) erro
// TODO M sends us δPT -> save locally?
// TODO M sends us δPT -> save locally?
case
*
proto
.
NotifyNodeInformation
:
case
*
proto
.
NotifyNodeInformation
:
// XXX check for my
UU
ID and consider it a command (like neo/py) does?
// XXX check for my
N
ID and consider it a command (like neo/py) does?
stor
.
node
.
UpdateNodeTab
(
ctx
,
msg
)
// XXX lock?
stor
.
node
.
UpdateNodeTab
(
ctx
,
msg
)
// XXX lock?
case
*
proto
.
NotifyClusterState
:
case
*
proto
.
NotifyClusterState
:
...
@@ -410,7 +410,7 @@ func (stor *Storage) m1serve1(ctx context.Context, req neonet.Request) error {
...
@@ -410,7 +410,7 @@ func (stor *Storage) m1serve1(ctx context.Context, req neonet.Request) error {
// identify processes identification request from connected peer.
// identify processes identification request from connected peer.
func
(
stor
*
Storage
)
identify
(
idReq
*
proto
.
RequestIdentification
)
(
proto
.
Msg
,
bool
)
{
func
(
stor
*
Storage
)
identify
(
idReq
*
proto
.
RequestIdentification
)
(
proto
.
Msg
,
bool
)
{
// XXX stub: we accept clients and don't care about their
UU
ID
// XXX stub: we accept clients and don't care about their
N
ID
if
idReq
.
NodeType
!=
proto
.
CLIENT
{
if
idReq
.
NodeType
!=
proto
.
CLIENT
{
return
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
"only clients are accepted"
},
false
return
&
proto
.
Error
{
proto
.
PROTOCOL_ERROR
,
"only clients are accepted"
},
false
}
}
...
@@ -429,8 +429,8 @@ func (stor *Storage) identify(idReq *proto.RequestIdentification) (proto.Msg, bo
...
@@ -429,8 +429,8 @@ func (stor *Storage) identify(idReq *proto.RequestIdentification) (proto.Msg, bo
return
&
proto
.
AcceptIdentification
{
return
&
proto
.
AcceptIdentification
{
NodeType
:
stor
.
node
.
MyInfo
.
Type
,
NodeType
:
stor
.
node
.
MyInfo
.
Type
,
My
UUID
:
stor
.
node
.
MyInfo
.
UU
ID
,
// XXX lock wrt update
My
NID
:
stor
.
node
.
MyInfo
.
N
ID
,
// XXX lock wrt update
Your
UUID
:
idReq
.
UU
ID
,
Your
NID
:
idReq
.
N
ID
,
},
true
},
true
}
}
...
...
go/neo/storage/sqlite/sqlite.go
View file @
5d5a4372
// Copyright (C) 2018-202
0
Nexedi SA and Contributors.
// Copyright (C) 2018-202
1
Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
// Kirill Smelkov <kirr@nexedi.com>
// schema & queries are based on neo/storage/database/sqlite.py
// schema & queries are based on neo/storage/database/sqlite.py
//
//
...
@@ -534,7 +534,7 @@ func Open(dburl string) (_ *Backend, err error) {
...
@@ -534,7 +534,7 @@ func Open(dburl string) (_ *Backend, err error) {
}
}
checkConfig
(
"version"
,
schemaVersion
)
checkConfig
(
"version"
,
schemaVersion
)
checkConfig
(
"nid"
,
int
(
proto
.
UU
ID
(
proto
.
STORAGE
,
1
)))
checkConfig
(
"nid"
,
int
(
proto
.
N
ID
(
proto
.
STORAGE
,
1
)))
checkConfig
(
"replicas"
,
0
)
// XXX neo/py uses nreplicas as 1 + n(replica)
checkConfig
(
"replicas"
,
0
)
// XXX neo/py uses nreplicas as 1 + n(replica)
err
=
errv
.
Err
()
err
=
errv
.
Err
()
...
...
go/neo/t_cluster_test.go
View file @
5d5a4372
...
@@ -430,7 +430,7 @@ func (t0 *tEnv) NewCluster_MS(name string, Sback storage.Backend) *tCluster {
...
@@ -430,7 +430,7 @@ func (t0 *tEnv) NewCluster_MS(name string, Sback storage.Backend) *tCluster {
t
.
Expect
(
"s-m"
,
netconnect
(
"s:2"
,
"m:2"
,
"m:1"
))
t
.
Expect
(
"s-m"
,
netconnect
(
"s:2"
,
"m:2"
,
"m:1"
))
t
.
Expect
(
"s-m"
,
conntx
(
"s:2"
,
"m:2"
,
1
,
&
proto
.
RequestIdentification
{
t
.
Expect
(
"s-m"
,
conntx
(
"s:2"
,
"m:2"
,
1
,
&
proto
.
RequestIdentification
{
NodeType
:
proto
.
STORAGE
,
NodeType
:
proto
.
STORAGE
,
UU
ID
:
0
,
N
ID
:
0
,
Address
:
xnaddr
(
"s:1"
),
Address
:
xnaddr
(
"s:1"
),
ClusterName
:
name
,
ClusterName
:
name
,
IdTime
:
proto
.
IdTimeNone
,
IdTime
:
proto
.
IdTimeNone
,
...
@@ -442,8 +442,8 @@ func (t0 *tEnv) NewCluster_MS(name string, Sback storage.Backend) *tCluster {
...
@@ -442,8 +442,8 @@ func (t0 *tEnv) NewCluster_MS(name string, Sback storage.Backend) *tCluster {
t
.
Expect
(
"s-m"
,
conntx
(
"m:2"
,
"s:2"
,
1
,
&
proto
.
AcceptIdentification
{
t
.
Expect
(
"s-m"
,
conntx
(
"m:2"
,
"s:2"
,
1
,
&
proto
.
AcceptIdentification
{
NodeType
:
proto
.
MASTER
,
NodeType
:
proto
.
MASTER
,
My
UUID
:
proto
.
UU
ID
(
proto
.
MASTER
,
1
),
My
NID
:
proto
.
N
ID
(
proto
.
MASTER
,
1
),
Your
UUID
:
proto
.
UU
ID
(
proto
.
STORAGE
,
1
),
Your
NID
:
proto
.
N
ID
(
proto
.
STORAGE
,
1
),
}))
}))
// M starts recovery on S
// M starts recovery on S
...
...
go/neo/t_events_test.go
View file @
5d5a4372
...
@@ -132,7 +132,7 @@ func nodei(laddr string, typ proto.NodeType, num int32, state proto.NodeState, i
...
@@ -132,7 +132,7 @@ func nodei(laddr string, typ proto.NodeType, num int32, state proto.NodeState, i
return
proto
.
NodeInfo
{
return
proto
.
NodeInfo
{
Type
:
typ
,
Type
:
typ
,
Addr
:
xnaddr
(
laddr
),
Addr
:
xnaddr
(
laddr
),
UUID
:
proto
.
UU
ID
(
typ
,
num
),
NID
:
proto
.
N
ID
(
typ
,
num
),
State
:
state
,
State
:
state
,
IdTime
:
idtime
,
IdTime
:
idtime
,
}
}
...
...
go/neo/xneo/nodetab.go
View file @
5d5a4372
...
@@ -39,9 +39,9 @@ import (
...
@@ -39,9 +39,9 @@ import (
//
//
// It is
// It is
//
//
//
UU
ID -> *Node
//
N
ID -> *Node
//
//
// mapping listing known nodes and associating their
uuid
with information
// mapping listing known nodes and associating their
node ID
with information
// about a node.
// about a node.
//
//
// Master maintains such table and provides it to its peers to know each other:
// Master maintains such table and provides it to its peers to know each other:
...
@@ -53,8 +53,8 @@ import (
...
@@ -53,8 +53,8 @@ import (
//
//
// Usage examples:
// Usage examples:
//
//
// - C needs to connect/talk to a storage by
uu
id
// - C needs to connect/talk to a storage by
n
id
// (the
uu
id itself is obtained from PartitionTable by oid).
// (the
n
id itself is obtained from PartitionTable by oid).
// - S pulls from other S.
// - S pulls from other S.
//
//
// NOTE once a node was added to NodeTable its entry is never deleted: if e.g.
// NOTE once a node was added to NodeTable its entry is never deleted: if e.g.
...
@@ -82,7 +82,7 @@ type NodeTable struct {
...
@@ -82,7 +82,7 @@ type NodeTable struct {
type
Node
struct
{
type
Node
struct
{
nodeTab
*
NodeTable
// this node is part of
nodeTab
*
NodeTable
// this node is part of
proto
.
NodeInfo
// .type, .addr, .
uu
id, ... XXX also protect by mu?
proto
.
NodeInfo
// .type, .addr, .
n
id, ... XXX also protect by mu?
linkMu
sync
.
Mutex
linkMu
sync
.
Mutex
link
*
neonet
.
NodeLink
// link to this peer; nil if not connected
link
*
neonet
.
NodeLink
// link to this peer; nil if not connected
...
@@ -118,11 +118,11 @@ func (nt *NodeTable) All() []*Node {
...
@@ -118,11 +118,11 @@ func (nt *NodeTable) All() []*Node {
return
nt
.
nodev
return
nt
.
nodev
}
}
// Get finds node by
uuid
.
// Get finds node by
node ID
.
func
(
nt
*
NodeTable
)
Get
(
uuid
proto
.
NodeUU
ID
)
*
Node
{
func
(
nt
*
NodeTable
)
Get
(
nid
proto
.
Node
ID
)
*
Node
{
// FIXME linear scan
// FIXME linear scan
for
_
,
node
:=
range
nt
.
nodev
{
for
_
,
node
:=
range
nt
.
nodev
{
if
node
.
UUID
==
uu
id
{
if
node
.
NID
==
n
id
{
return
node
return
node
}
}
}
}
...
@@ -135,7 +135,7 @@ func (nt *NodeTable) Get(uuid proto.NodeUUID) *Node {
...
@@ -135,7 +135,7 @@ func (nt *NodeTable) Get(uuid proto.NodeUUID) *Node {
//
//
// it returns corresponding node entry for convenience.
// it returns corresponding node entry for convenience.
func
(
nt
*
NodeTable
)
Update
(
nodeInfo
proto
.
NodeInfo
)
*
Node
{
func
(
nt
*
NodeTable
)
Update
(
nodeInfo
proto
.
NodeInfo
)
*
Node
{
node
:=
nt
.
Get
(
nodeInfo
.
UU
ID
)
node
:=
nt
.
Get
(
nodeInfo
.
N
ID
)
if
node
==
nil
{
if
node
==
nil
{
node
=
&
Node
{
nodeTab
:
nt
}
node
=
&
Node
{
nodeTab
:
nt
}
nt
.
nodev
=
append
(
nt
.
nodev
,
node
)
nt
.
nodev
=
append
(
nt
.
nodev
,
node
)
...
@@ -185,7 +185,7 @@ func (nt *NodeTable) String() string {
...
@@ -185,7 +185,7 @@ func (nt *NodeTable) String() string {
// XXX also for .storv
// XXX also for .storv
for
_
,
n
:=
range
nt
.
nodev
{
for
_
,
n
:=
range
nt
.
nodev
{
// XXX recheck output
// XXX recheck output
fmt
.
Fprintf
(
&
buf
,
"%s (%s)
\t
%s
\t
%s
\t
@ %s
\n
"
,
n
.
UU
ID
,
n
.
Type
,
n
.
State
,
n
.
Addr
,
n
.
IdTime
)
fmt
.
Fprintf
(
&
buf
,
"%s (%s)
\t
%s
\t
%s
\t
@ %s
\n
"
,
n
.
N
ID
,
n
.
Type
,
n
.
State
,
n
.
Addr
,
n
.
IdTime
)
}
}
return
buf
.
String
()
return
buf
.
String
()
...
@@ -331,7 +331,7 @@ func (p *Node) CloseLink(ctx context.Context) {
...
@@ -331,7 +331,7 @@ func (p *Node) CloseLink(ctx context.Context) {
// XXX p.* reading without lock - ok?
// XXX p.* reading without lock - ok?
// XXX app.MyInfo without lock - ok?
// XXX app.MyInfo without lock - ok?
func
(
p
*
Node
)
dial
(
ctx
context
.
Context
)
(
_
*
neonet
.
NodeLink
,
err
error
)
{
func
(
p
*
Node
)
dial
(
ctx
context
.
Context
)
(
_
*
neonet
.
NodeLink
,
err
error
)
{
defer
task
.
Runningf
(
&
ctx
,
"connect %s"
,
p
.
UU
ID
)(
&
err
)
// XXX "connect" good word here?
defer
task
.
Runningf
(
&
ctx
,
"connect %s"
,
p
.
N
ID
)(
&
err
)
// XXX "connect" good word here?
app
:=
p
.
nodeTab
.
nodeApp
app
:=
p
.
nodeTab
.
nodeApp
link
,
accept
,
err
:=
app
.
Dial
(
ctx
,
p
.
Type
,
p
.
Addr
.
String
())
link
,
accept
,
err
:=
app
.
Dial
(
ctx
,
p
.
Type
,
p
.
Addr
.
String
())
...
@@ -343,11 +343,11 @@ func (p *Node) dial(ctx context.Context) (_ *neonet.NodeLink, err error) {
...
@@ -343,11 +343,11 @@ func (p *Node) dial(ctx context.Context) (_ *neonet.NodeLink, err error) {
switch
{
switch
{
// type is already checked by app.Dial
// type is already checked by app.Dial
case
accept
.
My
UUID
!=
p
.
UU
ID
:
case
accept
.
My
NID
!=
p
.
N
ID
:
err
=
fmt
.
Errorf
(
"connected, but peer's
uuid is not %v (identifies as %v)"
,
p
.
UUID
,
accept
.
MyUU
ID
)
err
=
fmt
.
Errorf
(
"connected, but peer's
nid is not %v (identifies as %v)"
,
p
.
NID
,
accept
.
MyN
ID
)
case
accept
.
Your
UUID
!=
app
.
MyInfo
.
UU
ID
:
case
accept
.
Your
NID
!=
app
.
MyInfo
.
N
ID
:
err
=
fmt
.
Errorf
(
"connected, but peer gives us
uuid %v (our is %v)"
,
accept
.
YourUUID
,
app
.
MyInfo
.
UU
ID
)
err
=
fmt
.
Errorf
(
"connected, but peer gives us
nid %v (our is %v)"
,
accept
.
YourNID
,
app
.
MyInfo
.
N
ID
)
// XXX Node.Dial is currently used by Client only.
// XXX Node.Dial is currently used by Client only.
// XXX For Client it would be not correct to check #partition only at
// XXX For Client it would be not correct to check #partition only at
...
...
go/neo/xneo/parttab.go
View file @
5d5a4372
...
@@ -32,7 +32,7 @@ import (
...
@@ -32,7 +32,7 @@ import (
//
//
// It is
// It is
//
//
// oid -> []
uu
id
// oid -> []
n
id
//
//
// mapping associating object ID with list of storage nodes on where data for
// mapping associating object ID with list of storage nodes on where data for
// this oid should be written-to/loaded-from. This mapping is organized as follows:
// this oid should be written-to/loaded-from. This mapping is organized as follows:
...
@@ -124,7 +124,7 @@ type PartitionTable struct {
...
@@ -124,7 +124,7 @@ type PartitionTable struct {
// Cell describes one storage in a pid entry in partition table
// Cell describes one storage in a pid entry in partition table
type
Cell
struct
{
type
Cell
struct
{
proto
.
CellInfo
// .
uu
id + .state
proto
.
CellInfo
// .
n
id + .state
// XXX ? + .haveUpToTid associated node has data up to such tid
// XXX ? + .haveUpToTid associated node has data up to such tid
// = uptodate if haveUpToTid == lastTid
// = uptodate if haveUpToTid == lastTid
...
@@ -165,8 +165,8 @@ func MakePartTab(np int, nodev []*Node) *PartitionTable {
...
@@ -165,8 +165,8 @@ func MakePartTab(np int, nodev []*Node) *PartitionTable {
for
i
,
j
:=
0
,
0
;
i
<
np
;
i
,
j
=
i
+
1
,
j
+
1
%
len
(
nodev
)
{
for
i
,
j
:=
0
,
0
;
i
<
np
;
i
,
j
=
i
+
1
,
j
+
1
%
len
(
nodev
)
{
node
:=
nodev
[
j
]
node
:=
nodev
[
j
]
// XXX assert node.State > DOWN
// XXX assert node.State > DOWN
//fmt.Printf("tab[%d] <- %v\n", i, node.
UU
ID)
//fmt.Printf("tab[%d] <- %v\n", i, node.
N
ID)
tab
[
i
]
=
[]
Cell
{{
CellInfo
:
proto
.
CellInfo
{
node
.
UU
ID
,
proto
.
UP_TO_DATE
/*XXX ok?*/
}}}
tab
[
i
]
=
[]
Cell
{{
CellInfo
:
proto
.
CellInfo
{
node
.
N
ID
,
proto
.
UP_TO_DATE
/*XXX ok?*/
}}}
}
}
return
&
PartitionTable
{
tab
:
tab
}
return
&
PartitionTable
{
tab
:
tab
}
...
@@ -181,7 +181,7 @@ func MakePartTab(np int, nodev []*Node) *PartitionTable {
...
@@ -181,7 +181,7 @@ func MakePartTab(np int, nodev []*Node) *PartitionTable {
//
//
// information about nodes being up or down is obtained from supplied NodeTable
// information about nodes being up or down is obtained from supplied NodeTable
//
//
// XXX or keep not only Node
UU
ID in Cell - add *Node ?
// XXX or keep not only NodeID in Cell - add *Node ?
func
(
pt
*
PartitionTable
)
OperationalWith
(
nt
*
NodeTable
)
bool
{
func
(
pt
*
PartitionTable
)
OperationalWith
(
nt
*
NodeTable
)
bool
{
// empty partition table is never operational
// empty partition table is never operational
if
len
(
pt
.
tab
)
==
0
{
if
len
(
pt
.
tab
)
==
0
{
...
@@ -203,7 +203,7 @@ func (pt *PartitionTable) OperationalWith(nt *NodeTable) bool {
...
@@ -203,7 +203,7 @@ func (pt *PartitionTable) OperationalWith(nt *NodeTable) bool {
// to last_tid.
// to last_tid.
//
//
// We leave it as is for now.
// We leave it as is for now.
node
:=
nt
.
Get
(
cell
.
UU
ID
)
node
:=
nt
.
Get
(
cell
.
N
ID
)
if
node
==
nil
||
node
.
State
!=
proto
.
RUNNING
{
// XXX PENDING is also ok ?
if
node
==
nil
||
node
.
State
!=
proto
.
RUNNING
{
// XXX PENDING is also ok ?
continue
continue
}
}
...
@@ -237,7 +237,7 @@ func (pt *PartitionTable) String() string {
...
@@ -237,7 +237,7 @@ func (pt *PartitionTable) String() string {
}
}
for
_
,
cell
:=
range
cellv
{
for
_
,
cell
:=
range
cellv
{
fmt
.
Fprintf
(
buf
,
" %s(%s)"
,
cell
.
UU
ID
,
cell
.
State
)
fmt
.
Fprintf
(
buf
,
" %s(%s)"
,
cell
.
N
ID
,
cell
.
State
)
}
}
fmt
.
Fprintf
(
buf
,
"
\n
"
)
fmt
.
Fprintf
(
buf
,
"
\n
"
)
}
}
...
...
go/neo/xneo/parttab_test.go
View file @
5d5a4372
...
@@ -26,15 +26,15 @@ import (
...
@@ -26,15 +26,15 @@ import (
)
)
func
TestPartTabOperational
(
t
*
testing
.
T
)
{
func
TestPartTabOperational
(
t
*
testing
.
T
)
{
s1
:=
proto
.
UU
ID
(
proto
.
STORAGE
,
1
)
s1
:=
proto
.
N
ID
(
proto
.
STORAGE
,
1
)
s2
:=
proto
.
UU
ID
(
proto
.
STORAGE
,
2
)
s2
:=
proto
.
N
ID
(
proto
.
STORAGE
,
2
)
// create nodeinfo for
uu
id/state
// create nodeinfo for
n
id/state
n
:=
func
(
uuid
proto
.
NodeUU
ID
,
state
proto
.
NodeState
)
proto
.
NodeInfo
{
n
:=
func
(
nid
proto
.
Node
ID
,
state
proto
.
NodeState
)
proto
.
NodeInfo
{
return
proto
.
NodeInfo
{
UUID
:
uu
id
,
State
:
state
}
// XXX .Type?
return
proto
.
NodeInfo
{
NID
:
n
id
,
State
:
state
}
// XXX .Type?
}
}
// create nodetab with [](
uu
id, state)
// create nodetab with [](
n
id, state)
N
:=
func
(
nodeiv
...
proto
.
NodeInfo
)
*
NodeTable
{
N
:=
func
(
nodeiv
...
proto
.
NodeInfo
)
*
NodeTable
{
nt
:=
&
NodeTable
{}
nt
:=
&
NodeTable
{}
for
_
,
nodei
:=
range
nodeiv
{
for
_
,
nodei
:=
range
nodeiv
{
...
@@ -43,9 +43,9 @@ func TestPartTabOperational(t *testing.T) {
...
@@ -43,9 +43,9 @@ func TestPartTabOperational(t *testing.T) {
return
nt
return
nt
}
}
// create cell with
uu
id/state
// create cell with
n
id/state
C
:=
func
(
uuid
proto
.
NodeUU
ID
,
state
proto
.
CellState
)
Cell
{
C
:=
func
(
nid
proto
.
Node
ID
,
state
proto
.
CellState
)
Cell
{
return
Cell
{
proto
.
CellInfo
{
UUID
:
uu
id
,
State
:
state
}}
return
Cell
{
proto
.
CellInfo
{
NID
:
n
id
,
State
:
state
}}
}
}
// shortcut to create []Cell
// shortcut to create []Cell
...
...
go/neo/xneo/xneo.go
View file @
5d5a4372
...
@@ -66,7 +66,7 @@ type NodeApp struct {
...
@@ -66,7 +66,7 @@ type NodeApp struct {
// NewNodeApp creates new node application
// NewNodeApp creates new node application
func
NewNodeApp
(
net
xnet
.
Networker
,
typ
proto
.
NodeType
,
clusterName
,
masterAddr
string
)
*
NodeApp
{
func
NewNodeApp
(
net
xnet
.
Networker
,
typ
proto
.
NodeType
,
clusterName
,
masterAddr
string
)
*
NodeApp
{
app
:=
&
NodeApp
{
app
:=
&
NodeApp
{
MyInfo
:
proto
.
NodeInfo
{
Type
:
typ
,
Addr
:
proto
.
Address
{},
UU
ID
:
0
,
IdTime
:
proto
.
IdTimeNone
},
MyInfo
:
proto
.
NodeInfo
{
Type
:
typ
,
Addr
:
proto
.
Address
{},
N
ID
:
0
,
IdTime
:
proto
.
IdTimeNone
},
ClusterName
:
clusterName
,
ClusterName
:
clusterName
,
Net
:
net
,
Net
:
net
,
MasterAddr
:
masterAddr
,
MasterAddr
:
masterAddr
,
...
@@ -116,7 +116,7 @@ func (app *NodeApp) Dial(ctx context.Context, peerType proto.NodeType, addr stri
...
@@ -116,7 +116,7 @@ func (app *NodeApp) Dial(ctx context.Context, peerType proto.NodeType, addr stri
req
:=
&
proto
.
RequestIdentification
{
req
:=
&
proto
.
RequestIdentification
{
NodeType
:
app
.
MyInfo
.
Type
,
NodeType
:
app
.
MyInfo
.
Type
,
UUID
:
app
.
MyInfo
.
UU
ID
,
NID
:
app
.
MyInfo
.
N
ID
,
Address
:
app
.
MyInfo
.
Addr
,
Address
:
app
.
MyInfo
.
Addr
,
ClusterName
:
app
.
ClusterName
,
ClusterName
:
app
.
ClusterName
,
IdTime
:
app
.
MyInfo
.
IdTime
,
// XXX ok?
IdTime
:
app
.
MyInfo
.
IdTime
,
// XXX ok?
...
@@ -146,8 +146,8 @@ func (app *NodeApp) Dial(ctx context.Context, peerType proto.NodeType, addr stri
...
@@ -146,8 +146,8 @@ func (app *NodeApp) Dial(ctx context.Context, peerType proto.NodeType, addr stri
return
nil
,
nil
,
fmt
.
Errorf
(
"accepted, but peer is not %v (identifies as %v)"
,
peerType
,
accept
.
NodeType
)
return
nil
,
nil
,
fmt
.
Errorf
(
"accepted, but peer is not %v (identifies as %v)"
,
peerType
,
accept
.
NodeType
)
}
}
// XXX accept.My
UUID, link
// XXX register .NodeTab? no -> LinkTab as NodeTab is driven by M
// XXX accept.My
NID, link
// XXX register .NodeTab? no -> LinkTab as NodeTab is driven by M
// XXX accept.Your
UUID // XXX M can tell us to change UU
ID -> take in effect
// XXX accept.Your
NID // XXX M can tell us to change N
ID -> take in effect
// XXX accept.NumPartitions, ... wrt app.node.PartTab
// XXX accept.NumPartitions, ... wrt app.node.PartTab
log
.
Info
(
ctx
,
"identification accepted"
)
log
.
Info
(
ctx
,
"identification accepted"
)
...
@@ -232,7 +232,7 @@ func (app *NodeApp) UpdateNodeTab(ctx context.Context, msg *proto.NotifyNodeInfo
...
@@ -232,7 +232,7 @@ func (app *NodeApp) UpdateNodeTab(ctx context.Context, msg *proto.NotifyNodeInfo
// XXX we have to provide IdTime when requesting identification to other peers
// 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")
// (e.g. Spy checks this is what master broadcast them and if not replies "unknown by master")
if
nodeInfo
.
UUID
==
app
.
MyInfo
.
UU
ID
{
if
nodeInfo
.
NID
==
app
.
MyInfo
.
N
ID
{
// XXX recheck locking
// XXX recheck locking
// XXX do .MyInfo = nodeInfo ?
// XXX do .MyInfo = nodeInfo ?
app
.
MyInfo
.
IdTime
=
nodeInfo
.
IdTime
app
.
MyInfo
.
IdTime
=
nodeInfo
.
IdTime
...
...
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