Skip to content

Commit e12e3bd

Browse files
committed
CDRIVER-837: Weave mongoc_read_concern_t through everywhere
1 parent 2c90394 commit e12e3bd

12 files changed

+239
-5
lines changed

src/mongoc/mongoc-client-private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct _mongoc_client_t
7979
mongoc_topology_t *topology;
8080

8181
mongoc_read_prefs_t *read_prefs;
82+
mongoc_read_concern_t *read_concern;
8283
mongoc_write_concern_t *write_concern;
8384
};
8485

src/mongoc/mongoc-client.c

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ _mongoc_client_new_from_uri (const mongoc_uri_t *uri, mongoc_topology_t *topolog
721721
{
722722
mongoc_client_t *client;
723723
const mongoc_read_prefs_t *read_prefs;
724+
const mongoc_read_concern_t *read_concern;
724725
const mongoc_write_concern_t *write_concern;
725726

726727
BSON_ASSERT (uri);
@@ -735,6 +736,9 @@ _mongoc_client_new_from_uri (const mongoc_uri_t *uri, mongoc_topology_t *topolog
735736
write_concern = mongoc_uri_get_write_concern (client->uri);
736737
client->write_concern = mongoc_write_concern_copy (write_concern);
737738

739+
read_concern = mongoc_uri_get_read_concern (client->uri);
740+
client->read_concern = mongoc_read_concern_copy (read_concern);
741+
738742
read_prefs = mongoc_uri_get_read_prefs_t (client->uri);
739743
client->read_prefs = mongoc_read_prefs_copy (read_prefs);
740744

@@ -783,6 +787,7 @@ mongoc_client_destroy (mongoc_client_t *client)
783787
}
784788

785789
mongoc_write_concern_destroy (client->write_concern);
790+
mongoc_read_concern_destroy (client->read_concern);
786791
mongoc_read_prefs_destroy (client->read_prefs);
787792
mongoc_cluster_destroy (&client->cluster);
788793
mongoc_uri_destroy (client->uri);
@@ -847,7 +852,8 @@ mongoc_client_get_database (mongoc_client_t *client,
847852
BSON_ASSERT (client);
848853
BSON_ASSERT (name);
849854

850-
return _mongoc_database_new(client, name, client->read_prefs, client->write_concern);
855+
return _mongoc_database_new(client, name, client->read_prefs,
856+
client->read_concern, client->write_concern);
851857
}
852858

853859

@@ -922,7 +928,7 @@ mongoc_client_get_collection (mongoc_client_t *client,
922928
BSON_ASSERT (collection);
923929

924930
return _mongoc_collection_new(client, db, collection, client->read_prefs,
925-
client->write_concern);
931+
client->read_concern, client->write_concern);
926932
}
927933

928934

@@ -1024,6 +1030,64 @@ mongoc_client_set_write_concern (mongoc_client_t *client,
10241030
}
10251031

10261032

1033+
/*
1034+
*--------------------------------------------------------------------------
1035+
*
1036+
* mongoc_client_get_read_concern --
1037+
*
1038+
* Fetches the default read concern for @client.
1039+
*
1040+
* Returns:
1041+
* A mongoc_read_concern_t that should not be modified or freed.
1042+
*
1043+
* Side effects:
1044+
* None.
1045+
*
1046+
*--------------------------------------------------------------------------
1047+
*/
1048+
1049+
const mongoc_read_concern_t *
1050+
mongoc_client_get_read_concern (const mongoc_client_t *client)
1051+
{
1052+
BSON_ASSERT (client);
1053+
1054+
return client->read_concern;
1055+
}
1056+
1057+
1058+
/*
1059+
*--------------------------------------------------------------------------
1060+
*
1061+
* mongoc_client_set_read_concern --
1062+
*
1063+
* Sets the default read concern for @client.
1064+
*
1065+
* Returns:
1066+
* None.
1067+
*
1068+
* Side effects:
1069+
* None.
1070+
*
1071+
*--------------------------------------------------------------------------
1072+
*/
1073+
1074+
void
1075+
mongoc_client_set_read_concern (mongoc_client_t *client,
1076+
const mongoc_read_concern_t *read_concern)
1077+
{
1078+
BSON_ASSERT (client);
1079+
1080+
if (read_concern != client->read_concern) {
1081+
if (client->read_concern) {
1082+
mongoc_read_concern_destroy (client->read_concern);
1083+
}
1084+
client->read_concern = read_concern ?
1085+
mongoc_read_concern_copy (read_concern) :
1086+
mongoc_read_concern_new ();
1087+
}
1088+
}
1089+
1090+
10271091
/*
10281092
*--------------------------------------------------------------------------
10291093
*

src/mongoc/mongoc-client.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "mongoc-stream.h"
3737
#include "mongoc-uri.h"
3838
#include "mongoc-write-concern.h"
39+
#include "mongoc-read-concern.h"
3940

4041

4142
BSON_BEGIN_DECLS
@@ -140,6 +141,9 @@ int32_t mongoc_client_get_max_bson_size (mongoc_client
140141
const mongoc_write_concern_t *mongoc_client_get_write_concern (const mongoc_client_t *client);
141142
void mongoc_client_set_write_concern (mongoc_client_t *client,
142143
const mongoc_write_concern_t *write_concern);
144+
const mongoc_read_concern_t *mongoc_client_get_read_concern (const mongoc_client_t *client);
145+
void mongoc_client_set_read_concern (mongoc_client_t *client,
146+
const mongoc_read_concern_t *read_concern);
143147
const mongoc_read_prefs_t *mongoc_client_get_read_prefs (const mongoc_client_t *client);
144148
void mongoc_client_set_read_prefs (mongoc_client_t *client,
145149
const mongoc_read_prefs_t *read_prefs);

src/mongoc/mongoc-collection-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct _mongoc_collection_t
4040
uint32_t collectionlen;
4141
mongoc_buffer_t buffer;
4242
mongoc_read_prefs_t *read_prefs;
43+
mongoc_read_concern_t *read_concern;
4344
mongoc_write_concern_t *write_concern;
4445
bson_t *gle;
4546
};
@@ -49,6 +50,7 @@ mongoc_collection_t *_mongoc_collection_new (mongoc_client_t
4950
const char *db,
5051
const char *collection,
5152
const mongoc_read_prefs_t *read_prefs,
53+
const mongoc_read_concern_t *read_concern,
5254
const mongoc_write_concern_t *write_concern);
5355
mongoc_cursor_t *_mongoc_collection_find_indexes_legacy (mongoc_collection_t *collection,
5456
bson_error_t *error);

src/mongoc/mongoc-collection.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "mongoc-index.h"
3333
#include "mongoc-log.h"
3434
#include "mongoc-trace.h"
35+
#include "mongoc-read-concern-private.h"
3536
#include "mongoc-write-concern-private.h"
3637

3738

@@ -142,6 +143,7 @@ _mongoc_collection_write_command_execute (mongoc_write_command_t *command,
142143
* @db is the db name of the collection.
143144
* @collection is the name of the collection.
144145
* @read_prefs is the default read preferences to apply or NULL.
146+
* @read_concern is the default read concern to apply or NULL.
145147
* @write_concern is the default write concern to apply or NULL.
146148
*
147149
* Returns:
@@ -159,6 +161,7 @@ _mongoc_collection_new (mongoc_client_t *client,
159161
const char *db,
160162
const char *collection,
161163
const mongoc_read_prefs_t *read_prefs,
164+
const mongoc_read_concern_t *read_concern,
162165
const mongoc_write_concern_t *write_concern)
163166
{
164167
mongoc_collection_t *col;
@@ -174,6 +177,9 @@ _mongoc_collection_new (mongoc_client_t *client,
174177
col->write_concern = write_concern ?
175178
mongoc_write_concern_copy(write_concern) :
176179
mongoc_write_concern_new();
180+
col->read_concern = read_concern ?
181+
mongoc_read_concern_copy(read_concern) :
182+
mongoc_read_concern_new();
177183
col->read_prefs = read_prefs ?
178184
mongoc_read_prefs_copy(read_prefs) :
179185
mongoc_read_prefs_new(MONGOC_READ_PRIMARY);
@@ -226,6 +232,11 @@ mongoc_collection_destroy (mongoc_collection_t *collection) /* IN */
226232
collection->read_prefs = NULL;
227233
}
228234

235+
if (collection->read_concern) {
236+
mongoc_read_concern_destroy(collection->read_concern);
237+
collection->read_concern = NULL;
238+
}
239+
229240
if (collection->write_concern) {
230241
mongoc_write_concern_destroy(collection->write_concern);
231242
collection->write_concern = NULL;
@@ -1574,6 +1585,64 @@ mongoc_collection_set_read_prefs (mongoc_collection_t *collection,
15741585
}
15751586

15761587

1588+
/*
1589+
*--------------------------------------------------------------------------
1590+
*
1591+
* mongoc_collection_get_read_concern --
1592+
*
1593+
* Fetches the default read concern for the collection instance.
1594+
*
1595+
* Returns:
1596+
* A mongoc_read_concern_t that should not be modified or freed.
1597+
*
1598+
* Side effects:
1599+
* None.
1600+
*
1601+
*--------------------------------------------------------------------------
1602+
*/
1603+
1604+
const mongoc_read_concern_t *
1605+
mongoc_collection_get_read_concern (const mongoc_collection_t *collection)
1606+
{
1607+
BSON_ASSERT (collection);
1608+
1609+
return collection->read_concern;
1610+
}
1611+
1612+
1613+
/*
1614+
*--------------------------------------------------------------------------
1615+
*
1616+
* mongoc_collection_set_read_concern --
1617+
*
1618+
* Sets the default read concern for the collection instance.
1619+
*
1620+
* Returns:
1621+
* None.
1622+
*
1623+
* Side effects:
1624+
* None.
1625+
*
1626+
*--------------------------------------------------------------------------
1627+
*/
1628+
1629+
void
1630+
mongoc_collection_set_read_concern (mongoc_collection_t *collection,
1631+
const mongoc_read_concern_t *read_concern)
1632+
{
1633+
BSON_ASSERT (collection);
1634+
1635+
if (collection->read_concern) {
1636+
mongoc_read_concern_destroy(collection->read_concern);
1637+
collection->read_concern = NULL;
1638+
}
1639+
1640+
if (read_concern) {
1641+
collection->read_concern = mongoc_read_concern_copy(read_concern);
1642+
}
1643+
}
1644+
1645+
15771646
/*
15781647
*--------------------------------------------------------------------------
15791648
*

src/mongoc/mongoc-collection.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "mongoc-cursor.h"
2929
#include "mongoc-index.h"
3030
#include "mongoc-read-prefs.h"
31+
#include "mongoc-read-concern.h"
3132
#include "mongoc-write-concern.h"
3233
#include "mongoc-find-and-modify.h"
3334

@@ -155,6 +156,9 @@ mongoc_bulk_operation_t *mongoc_collection_create_bulk_operation(mongoc_col
155156
const mongoc_read_prefs_t *mongoc_collection_get_read_prefs (const mongoc_collection_t *collection);
156157
void mongoc_collection_set_read_prefs (mongoc_collection_t *collection,
157158
const mongoc_read_prefs_t *read_prefs);
159+
const mongoc_read_concern_t *mongoc_collection_get_read_concern (const mongoc_collection_t *collection);
160+
void mongoc_collection_set_read_concern (mongoc_collection_t *collection,
161+
const mongoc_read_concern_t *read_concern);
158162
const mongoc_write_concern_t *mongoc_collection_get_write_concern (const mongoc_collection_t *collection);
159163
void mongoc_collection_set_write_concern (mongoc_collection_t *collection,
160164
const mongoc_write_concern_t *write_concern);

src/mongoc/mongoc-database-private.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "mongoc-client.h"
2727
#include "mongoc-read-prefs.h"
28+
#include "mongoc-read-concern.h"
2829
#include "mongoc-write-concern.h"
2930

3031

@@ -35,14 +36,16 @@ struct _mongoc_database_t
3536
{
3637
mongoc_client_t *client;
3738
char name [128];
38-
mongoc_write_concern_t *write_concern;
3939
mongoc_read_prefs_t *read_prefs;
40+
mongoc_read_concern_t *read_concern;
41+
mongoc_write_concern_t *write_concern;
4042
};
4143

4244

4345
mongoc_database_t *_mongoc_database_new (mongoc_client_t *client,
4446
const char *name,
4547
const mongoc_read_prefs_t *read_prefs,
48+
const mongoc_read_concern_t *read_concern,
4649
const mongoc_write_concern_t *write_concern);
4750
mongoc_cursor_t *_mongoc_database_find_collections_legacy (mongoc_database_t *database,
4851
const bson_t *filter,

0 commit comments

Comments
 (0)