Skip to content

Commit 0b30bfb

Browse files
author
Christian Hergert
committed
write-command: use legacy op with unacknowledged write if server supports it
This should be faster than submitting write commands.
1 parent 1bdda07 commit 0b30bfb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/mongoc/mongoc-write-command.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,19 @@ _mongoc_write_command_delete (mongoc_write_command_t *command,
455455
BSON_ASSERT (hint);
456456
BSON_ASSERT (collection);
457457

458+
/*
459+
* If we have an unacknowledged write and the server supports the legacy
460+
* opcodes, then submit the legacy opcode so we don't need to wait for
461+
* a response from the server.
462+
*/
463+
if ((client->cluster.nodes [hint - 1].min_wire_version == 0) &&
464+
!_mongoc_write_concern_has_gle (write_concern)) {
465+
_mongoc_write_command_delete_legacy (command, client, hint, database,
466+
collection, write_concern, result,
467+
error);
468+
EXIT;
469+
}
470+
458471
BSON_APPEND_UTF8 (&cmd, "delete", collection);
459472
BSON_APPEND_DOCUMENT (&cmd, "writeConcern",
460473
WRITE_CONCERN_DOC (write_concern));
@@ -515,6 +528,19 @@ _mongoc_write_command_insert (mongoc_write_command_t *command,
515528
BSON_ASSERT (hint);
516529
BSON_ASSERT (collection);
517530

531+
/*
532+
* If we have an unacknowledged write and the server supports the legacy
533+
* opcodes, then submit the legacy opcode so we don't need to wait for
534+
* a response from the server.
535+
*/
536+
if ((client->cluster.nodes [hint - 1].min_wire_version == 0) &&
537+
!_mongoc_write_concern_has_gle (write_concern)) {
538+
_mongoc_write_command_insert_legacy (command, client, hint, database,
539+
collection, write_concern, result,
540+
error);
541+
EXIT;
542+
}
543+
518544
if (!command->u.insert.n_documents ||
519545
!bson_iter_init (&iter, command->u.insert.documents) ||
520546
!bson_iter_next (&iter)) {
@@ -618,6 +644,19 @@ _mongoc_write_command_update (mongoc_write_command_t *command,
618644
BSON_ASSERT (hint);
619645
BSON_ASSERT (collection);
620646

647+
/*
648+
* If we have an unacknowledged write and the server supports the legacy
649+
* opcodes, then submit the legacy opcode so we don't need to wait for
650+
* a response from the server.
651+
*/
652+
if ((client->cluster.nodes [hint - 1].min_wire_version == 0) &&
653+
!_mongoc_write_concern_has_gle (write_concern)) {
654+
_mongoc_write_command_update_legacy (command, client, hint, database,
655+
collection, write_concern, result,
656+
error);
657+
EXIT;
658+
}
659+
621660
BSON_APPEND_UTF8 (&cmd, "update", collection);
622661
BSON_APPEND_DOCUMENT (&cmd, "writeConcern",
623662
WRITE_CONCERN_DOC (write_concern));

0 commit comments

Comments
 (0)