Skip to content

Commit b825d5d

Browse files
committed
CDRIVER-2419 mongoc_bulk_operation_set_client_session
Assertions when setting client and client_session will ensure that the bulk never has a client_session belonging to a foreign client.
1 parent 278f2d4 commit b825d5d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/mongoc/mongoc-bulk-operation.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,10 @@ mongoc_bulk_operation_set_client (mongoc_bulk_operation_t *bulk, void *client)
841841
BSON_ASSERT (bulk);
842842
BSON_ASSERT (client);
843843

844+
if (bulk->session) {
845+
BSON_ASSERT (bulk->session->client == client);
846+
}
847+
844848
bulk->client = (mongoc_client_t *) client;
845849

846850
/* if you call set_client, bulk was likely made by mongoc_bulk_operation_new,
@@ -852,6 +856,22 @@ mongoc_bulk_operation_set_client (mongoc_bulk_operation_t *bulk, void *client)
852856
}
853857

854858

859+
void
860+
mongoc_bulk_operation_set_client_session (
861+
mongoc_bulk_operation_t *bulk,
862+
struct _mongoc_client_session_t *client_session)
863+
{
864+
BSON_ASSERT (bulk);
865+
BSON_ASSERT (client_session);
866+
867+
if (bulk->client) {
868+
BSON_ASSERT (bulk->client == client_session->client);
869+
}
870+
871+
bulk->session = client_session;
872+
}
873+
874+
855875
uint32_t
856876
mongoc_bulk_operation_get_hint (const mongoc_bulk_operation_t *bulk)
857877
{

src/mongoc/mongoc-bulk-operation.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
BSON_BEGIN_DECLS
3333

34+
/* forward decl */
35+
struct _mongoc_client_session_t;
3436

3537
typedef struct _mongoc_bulk_operation_t mongoc_bulk_operation_t;
3638
typedef struct _mongoc_bulk_write_flags_t mongoc_bulk_write_flags_t;
@@ -130,6 +132,10 @@ mongoc_bulk_operation_set_collection (mongoc_bulk_operation_t *bulk,
130132
const char *collection);
131133
MONGOC_EXPORT (void)
132134
mongoc_bulk_operation_set_client (mongoc_bulk_operation_t *bulk, void *client);
135+
MONGOC_EXPORT (void)
136+
mongoc_bulk_operation_set_client_session (
137+
mongoc_bulk_operation_t *bulk,
138+
struct _mongoc_client_session_t *client_session);
133139
/* These names include the term "hint" for backward compatibility, should be
134140
* mongoc_bulk_operation_get_server_id, mongoc_bulk_operation_set_server_id. */
135141
MONGOC_EXPORT (void)

0 commit comments

Comments
 (0)