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

Diff transfer improvements #3645

Merged
merged 14 commits into from
Feb 29, 2024
Merged

Diff transfer improvements #3645

merged 14 commits into from
Feb 29, 2024

Conversation

ffuugoo
Copy link
Contributor

@ffuugoo ffuugoo commented Feb 19, 2024

Minor fixes/improvements/cleanups for diff transfer related code.

Tracked in: #3477

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?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --all --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copy link
Member

@timvisee timvisee left a comment

Choose a reason for hiding this comment

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

Some of my comments on the current state.

lib/collection/src/shards/local_shard/mod.rs Outdated Show resolved Hide resolved
lib/collection/src/shards/shard.rs Outdated Show resolved Hide resolved
lib/collection/src/shards/shard.rs Outdated Show resolved Hide resolved
lib/collection/src/wal.rs Outdated Show resolved Hide resolved
lib/collection/src/wal.rs Outdated Show resolved Hide resolved
lib/collection/src/wal_delta.rs Outdated Show resolved Hide resolved
lib/collection/src/wal_delta.rs Outdated Show resolved Hide resolved
lib/collection/src/wal_delta.rs Outdated Show resolved Hide resolved
lib/collection/src/wal_delta.rs Outdated Show resolved Hide resolved
lib/collection/src/wal_delta.rs Outdated Show resolved Hide resolved
@ffuugoo ffuugoo force-pushed the diff-transfer-cleanup branch 4 times, most recently from a5dba1f to cd9c0f0 Compare February 23, 2024 14:14
@ffuugoo ffuugoo marked this pull request as ready for review February 23, 2024 14:15
@ffuugoo
Copy link
Contributor Author

ffuugoo commented Feb 23, 2024

Resolved all previous comments, organized history, rebased on dev, added a few more improvements. Also removed proto file changes (will open a separate PR in a moment).

Copy link
Member

@timvisee timvisee left a comment

Choose a reason for hiding this comment

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

Some comments (and ⛏️s) on a quick pass.

if clock_tag.clock_tick <= *tick {
/// Remove a clock referenced by the clock tag from this recovery point, if the clock is
/// *newer or equal* than the tick in the tag.
pub fn remove_clock_if_newer_than_or_equal_to_tag(&mut self, tag: ClockTag) {
Copy link
Member

Choose a reason for hiding this comment

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

In my opinion names like this are a bit too explicit:

  • 'clock's are obsolete because the only thing we manage is clocks
  • 'tag' is obsolete because the parameter already clarifies this

This screams Java

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kinda agree about "clock" part... but not about the "tag".

The problem with remove_if_newer_or_equal is that it's not 100% clear if:

  • we remove clock, if clock is newer than tag
  • or we remove clock, if tag is newer than clock

It's more reasonable to read clock_map.remove_if_newer_or_equal(tag) as "remove clock, if clock is newer than tag". But both cases are "reasonable enough". And so you have to go check documentation/code to verify what the actual behavior is. If we add _tag at the end, it's clear just from the method name.

Copy link
Contributor Author

@ffuugoo ffuugoo Feb 28, 2024

Choose a reason for hiding this comment

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

I don't see how it is clear. The argument name does not change the fact, that you can read "if newer or equal" both ways. What are we comparing to what? clock > tag or tag > clock?

It does make more sense to read "left to right", e.g., clock > tag, but, like, do you absolutely always do the most logical thing, or are you, like, human? :D

I mean, when you read this code for the first time, how can you be sure that it's clock > tag? You have to go read the documentation/code to verify that it is indeed clock > tag. Using newer_than_or_equal_to_tag clarifies clock > tag.

It is clear to you, because you've been working with it for the last two (three?) weeks.

Copy link
Member

Choose a reason for hiding this comment

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

remove_ge_tag?

The only reasonable assumption I can make about that is: we remove clocks, if greater or equal to the given tag.

Copy link
Member

Choose a reason for hiding this comment

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

Or retain_old_clocks(tag) with a comment describing the exact condition.

Copy link
Contributor Author

@ffuugoo ffuugoo Feb 28, 2024

Choose a reason for hiding this comment

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

remove_ge_tag?
The only reasonable assumption I can make about that is: we remove clocks, if greater or equal to the given tag.

You still can read it both ways. Like, it literally reads as "remove greater or equal tag". Which is a lot like "remove if tag is greater of equal". Why are you so against the conjunctions? Just add remove_ge_to_tag, and it's clear. Though, I'd still prefer fully verbose one. Not a huge fan of ge and such.

Or retain_old_clocks(tag) with a comment describing the exact condition.

That's exactly what I don't want. I don't want to have to go read the comment. I want it to be obvious when you just read the method name. :/

lib/collection/src/shards/local_shard/mod.rs Outdated Show resolved Hide resolved

channel_permit.send(UpdateSignal::Operation(OperationData {
op_num: operation_id,
operation: operation.operation,
sender: callback_sender,
wait,
}));
drop(wal_lock);
Copy link
Member

Choose a reason for hiding this comment

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

I put it here so we don't make the same mistake again 😄

Copy link
Contributor Author

@ffuugoo ffuugoo Feb 26, 2024

Choose a reason for hiding this comment

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

Ok, I kinda get your point now, but, IMO, it's not very effective and this part simply requires an explanation comment (with a lot of exclamation marks in it, maybe :D).

It's still super easy to just look at this code, see the drop, think "WTF is this here for?" and just remove the drop and refactor the wal_lock away same way we did earlier.

If we add the comment, then it will explain that the drop is intentional, and we have to hold the wal_lock for the duration of send... but at this point there's not much use in doing explicit drop, IMO.

Copy link
Member

Choose a reason for hiding this comment

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

If I see a drop I always think: it must be there for a reason, lets be very careful about it.

Comments don't do the same to me while refactoring.

But anyway, fine with both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm...... I usually do as well, but in this case it's kinda obvious that it's the end of the scope, so I usually assume it's just a leftover from a refactoring or something.

lib/collection/src/shards/local_shard/mod.rs Outdated Show resolved Hide resolved
lib/collection/src/shards/local_shard/mod.rs Outdated Show resolved Hide resolved
lib/collection/src/shards/local_shard/mod.rs Outdated Show resolved Hide resolved
lib/collection/src/shards/local_shard/mod.rs Outdated Show resolved Hide resolved
@@ -154,10 +176,10 @@ impl RecoverableWal {
/// If `None` - the remote WAL is already equal, and we don't have to send any records.
/// If `Err` - no delta can be resolved.
fn resolve_wal_delta(
operations: impl DoubleEndedIterator<Item = (u64, Option<ClockTag>)>,
Copy link
Member

Choose a reason for hiding this comment

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

This one is potentially dangerous, because we say nothing about the order we expect.

@ffuugoo
Copy link
Contributor Author

ffuugoo commented Feb 27, 2024

Ok, so the failing CI was my own fault (obviously, lol). It's fixed now. I think we can give it one last pass and merge.

(Forgot to rename newest_observer/oldest_resolvable. Will do soon-ish.)

lib/collection/src/wal.rs Outdated Show resolved Hide resolved
lib/collection/src/wal.rs Outdated Show resolved Hide resolved
@ffuugoo ffuugoo merged commit cba268c into dev Feb 29, 2024
17 checks passed
@ffuugoo ffuugoo deleted the diff-transfer-cleanup branch February 29, 2024 11:41
timvisee pushed a commit that referenced this pull request Mar 5, 2024
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.

None yet

2 participants