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); }