From 4df642e94119afbadcdca5142ad05ea2af6230d1 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 11 Sep 2023 15:12:55 +0300 Subject: [PATCH 1/3] [#162] netmap: Fix possible panic Placement policy is unvalidated external input. Under no circumstances should we panic here. Signed-off-by: Evgenii Stratonikov --- netmap/netmap.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/netmap/netmap.go b/netmap/netmap.go index 3e8d680..37f5cab 100644 --- a/netmap/netmap.go +++ b/netmap/netmap.go @@ -258,6 +258,9 @@ func (m NetMap) ContainerNodes(p PlacementPolicy, pivot []byte) ([][]NodeInfo, e } if p.unique { + if c.processedSelectors[sName] == nil { + return nil, fmt.Errorf("selector not found: '%s'", sName) + } nodes, err := c.getSelection(*c.processedSelectors[sName]) if err != nil { return nil, err -- 2.45.3 From 0a0b590df38aa9af77ecc89cbda7b75818e97bfb Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 11 Sep 2023 15:21:35 +0300 Subject: [PATCH 2/3] [#162] Fix pre-commit warnings Signed-off-by: Evgenii Stratonikov --- doc/image/filter_illustration.svg | 2 +- doc/image/placement_policy.svg | 2 +- doc/image/rep_illustration.svg | 2 +- doc/image/sample_netmap.svg | 2 +- doc/image/select_illustration.svg | 2 +- doc/policy.md | 20 ++++++++++---------- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/doc/image/filter_illustration.svg b/doc/image/filter_illustration.svg index a57aa68..7eedf3d 100644 --- a/doc/image/filter_illustration.svg +++ b/doc/image/filter_illustration.svg @@ -1,4 +1,4 @@ -
FILTER Color EQ 'Red' AS RedNodes
FILTER Color EQ 'Red' AS RedNodes
FILTER Color EQ 'Blue' AS BlueNodes
FILTER Color EQ 'Blue' AS BlueNodes
FILTER @RedNodes OR @BlueNodes AS MyNodes
FILTER @RedNodes OR @BlueNodes AS MyNodes
*
*
MyNodes
MyNodes
Text is not SVG - cannot display
\ No newline at end of file +
FILTER Color EQ 'Red' AS RedNodes
FILTER Color EQ 'Red' AS RedNodes
FILTER Color EQ 'Blue' AS BlueNodes
FILTER Color EQ 'Blue' AS BlueNodes
FILTER @RedNodes OR @BlueNodes AS MyNodes
FILTER @RedNodes OR @BlueNodes AS MyNodes
*
*
MyNodes
MyNodes
Text is not SVG - cannot display
diff --git a/doc/image/placement_policy.svg b/doc/image/placement_policy.svg index 9cc8a1a..2820c64 100644 --- a/doc/image/placement_policy.svg +++ b/doc/image/placement_policy.svg @@ -1,4 +1,4 @@ -
FILTER
FILTER
FILTER
FILTER
FILTER
FILTER
SELECT
SELECT
SELECT
SELECT
SELECT
SELECT
FILTER
FILTER
FILTER
FILTER
FILTER
FILTER
REP
REP
REP
REP
REP
REP
netmap
netmap
Text is not SVG - cannot display
\ No newline at end of file +
FILTER
FILTER
FILTER
FILTER
FILTER
FILTER
SELECT
SELECT
SELECT
SELECT
SELECT
SELECT
FILTER
FILTER
FILTER
FILTER
FILTER
FILTER
REP
REP
REP
REP
REP
REP
netmap
netmap
Text is not SVG - cannot display
diff --git a/doc/image/rep_illustration.svg b/doc/image/rep_illustration.svg index 8bcc327..6955499 100644 --- a/doc/image/rep_illustration.svg +++ b/doc/image/rep_illustration.svg @@ -1,4 +1,4 @@ -
(...)
(...)
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
MyNodes
MyNodes
REP 1 IN MyNodes
REP 1 IN MyNodes
Text is not SVG - cannot display
\ No newline at end of file +
(...)
(...)
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
MyNodes
MyNodes
REP 1 IN MyNodes
REP 1 IN MyNodes
Text is not SVG - cannot display
diff --git a/doc/image/sample_netmap.svg b/doc/image/sample_netmap.svg index 3d0b39f..ea4928e 100644 --- a/doc/image/sample_netmap.svg +++ b/doc/image/sample_netmap.svg @@ -1,4 +1,4 @@ -
C
C
A
A
Netmap
Netmap
B
B
D
D
E
E
F
F
G
G
H
H
I
I
Text is not SVG - cannot display
\ No newline at end of file +
C
C
A
A
Netmap
Netmap
B
B
D
D
E
E
F
F
G
G
H
H
I
I
Text is not SVG - cannot display
diff --git a/doc/image/select_illustration.svg b/doc/image/select_illustration.svg index 3a0956a..83ee783 100644 --- a/doc/image/select_illustration.svg +++ b/doc/image/select_illustration.svg @@ -1,4 +1,4 @@ -
FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes
FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes
RedOrBlueNodes
RedOrBlueNodes
(...)
(...)
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
MyNodes
MyNodes
Text is not SVG - cannot display
\ No newline at end of file +
FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes
FILTER @RedNodes OR @BlueNodes AS RedOrBlueNodes
RedOrBlueNodes
RedOrBlueNodes
(...)
(...)
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes
MyNodes
MyNodes
Text is not SVG - cannot display
diff --git a/doc/policy.md b/doc/policy.md index 6818468..c7597ea 100644 --- a/doc/policy.md +++ b/doc/policy.md @@ -101,16 +101,16 @@ In a nutshell, a `SELECT` takes a filter result as input and outputs a specific Let's see some examples ```sql -- Selects exactly one node from the entire netmap -SELECT 1 FROM * +SELECT 1 FROM * -- Same as above, but with an identifier for the selection -SELECT 1 FROM * AS ONE +SELECT 1 FROM * AS ONE --- Selects two nodes from the RedOrBlueNodes filter, such that both selected nodes +-- Selects two nodes from the RedOrBlueNodes filter, such that both selected nodes -- share the same value for the Color attribute, i.e. both red or both blue. -SELECT 2 IN SAME Color FROM RedOrBlueNodes +SELECT 2 IN SAME Color FROM RedOrBlueNodes --- Selects two nodes from the RedOrBlueNodes filter, such that the selected nodes +-- Selects two nodes from the RedOrBlueNodes filter, such that the selected nodes -- have distinct values for the Color attribute, i.e. one red and one blue. -- The selection is also given an identifier. SELECT 2 IN DISTINCT Color FROM RedOrBlueNodes AS MyNodes @@ -173,18 +173,18 @@ In additional to this basic syntax, there are a couple of additional useful opti ### The policy playground -> ℹ️ This section assumes you have an up-to-date version of the `frostfs-cli`. +> ℹ️ This section assumes you have an up-to-date version of the `frostfs-cli`. While simple placement policies have predictable results that can be understood at a glance, more complex ones need careful consideration before deployment. In order to simplify understanding a policy's outcome and experimenting while learning, a builtin tool is provided as part of the `frostfs-cli` for this purpose: the policy playground. -For the remainder of this guide, we will use the policy playground to setup a virtual netmap (that is, one that doesn't require any networking or deployment) and test various policies. In order to visualize this netmap easily, each node will have three attributes: a character, a shape and a color +For the remainder of this guide, we will use the policy playground to setup a virtual netmap (that is, one that doesn't require any networking or deployment) and test various policies. In order to visualize this netmap easily, each node will have three attributes: a character, a shape and a color ![Sample Netmap](./image/sample_netmap.svg) We can start the policy playground as follows: ```sh $ frostfs-cli container policy-playground -> +> ``` Since we didn't pass any endpoint, the initial netmap is empty, which we can verify with the `ls` command (to list the nodes in the netmap): @@ -400,7 +400,7 @@ FILTER Color EQ 'Green' AS GreenNodes #### Example #6 ```sql REP 1 IN MyNodes -REP 2 +REP 2 CBF 2 SELECT 1 FROM CuteNodes AS MyNodes FILTER (Color EQ 'Blue') AND NOT (Shape EQ 'Circle' OR Shape EQ 'Square') AS CuteNodes @@ -442,4 +442,4 @@ Others: - `ls`: list nodes in the current netmap and their attributes - `add`: add a node to the current netmap. If it already exists, it will be overwritten. - `remove`: remove a node from the current netmap. -- `eval`: evaluate a placement policy on the current netmap. \ No newline at end of file +- `eval`: evaluate a placement policy on the current netmap. -- 2.45.3 From ac8fc6d4400c4b842fc77d993d2a13598c51970d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 8 Sep 2023 16:57:41 +0300 Subject: [PATCH 3/3] [#162] netmap: Allow to parse single unnamed selectors Signed-off-by: Evgenii Stratonikov --- doc/policy.md | 3 ++- netmap/netmap.go | 2 +- netmap/policy.go | 5 ++-- netmap/policy_decode_test.go | 12 ++++++--- netmap/selector_test.go | 49 ++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 8 deletions(-) diff --git a/doc/policy.md b/doc/policy.md index c7597ea..28744ef 100644 --- a/doc/policy.md +++ b/doc/policy.md @@ -131,7 +131,8 @@ Its basic syntax is as follows: REP {IN