Skip to content

RUST-1875 Define separate types for summary and verbose bulk write results #1103

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

Merged
merged 5 commits into from
May 16, 2024

Conversation

isabelatkinson
Copy link
Contributor

No description provided.

@isabelatkinson isabelatkinson marked this pull request as ready for review May 15, 2024 21:00
@isabelatkinson isabelatkinson requested a review from abr-egn May 15, 2024 21:00
}

#[derive(Clone, Debug)]
#[cfg_attr(test, derive(serde::Serialize))]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See RUST-1944, we haven't triaged that ticket yet but I think it'd be good to keep test-only serde impls out of the public API

};

#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct BulkWriteError {
pub write_concern_errors: Vec<WriteConcernError>,
pub write_errors: HashMap<usize, WriteError>,
pub partial_result: Option<BulkWriteResult>,
pub partial_result: Option<PartialBulkWriteResult>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the sticky part of this work and why I kept it out of the main PR. There were a few ideas I thought of here, the others being:

  • Make this BulkWriteError<R: BulkWriteResult>, store Option<R> in partial_result, and define ErrorKind::SummaryBulkWrite(BulkWriteError<SummaryBulkWriteResult>) and ErrorKind::VerboseBulkWrite(BulkWriteError<VerboseBulkWriteResult>). This has the benefit of removing indirection in the partial_result field, but I didn't like the duplication in ErrorKind both for internal purposes and API implications.
  • Define a separate non-sealed BulkWriteResult trait with accessor methods and make the partial_result field an Option<Box<dyn BulkWriteResult>>. I was having a hard time getting something like this to compile (lots of object-safety-related errors), and I think Box<dyn Trait> is generally kind of annoying to work with so it didn't seem worth it to go down this path.

Matching on PartialBulkWriteResult will be kind of annoying, and it's a bummer that we can't provide the same type guarantees that we can for the actual result types when configuring verbose_results. But I think this will be fine-enough to work with, and we can add accessor methods to the enum directly if this becomes a pain point for users. (FWIW, from the discussions that we had when writing the spec it seems like users are mostly just logging these kinds of error fields.)

Copy link
Contributor

@abr-egn abr-egn left a comment

Choose a reason for hiding this comment

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

LGTM! A couple of potential changes but I don't feel strongly about either, and no need for a re-review either way.

(Self::Summary(this), Self::Summary(other)) => this.merge(other),
(Self::Verbose(this), Self::Verbose(other)) => this.merge(other),
// The operation execution path makes this an unreachable state
_ => {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe unreachable!() here?

#[cfg_attr(test, serde(rename_all = "camelCase"))]
#[non_exhaustive]
pub struct VerboseBulkWriteResult {
pub inserted_count: i64,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it'd be worth having pub summary: SummaryBulkWriteResult instead of duplicating the fields? API-wise it makes the superset relationship clear, and it would mean the impl would have a little less repeated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I think that makes sense. this might be the first time I've wanted subclasses in Rust...

@isabelatkinson isabelatkinson merged commit 17da603 into mongodb:main May 16, 2024
6 of 8 checks passed
@isabelatkinson isabelatkinson deleted the bulk-write-results branch May 17, 2024 14:13
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