Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

CDRIVER-5856 add function to check if bulkwrite is acknowledged #2100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
connorsmacd wants to merge 7 commits into mongodb:master
base: master
Choose a base branch
Loading
from connorsmacd:bulkwrite-is-acknowledged.CDRIVER-5856

Conversation

Copy link

@connorsmacd connorsmacd commented Aug 27, 2025
edited
Loading

  • Write test cases for is_acknowledged checks where write concerns are provided both by the client and overridden in mongo_bulkwriteopts_t.
  • Add is_acknowledged member to mongo_bulkwrite_t.
  • Replace usage of is_acknowledged in mongo_bulkwrite_execute with self->is_acknowledged.
  • Expose is_acknowledged in public API via mongo_bulkwrite_is_acknowledged.

@connorsmacd connorsmacd marked this pull request as ready for review August 27, 2025 19:02
@connorsmacd connorsmacd requested a review from a team as a code owner August 27, 2025 19:02
// `mongoc_bulkwrite_is_acknowledged` returns true if the previous call to `mongoc_bulkwrite_execute` used an
// acknowledged write concern.
MONGOC_EXPORT(bool)
mongoc_bulkwrite_is_acknowledged(mongoc_bulkwrite_t const *self);
Copy link
Author

@connorsmacd connorsmacd Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we should also cover the case where this is called before the call to mongoc_bulkwrite_execute. I can think of a few ways to handle this:

  • Document the current behavior, which is to return false (simple, but potentially misleading)
  • Do the same as above, but document as undefined behavior (also simple, but I generally prefer to specify behavior)
  • Add BSON_ASSERT(self->executed) to the implementation (specifies behavior in a predictable way, but makes the error non-recoverable)
  • Add a bson_error_t out-param to capture the error condition where self->executed is false (consistent with how other bulkwrite functions handle the case where self->executed is true, but seems like overkill)

Thoughts?

Copy link
Collaborator

@kevinAlbs kevinAlbs Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea. I would rather BSON_ASSERT(self->executed) or add a bson_error_t out-param. I slightly prefer a bson_error_t out-param for API consistency at the cost of a more verbose API.

connorsmacd reacted with thumbs up emoji
Copy link
Author

@connorsmacd connorsmacd Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slightly prefer a bson_error_t out-param for API consistency at the cost of a more verbose API.

I also prefer this, but it will make this function signature a bit awkward. As far as I can tell, the API always uses bson_error_t out-params in conjunction with a bool or pointer return type, where false or NULL indicate the error is set. In this case, since we are already using the bool return to indicate whether or not the bulk write is acknowledged, it's not exactly clear how best to handle this.

We could use another bool out-param, but this makes it easy to confuse the meanings of the two bools:

MONGOC_EXPORT(bool)
mongoc_bulkwrite_is_acknowledged(mongoc_bulkwrite_t const *self, bool *error_is_set, bson_error_t *error);

We could use a tristate, and in that case I would also change the function's name slightly:

typedef enum {
 MONGOC_BULKWRITE_CHECK_ACKNOWLEDGED_ERROR = -1,
 MONGOC_BULKWRITE_UNACKNOWLEDGED,
 MONGOC_BULKWRITE_ACKNOWLEDGED,
} mongoc_bulkwrite_check_acknowledged_t;
MONGOC_EXPORT(mongoc_bulkwrite_check_acknowledged_t)
mongoc_bulkwrite_check_acknowledged(mongoc_bulkwrite_t const *self, bson_error_t *error);

Or a struct:

typedef struct {
 bool is_error;
 bool is_acknowledged;
} mongoc_bulkwrite_check_acknowledged_t;
MONGOC_EXPORT(mongoc_bulkwrite_check_acknowledged_t)
mongoc_bulkwrite_check_acknowledged(mongoc_bulkwrite_t const *self, bson_error_t *error);

I am just trying to pin down what the standard approach should be here, at the risk of bikeshedding.

Copy link
Collaborator

@kevinAlbs kevinAlbs Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, the API always uses bson_error_t out-params in conjunction with a bool or pointer return type, where false or NULL indicate the error is set.

Yes, I think that is a widely used pattern in the C driver.

On a brief look at declarations marked BSON_EXPORT and MONGOC_EXPORT I do not see functions with bool out-params.

I like the tristate and struct return ideas. I think it simplifies the call (no need to separately declare a short-lived bool). The tristate return might introduce a slight inconsistency with the soon-to-be-added API to get the server ID in CDRIVER-5843. Maybe a struct return could be used for both:

typedef struct {
 bool is_error;
 bool is_acknowledged;
} mongoc_bulkwrite_acknowledged_t;
MONGOC_EXPORT(mongoc_bulkwrite_check_acknowledged_t)
mongoc_bulkwrite_check_acknowledged(mongoc_bulkwrite_t const *self, bson_error_t *error);
typedef struct {
 bool is_error;
 uint32_t server_id;
} mongoc_bulkwrite_serverid_t;
MONGOC_EXPORT(mongoc_bulkwrite_serverid_t)
mongoc_bulkwrite_get_serverid(mongoc_bulkwrite_t const *self, bson_error_t *error);

Copy link
Author

@connorsmacd connorsmacd Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about CDRIVER-5843 -- I'll need to change my implementation to account for the error case. I think the struct return is the best option for both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@kevinAlbs kevinAlbs kevinAlbs approved these changes

@vector-of-bool vector-of-bool Awaiting requested review from vector-of-bool

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /