Commit be36b5ee authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/proto: UUID -> NID (NodeID)

NEO/py switched from UUID to 4-byte NodeID long time ago in
nexedi/neoppod@23fad3af and has a TODO to
rename uuid to nid.

NEO protocol also talks about renaming uuid to nid:

    note: the uuid variable should be renamed into nid
    https://neo.nexedi.com/P-NEO-Protocol.Specification.2019?portal_skin=CI_slideshow#/9/5

NEO/go can do the rename now.
parent f76d824c
......@@ -59,22 +59,22 @@ func (e *Error) Error() string {
// 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)
......@@ -100,8 +100,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)
......@@ -121,9 +121,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)
}
// ----------------------------------------
......
......@@ -88,7 +88,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
......@@ -263,7 +263,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:
//
......@@ -272,17 +272,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.
......@@ -373,14 +373,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
}
......@@ -408,7 +408,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
......@@ -420,8 +420,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.
......@@ -445,7 +445,7 @@ type PrimaryMaster struct {
}
type AnswerPrimary struct {
PrimaryNodeUUID NodeUUID
PrimaryNodeID NodeID
}
// Notify peer that I'm not the primary master. Attach any extra information
......@@ -453,7 +453,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
}
......@@ -609,7 +609,7 @@ type AnswerBeginTransaction struct {
//neo:nodes C -> M
type FailedVote struct {
Tid zodb.Tid
NodeList []NodeUUID
NodeList []NodeID
// answer = Error
}
......@@ -741,7 +741,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.
......@@ -840,7 +840,7 @@ type AnswerObjectHistory struct {
type PartitionList struct {
MinOffset uint32 // PNumber
MaxOffset uint32 // PNumber
NodeUUID NodeUUID
NodeID NodeID
}
type AnswerPartitionList struct {
......@@ -864,7 +864,7 @@ type AnswerNodeList struct {
//
//neo:nodes ctl -> A -> M
type SetNodeState struct {
NodeUUID
NodeID
NodeState
// answer = Error
......@@ -875,7 +875,7 @@ type SetNodeState struct {
//
//neo:nodes ctl -> A -> M
type AddPendingNodes struct {
NodeList []NodeUUID
NodeList []NodeID
// answer = Error
}
......@@ -886,7 +886,7 @@ type AddPendingNodes struct {
//neo:nodes ctl -> A -> M
type TweakPartitionTable struct {
DryRun bool
NodeList []NodeUUID
NodeList []NodeID
// answer = Error
}
......@@ -924,7 +924,7 @@ type repairFlags struct {
//
//neo:nodes ctl -> A -> M
type Repair struct {
NodeList []NodeUUID
NodeList []NodeID
repairFlags
}
......@@ -1016,7 +1016,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
......@@ -1083,7 +1083,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.
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