Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Add truncation to message log #526

Merged
merged 1 commit into from
Nov 9, 2023
Merged

core: Add truncation to message log #526

merged 1 commit into from
Nov 9, 2023

Conversation

kim
Copy link
Contributor

@kim kim commented Nov 6, 2023

Description of Changes

Adds a method reset_to(offset) to MessageLog, which allows to truncate the log to the given message offset.

Note that this currently requires to iterate over the last segment until the message offset is found -- we may in the future maintain an offset index (a la Kafka) to be able to seek closer to the desired message offset.

reset_to subsumes the unused reset_hard method, and is itself not yet used (this will be added in a later patch).

Note The first commit is submitted separately in #496

API and ABI

  • This is a breaking change to the module ABI
  • This is a breaking change to the module API
  • This is a breaking change to the ClientAPI
  • This is a breaking change to the SDK API

If the API is breaking, please state below what will break

Expected complexity level and risk

3

@kim kim mentioned this pull request Nov 6, 2023
4 tasks
@kim kim force-pushed the kim/truncate-mlog branch from 39f96cb to 29da610 Compare November 6, 2023 12:49
Copy link
Contributor

@kulakowski kulakowski left a comment

Choose a reason for hiding this comment

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

If there's no rush I'd like to finish the review after #496 lands

crates/core/src/db/message_log.rs Outdated Show resolved Hide resolved
@kim kim force-pushed the kim/truncate-mlog branch from 29da610 to 97093dd Compare November 7, 2023 07:58
@kim kim force-pushed the kim/truncate-mlog branch 2 times, most recently from 426d943 to 8f0fb19 Compare November 8, 2023 07:48
let to_retain = self.open_segment_max_offset - offset;
let mut retained = 0;
for message in iter.by_ref().take(to_retain as usize) {
let _ = message?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only place I don't immediately understand, just because I don't know what would cause this to return via the ?. Could you comment about that please?

Adds a method `reset_to(offset)` to `MessageLog`, which allows to
truncate the log to the given message offset.

Note that this currently requires to iterate over the last segment until
the message offset is found -- we may in the future maintain an offset
index (a la Kafka) to be able to seek closer to the desired message
offset.

`reset_to` subsumes the unused `reset_hard` method, and is itself not
yet used (this will be added in a later patch).
@kim kim force-pushed the kim/truncate-mlog branch from 8f0fb19 to 0039797 Compare November 9, 2023 08:48
@kim kim enabled auto-merge (rebase) November 9, 2023 08:49
@kim kim merged commit fa96dc2 into master Nov 9, 2023
5 checks passed
@kim kim deleted the kim/truncate-mlog branch November 9, 2023 09:08
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