Skip to content

Commit fb9f568

Browse files
spencemckevinAlbs
authored andcommitted
CDRIVER-2647 refactor mongoc write command
1 parent cb4aa08 commit fb9f568

File tree

2 files changed

+15
-79
lines changed

2 files changed

+15
-79
lines changed

src/libmongoc/src/mongoc/mongoc-write-command.c

Lines changed: 13 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,8 @@ _mongoc_write_command_execute (
836836
mongoc_client_session_t *cs, /* IN */
837837
mongoc_write_result_t *result) /* OUT */
838838
{
839+
mongoc_crud_opts_t crud = {0};
840+
839841
ENTRY;
840842

841843
BSON_ASSERT (command);
@@ -858,83 +860,17 @@ _mongoc_write_command_execute (
858860
EXIT;
859861
}
860862

861-
if (command->flags.has_collation) {
862-
if (!mongoc_write_concern_is_acknowledged (write_concern)) {
863-
result->failed = true;
864-
bson_set_error (&result->error,
865-
MONGOC_ERROR_COMMAND,
866-
MONGOC_ERROR_COMMAND_INVALID_ARG,
867-
"Cannot set collation for unacknowledged writes");
868-
EXIT;
869-
}
870-
if (server_stream->sd->max_wire_version < WIRE_VERSION_COLLATION) {
871-
bson_set_error (&result->error,
872-
MONGOC_ERROR_COMMAND,
873-
MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION,
874-
"Collation is not supported by the selected server");
875-
result->failed = true;
876-
EXIT;
877-
}
878-
}
879-
if (command->flags.bypass_document_validation !=
880-
MONGOC_BYPASS_DOCUMENT_VALIDATION_DEFAULT) {
881-
if (!mongoc_write_concern_is_acknowledged (write_concern)) {
882-
result->failed = true;
883-
bson_set_error (
884-
&result->error,
885-
MONGOC_ERROR_COMMAND,
886-
MONGOC_ERROR_COMMAND_INVALID_ARG,
887-
"Cannot set bypassDocumentValidation for unacknowledged writes");
888-
EXIT;
889-
}
890-
}
891-
if (command->payload.len == 0) {
892-
_empty_error (command, &result->error);
893-
EXIT;
894-
}
895-
896-
if (server_stream->sd->max_wire_version >= WIRE_VERSION_OP_MSG) {
897-
if (cs && !mongoc_write_concern_is_acknowledged (write_concern)) {
898-
bson_set_error (
899-
&result->error,
900-
MONGOC_ERROR_COMMAND,
901-
MONGOC_ERROR_COMMAND_INVALID_ARG,
902-
"Cannot use client session with unacknowledged writes");
903-
EXIT;
904-
}
905-
_mongoc_write_opmsg (command,
906-
client,
907-
server_stream,
908-
database,
909-
collection,
910-
write_concern,
911-
offset,
912-
cs,
913-
result,
914-
&result->error);
915-
} else {
916-
if (mongoc_write_concern_is_acknowledged (write_concern)) {
917-
_mongoc_write_opquery (command,
918-
client,
919-
server_stream,
920-
database,
921-
collection,
922-
write_concern,
923-
offset,
924-
result,
925-
&result->error);
926-
} else {
927-
gLegacyWriteOps[command->type](command,
928-
client,
929-
server_stream,
930-
database,
931-
collection,
932-
offset,
933-
result,
934-
&result->error);
935-
}
936-
}
937-
863+
crud.client_session = cs;
864+
crud.writeConcern = (mongoc_write_concern_t *) write_concern;
865+
866+
_mongoc_write_command_execute_idl (command,
867+
client,
868+
server_stream,
869+
database,
870+
collection,
871+
offset,
872+
&crud,
873+
result);
938874
EXIT;
939875
}
940876

src/libmongoc/tests/test-mongoc-bulk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4172,7 +4172,7 @@ _test_bulk_collation (int w, int wire_version, bulkop op)
41724172
error,
41734173
MONGOC_ERROR_COMMAND,
41744174
MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION,
4175-
"Collation is not supported by the selected server");
4175+
"The selected server does not support collation");
41764176
} else {
41774177
ASSERT_ERROR_CONTAINS (
41784178
error,
@@ -4247,7 +4247,7 @@ _test_bulk_collation_multi (int w, int wire_version)
42474247
error,
42484248
MONGOC_ERROR_COMMAND,
42494249
MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION,
4250-
"Collation is not supported by the selected server");
4250+
"The selected server does not support collation");
42514251
} else {
42524252
ASSERT_ERROR_CONTAINS (
42534253
error,

0 commit comments

Comments
 (0)