diff --git a/src/cmd/cli_pg_ls.cpp b/src/cmd/cli_pg_ls.cpp index 711489b0..6ad89958 100644 --- a/src/cmd/cli_pg_ls.cpp +++ b/src/cmd/cli_pg_ls.cpp @@ -251,7 +251,7 @@ resume_1: { "title", "MISPLACED" }, }); cols.push_back(json11::Json::object{ - { "key", "fmt_misplaced" }, + { "key", "fmt_degraded" }, { "title", "DEGRADED" }, }); cols.push_back(json11::Json::object{ @@ -273,6 +273,8 @@ resume_1: load_pg_stats(); if (parent->waiting > 0) return; + if (state == 100) + return; format_pgs(); state = 100; } diff --git a/tests/run_tests.sh b/tests/run_tests.sh index d72fcf78..edee3cd7 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -61,6 +61,7 @@ OLD=1 SCHEME=ec ./test_snapshot.sh OLD=1 ./test_move_reappear.sh ./test_degraded.sh +./test_pg_ls.sh ./test_rm.sh diff --git a/tests/test_pg_ls.sh b/tests/test_pg_ls.sh new file mode 100755 index 00000000..3ef5cee0 --- /dev/null +++ b/tests/test_pg_ls.sh @@ -0,0 +1,47 @@ +#!/bin/bash -ex + +# Test vitastor-cli ls-pgs on degraded PGs + +PG_COUNT=4 +PG_SIZE=3 +PG_MINSIZE=2 +# Keep degraded objects until the checks are done +GLOBAL_CONFIG=',"no_recovery":true' +. `dirname $0`/run_3osds.sh + +$VITASTOR_CLI create -s 32M testimg + +# Data written while OSD 3 is down is degraded when it comes back +kill -9 $OSD3_PID +$ETCDCTL del /vitastor/osd/state/3 +wait_condition 60 "$ETCDCTL get --prefix /vitastor/pg/state/ --print-value-only | jq -s -e '[ .[] | select(.state | index(\"degraded\")) ] | length == $PG_COUNT'" "PG peering without OSD 3" +$VITASTOR_CLI dd if=/dev/urandom oimg=testimg bs=1M count=32 +start_osd 3 +wait_condition 60 "$ETCDCTL get --prefix /vitastor/pgstats/ --print-value-only | jq -s -e '[ .[] | select(.degraded_count > 0) ] | length == $PG_COUNT'" "PG degradation" + +$VITASTOR_CLI ls-pgs + +# NUM and DEGRADED of every PG from the table, and degraded_count from JSON +$VITASTOR_CLI ls-pgs | awk 'NR == 1 { n = index($0, "NUM"); d = index($0, "DEGRADED"); e = index($0, "INCOMPLETE") } + NR > 1 { num = substr($0, n); sub(/ .*/, "", num); deg = substr($0, d, e-d); sub(/ +$/, "", deg); print num " " deg }' > ./testdata/pg_ls.txt +$VITASTOR_CLI ls-pgs --json | jq -r '.[] | "\(.pg_num) \(.degraded_count // 0)"' > ./testdata/pg_ls_json.txt + +if [[ $(wc -l < ./testdata/pg_ls.txt) != $PG_COUNT ]]; then + format_error "ls-pgs should list $PG_COUNT PGs" +fi +while read num count; do + shown=$(awk '$1 == '$num' { $1 = ""; sub(/^ /, ""); print }' ./testdata/pg_ls.txt) + if [[ -z "$shown" || $count -gt 0 && "$shown" = "0 B" || $count -eq 0 && "$shown" != "0 B" ]]; then + format_error "ls-pgs shows DEGRADED=$shown for PG $num with $count degraded objects" + fi +done < ./testdata/pg_ls_json.txt + +# An unknown pool is an error, not an empty table +if out=$($VITASTOR_CLI ls-pgs --pool nosuchpool 2>&1); then + format_error "ls-pgs should fail for an unknown pool" +fi +if [[ "$out" != "Pool nosuchpool not found" ]]; then + format_error "ls-pgs prints '$out' instead of the unknown pool error" +fi + +format_green OK