From 1eec4407abdfcf34870991ba74045184fc1055a4 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Mon, 6 Jun 2022 16:34:02 +0300 Subject: [PATCH] Fix inode creation when /index/maxid is out of sync --- src/cli_create.cpp | 3 ++- tests/run_tests.sh | 2 ++ tests/test_create_nomaxid.sh | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100755 tests/test_create_nomaxid.sh diff --git a/src/cli_create.cpp b/src/cli_create.cpp index 4fafcddd..8963838f 100644 --- a/src/cli_create.cpp +++ b/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--; diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 151e7faf..f021851e 100755 --- a/tests/run_tests.sh +++ b/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 diff --git a/tests/test_create_nomaxid.sh b/tests/test_create_nomaxid.sh new file mode 100755 index 00000000..17f2a4c1 --- /dev/null +++ b/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