cli: Remove images of a deleted pool without their data #189
@@ -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);
|
||||
|
||||
@@ -172,6 +172,8 @@ public:
|
||||
uint64_t etcd_watch_revision_pg = 0;
|
||||
|
||||
std::map<pool_id_t, pool_config_t> pool_config;
|
||||
// IDs in /config/pools, valid or not: a pool missing here is deleted
|
||||
std::set<pool_id_t> pools_in_config;
|
||||
std::map<osd_num_t, json11::Json> peer_states;
|
||||
std::map<inode_t, inode_config_t> inode_config;
|
||||
std::map<std::string, inode_t> inode_by_name;
|
||||
|
||||
@@ -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)
|
||||
@@ -812,6 +834,13 @@ resume_100:
|
||||
state = 100;
|
||||
return;
|
||||
}
|
||||
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
|
||||
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) },
|
||||
|
||||
@@ -45,9 +45,9 @@ 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" };
|
||||
result = (cli_result_t){ .err = EINVAL, .text = "Pool "+std::to_string(pool_id)+" does not exist or its configuration is invalid" };
|
||||
state = 100;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
46
tests/test_rm_deleted_pool.sh
Executable file
46
tests/test_rm_deleted_pool.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash -ex
|
||||
|
||||
# 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
|
||||
|
||||
$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 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 == 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"
|
||||
|
||||
$VITASTOR_CLI rm-pool --force testpool2
|
||||
timeout 60 $VITASTOR_CLI rm testimg2
|
||||
|
||||
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"
|
||||
|
||||
format_green OK
|
||||
Reference in New Issue
Block a user