Skip to content

Commit

Permalink
fix(sink): fix mogodb write error handling (#19869)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxhZs authored Dec 24, 2024
1 parent af66670 commit 1b9b5a7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/connector/src/sink/mongodb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,23 @@ mod send_bulk_write_command_future {
)))
})?;

if let Ok(ok) = result.get_i32("ok")
&& ok != 1
{
return Err(SinkError::Mongodb(anyhow!("bulk write write errors")));
}

if let Ok(write_errors) = result.get_array("writeErrors") {
return Err(SinkError::Mongodb(anyhow!(
"bulk write respond with write errors: {:?}",
write_errors,
)));
}

let n = result.get_i32("n").map_err(|err| {
SinkError::Mongodb(
anyhow!(err).context("can't extract field n from bulk write response"),
)
})?;
if n < 1 {
if let Ok(write_concern_error) = result.get_array("writeConcernError") {
return Err(SinkError::Mongodb(anyhow!(
"bulk write respond with an abnormal state, n = {}",
n
"bulk write respond with write errors: {:?}",
write_concern_error,
)));
}

Expand Down

0 comments on commit 1b9b5a7

Please sign in to comment.