Compare commits

...

2 Commits

Author SHA1 Message Date
fe85092910 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.
2026-10-20 10:39:51 +03:00
19d20291ba 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.
2026-10-20 10:38:23 +03:00
3 changed files with 51 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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

47
tests/test_pg_ls.sh Executable file
View File

@@ -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