diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index cf503b47..b186179b 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -810,6 +810,24 @@ jobs: echo "" done + test_reweight_half: + runs-on: ubuntu-latest + needs: build + container: ${{env.TEST_IMAGE}}:${{github.sha}} + steps: + - name: Run test + id: test + timeout-minutes: 3 + run: /root/vitastor/tests/test_reweight_half.sh + - name: Print logs + if: always() && steps.test.outcome == 'failure' + run: | + for i in /root/vitastor/testdata/*.log /root/vitastor/testdata/*.txt; do + echo "-------- $i --------" + cat $i + echo "" + done + test_heal_csum_32k_dmj: runs-on: ubuntu-latest needs: build diff --git a/mon/osd_tree.js b/mon/osd_tree.js index b2182cce..5ce6d0dd 100644 --- a/mon/osd_tree.js +++ b/mon/osd_tree.js @@ -15,7 +15,7 @@ function get_osd_tree(global_config, state) const stat = state.osd.stats[osd_num]; const osd_cfg = state.config.osd[osd_num]; let reweight = osd_cfg == null ? 1 : Number(osd_cfg.reweight); - if (isNaN(reweight) || reweight < 0 || reweight > 0) + if (isNaN(reweight) || reweight < 0 || reweight > 1) reweight = 1; if (stat && stat.size && reweight && (state.osd.state[osd_num] || Number(stat.time) >= down_time || osd_cfg && osd_cfg.noout)) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 734d3858..25221680 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -70,6 +70,8 @@ TEST_NAME=local_read POOLCFG='"local_reads":"random",' ./test_heal.sh SCHEME=ec ./test_heal.sh ANTIETCD=1 ./test_heal.sh +./test_reweight_half.sh + TEST_NAME=csum_32k_dmj OSD_ARGS="--data_csum_type crc32c --csum_block_size 32k --inmemory_metadata false --inmemory_journal false" OFFSET_ARGS=$OSD_ARGS ./test_heal.sh TEST_NAME=csum_32k_dj OSD_ARGS="--data_csum_type crc32c --csum_block_size 32k --inmemory_journal false" OFFSET_ARGS=$OSD_ARGS ./test_heal.sh TEST_NAME=csum_32k OSD_ARGS="--data_csum_type crc32c --csum_block_size 32k" OFFSET_ARGS=$OSD_ARGS ./test_heal.sh diff --git a/tests/test_reweight_half.sh b/tests/test_reweight_half.sh new file mode 100755 index 00000000..6c007f06 --- /dev/null +++ b/tests/test_reweight_half.sh @@ -0,0 +1,41 @@ +#!/bin/bash -ex + +. `dirname $0`/common.sh + +node mon/mon-main.js $MON_PARAMS --etcd_address $ETCD_URL --etcd_prefix "/vitastor" >>./testdata/mon.log 2>&1 & +MON_PID=$! +wait_etcd + +TIME=$(date '+%s') +$ETCDCTL put /vitastor/osd/stats/1 '{"host":"host1","size":1073741824,"time":"'$TIME'"}' +$ETCDCTL put /vitastor/osd/stats/2 '{"host":"host1","size":1073741824,"time":"'$TIME'"}' +$ETCDCTL put /vitastor/osd/stats/3 '{"host":"host2","size":1073741824,"time":"'$TIME'"}' +$ETCDCTL put /vitastor/osd/stats/4 '{"host":"host2","size":1073741824,"time":"'$TIME'"}' +build/src/cmd/vitastor-cli --etcd_address $ETCD_URL create-pool testpool -s 2 -n 16 --force + +sleep 2 + +# check that all OSDs have 8 PGs +$ETCDCTL get /vitastor/pg/config --print-value-only | \ + jq -s -e '([ .[0].items["1"] | .[].osd_set | map_values(. | tonumber) | select(.[0] == 1 or .[1] == 1) ] | length) == 8' +$ETCDCTL get /vitastor/pg/config --print-value-only | \ + jq -s -e '([ .[0].items["1"] | .[].osd_set | map_values(. | tonumber) | select(.[0] == 2 or .[1] == 2) ] | length) == 8' +$ETCDCTL get /vitastor/pg/config --print-value-only | \ + jq -s -e '([ .[0].items["1"] | .[].osd_set | map_values(. | tonumber) | select(.[0] == 3 or .[1] == 3) ] | length) == 8' +$ETCDCTL get /vitastor/pg/config --print-value-only | \ + jq -s -e '([ .[0].items["1"] | .[].osd_set | map_values(. | tonumber) | select(.[0] == 4 or .[1] == 4) ] | length) == 8' + +build/src/cmd/vitastor-cli --etcd_address $ETCD_URL modify-osd --reweight 0.5 3 + +sleep 2 + +$ETCDCTL get /vitastor/pg/config --print-value-only | \ + jq -s -e '([ .[0].items["1"] | .[].osd_set | map_values(. | tonumber) | select(.[0] == 1 or .[1] == 1) ] | length) == 8' +$ETCDCTL get /vitastor/pg/config --print-value-only | \ + jq -s -e '([ .[0].items["1"] | .[].osd_set | map_values(. | tonumber) | select(.[0] == 2 or .[1] == 2) ] | length) == 8' +$ETCDCTL get /vitastor/pg/config --print-value-only | \ + jq -s -e '([ .[0].items["1"] | .[].osd_set | map_values(. | tonumber) | select(.[0] == 3 or .[1] == 3) ] | length) <= 6' +$ETCDCTL get /vitastor/pg/config --print-value-only | \ + jq -s -e '([ .[0].items["1"] | .[].osd_set | map_values(. | tonumber) | select(.[0] == 4 or .[1] == 4) ] | length) >= 10' + +format_green OK