diff --git a/v2/netmap/convert.go b/v2/netmap/convert.go index caf7e335..e08d17c9 100644 --- a/v2/netmap/convert.go +++ b/v2/netmap/convert.go @@ -54,6 +54,7 @@ func SelectorToGRPCMessage(s *Selector) *netmap.Selector { m.SetName(s.GetName()) m.SetCount(s.GetCount()) + m.SetClause(ClauseToGRPCMessage(s.GetClause())) m.SetFilter(s.GetFilter()) m.SetAttribute(s.GetAttribute()) @@ -69,6 +70,7 @@ func SelectorFromGRPCMessage(m *netmap.Selector) *Selector { s.SetName(m.GetName()) s.SetCount(m.GetCount()) + s.SetClause(ClauseFromGRPCMessage(m.GetClause())) s.SetFilter(m.GetFilter()) s.SetAttribute(m.GetAttribute()) @@ -160,6 +162,14 @@ func PlacementPolicyFromGRPCMessage(m *netmap.PlacementPolicy) *PlacementPolicy return p } +func ClauseToGRPCMessage(n Clause) netmap.Clause { + return netmap.Clause(n) +} + +func ClauseFromGRPCMessage(n netmap.Clause) Clause { + return Clause(n) +} + func OperationToGRPCMessage(n Operation) netmap.Operation { return netmap.Operation(n) } diff --git a/v2/netmap/grpc/types.go b/v2/netmap/grpc/types.go index a912cb23..e478d98f 100644 --- a/v2/netmap/grpc/types.go +++ b/v2/netmap/grpc/types.go @@ -92,6 +92,13 @@ func (m *Selector) SetFilter(v string) { } } +// SetClause of placement selector. +func (m *Selector) SetClause(v Clause) { + if m != nil { + m.Clause = v + } +} + // SetCount of object replica. func (m *Replica) SetCount(v uint32) { if m != nil { diff --git a/v2/netmap/grpc/types.pb.go b/v2/netmap/grpc/types.pb.go index 5b0376fc..a16be672 100644 Binary files a/v2/netmap/grpc/types.pb.go and b/v2/netmap/grpc/types.pb.go differ diff --git a/v2/netmap/marshal.go b/v2/netmap/marshal.go index a38d8a27..2fada3ea 100644 --- a/v2/netmap/marshal.go +++ b/v2/netmap/marshal.go @@ -13,8 +13,9 @@ const ( nameSelectorField = 1 countSelectorField = 2 - attributeSelectorField = 3 - filterSelectorField = 4 + clauseSelectorField = 3 + attributeSelectorField = 4 + filterSelectorField = 5 countReplicaField = 1 selectorReplicaField = 2 @@ -128,6 +129,13 @@ func (s *Selector) StableMarshal(buf []byte) ([]byte, error) { offset += n + n, err = proto.EnumMarshal(clauseSelectorField, buf[offset:], int32(s.clause)) + if err != nil { + return nil, err + } + + offset += n + n, err = proto.StringMarshal(attributeSelectorField, buf[offset:], s.attribute) if err != nil { return nil, err @@ -146,6 +154,7 @@ func (s *Selector) StableMarshal(buf []byte) ([]byte, error) { func (s *Selector) StableSize() (size int) { size += proto.StringSize(nameSelectorField, s.name) size += proto.UInt32Size(countSelectorField, s.count) + size += proto.EnumSize(countSelectorField, int32(s.clause)) size += proto.StringSize(attributeSelectorField, s.attribute) size += proto.StringSize(filterSelectorField, s.filter) diff --git a/v2/netmap/marshal_test.go b/v2/netmap/marshal_test.go index 7178a201..5a4ce6ca 100644 --- a/v2/netmap/marshal_test.go +++ b/v2/netmap/marshal_test.go @@ -151,6 +151,7 @@ func generateSelector(name string) *netmap.Selector { s := new(netmap.Selector) s.SetName(name) s.SetAttribute("attribute") + s.SetClause(netmap.Distinct) s.SetCount(10) s.SetFilter("filter") diff --git a/v2/netmap/types.go b/v2/netmap/types.go index c16fa509..b91d6e57 100644 --- a/v2/netmap/types.go +++ b/v2/netmap/types.go @@ -11,6 +11,7 @@ type Filter struct { type Selector struct { name string count uint32 + clause Clause attribute string filter string } @@ -47,6 +48,9 @@ type NodeInfo struct { // NodeState of storage node. type NodeState uint32 +// Clause of placement selector. +type Clause uint32 + const ( UnspecifiedState NodeState = iota Online @@ -65,6 +69,12 @@ const ( AND ) +const ( + UnspecifiedClause Clause = iota + Same + Distinct +) + func (f *Filter) GetFilters() []*Filter { if f != nil { return f.filters @@ -162,6 +172,20 @@ func (s *Selector) SetAttribute(attribute string) { } } +func (s *Selector) GetClause() Clause { + if s != nil { + return s.clause + } + + return UnspecifiedClause +} + +func (s *Selector) SetClause(clause Clause) { + if s != nil { + s.clause = clause + } +} + func (s *Selector) GetCount() uint32 { if s != nil { return s.count