[CDRIVER-655] Prevent re-execution of bulk ops Created: 15/May/15  Updated: 16/Oct/23

Status: Backlog
Project: C Driver
Component/s: Bulk API, libmongoc
Affects Version/s: None
Fix Version/s: 2.0.0

Type: Improvement Priority: Minor - P4
Reporter: A. Jesse Jiryu Davis Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: CDRIVER-4742
Backwards Compatibility: Major Change

 Description   

Contradicting the Bulk API spec, the driver allows multiple calls to the same mongoc_bulk_operation_execute ().

If the bulk operation is only updates or removes then they'll be run twice. If inserts are included, the driver prepends object ids to the documents for insertion before the first execution, so the inserts fail with duplicate key error on the second and subsequent executions.

API change, can't do it until 2.0.



 Comments   
Comment by A. Jesse Jiryu Davis [ 16/May/15 ]

Marking 1.2-desired; fixing this is an API break for some conceivable application that reuses a mongoc_bulk_operation_t for repeating a set of update and / or remove operations.

Comment by A. Jesse Jiryu Davis [ 15/May/15 ]

 
static void
test_multiple_execution ()
{
   mongoc_bulk_operation_t *bulk;
   mongoc_collection_t *collection;
   mongoc_client_t *client;
 
   bson_error_t error;
 
   client = test_framework_client_new (NULL);
   assert (client);
 
   collection = get_test_collection (client, "test_multiple_execution");
   assert (collection);
 
   mongoc_collection_insert (collection, MONGOC_INSERT_NONE,
                             tmp_bson ("{'x': 0}"),
                             NULL, NULL);
 
   bulk = mongoc_collection_create_bulk_operation (collection, true, NULL);
   assert (bulk);
   mongoc_bulk_operation_update (bulk, tmp_bson ("{}"),
                                 tmp_bson ("{'$inc': {'x': 1}}"), false);
   assert (mongoc_bulk_operation_execute (bulk, NULL, NULL));
   assert (!mongoc_bulk_operation_execute (bulk, NULL, &error));
   ASSERT_CMPINT (MONGOC_ERROR_CLIENT, ==, error.domain);
}

Generated at Wed Feb 07 21:10:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.