[CDRIVER-947] Allow setting of ordered option on bulk writes Created: 20/Oct/15  Updated: 23/Oct/15  Resolved: 20/Oct/15

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.3.0-beta0

Type: Improvement Priority: Major - P3
Reporter: Matt Cotter Assignee: Matt Cotter
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CXX-582 improve bulk write API Closed

 Description   

The new CRUD API requires the ability to set the ordered option on bulk operations. The C driver should have a helper for this because the underlying flags struct is not exposed.



 Comments   
Comment by Hannes Magnusson [ 20/Oct/15 ]

I think originally originally then the driver branched on `ordered` while adding stuff to the bulk, hence requiring the need of specifying `ordered` upfront.
The original fluent apis and crud specs also branched on `ordered` with .initializeOrderedBulk() and .initializeUnorderedBulk().

Today, there is no need (that I can think of) to initialize it upfront - but on the other hand, I also don't see the need to set it explicitly after instantiating a bulk_operation.

If you want a concrete case, then please do re-open the ticket - for now, I'm marking it as works-as-designed

Comment by Matt Cotter [ 20/Oct/15 ]

Ah, the PyMongo example clarified my confusion! In my interpretation of the spec (and PyMongo) the logic goes like:

  1. create a list
  2. append write models to that list
  3. call bulk_write and pass the list and some options

But in the C (and current C++11 driver), the logic is:

  1. initialize a bulk op (ordered or unordered)
  2. append write models and / or change options (other than ordered)
  3. execute the op

Hopefully that illustrates the source of my confusion.

It seems now that this ticket is inapplicable, and likely that the C++11 driver will have to stay as is. What do you two think?

(edit: formatting)

Comment by A. Jesse Jiryu Davis [ 20/Oct/15 ]

You sure the spec requires setting the option after creation? PyMongo, at least, doesn't:

https://github.com/mongodb/mongo-python-driver/blob/dc709127e339e1ee76a2f1e6c1870bafac0d16a6/pymongo/collection.py#L319-L319

And I don't see anything in the spec that requires you to let the user change her mind.

Comment by Matt Cotter [ 20/Oct/15 ]

When does it need to be set? For the CRUD API, the C++ driver needs to implement the bulk write options:

class BulkWriteOptions {
 
  /**
   * If true, when a write fails, return without performing the remaining
   * writes. If false, when a write fails, continue with the remaining writes, if any.
   * Defaults to true.
   */
  ordered: Boolean;
 
  /**
   * If true, allows the write to opt-out of document level validation.
   *
   * On servers >= 3.2, the default is no value: no
   * "bypassDocumentValidation" option is sent with the "aggregate" command.
   *
   * On servers < 3.2, this option is ignored.
   */
  bypassDocumentValidation: Optional<Boolean>;
 
}

Edit: As it stands, the C++ driver only supports setting the order upon creation.

Comment by Hannes Magnusson [ 20/Oct/15 ]

/*
 * The following functions are really only useful by language bindings and
 * those wanting to replay a bulk operation to a number of clients or
 * collections.
 */
mongoc_bulk_operation_t *mongoc_bulk_operation_new               (bool                          ordered);
void                     mongoc_bulk_operation_set_write_concern (mongoc_bulk_operation_t      *bulk,
                                                                  const mongoc_write_concern_t *write_concern);
void                     mongoc_bulk_operation_set_database      (mongoc_bulk_operation_t      *bulk,
                                                                  const char                   *database);
void                     mongoc_bulk_operation_set_collection    (mongoc_bulk_operation_t      *bulk,
                                                                  const char                   *collection);
void                     mongoc_bulk_operation_set_client        (mongoc_bulk_operation_t      *bulk,
                                                                  void                         *client);
void                     mongoc_bulk_operation_set_hint          (mongoc_bulk_operation_t      *bulk,
                                                                  uint32_t                      hint);

Is it not enough to initialize the batch as ordered/unordered?
You really must know that upfront to be able to handle the bulk correctly.

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