From 5dd37f519a34a5b1441bdc852dc448408c76c7aa Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Mon, 28 Apr 2025 02:16:45 +0300 Subject: [PATCH] Fix node folding in case of empty rules (pool with size 1), add a test --- mon/lp_optimizer/fold.js | 2 +- mon/lp_optimizer/test-optimize-fold.js | 12 ++++++++++++ tests/common.sh | 16 ++++++++++++++++ tests/run_3osds.sh | 16 ---------------- tests/test_failure_domain.sh | 4 ++++ 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/mon/lp_optimizer/fold.js b/mon/lp_optimizer/fold.js index 9a70c4d3..ebcf0ca2 100644 --- a/mon/lp_optimizer/fold.js +++ b/mon/lp_optimizer/fold.js @@ -34,7 +34,7 @@ function fold_failure_domains(node_list, rules) folded = false; for (const node_id in per_parent) { - const fold_node = per_parent[node_id].filter(child => per_parent[child.id||''] || interest[child.level]).length == 0; + const fold_node = node_id !== '' && per_parent[node_id].length > 0 && per_parent[node_id].filter(child => per_parent[child.id||''] || interest[child.level]).length == 0; if (fold_node) { const old_node = node_map[node_id]; diff --git a/mon/lp_optimizer/test-optimize-fold.js b/mon/lp_optimizer/test-optimize-fold.js index aac5a3d2..ac5b951a 100644 --- a/mon/lp_optimizer/test-optimize-fold.js +++ b/mon/lp_optimizer/test-optimize-fold.js @@ -36,6 +36,18 @@ async function run() [ [ [ 'dc' ], [ 'host' ] ] ] ), 0, 2)); + console.log('\nfold_failure_domains empty rules'); + console.log(JSON.stringify(fold_failure_domains( + [ + { id: 1, level: 'osd', size: 1, parent: 'disk1' }, + { id: 2, level: 'osd', size: 2, parent: 'disk1' }, + { id: 'disk1', level: 'disk', parent: 'host1' }, + { id: 'host1', level: 'host', parent: 'dc1' }, + { id: 'dc1', level: 'dc' }, + ], + [] + ), 0, 2)); + console.log('\noptimize_folded'); // 5 DCs, 2 hosts per DC, 10 OSD per host const nodes = []; diff --git a/tests/common.sh b/tests/common.sh index 8295ebe0..73415d26 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -87,6 +87,22 @@ wait_etcd() done } +wait_condition() +{ + sec=$1 + check=$2 + proc=$3 + i=0 + while [[ $i -lt $sec ]]; do + eval "$check" && break + if [ $i -eq $sec ]; then + format_error "$proc couldn't finish in $sec seconds" + fi + sleep 1 + i=$((i+1)) + done +} + if [[ -n "$ANTIETCD" ]]; then ETCDCTL="node mon/node_modules/.bin/anticli -e $ETCD_URL" MON_PARAMS="--use_antietcd 1 --antietcd_data_dir ./testdata --antietcd_persist_interval 500 $MON_PARAMS" diff --git a/tests/run_3osds.sh b/tests/run_3osds.sh index 52e6763d..f5dd0aa4 100644 --- a/tests/run_3osds.sh +++ b/tests/run_3osds.sh @@ -127,22 +127,6 @@ try_reweight() sleep 3 } -wait_condition() -{ - sec=$1 - check=$2 - proc=$3 - i=0 - while [[ $i -lt $sec ]]; do - eval "$check" && break - if [ $i -eq $sec ]; then - format_error "$proc couldn't finish in $sec seconds" - fi - sleep 1 - i=$((i+1)) - done -} - wait_finish_rebalance() { sec=$1 diff --git a/tests/test_failure_domain.sh b/tests/test_failure_domain.sh index d626b940..392ef18f 100755 --- a/tests/test_failure_domain.sh +++ b/tests/test_failure_domain.sh @@ -31,4 +31,8 @@ sleep 2 $ETCDCTL get --prefix /vitastor/pg/config --print-value-only | \ jq -s -e '([ .[0].items["1"] | .[].osd_set | map_values(. | tonumber) | select((.[0] <= 4) != (.[1] <= 4)) ] | length) == 4' +# test pool with size 1 +build/src/cmd/vitastor-cli --etcd_address $ETCD_URL create-pool size1pool -s 1 -n 1 --force +wait_condition 10 "$ETCDCTL get --prefix /vitastor/pg/config --print-value-only | jq -s -e '.[0].items["'"'"2"'"'"]'" + format_green OK