Store v2: Do not return unstable entries beyond the listing page #136

Merged
vitalif merged 1 commits from koolkhel/vitastor:list-trim-unstable into master 2026-11-21 11:26:03 +03:00
Contributor

Description

BS_OP_LIST with list_stable_limit promises unstable versions only from the range of the returned stable objects, and Store v1 keeps to it (it moves max_oid to the last stable object once the page is full). Store v2 limited only the stable part and returned every unstable version of the PG.

The paged caller is scrub, locally or through SEC_LIST: it walks all returned entries and then lists the next page starting just after the last stable object it got. So unstable versions past the page were handled in that page and again in a later one. This drops them once the page is full, also when it is filled exactly to the limit, since such a page also makes the caller ask for the next one.

Tested: test_blockstore (test_list_limit extended with an unstable-only object past the page, listed with a limit below and exactly at the stable count; fails on master).

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description BS_OP_LIST with list_stable_limit promises unstable versions only from the range of the returned stable objects, and Store v1 keeps to it (it moves max_oid to the last stable object once the page is full). Store v2 limited only the stable part and returned every unstable version of the PG. The paged caller is scrub, locally or through SEC_LIST: it walks all returned entries and then lists the next page starting just after the last stable object it got. So unstable versions past the page were handled in that page and again in a later one. This drops them once the page is full, also when it is filled exactly to the limit, since such a page also makes the caller ask for the next one. Tested: test_blockstore (test_list_limit extended with an unstable-only object past the page, listed with a limit below and exactly at the stable count; fails on master). ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-11-20 08:18:18 +03:00
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.
vitalif requested changes 2026-11-20 19:17:59 +03:00
@@ -380,0 +381,4 @@
size_t kept = 0;
for (size_t i = 0; i < unstable_count; i++)
{
if (!(last_oid < result[stable_count+i].oid))
Owner

Я не вижу нигде в сторе v1 такой проверки. И stable и unstable лимитируются одними и теми же min/max oid. И в v2 как будто тоже. В чём же тогда разница, зачем изменение?

Я не вижу нигде в сторе v1 такой проверки. И stable и unstable лимитируются одними и теми же min/max oid. И в v2 как будто тоже. В чём же тогда разница, зачем изменение?
koolkhel reviewed 2026-11-21 10:08:39 +03:00
@@ -380,0 +381,4 @@
size_t kept = 0;
for (size_t i = 0; i < unstable_count; i++)
{
if (!(last_oid < result[stable_count+i].oid))
Author
Contributor

Проверка в v1 есть, только сделана иначе, и в двух местах. Когда набралось list_stable_limit чистых объектов, v1 сужает max_oid до последнего возвращённого стабильного объекта (v1/impl.cpp:655), и dirty_db обходится уже до него (v1/impl.cpp:690). А если страница набралась на стабильных записях dirty_db, обход просто останавливается (v1/impl.cpp:736). Это и обещает blockstore.h:129: unstable только из (min_oid .. min(max_oid, max(returned stable OIDs))).

В v2 heap->list_objects() получает исходные min_oid/max_oid (blockstore_impl.cpp:371), после сортировки обрезается только stable-часть, а unstable копируются все (blockstore_impl.cpp:379). У скраба max_oid равен концу пула, так что каждая страница несёт все unstable-версии PG от min_oid до конца пула.

Пример из test_list_limit в PR: stable 1:0 v1, 1:128K v1, 1:256K v1; unstable 1:0 v2 и 1:384K v1 (у 1:384K есть только unstable-версия). BS_OP_LIST с list_stable_limit=1:

  • v1 1:384K не вернёт;
  • v2 на master вернёт [1:0 v1] + [1:0 v2, 1:384K v1], retval 3. Проверил: master плюс только тест из PR падает на assert(op.retval == 2) (test_blockstore.cpp:1091), с исправлением проходит.

Скраб обходит все записи ответа (osd_scrub.cpp:137), то есть проверяет 1:384K, потом просит следующую страницу после 1:0 (osd_scrub.cpp:169) и получает 1:384K снова. Так на каждой странице, пока стабильные объекты до него не дойдут. Отсюда и >=: при list_stable_limit=3 страница заполнена ровно, master в обрезку не заходит, а скраб всё равно запрашивает следующую страницу (osd_scrub.cpp:159).

Данные это не портит: это повторная проверка тех же объектов и лишние записи в каждом ответе. Предлагаю оставить, как в v1 и в blockstore.h. Если для v2 этот контракт не нужен, закрою PR.

Проверка в v1 есть, только сделана иначе, и в двух местах. Когда набралось `list_stable_limit` чистых объектов, v1 сужает `max_oid` до последнего возвращённого стабильного объекта ([v1/impl.cpp:655](https://git.yourcmc.ru/vitalif/vitastor/src/commit/cf5c466e83195bf7d870b60805ea23720c9ed76e/src/blockstore/v1/impl.cpp#L655)), и `dirty_db` обходится уже до него ([v1/impl.cpp:690](https://git.yourcmc.ru/vitalif/vitastor/src/commit/cf5c466e83195bf7d870b60805ea23720c9ed76e/src/blockstore/v1/impl.cpp#L690)). А если страница набралась на стабильных записях `dirty_db`, обход просто останавливается ([v1/impl.cpp:736](https://git.yourcmc.ru/vitalif/vitastor/src/commit/cf5c466e83195bf7d870b60805ea23720c9ed76e/src/blockstore/v1/impl.cpp#L736)). Это и обещает [blockstore.h:129](https://git.yourcmc.ru/vitalif/vitastor/src/commit/cf5c466e83195bf7d870b60805ea23720c9ed76e/src/blockstore/blockstore.h#L129): unstable только из `(min_oid .. min(max_oid, max(returned stable OIDs)))`. В v2 `heap->list_objects()` получает исходные `min_oid`/`max_oid` ([blockstore_impl.cpp:371](https://git.yourcmc.ru/vitalif/vitastor/src/commit/cf5c466e83195bf7d870b60805ea23720c9ed76e/src/blockstore/blockstore_impl.cpp#L371)), после сортировки обрезается только stable-часть, а unstable копируются все ([blockstore_impl.cpp:379](https://git.yourcmc.ru/vitalif/vitastor/src/commit/cf5c466e83195bf7d870b60805ea23720c9ed76e/src/blockstore/blockstore_impl.cpp#L379)). У скраба `max_oid` равен концу пула, так что каждая страница несёт все unstable-версии PG от `min_oid` до конца пула. Пример из `test_list_limit` в PR: stable `1:0 v1`, `1:128K v1`, `1:256K v1`; unstable `1:0 v2` и `1:384K v1` (у `1:384K` есть только unstable-версия). `BS_OP_LIST` с `list_stable_limit=1`: - v1 `1:384K` не вернёт; - v2 на master вернёт `[1:0 v1]` + `[1:0 v2, 1:384K v1]`, retval 3. Проверил: master плюс только тест из PR падает на `assert(op.retval == 2)` (test_blockstore.cpp:1091), с исправлением проходит. Скраб обходит все записи ответа ([osd_scrub.cpp:137](https://git.yourcmc.ru/vitalif/vitastor/src/commit/cf5c466e83195bf7d870b60805ea23720c9ed76e/src/osd/osd_scrub.cpp#L137)), то есть проверяет `1:384K`, потом просит следующую страницу после `1:0` ([osd_scrub.cpp:169](https://git.yourcmc.ru/vitalif/vitastor/src/commit/cf5c466e83195bf7d870b60805ea23720c9ed76e/src/osd/osd_scrub.cpp#L169)) и получает `1:384K` снова. Так на каждой странице, пока стабильные объекты до него не дойдут. Отсюда и `>=`: при `list_stable_limit=3` страница заполнена ровно, master в обрезку не заходит, а скраб всё равно запрашивает следующую страницу ([osd_scrub.cpp:159](https://git.yourcmc.ru/vitalif/vitastor/src/commit/cf5c466e83195bf7d870b60805ea23720c9ed76e/src/osd/osd_scrub.cpp#L159)). Данные это не портит: это повторная проверка тех же объектов и лишние записи в каждом ответе. Предлагаю оставить, как в v1 и в blockstore.h. Если для v2 этот контракт не нужен, закрою PR.
vitalif merged commit e4030c9f73 into master 2026-11-21 11:26:03 +03:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#136
No description provided.