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

CoreService refactor #169

Merged
merged 1 commit into from
Jul 21, 2023
Merged

CoreService refactor #169

merged 1 commit into from
Jul 21, 2023

Conversation

lann
Copy link
Collaborator

@lann lann commented Jul 19, 2023

This flattens all of the (other) server services into CoreService. I've mostly kept the external interfaces the same for now, with some notable exceptions:

  • CoreService now contains an Arc<Inner>, so no longer needs a wrapping Arc
  • Since the log and map services went away, so too have CoreService::log_data() and ::map_data(). The related proof methods have been flattened into CoreService as e.g. ::log_consistency_proof

The core.rs diff is completely useless; see just the new version here: https://github.com/bytecodealliance/registry/blob/core-svc-refactor/crates/server/src/services/core.rs

The new implementation reuses a lot of the existing services' code but does make some functional changes:

  • Rather than attempting to write a final checkpoint on shutdown, a new checkpoint may be written just after initialization, which will also help recover from non-graceful shutdowns.
  • Locks are all handled internally now, rather than some being held by callers.
  • The CancellationToken has gone away; the service can now be stopped by dropping all references to it. This also meant the StopHandle could be reduced to a normal tokio JoinHandle which can be awaited to give the record processing loop a chance to finish any queued updates.

@lann lann force-pushed the core-svc-refactor branch 2 times, most recently from 668a759 to 429581f Compare July 20, 2023 19:41
@@ -80,7 +80,7 @@ where
Hash::of((0b1, lhs, rhs))
}

pub trait SupportedDigest: Digest + private::Sealed + Sized + 'static {
pub trait SupportedDigest: Digest + private::Sealed + Default + Sized + 'static {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sha256 already implements Default; this just makes #[derive(Default)] work more places.

@lann lann marked this pull request as ready for review July 20, 2023 20:00
Copy link
Collaborator

@calvinrp calvinrp left a comment

Choose a reason for hiding this comment

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

Much simpler. Really good work refactoring tricky code. Looks good to me, but I'd love @peterhuene review as well.

Comment on lines +203 to 206
if last_checkpoint != checkpoint {
state.checkpoint(); // for the side-effect of updating map_index
last_checkpoint = checkpoint;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this contains a bug copied over from my initial implementation of server restart that I haven't gotten around to fixing.

Let's say the initial stream looks like (in record insert order):

Leaf Checkpoint
A C1
B C2
C C3
D C3
E C3
F C4

I think this code would correctly create a checkpoint C1 containing A (C1 != <empty-hash>) and a checkpoint C2 containing B (C2 != C1), but would not correctly checkpoint C3 because we're checkpointing at the transition from leaf B to C (C3 != C2) in the stream, which results in only including leaf C in the checkpoint.

The next checkpoint would then incorrectly include leafs D, E, and F (C4 != C3).

Does that make sense or am I completely off-base?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yeah I was a little confused about this but wanted to stick with existing behavior. I'm currently working on a followup refactor that avoids this problem entirely, but I can retrofit this PR if you'd prefer.

Copy link
Member

Choose a reason for hiding this comment

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

I'll approve and leave it up to you whether you want to include it now or wait to the refactor.

Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

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

Other than what I believe to be that existing bug, these changes look really good and make this much easier to wrap one's brain around.

@lann
Copy link
Collaborator Author

lann commented Jul 21, 2023

OK, since this is such a big diff I'm going to get it out of the way.

@lann lann merged commit 34c432a into main Jul 21, 2023
6 checks passed
@lann lann deleted the core-svc-refactor branch July 21, 2023 20:36
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.

3 participants