Skip to content

[IMPROVED] Stream catchup with many deleted messages#7512

Merged
neilalexander merged 1 commit intomainfrom
maurice/catchup-load-next
Nov 5, 2025
Merged

[IMPROVED] Stream catchup with many deleted messages#7512
neilalexander merged 1 commit intomainfrom
maurice/catchup-load-next

Conversation

@MauriceVanVeen
Copy link
Copy Markdown
Member

Stream catchup could be very slow if the stream contained many millions of deleted messages, but didn't pass the threshold of having more deletes than 10x the total messages. Generally LoadMsg will be faster than LoadNextMsg if there are (nearly) no deleted messages, but LoadNextMsg becomes faster the more deletes there are in the stream.

Imagine a stream with 40 million messages and 90 million interior deletes. Under the old logic there would not be 400 million deletes, so we'd linearly scan through the whole stream whereas we could skip ahead way more effectively. This ratio is decreased to having 2x as many deletes as messages with an upper bound of 1 million deleted messages such that a stream with 40 million messages and the same amount of deletes would still use the optimized LoadNextMsg.

This PR also adds the time taken for the catchup to complete.

Signed-off-by: Maurice van Veen github@mauricevanveen.com

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner November 5, 2025 12:36
Copy link
Copy Markdown
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

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

LGTM

@neilalexander neilalexander merged commit eeccca1 into main Nov 5, 2025
90 of 92 checks passed
@neilalexander neilalexander deleted the maurice/catchup-load-next branch November 5, 2025 13:02
neilalexander added a commit that referenced this pull request Nov 5, 2025
Includes the following:

- #7499
- #7503
- #7508
- #7510
- #7509
- #7512
- #7516
- #7515

Signed-off-by: Neil Twigg <neil@nats.io>
neilalexander added a commit that referenced this pull request Nov 5, 2025
Includes the following:

- #7416
- #7425
- #7486
- #7495
- #7482
- #7496
- #7499
- #7503
- #7508 (excluding weak
pointer/cache-related changes that apply only to 2.12.x)
- #7510
- #7509
- #7512
- #7516
- #7515

Signed-off-by: Neil Twigg <neil@nats.io>
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.

2 participants