Skip to content

Improved segment flush ordering#7381

Merged
timvisee merged 6 commits intodevfrom
improved-segment-flush-ordering
Oct 21, 2025
Merged

Improved segment flush ordering#7381
timvisee merged 6 commits intodevfrom
improved-segment-flush-ordering

Conversation

@timvisee
Copy link
Member

@timvisee timvisee commented Oct 10, 2025

Depends on #7388

Improves flush ordering for segments. The main problem is proxy segments shadowing appendable state of the actual segments.

We have a strict ordering requirement for segments when flushing to retain data consistency. We must flush appendable segments first.

Proxy segments are always considered non-appendable since #7345, even though the wrapped segment might originally have been appendable.

In case of flushing, we care about the wrapped segments. They hold the physical data and might have changes pending flush. A proxy wrapping an appendable segment must still always be flushed before any non-appendable segments.

The proxy segments shadowed the appendable state, which messed with the flush ordering. To solve this, I now define desired flush ordering for each segment with a state. Proxy segments are flushed in between regular appendable and non-appendable segments.

As a secondary change this also enforces the same ordering for proxying all segments during snapshot. Snapshots now explicitly flush segments, and so it must follow the same ordering requirements.

Tasks

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

@timvisee timvisee mentioned this pull request Oct 13, 2025
@timvisee timvisee force-pushed the improved-segment-flush-ordering branch from 5be91d5 to 28d48c1 Compare October 13, 2025 12:41
@timvisee timvisee changed the base branch from always-sync-force-flush to single-thread-flush October 13, 2025 12:41
@timvisee timvisee force-pushed the improved-segment-flush-ordering branch from 30d264d to 18b2aa6 Compare October 13, 2025 14:10
@timvisee timvisee changed the title Draft: improved segment flush ordering Improved segment flush ordering Oct 13, 2025
@agourlay
Copy link
Member

This branch is Crasher approved ✔️

cargo run -r -- --working-dir "/home/agourlay/Workspace/qdrant/" --exec-path "target/perf/qdrant" --crash-probability 0.5 --segment-count 2 --cpu-quota 8

@generall generall force-pushed the single-thread-flush branch from 995bf4f to 239e6c6 Compare October 14, 2025 13:16
Base automatically changed from single-thread-flush to dev October 14, 2025 14:39
@timvisee timvisee force-pushed the improved-segment-flush-ordering branch from 26dc545 to 20f4562 Compare October 14, 2025 14:40
@timvisee timvisee marked this pull request as ready for review October 14, 2025 14:40
@timvisee timvisee requested review from agourlay and generall October 14, 2025 14:40
@qdrant qdrant deleted a comment from coderabbitai bot Oct 14, 2025
@qdrant qdrant deleted a comment from coderabbitai bot Oct 14, 2025
@timvisee timvisee requested a review from ffuugoo October 15, 2025 08:58
@@ -62,13 +62,8 @@
.collect();
segment_reads.reverse();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this reverse if we do sort_* right after?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

/// If there are unsaved changes after flush - detects lowest unsaved change version.
/// If all changes are saved - returns max version.
pub fn flush_all(&self, sync: bool, force: bool) -> OperationResult<SeqNumberType> {
let lock_order: Vec<_> = self.segment_flush_ordering().collect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we need to adjust this as well? Open question, cause I'm not sure if we do. But it's a bit confusing that we have segment_flush_ordering method and SegmentFlushOrdering type, and they are not related (e.g., one does not depend on the other).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this is confusing.
Can we unify them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we must unify this. I have some changes for the segment holder in mind, and will do that in a bit.

@ffuugoo
Copy link
Contributor

ffuugoo commented Oct 16, 2025

Overall, the idea of PR makes sense IMO, but I'm confused by segment_flush_ordering method and SegmentFlushOrdering type (and that they are not directly depend on each other): when segment_flush_ordering is enough, and when SegmentFlushOrdering should be additionally enforced?

Co-authored-by: Arnaud Gourlay <arnaud.gourlay@gmail.com>
coderabbitai[bot]

This comment was marked as resolved.

@qdrant qdrant deleted a comment from coderabbitai bot Oct 21, 2025
Copy link
Member

@agourlay agourlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to let it bake on our mean CIs.

Expecting the mentioned unification to be part of a next PR.

@timvisee
Copy link
Member Author

timvisee commented Oct 21, 2025

I agree the current design isn't great as noted in #7381 (comment). Though, we do agree that a change like this makes sense.

Even though a better design is pending, I'll now merge this anyway. It gives us a bit more time to test the change in practice on our chaos testing setup.

I have a better design approach in mind which I'll implement asynchronously to still meet with the review remarks. I'll not change behavior and so merging this should be fine. Then we can discuss the design changes in more detail in a dedicated PR.

Update: initial design improvements handled in #7436

@timvisee timvisee merged commit 27cf6e3 into dev Oct 21, 2025
15 checks passed
@timvisee timvisee deleted the improved-segment-flush-ordering branch October 21, 2025 14:21
timvisee added a commit that referenced this pull request Nov 14, 2025
* Re-sort segments on flush, don't use proxy but inner segment state

* Also sort segments when proxying all segments for snapshot

The snapshot operation explicitly flushes segments. We therefore must
satisfy flush ordering there too.

* Add some helpful comments

* Add explicit flush ordering enum for segments

* Minor tweaks

* Fix spelling in comment

Co-authored-by: Arnaud Gourlay <arnaud.gourlay@gmail.com>

---------

Co-authored-by: Arnaud Gourlay <arnaud.gourlay@gmail.com>
@timvisee timvisee mentioned this pull request Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants