From 70e9e40c7f3d0045050b900357cd2e3d8cdbdeda Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 22 Feb 2024 22:29:25 +0300 Subject: [PATCH] [#205] netmap: Add EC statement to placement policy Signed-off-by: Evgenii Stratonikov --- netmap/netmap.go | 26 +- netmap/parser/Query.g4 | 6 +- netmap/parser/Query.interp | Bin 5170 -> 5562 bytes netmap/parser/Query.tokens | Bin 372 -> 400 bytes netmap/parser/QueryLexer.g4 | 2 + netmap/parser/QueryLexer.interp | Bin 7459 -> 7764 bytes netmap/parser/QueryLexer.tokens | Bin 372 -> 400 bytes netmap/parser/query_base_visitor.go | 6 +- netmap/parser/query_lexer.go | 242 +++++----- netmap/parser/query_parser.go | 711 ++++++++++++++++++++-------- netmap/parser/query_visitor.go | 5 +- netmap/policy.go | 72 ++- netmap/policy_decode_test.go | 2 + 13 files changed, 728 insertions(+), 344 deletions(-) diff --git a/netmap/netmap.go b/netmap/netmap.go index 530b06d..f0ece7d 100644 --- a/netmap/netmap.go +++ b/netmap/netmap.go @@ -209,6 +209,25 @@ func (m NetMap) SelectFilterNodes(expr *SelectFilterExpr) ([][]NodeInfo, error) return ret, nil } +func countNodes(r netmap.Replica) uint32 { + if r.GetCount() != 0 { + return r.GetCount() + } + return r.GetECDataCount() + r.GetECParityCount() +} + +func (p PlacementPolicy) isUnique() bool { + if p.unique { + return true + } + for _, r := range p.replicas { + if r.GetECDataCount() != 0 || r.GetECParityCount() != 0 { + return true + } + } + return false +} + // ContainerNodes returns two-dimensional list of nodes as a result of applying // given PlacementPolicy to the NetMap. Each line of the list corresponds to a // replica descriptor. Line order corresponds to order of ReplicaDescriptor list @@ -230,6 +249,7 @@ func (m NetMap) ContainerNodes(p PlacementPolicy, pivot []byte) ([][]NodeInfo, e return nil, err } + unique := p.isUnique() result := make([][]NodeInfo, len(p.replicas)) // Note that the cached selectors are not used when the policy contains the UNIQUE flag. @@ -240,7 +260,7 @@ func (m NetMap) ContainerNodes(p PlacementPolicy, pivot []byte) ([][]NodeInfo, e sName := p.replicas[i].GetSelector() if sName == "" && !(len(p.replicas) == 1 && len(p.selectors) == 1) { var s netmap.Selector - s.SetCount(p.replicas[i].GetCount()) + s.SetCount(countNodes(p.replicas[i])) s.SetFilter(mainFilterName) nodes, err := c.getSelection(s) @@ -250,14 +270,14 @@ func (m NetMap) ContainerNodes(p PlacementPolicy, pivot []byte) ([][]NodeInfo, e result[i] = append(result[i], flattenNodes(nodes)...) - if p.unique { + if unique { c.addUsedNodes(result[i]...) } continue } - if p.unique { + if unique { if c.processedSelectors[sName] == nil { return nil, fmt.Errorf("selector not found: '%s'", sName) } diff --git a/netmap/parser/Query.g4 b/netmap/parser/Query.g4 index 72fa880..0a5b314 100644 --- a/netmap/parser/Query.g4 +++ b/netmap/parser/Query.g4 @@ -4,10 +4,14 @@ options { tokenVocab = QueryLexer; } -policy: UNIQUE? repStmt+ cbfStmt? selectStmt* filterStmt* EOF; +policy: UNIQUE? (repStmt | ecStmt)+ cbfStmt? selectStmt* filterStmt* EOF; selectFilterExpr: cbfStmt? selectStmt? filterStmt* EOF; +ecStmt: + EC Data = NUMBER1 DOT Parity = NUMBER1 // erasure code configuration + (IN Selector = ident)?; // optional selector name + repStmt: REP Count = NUMBER1 // number of object replicas (IN Selector = ident)?; // optional selector name diff --git a/netmap/parser/Query.interp b/netmap/parser/Query.interp index a8fb219e6ebe10b7437f9f3f946010b562b52f2d..3f7a9ad50456f472f2f5103076fb7f55c6cfe1e3 100644 GIT binary patch literal 5562 zcmbW4TW=dT5QX3QEBxlRa0^j)<*ACS6hdvumE;C!Q3Q^&0gT8_V9RLz@B5t@?rKT3 zK~Z2$at`NmX2@NQ_n$vi4=203ef4;=J9)Uduby6ohv(fcoGw?}({MUno-?l2rwP4Y zE`GV51Fh#*jPn`8V#zSwFw9=RVcg6w<}(?;S+6cNEiSfmJe+>V-w*t4rk8SYzSwLR zOVj)Y@mv0WOmUn-r!9rOaeaEZfB$)Rcbk!g>$}xefUKs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