From 19d20291ba3a347e841eddf0a469e4e55a286404 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Tue, 20 Oct 2026 10:38:23 +0300 Subject: [PATCH 1/2] Fix vitastor-cli ls-pgs DEGRADED column showing misplaced data The DEGRADED column of the ls-pgs table used the fmt_misplaced key, so it repeated MISPLACED and never showed degraded data. The JSON output was correct. --- src/cmd/cli_pg_ls.cpp | 2 +- tests/run_tests.sh | 1 + tests/test_pg_ls.sh | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 tests/test_pg_ls.sh diff --git a/src/cmd/cli_pg_ls.cpp b/src/cmd/cli_pg_ls.cpp index 711489b0..d1cd9c9b 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{ 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..38166ec0 --- /dev/null +++ b/tests/test_pg_ls.sh @@ -0,0 +1,39 @@ +#!/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 + +format_green OK -- 2.47.3 From fe85092910062ace84114f8d7b77a2e3dbc6e631 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Tue, 20 Oct 2026 10:39:51 +0300 Subject: [PATCH 2/2] Fix vitastor-cli ls-pgs printing an empty table instead of an error When the pool was not found or the etcd request failed, load_pg_stats() stored the error, but loop() still ran format_pgs() which replaced the message with a table built from the pool config. ls-pgs then printed only a table header, or a table without stats, instead of the error. --- src/cmd/cli_pg_ls.cpp | 2 ++ tests/test_pg_ls.sh | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/cmd/cli_pg_ls.cpp b/src/cmd/cli_pg_ls.cpp index d1cd9c9b..6ad89958 100644 --- a/src/cmd/cli_pg_ls.cpp +++ b/src/cmd/cli_pg_ls.cpp @@ -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/test_pg_ls.sh b/tests/test_pg_ls.sh index 38166ec0..3ef5cee0 100755 --- a/tests/test_pg_ls.sh +++ b/tests/test_pg_ls.sh @@ -36,4 +36,12 @@ while read num count; do 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 -- 2.47.3