Commit 72eab8e6 authored by Levin Zimmermann's avatar Levin Zimmermann

go/neo/proto: Update enum order to new protocol

The enum order has changed in the migration to the msgpack encoded
protocol.

See here for pre-msgpack order:

https://lab.nexedi.com/nexedi/neoppod/-/blob/6332112cb/neo/lib/protocol.py#L62-141

And here for post-msgpack order:

https://lab.nexedi.com/nexedi/neoppod/-/blob/9d0bf97a1327182ac29e95d65fd9e18742c43d1f/neo/lib/protocol.py#L102-181

As this order defines the encoding of the enum values, this needs to be
strictly followed to be compatible (to follow the protocol declaration).
parent 3eefaf31
......@@ -174,21 +174,24 @@ var ErrDecodeOverflow = errors.New("decode: buffer overflow")
// ---- messages ----
//neo:proto enum
type ErrorCode uint32
type CellState int8
const (
ACK ErrorCode = iota
DENIED
NOT_READY
OID_NOT_FOUND
TID_NOT_FOUND
OID_DOES_NOT_EXIST
PROTOCOL_ERROR
REPLICATION_ERROR
CHECKING_ERROR
BACKEND_NOT_IMPLEMENTED
NON_READABLE_CELL
READ_ONLY_ACCESS
INCOMPLETE_TRANSACTION
// Write-only cell. Last transactions are missing because storage is/was down
// for a while, or because it is new for the partition. It usually becomes
// UP_TO_DATE when replication is done.
OUT_OF_DATE CellState = iota //short: O // XXX tag prefix name ?
// Normal state: cell is writable/readable, and it isn't planned to drop it.
UP_TO_DATE //short: U
// Same as UP_TO_DATE, except that it will be discarded as soon as another
// node finishes to replicate it. It means a partition is moved from 1 node
// to another. It is also discarded immediately if out-of-date.
FEEDING //short: F
// A check revealed that data differs from other replicas. Cell is neither
// readable nor writable.
CORRUPTED //short: C
// Not really a state: only used in network messages to tell storages to drop
// partitions.
DISCARDED //short: D
)
// XXX move this to neo.clusterState wrapping proto.ClusterState?
......@@ -229,12 +232,21 @@ const (
)
//neo:proto enum
type NodeType int8
type ErrorCode uint32
const (
MASTER NodeType = iota
STORAGE
CLIENT
ADMIN
ACK ErrorCode = iota
DENIED
NOT_READY
OID_NOT_FOUND
TID_NOT_FOUND
OID_DOES_NOT_EXIST
PROTOCOL_ERROR
REPLICATION_ERROR
CHECKING_ERROR
BACKEND_NOT_IMPLEMENTED
NON_READABLE_CELL
READ_ONLY_ACCESS
INCOMPLETE_TRANSACTION
)
//neo:proto enum
......@@ -247,24 +259,12 @@ const (
)
//neo:proto enum
type CellState int8
type NodeType int8
const (
// Write-only cell. Last transactions are missing because storage is/was down
// for a while, or because it is new for the partition. It usually becomes
// UP_TO_DATE when replication is done.
OUT_OF_DATE CellState = iota //short: O // XXX tag prefix name ?
// Normal state: cell is writable/readable, and it isn't planned to drop it.
UP_TO_DATE //short: U
// Same as UP_TO_DATE, except that it will be discarded as soon as another
// node finishes to replicate it. It means a partition is moved from 1 node
// to another. It is also discarded immediately if out-of-date.
FEEDING //short: F
// A check revealed that data differs from other replicas. Cell is neither
// readable nor writable.
CORRUPTED //short: C
// Not really a state: only used in network messages to tell storages to drop
// partitions.
DISCARDED //short: D
MASTER NodeType = iota
STORAGE
CLIENT
ADMIN
)
// NodeID is a node identifier, 4-bytes signed integer
......
......@@ -175,7 +175,7 @@ func TestMsgMarshal(t *testing.T) {
// uint32(N)/enum(M), string
{&Error{Code: 0x00000045, Message: "hello"},
"\x00\x00\x00\x45\x00\x00\x00\x05hello",
hex("92") + hex("d40045") + "\xc4\x05hello",
hex("92") + hex("d40245") + "\xc4\x05hello",
},
// Oid, Tid, bool, Checksum, []byte
......@@ -229,9 +229,9 @@ func TestMsgMarshal(t *testing.T) {
hex("cf0102030405060708") +
hex("22") +
hex("93") +
hex("91"+"92"+"920bd40401"+"9211d40400") +
hex("91"+"91"+"920bd40402") +
hex("91"+"93"+"920bd40403"+"920fd40404"+"9217d40401"),
hex("91"+"92"+"920bd40001"+"9211d40000") +
hex("91"+"91"+"920bd40002") +
hex("91"+"93"+"920bd40003"+"920fd40004"+"9217d40001"),
},
// map[Oid]struct {Tid,Tid,bool}
......@@ -318,7 +318,7 @@ func TestMsgMarshal(t *testing.T) {
// M
hex("97") +
hex("d40202") +
hex("d40402") +
hex("11") +
hex("92") + hex("c409")+"localhost" + hex("cd")+u16(7777) +
hex("c406")+"myname" +
......@@ -339,7 +339,7 @@ func TestMsgMarshal(t *testing.T) {
hex("cb" + "41d66b15517b469d") +
hex("91") +
hex("95") +
hex("d40202") +
hex("d40402") +
hex("92" + "c400"+"" + "00") +
hex("d2" + "e0000001") +
hex("d40302") +
......
......@@ -68,7 +68,7 @@ func (p *Error) neoMsgEncodedLenM() int {
func (p *Error) neoMsgEncodeM(data []byte) {
data[0] = byte(msgpack.FixArray_4 | 2)
data[1] = byte(msgpack.FixExt1)
data[2] = 0
data[2] = 2
if !(0 <= p.Code && p.Code <= 0x7f) {
panic("p.Code: invalid ErrorCode enum value)")
}
......@@ -93,8 +93,8 @@ func (p *Error) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[1]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("Error.Code", op, msgpack.FixExt1)
}
if enumType := data[2]; enumType != 0 {
return 0, mdecodeEnumTypeErr("Error.Code", enumType, 0)
if enumType := data[2]; enumType != 2 {
return 0, mdecodeEnumTypeErr("Error.Code", enumType, 2)
}
{
v := data[3]
......@@ -280,7 +280,7 @@ func (p *RequestIdentification) neoMsgEncodedLenM() int {
func (p *RequestIdentification) neoMsgEncodeM(data []byte) {
data[0] = byte(msgpack.FixArray_4 | 7)
data[1] = byte(msgpack.FixExt1)
data[2] = 2
data[2] = 4
if !(0 <= p.NodeType && p.NodeType <= 0x7f) {
panic("p.NodeType: invalid NodeType enum value)")
}
......@@ -350,8 +350,8 @@ func (p *RequestIdentification) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[1]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("RequestIdentification.NodeType", op, msgpack.FixExt1)
}
if enumType := data[2]; enumType != 2 {
return 0, mdecodeEnumTypeErr("RequestIdentification.NodeType", enumType, 2)
if enumType := data[2]; enumType != 4 {
return 0, mdecodeEnumTypeErr("RequestIdentification.NodeType", enumType, 4)
}
{
v := data[3]
......@@ -497,7 +497,7 @@ func (p *AcceptIdentification) neoMsgEncodedLenM() int {
func (p *AcceptIdentification) neoMsgEncodeM(data []byte) {
data[0] = byte(msgpack.FixArray_4 | 3)
data[1] = byte(msgpack.FixExt1)
data[2] = 2
data[2] = 4
if !(0 <= p.NodeType && p.NodeType <= 0x7f) {
panic("p.NodeType: invalid NodeType enum value)")
}
......@@ -523,8 +523,8 @@ func (p *AcceptIdentification) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[1]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("AcceptIdentification.NodeType", op, msgpack.FixExt1)
}
if enumType := data[2]; enumType != 2 {
return 0, mdecodeEnumTypeErr("AcceptIdentification.NodeType", enumType, 2)
if enumType := data[2]; enumType != 4 {
return 0, mdecodeEnumTypeErr("AcceptIdentification.NodeType", enumType, 4)
}
{
v := data[3]
......@@ -1050,7 +1050,7 @@ func (p *NotifyNodeInformation) neoMsgEncodeM(data []byte) {
a := &p.NodeList[i]
data[0] = byte(msgpack.FixArray_4 | 5)
data[1] = byte(msgpack.FixExt1)
data[2] = 2
data[2] = 4
if !(0 <= (*a).Type && (*a).Type <= 0x7f) {
panic("(*a).Type: invalid NodeType enum value)")
}
......@@ -1121,8 +1121,8 @@ func (p *NotifyNodeInformation) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[1]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("NotifyNodeInformation.Type", op, msgpack.FixExt1)
}
if enumType := data[2]; enumType != 2 {
return 0, mdecodeEnumTypeErr("NotifyNodeInformation.Type", enumType, 2)
if enumType := data[2]; enumType != 4 {
return 0, mdecodeEnumTypeErr("NotifyNodeInformation.Type", enumType, 4)
}
{
v := data[3]
......@@ -1588,7 +1588,7 @@ func (p *AnswerPartitionTable) neoMsgEncodeM(data []byte) {
data = data[1+n:]
}
data[0] = byte(msgpack.FixExt1)
data[1] = 4
data[1] = 0
if !(0 <= (*a).State && (*a).State <= 0x7f) {
panic("(*a).State: invalid CellState enum value)")
}
......@@ -1676,8 +1676,8 @@ func (p *AnswerPartitionTable) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[0]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("AnswerPartitionTable.State", op, msgpack.FixExt1)
}
if enumType := data[1]; enumType != 4 {
return 0, mdecodeEnumTypeErr("AnswerPartitionTable.State", enumType, 4)
if enumType := data[1]; enumType != 0 {
return 0, mdecodeEnumTypeErr("AnswerPartitionTable.State", enumType, 0)
}
{
v := data[2]
......@@ -1820,7 +1820,7 @@ func (p *SendPartitionTable) neoMsgEncodeM(data []byte) {
data = data[1+n:]
}
data[0] = byte(msgpack.FixExt1)
data[1] = 4
data[1] = 0
if !(0 <= (*a).State && (*a).State <= 0x7f) {
panic("(*a).State: invalid CellState enum value)")
}
......@@ -1908,8 +1908,8 @@ func (p *SendPartitionTable) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[0]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("SendPartitionTable.State", op, msgpack.FixExt1)
}
if enumType := data[1]; enumType != 4 {
return 0, mdecodeEnumTypeErr("SendPartitionTable.State", enumType, 4)
if enumType := data[1]; enumType != 0 {
return 0, mdecodeEnumTypeErr("SendPartitionTable.State", enumType, 0)
}
{
v := data[2]
......@@ -2026,7 +2026,7 @@ func (p *NotifyPartitionChanges) neoMsgEncodeM(data []byte) {
data = data[1+n:]
}
data[0] = byte(msgpack.FixExt1)
data[1] = 4
data[1] = 0
if !(0 <= (*a).CellInfo.State && (*a).CellInfo.State <= 0x7f) {
panic("(*a).CellInfo.State: invalid CellState enum value)")
}
......@@ -2114,8 +2114,8 @@ func (p *NotifyPartitionChanges) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[0]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("NotifyPartitionChanges.CellInfo.State", op, msgpack.FixExt1)
}
if enumType := data[1]; enumType != 4 {
return 0, mdecodeEnumTypeErr("NotifyPartitionChanges.CellInfo.State", enumType, 4)
if enumType := data[1]; enumType != 0 {
return 0, mdecodeEnumTypeErr("NotifyPartitionChanges.CellInfo.State", enumType, 0)
}
{
v := data[2]
......@@ -6056,7 +6056,7 @@ func (p *AnswerPartitionList) neoMsgEncodeM(data []byte) {
data = data[1+n:]
}
data[0] = byte(msgpack.FixExt1)
data[1] = 4
data[1] = 0
if !(0 <= (*a).State && (*a).State <= 0x7f) {
panic("(*a).State: invalid CellState enum value)")
}
......@@ -6144,8 +6144,8 @@ func (p *AnswerPartitionList) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[0]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("AnswerPartitionList.State", op, msgpack.FixExt1)
}
if enumType := data[1]; enumType != 4 {
return 0, mdecodeEnumTypeErr("AnswerPartitionList.State", enumType, 4)
if enumType := data[1]; enumType != 0 {
return 0, mdecodeEnumTypeErr("AnswerPartitionList.State", enumType, 0)
}
{
v := data[2]
......@@ -6199,7 +6199,7 @@ func (p *NodeList) neoMsgEncodedLenM() int {
func (p *NodeList) neoMsgEncodeM(data []byte) {
data[0] = byte(msgpack.FixArray_4 | 1)
data[1] = byte(msgpack.FixExt1)
data[2] = 2
data[2] = 4
if !(0 <= p.NodeType && p.NodeType <= 0x7f) {
panic("p.NodeType: invalid NodeType enum value)")
}
......@@ -6216,8 +6216,8 @@ func (p *NodeList) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[1]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("NodeList.NodeType", op, msgpack.FixExt1)
}
if enumType := data[2]; enumType != 2 {
return 0, mdecodeEnumTypeErr("NodeList.NodeType", enumType, 2)
if enumType := data[2]; enumType != 4 {
return 0, mdecodeEnumTypeErr("NodeList.NodeType", enumType, 4)
}
{
v := data[3]
......@@ -6335,7 +6335,7 @@ func (p *AnswerNodeList) neoMsgEncodeM(data []byte) {
a := &p.NodeList[i]
data[0] = byte(msgpack.FixArray_4 | 5)
data[1] = byte(msgpack.FixExt1)
data[2] = 2
data[2] = 4
if !(0 <= (*a).Type && (*a).Type <= 0x7f) {
panic("(*a).Type: invalid NodeType enum value)")
}
......@@ -6397,8 +6397,8 @@ func (p *AnswerNodeList) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[1]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("AnswerNodeList.Type", op, msgpack.FixExt1)
}
if enumType := data[2]; enumType != 2 {
return 0, mdecodeEnumTypeErr("AnswerNodeList.Type", enumType, 2)
if enumType := data[2]; enumType != 4 {
return 0, mdecodeEnumTypeErr("AnswerNodeList.Type", enumType, 4)
}
{
v := data[3]
......@@ -6899,7 +6899,7 @@ func (p *AnswerTweakPartitionTable) neoMsgEncodeM(data []byte) {
data = data[1+n:]
}
data[0] = byte(msgpack.FixExt1)
data[1] = 4
data[1] = 0
if !(0 <= (*a).State && (*a).State <= 0x7f) {
panic("(*a).State: invalid CellState enum value)")
}
......@@ -6977,8 +6977,8 @@ func (p *AnswerTweakPartitionTable) neoMsgDecodeM(data []byte) (int, error) {
if op := msgpack.Op(data[0]); op != msgpack.FixExt1 {
return 0, mdecodeOpErr("AnswerTweakPartitionTable.State", op, msgpack.FixExt1)
}
if enumType := data[1]; enumType != 4 {
return 0, mdecodeEnumTypeErr("AnswerTweakPartitionTable.State", enumType, 4)
if enumType := data[1]; enumType != 0 {
return 0, mdecodeEnumTypeErr("AnswerTweakPartitionTable.State", enumType, 0)
}
{
v := data[2]
......
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