Commit 634ba655 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 802ecf7e
......@@ -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("92"+"920bd40401"+"9211d40400") +
hex("91"+"920bd40402") +
hex("93"+"920bd40403"+"920fd40404"+"9217d40401"),
hex("92"+"920bd40001"+"9211d40000") +
hex("91"+"920bd40002") +
hex("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]
......@@ -1046,7 +1046,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)")
}
......@@ -1117,8 +1117,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]
......@@ -1583,7 +1583,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)")
}
......@@ -1664,8 +1664,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]
......@@ -1806,7 +1806,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)")
}
......@@ -1887,8 +1887,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]
......@@ -2004,7 +2004,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)")
}
......@@ -2092,8 +2092,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]
......@@ -6057,7 +6057,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)")
}
......@@ -6138,8 +6138,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]
......@@ -6192,7 +6192,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)")
}
......@@ -6209,8 +6209,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]
......@@ -6328,7 +6328,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)")
}
......@@ -6390,8 +6390,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]
......@@ -6891,7 +6891,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)")
}
......@@ -6962,8 +6962,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