Commit b6099dc4 authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/proto: RequestIdentification += DevPath

This corresponds to NEO/py commit 97af23cc (Maximize resiliency by
taking into account the topology of storage nodes).
parent 238e14a7
// Copyright (C) 2016-2018 Nexedi SA and Contributors. // Copyright (C) 2016-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -113,6 +113,7 @@ func (app *NodeApp) Dial(ctx context.Context, peerType proto.NodeType, addr stri ...@@ -113,6 +113,7 @@ func (app *NodeApp) Dial(ctx context.Context, peerType proto.NodeType, addr stri
UUID: app.MyInfo.UUID, UUID: app.MyInfo.UUID,
Address: app.MyInfo.Addr, Address: app.MyInfo.Addr,
ClusterName: app.ClusterName, ClusterName: app.ClusterName,
DevPath: nil, // XXX stub
IdTime: app.MyInfo.IdTime, // XXX ok? IdTime: app.MyInfo.IdTime, // XXX ok?
} }
accept := &proto.AcceptIdentification{} accept := &proto.AcceptIdentification{}
......
...@@ -107,6 +107,7 @@ func TestMasterStorage(t0 *testing.T) { ...@@ -107,6 +107,7 @@ func TestMasterStorage(t0 *testing.T) {
UUID: 0, UUID: 0,
Address: xnaddr("s:1"), Address: xnaddr("s:1"),
ClusterName: "abc1", ClusterName: "abc1",
DevPath: nil,
IdTime: proto.IdTimeNone, IdTime: proto.IdTimeNone,
})) }))
...@@ -208,6 +209,7 @@ func TestMasterStorage(t0 *testing.T) { ...@@ -208,6 +209,7 @@ func TestMasterStorage(t0 *testing.T) {
UUID: 0, UUID: 0,
Address: xnaddr(""), Address: xnaddr(""),
ClusterName: "abc1", ClusterName: "abc1",
DevPath: nil,
IdTime: proto.IdTimeNone, IdTime: proto.IdTimeNone,
})) }))
...@@ -293,6 +295,7 @@ func TestMasterStorage(t0 *testing.T) { ...@@ -293,6 +295,7 @@ func TestMasterStorage(t0 *testing.T) {
UUID: proto.UUID(proto.CLIENT, 1), UUID: proto.UUID(proto.CLIENT, 1),
Address: xnaddr(""), Address: xnaddr(""),
ClusterName: "abc1", ClusterName: "abc1",
DevPath: nil,
IdTime: 0.02, IdTime: 0.02,
})) }))
......
...@@ -372,6 +372,7 @@ type RequestIdentification struct { ...@@ -372,6 +372,7 @@ type RequestIdentification struct {
UUID NodeUUID UUID NodeUUID
Address Address // where requesting node is also accepting connections Address Address // where requesting node is also accepting connections
ClusterName string ClusterName string
DevPath []string // [] of devid
IdTime IdTime IdTime IdTime
} }
......
...@@ -250,11 +250,12 @@ func TestMsgMarshal(t *testing.T) { ...@@ -250,11 +250,12 @@ func TestMsgMarshal(t *testing.T) {
}, },
// uint32, Address, string, IdTime // uint32, Address, string, IdTime
{&RequestIdentification{CLIENT, 17, Address{"localhost", 7777}, "myname", 0.12345678}, {&RequestIdentification{CLIENT, 17, Address{"localhost", 7777}, "myname", []string{"room1", "rack234"}, 0.12345678},
u8(2) + u32(17) + u32(9) + u8(2) + u32(17) + u32(9) +
"localhost" + u16(7777) + "localhost" + u16(7777) +
u32(6) + "myname" + u32(6) + "myname" +
u32(2) + u32(5)+"room1" + u32(7)+"rack234" +
hex("3fbf9add1091c895"), hex("3fbf9add1091c895"),
}, },
......
...@@ -65,7 +65,12 @@ func (*RequestIdentification) NEOMsgCode() uint16 { ...@@ -65,7 +65,12 @@ func (*RequestIdentification) NEOMsgCode() uint16 {
} }
func (p *RequestIdentification) NEOMsgEncodedLen() int { func (p *RequestIdentification) NEOMsgEncodedLen() int {
return 9 + p.Address.neoEncodedLen() + len(p.ClusterName) + p.IdTime.neoEncodedLen() var size int
for i := 0; i < len(p.DevPath); i++ {
a := &p.DevPath[i]
size += len((*a))
}
return 13 + p.Address.neoEncodedLen() + len(p.ClusterName) + len(p.DevPath)*4 + p.IdTime.neoEncodedLen() + size
} }
func (p *RequestIdentification) NEOMsgEncode(data []byte) { func (p *RequestIdentification) NEOMsgEncode(data []byte) {
...@@ -82,6 +87,22 @@ func (p *RequestIdentification) NEOMsgEncode(data []byte) { ...@@ -82,6 +87,22 @@ func (p *RequestIdentification) NEOMsgEncode(data []byte) {
copy(data, p.ClusterName) copy(data, p.ClusterName)
data = data[l:] data = data[l:]
} }
{
l := uint32(len(p.DevPath))
binary.BigEndian.PutUint32(data[0:], l)
data = data[4:]
for i := 0; uint32(i) < l; i++ {
a := &p.DevPath[i]
{
l := uint32(len((*a)))
binary.BigEndian.PutUint32(data[0:], l)
data = data[4:]
copy(data, (*a))
data = data[l:]
}
data = data[0:]
}
}
{ {
n := p.IdTime.neoEncode(data[0:]) n := p.IdTime.neoEncode(data[0:])
data = data[0+n:] data = data[0+n:]
...@@ -110,13 +131,35 @@ func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) { ...@@ -110,13 +131,35 @@ func (p *RequestIdentification) NEOMsgDecode(data []byte) (int, error) {
{ {
l := binary.BigEndian.Uint32(data[0 : 0+4]) l := binary.BigEndian.Uint32(data[0 : 0+4])
data = data[4:] data = data[4:]
if uint64(len(data)) < uint64(l) { if uint64(len(data)) < 4+uint64(l) {
goto overflow goto overflow
} }
nread += uint64(l) nread += 4 + uint64(l)
p.ClusterName = string(data[:l]) p.ClusterName = string(data[:l])
data = data[l:] data = data[l:]
} }
{
l := binary.BigEndian.Uint32(data[0 : 0+4])
data = data[4:]
p.DevPath = make([]string, l)
for i := 0; uint32(i) < l; i++ {
a := &p.DevPath[i]
if len(data) < 4 {
goto overflow
}
{
l := binary.BigEndian.Uint32(data[0 : 0+4])
data = data[4:]
if uint64(len(data)) < uint64(l) {
goto overflow
}
nread += uint64(l)
(*a) = string(data[:l])
data = data[l:]
}
}
nread += uint64(l) * 4
}
{ {
n, ok := p.IdTime.neoDecode(data) n, ok := p.IdTime.neoDecode(data)
if !ok { if !ok {
......
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