From 4a30eb2f5af57f052d5e531c78e433df9cad250a Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Wed, 25 Nov 2026 20:14:23 +0300 Subject: [PATCH 1/3] cli: Remove images of a deleted pool without their data rm-pool --force leaves the pool's images in /config/inode, and rm could never remove them: it marked the image deleted and then failed with "Pool does not exist", or hung while the monitor was still removing the pool's PGs, because the pool stays in pool_config with exists=false until then. Skip the data of a layer whose pool is gone and remove only its metadata. Treat a pool with exists=false as missing in rm-data and in rm's statistics read too, so neither waits for PGs of a deleted pool. --- src/cmd/cli_rm.cpp | 15 +++++++++++---- src/cmd/cli_rm_data.cpp | 2 +- tests/run_tests.sh | 1 + tests/test_rm_deleted_pool.sh | 22 ++++++++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100755 tests/test_rm_deleted_pool.sh diff --git a/src/cmd/cli_rm.cpp b/src/cmd/cli_rm.cpp index 48d4d8cf..eb01af57 100644 --- a/src/cmd/cli_rm.cpp +++ b/src/cmd/cli_rm.cpp @@ -460,11 +460,9 @@ resume_100: return; } auto pool_cfg_it = parent->cli->st_cli->pool_config.find(pool_id); - if (pool_cfg_it == parent->cli->st_cli->pool_config.end()) + if (pool_cfg_it == parent->cli->st_cli->pool_config.end() || !pool_cfg_it->second.exists) { - result = (cli_result_t){ .err = ENOENT, .text = "Pool "+std::to_string(pool_id)+" does not exist" }; - state = 100; - return; + continue; } inode = INODE_WITH_POOL(pool_id, inode); auto & pool_cfg = pool_cfg_it->second; @@ -812,6 +810,15 @@ resume_100: state = 100; return; } + auto pool_it = parent->cli->st_cli->pool_config.find(INODE_POOL(inode)); + if (pool_it == parent->cli->st_cli->pool_config.end() || !pool_it->second.exists) + { + // rm-pool --force leaves the pool's images: only their metadata can be removed + if (parent->progress) + fprintf(stderr, "Pool %u does not exist, removing layer %s without its data\n", + INODE_POOL(inode), source->second.name.c_str()); + return; + } cb = parent->start_rm_data(json11::Json::object { { "inode", inode }, { "pool", (uint64_t)INODE_POOL(inode) }, diff --git a/src/cmd/cli_rm_data.cpp b/src/cmd/cli_rm_data.cpp index 77d31ae6..a5b9e3e9 100644 --- a/src/cmd/cli_rm_data.cpp +++ b/src/cmd/cli_rm_data.cpp @@ -45,7 +45,7 @@ struct rm_inode_t void start_delete() { auto pool_it = parent->cli->st_cli->pool_config.find(pool_id); - if (pool_it == parent->cli->st_cli->pool_config.end()) + if (pool_it == parent->cli->st_cli->pool_config.end() || !pool_it->second.exists) { result = (cli_result_t){ .err = EINVAL, .text = "Pool does not exist" }; state = 100; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index caac41b7..336b7f52 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -69,6 +69,7 @@ OLD=1 ./test_move_reappear.sh ./test_modify_image_resize.sh ./test_rm_degraded.sh +./test_rm_deleted_pool.sh ./test_describe.sh ./test_snapshot_chain.sh diff --git a/tests/test_rm_deleted_pool.sh b/tests/test_rm_deleted_pool.sh new file mode 100755 index 00000000..f96c5cfe --- /dev/null +++ b/tests/test_rm_deleted_pool.sh @@ -0,0 +1,22 @@ +#!/bin/bash -ex + +# rm-pool --force leaves the pool's images: rm must remove them while the monitor +# is still dropping the pool's PGs, and after it has dropped them + +. `dirname $0`/run_3osds.sh + +$VITASTOR_CLI create-pool testpool2 -s 2 -n 4 --failure_domain osd +wait_pool_up 30 2 2 4 + +$VITASTOR_CLI create -s 16M -p testpool2 testimg2 +$VITASTOR_CLI create -s 16M -p testpool2 testimg3 +$VITASTOR_CLI rm-pool --force testpool2 + +timeout 60 $VITASTOR_CLI rm testimg2 +wait_condition 30 "$ETCDCTL get /vitastor/pg/config --print-value-only | jq -e '.items[\"2\"] == null'" "Removing PGs of the deleted pool" +timeout 60 $VITASTOR_CLI rm testimg3 + +[[ -z "$($ETCDCTL get --prefix /vitastor/config/inode/2/ --keys-only)" ]] || format_error "Image config of the deleted pool not removed" +[[ -z "$($ETCDCTL get --prefix /vitastor/index/image/testimg --keys-only)" ]] || format_error "Image index of the deleted pool not removed" + +format_green OK -- 2.47.3 From d1f473822abb1c61dd98ccbac1777085538d97c6 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Thu, 26 Nov 2026 02:17:35 +0300 Subject: [PATCH 2/3] cli: Skip data in rm only for pools missing from /config/pools pool_config's exists flag is also false for a pool whose configuration fails validation, for example one written by a newer version, and rm then removed such a pool's images without their data. Track the pool IDs present in /config/pools and remove a layer without its data only when its pool is not there. Refuse to remove layers with children when a pool of the merge is deleted: merging needs the data, and the CLI crashed on the missing pool. Print the warning about the skipped data with --json too. --- src/client/etcd_state_client.cpp | 4 ++++ src/client/etcd_state_client.h | 2 ++ src/cmd/cli_rm.cpp | 36 +++++++++++++++++++++++++------- src/cmd/cli_rm_data.cpp | 2 +- tests/test_rm_deleted_pool.sh | 32 ++++++++++++++++++++++++---- 5 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/client/etcd_state_client.cpp b/src/client/etcd_state_client.cpp index c870386a..707d765e 100644 --- a/src/client/etcd_state_client.cpp +++ b/src/client/etcd_state_client.cpp @@ -445,6 +445,7 @@ void etcd_state_client_t::parse_state(const etcd_kv_t & kv) const json11::Json & value = kv.value; if (key == etcd_prefix+"/config/pools") { + pools_in_config.clear(); for (auto & pool_item: this->pool_config) { pool_item.second.exists = false; @@ -456,6 +457,9 @@ void etcd_state_client_t::parse_state(const etcd_kv_t & kv) pool_id_t pool_id; char null_byte = 0; int scanned = sscanf(pool_item.first.c_str(), "%u%c", &pool_id, &null_byte); + // A malformed key like "3 " most likely still names pool 3 + if (scanned >= 1 && pool_id && pool_id < POOL_ID_MAX) + pools_in_config.insert(pool_id); if (scanned != 1 || !pool_id || pool_id >= POOL_ID_MAX) { fprintf(stderr, "Pool ID %s is invalid (must be a number less than 0x%x), skipping pool\n", pool_item.first.c_str(), POOL_ID_MAX); diff --git a/src/client/etcd_state_client.h b/src/client/etcd_state_client.h index 09066996..fcc75576 100644 --- a/src/client/etcd_state_client.h +++ b/src/client/etcd_state_client.h @@ -172,6 +172,8 @@ public: uint64_t etcd_watch_revision_pg = 0; std::map pool_config; + // IDs in /config/pools, valid or not: a pool missing here is deleted + std::set pools_in_config; std::map peer_states; std::map inode_config; std::map inode_by_name; diff --git a/src/cmd/cli_rm.cpp b/src/cmd/cli_rm.cpp index eb01af57..f8b73c58 100644 --- a/src/cmd/cli_rm.cpp +++ b/src/cmd/cli_rm.cpp @@ -137,6 +137,9 @@ resume_11: return; // Get children to merge - from this point, images shouldn't be rebased to deleted layers get_merge_children(); + check_merge_pools(); + if (state == 100) + return; // Try to select an inode for the "inverse" optimized scenario // Read statistics from etcd to do it read_stats(); @@ -397,6 +400,25 @@ resume_100: } } + // Merging layers into their children needs the layers' data, which is gone with a deleted pool + void check_merge_pools() + { + auto & pools = parent->cli->st_cli->pools_in_config; + inode_t gone = 0; + for (auto & ic: sources) + if (!pools.count(INODE_POOL(ic.first))) + gone = ic.first; + for (auto & ic: merge_children) + if (!pools.count(INODE_POOL(ic.first))) + gone = ic.first; + if (gone && merge_children.size()) + { + result = (cli_result_t){ .err = ENOENT, .text = "Pool "+std::to_string(INODE_POOL(gone))+ + " does not exist, so layers can't be merged into their children. Remove the children first" }; + state = 100; + } + } + void read_stats() { if (inverse_candidates.size() == 0) @@ -460,9 +482,11 @@ resume_100: return; } auto pool_cfg_it = parent->cli->st_cli->pool_config.find(pool_id); - if (pool_cfg_it == parent->cli->st_cli->pool_config.end() || !pool_cfg_it->second.exists) + if (pool_cfg_it == parent->cli->st_cli->pool_config.end()) { - continue; + result = (cli_result_t){ .err = ENOENT, .text = "Pool "+std::to_string(pool_id)+" does not exist" }; + state = 100; + return; } inode = INODE_WITH_POOL(pool_id, inode); auto & pool_cfg = pool_cfg_it->second; @@ -810,13 +834,11 @@ resume_100: state = 100; return; } - auto pool_it = parent->cli->st_cli->pool_config.find(INODE_POOL(inode)); - if (pool_it == parent->cli->st_cli->pool_config.end() || !pool_it->second.exists) + if (!parent->cli->st_cli->pools_in_config.count(INODE_POOL(inode))) { // rm-pool --force leaves the pool's images: only their metadata can be removed - if (parent->progress) - fprintf(stderr, "Pool %u does not exist, removing layer %s without its data\n", - INODE_POOL(inode), source->second.name.c_str()); + fprintf(stderr, "Pool %u does not exist, removing layer %s without its data\n", + INODE_POOL(inode), source->second.name.c_str()); return; } cb = parent->start_rm_data(json11::Json::object { diff --git a/src/cmd/cli_rm_data.cpp b/src/cmd/cli_rm_data.cpp index a5b9e3e9..6bffaffd 100644 --- a/src/cmd/cli_rm_data.cpp +++ b/src/cmd/cli_rm_data.cpp @@ -47,7 +47,7 @@ struct rm_inode_t auto pool_it = parent->cli->st_cli->pool_config.find(pool_id); if (pool_it == parent->cli->st_cli->pool_config.end() || !pool_it->second.exists) { - result = (cli_result_t){ .err = EINVAL, .text = "Pool does not exist" }; + result = (cli_result_t){ .err = EINVAL, .text = "Pool "+std::to_string(pool_id)+" does not exist or its configuration is invalid" }; state = 100; return; } diff --git a/tests/test_rm_deleted_pool.sh b/tests/test_rm_deleted_pool.sh index f96c5cfe..8833f0d3 100755 --- a/tests/test_rm_deleted_pool.sh +++ b/tests/test_rm_deleted_pool.sh @@ -1,7 +1,7 @@ #!/bin/bash -ex -# rm-pool --force leaves the pool's images: rm must remove them while the monitor -# is still dropping the pool's PGs, and after it has dropped them +# rm-pool --force leaves the pool's images: rm must remove them before the monitor +# drops the pool's PGs, and after it has dropped them . `dirname $0`/run_3osds.sh @@ -10,11 +10,35 @@ wait_pool_up 30 2 2 4 $VITASTOR_CLI create -s 16M -p testpool2 testimg2 $VITASTOR_CLI create -s 16M -p testpool2 testimg3 -$VITASTOR_CLI rm-pool --force testpool2 +$VITASTOR_CLI snap-create testimg3@snap +# The PGs of the deleted pool stay in /pg/config while the monitor is down +kill -9 $MON_PID +wait $MON_PID || true + +# A pool with an invalid configuration is not deleted: rm must keep its images +POOLS=$($ETCDCTL get /vitastor/config/pools --print-value-only) +$ETCDCTL put /vitastor/config/pools "$(jq -c '.["2"].name = ""' <<<"$POOLS")" +rc=0 +timeout 60 $VITASTOR_CLI rm testimg2 || rc=$? +[[ $rc != 0 && -n "$($ETCDCTL get /vitastor/index/image/testimg2 --keys-only)" ]] || \ + format_error "rm of an image in a pool with an invalid configuration exited with $rc" +$ETCDCTL put /vitastor/config/pools "$POOLS" + +$VITASTOR_CLI rm-pool --force testpool2 timeout 60 $VITASTOR_CLI rm testimg2 -wait_condition 30 "$ETCDCTL get /vitastor/pg/config --print-value-only | jq -e '.items[\"2\"] == null'" "Removing PGs of the deleted pool" + +node mon/mon-main.js $MON_PARAMS --verbose 1 >>./testdata/mon.log 2>&1 & +MON_PID=$! +wait_condition 60 "$ETCDCTL get /vitastor/pg/config --print-value-only | jq -e '.items[\"2\"] == null'" "Removing PGs of the deleted pool" + +# A layer with children can't be merged into them without its data +rc=0 +timeout 60 $VITASTOR_CLI rm testimg3@snap 2> ./testdata/rm.err || rc=$? +[[ $rc == 2 ]] && grep -q "Remove the children first" ./testdata/rm.err || \ + format_error "rm of a snapshot with children in a deleted pool exited with $rc: $(cat ./testdata/rm.err)" timeout 60 $VITASTOR_CLI rm testimg3 +timeout 60 $VITASTOR_CLI rm testimg3@snap [[ -z "$($ETCDCTL get --prefix /vitastor/config/inode/2/ --keys-only)" ]] || format_error "Image config of the deleted pool not removed" [[ -z "$($ETCDCTL get --prefix /vitastor/index/image/testimg --keys-only)" ]] || format_error "Image index of the deleted pool not removed" -- 2.47.3 From aff08c58475a9191ecb4542f98c139bb4828210a Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Thu, 26 Nov 2026 08:30:08 +0300 Subject: [PATCH 3/3] cli: Expect EINVAL from rm in a pool with an invalid configuration The test accepted any non-zero exit code there, so a hang killed by timeout (124) passed it as well. --- tests/test_rm_deleted_pool.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_rm_deleted_pool.sh b/tests/test_rm_deleted_pool.sh index 8833f0d3..d7d9ff60 100755 --- a/tests/test_rm_deleted_pool.sh +++ b/tests/test_rm_deleted_pool.sh @@ -21,7 +21,7 @@ POOLS=$($ETCDCTL get /vitastor/config/pools --print-value-only) $ETCDCTL put /vitastor/config/pools "$(jq -c '.["2"].name = ""' <<<"$POOLS")" rc=0 timeout 60 $VITASTOR_CLI rm testimg2 || rc=$? -[[ $rc != 0 && -n "$($ETCDCTL get /vitastor/index/image/testimg2 --keys-only)" ]] || \ +[[ $rc == 22 && -n "$($ETCDCTL get /vitastor/index/image/testimg2 --keys-only)" ]] || \ format_error "rm of an image in a pool with an invalid configuration exited with $rc" $ETCDCTL put /vitastor/config/pools "$POOLS" -- 2.47.3