Browse Source

Fix inode creation when /index/maxid is out of sync

lrc-matrix
Vitaliy Filippov 6 months ago
parent
commit
1eec4407ab
  1. 3
      src/cli_create.cpp
  2. 2
      tests/run_tests.sh
  3. 21
      tests/test_create_nomaxid.sh

3
src/cli_create.cpp

@ -276,7 +276,8 @@ resume_4:
new_id = 1+INODE_NO_POOL(kv.value.uint64_value());
max_id_mod_rev = kv.mod_revision;
}
auto ino_it = parent->cli->st_cli.inode_config.lower_bound(INODE_WITH_POOL(new_pool_id, 0));
// Also check existing inodes - for the case when some inodes are created without changing /index/maxid
auto ino_it = parent->cli->st_cli.inode_config.lower_bound(INODE_WITH_POOL(new_pool_id+1, 0));
if (ino_it != parent->cli->st_cli.inode_config.begin())
{
ino_it--;

2
tests/run_tests.sh

@ -12,6 +12,8 @@ SCHEME=ec ./test_change_pg_count.sh
./test_change_pg_size.sh
./test_create_nomaxid.sh
./test_etcd_fail.sh
./test_failure_domain.sh

21
tests/test_create_nomaxid.sh

@ -0,0 +1,21 @@
#!/bin/bash -ex
# Test vitastor-cli create when /index/maxid is out of sync
. `dirname $0`/run_3osds.sh
$ETCDCTL put /vitastor/config/inode/1/120 '{"name":"testimg","size":'$((1024*1024*1024))'}'
build/src/vitastor-cli create --etcd_address $ETCD_URL -s 1G testimg2
t=$($ETCDCTL get --print-value-only /vitastor/config/inode/1/121 | jq -r .name)
if [[ "$t" != "testimg2" ]]; then
format_error "testimg2 should've been created as inode 121"
fi
t=$($ETCDCTL get --print-value-only /vitastor/index/maxid/1)
if [[ "$t" != 121 ]]; then
format_error "/index/maxid should've been set to 121"
fi
format_green OK
Loading…
Cancel
Save