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

refactor(storage-manager): replication log lookup #1566

Merged
merged 2 commits into from
Oct 28, 2024

Conversation

J-Loudet
Copy link
Contributor

This commit optimises the method lookup to only lookup for newer (and
thus rename it to lookup_newer) Event.

As it is only looking for a newer Event, this method skips the Intervals
and SubIntervals that, by construction of the Replication Log, only
contain Events with lower timestamps.

This method now iterates over both the `SubIntervalIdx` and
`SubInterval` instead of only the `SubInterval`.

This change will be needed to optimise the `LogLatest::lookup` method.

* plugins/zenoh-plugin-storage-manager/src/replication/classification.rs:
  change the signature of the method `Interval::sub_intervals` to
  iterate over both the sub-interval index and sub-interval.

* plugins/zenoh-plugin-storage-manager/src/replication/core/aligner_query.rs:
  update due to the change.

Signed-off-by: Julien Loudet <[email protected]>
@J-Loudet J-Loudet added the enhancement Existing things could work better label Oct 28, 2024
@J-Loudet J-Loudet requested a review from oteffahi October 28, 2024 10:59
Copy link
Contributor

@oteffahi oteffahi left a comment

Choose a reason for hiding this comment

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

The logic makes sense to me. I also ran the intergration tests and it looks good.

Found two nitpicks to be addressed 😅

if event.timestamp >= event_to_lookup.timestamp {
EventLookup::NewerOrIdentical(event)
} else {
EventLookup::Older
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure it will never be useful to get the event in case of an EventLookup::Older?
IMO semantically the event exists, we should return it and it should be up to the calling logic to use it or not (unless this has a significant impact on performance).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand your point of view however as that code is only called from the Replication and that, for now, there are no cases where the metadata of an older event is needed, adding it brings no value (YAGNI).

This commit optimises the method `lookup` to only lookup for newer (and
thus rename it to `lookup_newer`) Event.

As it is only looking for a newer Event, this method skips the Intervals
and SubIntervals that, by construction of the Replication Log, only
contain Events with lower timestamps.

* plugins/zenoh-plugin-storage-manager/src/replication/classification.rs:
  - Added new enumeration `EventLookup`.
  - Removed the `Interval::lookup` method as this commit made it unneeded.
  - Updated the `SubInterval::lookup` method to return the newly created
    `EventLookup` enumeration.

* plugins/zenoh-plugin-storage-manager/src/replication/core/aligner_reply.rs:
  - Removed the code to filter out an Event with an older timestamp as
    the method `LogLatest::lookup_newer` already does it.
  - Create the `EventMetadata` before calling `LogLatest::remove_event` to
    avoid multiple borrows.

* plugins/zenoh-plugin-storage-manager/src/replication/log.rs: renamed
  the method `LogLatest::lookup` to `LogLatest::lookup_newer` and
  modified its behaviour to only look for newer Event.

* plugins/zenoh-plugin-storage-manager/src/storages_mgt/service.rs:
  only test if `LogLatest::lookup_newer` returned something.

Signed-off-by: Julien Loudet <[email protected]>
@J-Loudet J-Loudet force-pushed the refactor/storage-manager/replication-log-lookup branch from 32b93d8 to 9b5c1d6 Compare October 28, 2024 14:25
Copy link
Contributor

@oteffahi oteffahi left a comment

Choose a reason for hiding this comment

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

LGTM

@J-Loudet J-Loudet merged commit f5ba1cb into main Oct 28, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Existing things could work better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants