osd: Merge object lists on peering instead of copying and sorting them #180

Open
koolkhel wants to merge 3 commits from koolkhel/vitastor:osd-peering-merge into master
Contributor

Description

calc_object_states() copied every listed object version into one array (40 bytes per version) and sorted it. On a PG with ~850k objects in an EC 8+2 pool (8.5M versions) this takes about 1.3 s on a desktop CPU and allocates a 340 MB temporary array, and the OSD event loop is blocked all that time: client I/O on the OSD stops and pings go unanswered.

Store v1 lists are already made of a few sorted runs (the clean part, the dirty-stable objects appended after it, the unstable part), so this change merges the runs with a heap and checks objects one at a time; the object state walk itself is unchanged. A list segment that is not made of a few sorted runs (the new store lists objects unordered) is sorted on its own first. The merged order is the same as after the full sort.

Measured calc_object_states() on that PG, 8.5M versions (master de3644bc against this PR, median of 3 runs):

Lists before after
all objects clean 1298 ms 200 ms
all objects misplaced (2 roles moved) 1364 ms 292 ms
store v1 shape: 2% new objects, some unstable versions 1269 ms 439 ms

osd_peering_pg_test (3 lists of 8M versions, default RelWithDebInfo flags): 3.3 s / 1.8 GB RSS before, 1.3 s / 0.6 GB after.

Found: seen on a large cluster under load: peering a PG with about 8.5M object versions kept the OSD event loop busy for 2-4 s, peers dropped the OSD by timeout, and a peering storm followed.

Tested: osd_peering_pg_test with a new check that the merged order equals a full sort (200 seeds; sorted, two-part, version-ascending and unordered segments, with tombstones), test_peering_tombstone, osd_test, test_pg_chaos; osd_peering_pg_test and test_peering_tombstone also under ASan+UBSan.

Contributor Name

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

CLA

### Description `calc_object_states()` copied every listed object version into one array (40 bytes per version) and sorted it. On a PG with ~850k objects in an EC 8+2 pool (8.5M versions) this takes about 1.3 s on a desktop CPU and allocates a 340 MB temporary array, and the OSD event loop is blocked all that time: client I/O on the OSD stops and pings go unanswered. Store v1 lists are already made of a few sorted runs (the clean part, the dirty-stable objects appended after it, the unstable part), so this change merges the runs with a heap and checks objects one at a time; the object state walk itself is unchanged. A list segment that is not made of a few sorted runs (the new store lists objects unordered) is sorted on its own first. The merged order is the same as after the full sort. Measured `calc_object_states()` on that PG, 8.5M versions (master de3644bc against this PR, median of 3 runs): | Lists | before | after | |---|---|---| | all objects clean | 1298 ms | 200 ms | | all objects misplaced (2 roles moved) | 1364 ms | 292 ms | | store v1 shape: 2% new objects, some unstable versions | 1269 ms | 439 ms | `osd_peering_pg_test` (3 lists of 8M versions, default RelWithDebInfo flags): 3.3 s / 1.8 GB RSS before, 1.3 s / 0.6 GB after. Found: seen on a large cluster under load: peering a PG with about 8.5M object versions kept the OSD event loop busy for 2-4 s, peers dropped the OSD by timeout, and a peering storm followed. Tested: `osd_peering_pg_test` with a new check that the merged order equals a full sort (200 seeds; sorted, two-part, version-ascending and unordered segments, with tombstones), `test_peering_tombstone`, `osd_test`, `test_pg_chaos`; `osd_peering_pg_test` and `test_peering_tombstone` also under ASan+UBSan. ### 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-24 23:08:34 +03:00
calc_object_states() copied every listed object version into one array
and sorted it, which blocks the OSD event loop for seconds when a PG
holds millions of object versions. Store v1 lists consist of a few
sorted runs, so merge the runs with a heap and check objects one at a
time. A list that is not made of a few sorted runs (the new store lists
objects unordered) is sorted on its own first. The result is the same
as with the full sort.
koolkhel added 1 commit 2026-11-25 03:08:35 +03:00
Put the stable, unstable and tombstone segments of an OSD into one
buffer, as LIST returns them, so a sort running past its segment is
caught. Set pg_data_size in the large XOR test, so it checks that the
unstable version on one OSD is rolled back.
koolkhel added 1 commit 2026-11-25 20:40:09 +03:00
A peer may report stable and tombstone counts above the number of
entries it sent; check that the merge clamps them and does not read
past the buffer. Also assert the rollback target in the large XOR
test: the OSD that rolls back holds no older version of its part.
Author
Contributor

Цифры в описании перемерил на финальном коде PR с одинаковыми флагами сборки (медиана 3 прогонов).
Прежние были сняты с прототипа, а 6,3 с — со сборки с другими флагами.

Цифры в описании перемерил на финальном коде PR с одинаковыми флагами сборки (медиана 3 прогонов). Прежние были сняты с прототипа, а 6,3 с — со сборки с другими флагами.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u osd-peering-merge:koolkhel-osd-peering-merge
git checkout koolkhel-osd-peering-merge
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#180
No description provided.