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

[ENH] clean up component channels #2429

Merged
merged 12 commits into from
Jul 1, 2024
Merged

Conversation

codetheweb
Copy link
Contributor

@codetheweb codetheweb commented Jun 28, 2024

This is a small refactor to clean up internal types around component channels. Changes include:

  • renames for clarity
  • split up receiver and message wrapper related code into separate files
  • makes the Sender ("ComponentSender") an internal concept not exposed to components directly
  • makes the ComponentHandle threadsafe so it can be passed around and .clone()d

Should make the implementation of #2428 cleaner.

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@codetheweb codetheweb force-pushed the chore-cleanup-component-channels branch from e4f3450 to ba9fd7f Compare June 28, 2024 21:53
@codetheweb codetheweb force-pushed the chore-cleanup-component-channels branch from ba9fd7f to 3c7d4c8 Compare June 28, 2024 21:59
@@ -116,7 +117,7 @@ impl WorkerServer {
Ok(())
}

pub(crate) fn set_dispatcher(&mut self, dispatcher: Box<dyn Receiver<TaskMessage>>) {
pub(crate) fn set_dispatcher(&mut self, dispatcher: ComponentHandle<Dispatcher>) {
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'm fine keeping this as Box<dyn Receiver<TaskMessage>> if that style is preferred

Copy link
Collaborator

Choose a reason for hiding this comment

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

i prefer this! nice cleanup

@codetheweb codetheweb force-pushed the chore-cleanup-component-channels branch from a398448 to e3ab429 Compare June 28, 2024 23:00
Comment on lines +126 to +129
self.sender
.send(wrap(message, tracing_context))
.await
.map_err(|_| ChannelError::SendError)
Copy link
Contributor Author

@codetheweb codetheweb Jun 28, 2024

Choose a reason for hiding this comment

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

was hoping to get rid of this struct and make it a type alias, but there's 3 separate places that would have to implement the same wrapping code here in that case

(and while these 4 lines are straightforward, the upcoming .request() method will be more complex and should really only be defined once)

@codetheweb codetheweb changed the title [ENH] [WIP] clean up component channels [ENH] clean up component channels Jun 28, 2024
@codetheweb codetheweb marked this pull request as ready for review June 28, 2024 23:29
@codetheweb codetheweb requested a review from HammadB June 28, 2024 23:29
@@ -42,7 +43,7 @@ pub(crate) struct CompactionManager {
blockfile_provider: BlockfileProvider,
hnsw_index_provider: HnswIndexProvider,
// Dispatcher
dispatcher: Option<Box<dyn Receiver<TaskMessage>>>,
dispatcher: Option<ComponentHandle<Dispatcher>>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks so much nicer

@@ -95,7 +96,7 @@ impl CompactionManager {
compaction_job: &CompactionJob,
) -> Result<CompactionResponse, Box<dyn ChromaError>> {
let dispatcher = match self.dispatcher {
Some(ref dispatcher) => dispatcher,
Some(ref dispatcher) => dispatcher.clone(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need to clone here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, because CompactOrchestrator takes ownership

Copy link
Collaborator

@HammadB HammadB left a comment

Choose a reason for hiding this comment

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

Nice - have some ignorable / disagreeable nits but I think the locking changes we should make and ideally stop() doesn't have to be async then

@codetheweb codetheweb force-pushed the chore-cleanup-component-channels branch from fa17e4e to d764517 Compare July 1, 2024 20:43
@codetheweb codetheweb force-pushed the chore-cleanup-component-channels branch from d764517 to 5223f71 Compare July 1, 2024 20:44
@codetheweb codetheweb merged commit 79eb785 into main Jul 1, 2024
65 checks passed
@codetheweb codetheweb deleted the chore-cleanup-component-channels branch July 1, 2024 22:58
Ishiihara pushed a commit that referenced this pull request Jul 16, 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.

2 participants