-
Notifications
You must be signed in to change notification settings - Fork 178
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
isabelatkinson
merged 5 commits into
mongodb:main
from
isabelatkinson:bulk-write-results
May 16, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,27 +4,46 @@ use std::collections::HashMap; | |
|
||
use crate::{ | ||
error::{WriteConcernError, WriteError}, | ||
results::BulkWriteResult, | ||
results::{BulkWriteResult, SummaryBulkWriteResult, VerboseBulkWriteResult}, | ||
}; | ||
|
||
#[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>, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
#[cfg_attr(test, derive(serde::Serialize))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
#[cfg_attr(test, serde(untagged))] | ||
pub enum PartialBulkWriteResult { | ||
Summary(SummaryBulkWriteResult), | ||
Verbose(VerboseBulkWriteResult), | ||
} | ||
|
||
impl PartialBulkWriteResult { | ||
pub(crate) fn merge(&mut self, other: Self) { | ||
match (self, other) { | ||
(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 | ||
_ => unreachable!(), | ||
} | ||
} | ||
} | ||
|
||
impl BulkWriteError { | ||
pub(crate) fn merge(&mut self, other: BulkWriteError) { | ||
pub(crate) fn merge(&mut self, other: Self) { | ||
self.write_concern_errors.extend(other.write_concern_errors); | ||
self.write_errors.extend(other.write_errors); | ||
if let Some(other_partial_result) = other.partial_result { | ||
self.merge_partial_results(other_partial_result); | ||
} | ||
} | ||
|
||
pub(crate) fn merge_partial_results(&mut self, other_partial_result: BulkWriteResult) { | ||
pub(crate) fn merge_partial_results(&mut self, other_partial_result: PartialBulkWriteResult) { | ||
if let Some(ref mut partial_result) = self.partial_result { | ||
partial_result.merge(other_partial_result); | ||
} else { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
BulkWriteError<R: BulkWriteResult>
, storeOption<R>
inpartial_result
, and defineErrorKind::SummaryBulkWrite(BulkWriteError<SummaryBulkWriteResult>)
andErrorKind::VerboseBulkWrite(BulkWriteError<VerboseBulkWriteResult>)
. This has the benefit of removing indirection in thepartial_result
field, but I didn't like the duplication inErrorKind
both for internal purposes and API implications.BulkWriteResult
trait with accessor methods and make thepartial_result
field anOption<Box<dyn BulkWriteResult>>
. I was having a hard time getting something like this to compile (lots of object-safety-related errors), and I thinkBox<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 configuringverbose_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.)