Commit 5d5a4372 authored by Kirill Smelkov's avatar Kirill Smelkov

X UUID -> NID (NodeID)

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