Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-array-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
BSON_BEGIN_DECLS


// mongoc_array_t stores an array of objects of type T.
//
// T must be trivially relocatable. In particular, `bson_t` is not trivially relocatable (CDRIVER-6113).
typedef struct _mongoc_array_t mongoc_array_t;


Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/src/mongoc/mongoc-write-command-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef struct {
uint32_t n_documents;
mongoc_bulk_write_flags_t flags;
int64_t operation_id;
bson_t cmd_opts;
bson_t *cmd_opts;
} mongoc_write_command_t;


Expand Down
8 changes: 4 additions & 4 deletions src/libmongoc/src/mongoc/mongoc-write-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ _mongoc_write_command_init_bulk (
command->flags = flags;
command->operation_id = operation_id;
if (!bson_empty0 (opts)) {
bson_copy_to (opts, &command->cmd_opts);
command->cmd_opts = bson_copy (opts);
} else {
bson_init (&command->cmd_opts);
command->cmd_opts = bson_new ();
}

_mongoc_buffer_init (&command->payload, NULL, 0, NULL, NULL);
Expand Down Expand Up @@ -671,7 +671,7 @@ _mongoc_write_opmsg (mongoc_write_command_t *command,
? MONGOC_CMD_PARTS_ALLOW_TXN_NUMBER_NO
: MONGOC_CMD_PARTS_ALLOW_TXN_NUMBER_YES;

BSON_ASSERT (bson_iter_init (&iter, &command->cmd_opts));
BSON_ASSERT (bson_iter_init (&iter, command->cmd_opts));
if (!mongoc_cmd_parts_append_opts (&parts, &iter, error)) {
bson_destroy (&cmd);
mongoc_cmd_parts_cleanup (&parts);
Expand Down Expand Up @@ -944,7 +944,7 @@ _mongoc_write_command_destroy (mongoc_write_command_t *command)
ENTRY;

if (command) {
bson_destroy (&command->cmd_opts);
bson_destroy (command->cmd_opts);
_mongoc_buffer_destroy (&command->payload);
}

Expand Down
56 changes: 56 additions & 0 deletions src/libmongoc/tests/test-mongoc-bulk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4768,6 +4768,55 @@ test_bulk_write_set_client_updates_operation_id_when_client_changes (void)
mock_server_destroy (mock_server);
}

// `test_bulk_big_let` tests a bulk operation with a large let document to reproduce CDRIVER-6112:
static void
test_bulk_big_let (void *unused)
{
BSON_UNUSED (unused);

mongoc_client_t *client = test_framework_new_default_client ();
mongoc_collection_t *coll = get_test_collection (client, "test_big_let");
bson_error_t error;

// Create bulk operation similar to PHP driver:
mongoc_bulk_operation_t *bulk = mongoc_bulk_operation_new (true /* ordered */);

// Set a large `let`: { "testDocument": { "a": "aaa..." } }
{
bson_t let = BSON_INITIALIZER, testDocument;
bson_append_document_begin (&let, "testDocument", -1, &testDocument);

// Append big string:
{
size_t num_chars = 79;
char *big_string = bson_malloc0 (num_chars + 1);
memset (big_string, 'a', num_chars);
BSON_APPEND_UTF8 (&testDocument, "a", big_string);
bson_free (big_string);
}

bson_append_document_end (&let, &testDocument);
mongoc_bulk_operation_set_let (bulk, &let);
bson_destroy (&let);
}


mongoc_bulk_operation_set_client (bulk, client);
mongoc_bulk_operation_set_database (bulk, "db");
mongoc_bulk_operation_set_collection (bulk, "coll");

mongoc_bulk_operation_update (
bulk, tmp_bson ("{'_id': 1}"), tmp_bson ("{'$set': {'document': '$$testDocument'}}"), true);


ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, NULL, &error), error);

mongoc_bulk_operation_destroy (bulk);
mongoc_collection_destroy (coll);
mongoc_client_destroy (client);
}


void
test_bulk_install (TestSuite *suite)
{
Expand Down Expand Up @@ -4946,4 +4995,11 @@ test_bulk_install (TestSuite *suite)
TestSuite_AddMockServerTest (suite,
"/BulkOperation/set_client_updates_operation_id_when_client_changes",
test_bulk_write_set_client_updates_operation_id_when_client_changes);
TestSuite_AddFull (
suite,
"/BulkOperation/big_let",
test_bulk_big_let,
NULL,
NULL,
test_framework_skip_if_max_wire_version_less_than_13 /* 5.0+ for 'let' support in CRUD commands */);
}