From 5bcffd061e4184e4658c4657964084c1468eb1c6 Mon Sep 17 00:00:00 2001 From: Vitaliy Idelson Date: Fri, 20 Nov 2026 07:42:21 +0300 Subject: [PATCH] Store v2: Do not return unstable entries beyond the listing page BS_OP_LIST with list_stable_limit promises unstable versions only from the range of the returned stable objects, and the old store keeps to it. The new store returned every unstable version of the PG, so a paged caller (scrub, locally or through SEC_LIST) got the ones past the page and got them again with the next page. Drop them once the page is full, also when it is filled exactly to the limit. --- src/blockstore/blockstore_impl.cpp | 12 ++++++++++-- src/test/test_blockstore.cpp | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/blockstore/blockstore_impl.cpp b/src/blockstore/blockstore_impl.cpp index 5861e09d..f14bb3b5 100644 --- a/src/blockstore/blockstore_impl.cpp +++ b/src/blockstore/blockstore_impl.cpp @@ -374,9 +374,17 @@ void blockstore_impl_t::process_list(blockstore_op_t *op) // Ordered result is expected - used by scrub // We use an unordered map std::sort(result, result + stable_count); - if (stable_count > op->list_stable_limit) + if (stable_count >= op->list_stable_limit) { - memmove(result + op->list_stable_limit, result + stable_count, unstable_count*sizeof(obj_ver_id)); + // Return unstable versions only up to the last stable object, the caller continues after it + object_id last_oid = result[op->list_stable_limit-1].oid; + size_t kept = 0; + for (size_t i = 0; i < unstable_count; i++) + { + if (!(last_oid < result[stable_count+i].oid)) + result[op->list_stable_limit + kept++] = result[stable_count+i]; + } + unstable_count = kept; stable_count = op->list_stable_limit; } } diff --git a/src/test/test_blockstore.cpp b/src/test/test_blockstore.cpp index 2730b5ab..a0504da5 100644 --- a/src/test/test_blockstore.cpp +++ b/src/test/test_blockstore.cpp @@ -1071,6 +1071,12 @@ static void test_list_limit() test.exec_op(&op); assert(op.retval == op.len); + printf("writing 1:384K 4K+4K unstable\n"); + op.oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 384*1024 }; + op.version = 1; + test.exec_op(&op); + assert(op.retval == op.len); + op.opcode = BS_OP_LIST; free(op.buf); op.buf = NULL; @@ -1087,6 +1093,17 @@ static void test_list_limit() obj_ver_id *lst = (obj_ver_id*)op.buf; assert((lst[0] == (obj_ver_id){ .oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 }, .version = 1 })); assert((lst[1] == (obj_ver_id){ .oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 }, .version = 2 })); + free(op.buf); + + // A page filled exactly to the limit leaves 1:384K to the next page too + op.buf = NULL; + op.max_oid = { .inode = INODE_WITH_POOL(1, 1000), .stripe = 0 }; + op.list_stable_limit = 3; + test.exec_op(&op); + assert(op.retval == 4); + assert(op.version == 3); + lst = (obj_ver_id*)op.buf; + assert((lst[3] == (obj_ver_id){ .oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 }, .version = 2 })); free(op.buf); } -- 2.47.3