Skip to content

Commit a7f5dba

Browse files
authored
Vendor in libmongoc latest (#658)
1 parent a30ad32 commit a7f5dba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1327
-317
lines changed

Sources/CLibMongoC/include/CLibMongoC_mongoc-apm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ mongoc_apm_command_started_get_host (const mongoc_apm_command_started_t *event);
9999
MONGOC_EXPORT (uint32_t)
100100
mongoc_apm_command_started_get_server_id (
101101
const mongoc_apm_command_started_t *event);
102+
MONGOC_EXPORT (const bson_oid_t *)
103+
mongoc_apm_command_started_get_service_id (
104+
const mongoc_apm_command_started_t *event);
102105
MONGOC_EXPORT (void *)
103106
mongoc_apm_command_started_get_context (
104107
const mongoc_apm_command_started_t *event);
@@ -126,6 +129,9 @@ mongoc_apm_command_succeeded_get_host (
126129
MONGOC_EXPORT (uint32_t)
127130
mongoc_apm_command_succeeded_get_server_id (
128131
const mongoc_apm_command_succeeded_t *event);
132+
MONGOC_EXPORT (const bson_oid_t *)
133+
mongoc_apm_command_succeeded_get_service_id (
134+
const mongoc_apm_command_succeeded_t *event);
129135
MONGOC_EXPORT (void *)
130136
mongoc_apm_command_succeeded_get_context (
131137
const mongoc_apm_command_succeeded_t *event);
@@ -155,6 +161,9 @@ mongoc_apm_command_failed_get_host (const mongoc_apm_command_failed_t *event);
155161
MONGOC_EXPORT (uint32_t)
156162
mongoc_apm_command_failed_get_server_id (
157163
const mongoc_apm_command_failed_t *event);
164+
MONGOC_EXPORT (const bson_oid_t *)
165+
mongoc_apm_command_failed_get_service_id (
166+
const mongoc_apm_command_failed_t *event);
158167
MONGOC_EXPORT (void *)
159168
mongoc_apm_command_failed_get_context (
160169
const mongoc_apm_command_failed_t *event);

Sources/CLibMongoC/include/CLibMongoC_mongoc-client-session.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ mongoc_session_opts_set_causal_consistency (mongoc_session_opt_t *opts,
9191
MONGOC_EXPORT (bool)
9292
mongoc_session_opts_get_causal_consistency (const mongoc_session_opt_t *opts);
9393

94+
MONGOC_EXPORT (void)
95+
mongoc_session_opts_set_snapshot (mongoc_session_opt_t *opts, bool snapshot);
96+
97+
MONGOC_EXPORT (bool)
98+
mongoc_session_opts_get_snapshot (const mongoc_session_opt_t *opts);
99+
94100
MONGOC_EXPORT (void)
95101
mongoc_session_opts_set_default_transaction_opts (
96102
mongoc_session_opt_t *opts, const mongoc_transaction_opt_t *txn_opts);

Sources/CLibMongoC/include/CLibMongoC_mongoc-client.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ mongoc_client_set_server_api (mongoc_client_t *client,
274274
const mongoc_server_api_t *api,
275275
bson_error_t *error);
276276

277+
MONGOC_EXPORT (mongoc_server_description_t *)
278+
mongoc_client_get_handshake_description (mongoc_client_t *client,
279+
uint32_t server_id,
280+
bson_t *opts,
281+
bson_error_t *error);
282+
277283
BSON_END_DECLS
278284

279285

Sources/CLibMongoC/include/CLibMongoC_mongoc-error.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ typedef enum {
131131
MONGOC_ERROR_CLIENT_API_ALREADY_SET,
132132
MONGOC_ERROR_CLIENT_API_FROM_POOL,
133133
MONGOC_ERROR_POOL_API_ALREADY_SET,
134-
MONGOC_ERROR_POOL_API_TOO_LATE
134+
MONGOC_ERROR_POOL_API_TOO_LATE,
135+
136+
MONGOC_ERROR_CLIENT_INVALID_LOAD_BALANCER,
135137
} mongoc_error_code_t;
136138

137139
MONGOC_EXPORT (bool)

Sources/CLibMongoC/include/CLibMongoC_mongoc-uri.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#define MONGOC_URI_GSSAPISERVICENAME "gssapiservicename"
4545
#define MONGOC_URI_HEARTBEATFREQUENCYMS "heartbeatfrequencyms"
4646
#define MONGOC_URI_JOURNAL "journal"
47+
#define MONGOC_URI_LOADBALANCED "loadbalanced"
4748
#define MONGOC_URI_LOCALTHRESHOLDMS "localthresholdms"
4849
#define MONGOC_URI_MAXIDLETIMEMS "maxidletimems"
4950
#define MONGOC_URI_MAXPOOLSIZE "maxpoolsize"

Sources/CLibMongoC/mongoc/mongoc-apm-private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct _mongoc_apm_command_started_t {
5555
int64_t operation_id;
5656
const mongoc_host_list_t *host;
5757
uint32_t server_id;
58+
bson_oid_t service_id;
5859
void *context;
5960
};
6061

@@ -67,6 +68,7 @@ struct _mongoc_apm_command_succeeded_t {
6768
int64_t operation_id;
6869
const mongoc_host_list_t *host;
6970
uint32_t server_id;
71+
bson_oid_t service_id;
7072
void *context;
7173
};
7274

@@ -80,6 +82,7 @@ struct _mongoc_apm_command_failed_t {
8082
int64_t operation_id;
8183
const mongoc_host_list_t *host;
8284
uint32_t server_id;
85+
bson_oid_t service_id;
8386
void *context;
8487
};
8588

@@ -155,6 +158,7 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
155158
int64_t operation_id,
156159
const mongoc_host_list_t *host,
157160
uint32_t server_id,
161+
const bson_oid_t *service_id,
158162
bool *is_redacted, /* out */
159163
void *context);
160164

@@ -177,6 +181,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
177181
int64_t operation_id,
178182
const mongoc_host_list_t *host,
179183
uint32_t server_id,
184+
const bson_oid_t *service_id,
180185
bool force_redaction,
181186
void *context);
182187

@@ -193,6 +198,7 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
193198
int64_t operation_id,
194199
const mongoc_host_list_t *host,
195200
uint32_t server_id,
201+
const bson_oid_t *service_id,
196202
bool force_redaction,
197203
void *context);
198204

Sources/CLibMongoC/mongoc/mongoc-apm.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "mongoc-cmd-private.h"
2020
#include "mongoc-handshake-private.h"
2121

22+
static bson_oid_t kObjectIdZero = {{0}};
23+
2224
/*
2325
* An Application Performance Management (APM) implementation, complying with
2426
* MongoDB's Command Monitoring Spec:
@@ -74,6 +76,7 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
7476
int64_t operation_id,
7577
const mongoc_host_list_t *host,
7678
uint32_t server_id,
79+
const bson_oid_t *service_id,
7780
bool *is_redacted, /* out */
7881
void *context)
7982
{
@@ -129,6 +132,8 @@ mongoc_apm_command_started_init (mongoc_apm_command_started_t *event,
129132
event->host = host;
130133
event->server_id = server_id;
131134
event->context = context;
135+
136+
bson_oid_copy_unsafe (service_id, &event->service_id);
132137
}
133138

134139

@@ -159,6 +164,7 @@ mongoc_apm_command_started_init_with_cmd (mongoc_apm_command_started_t *event,
159164
cmd->operation_id,
160165
&cmd->server_stream->sd->host,
161166
cmd->server_stream->sd->id,
167+
&cmd->server_stream->sd->service_id,
162168
is_redacted,
163169
context);
164170

@@ -197,6 +203,7 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
197203
int64_t operation_id,
198204
const mongoc_host_list_t *host,
199205
uint32_t server_id,
206+
const bson_oid_t *service_id,
200207
bool force_redaction,
201208
void *context)
202209
{
@@ -220,6 +227,8 @@ mongoc_apm_command_succeeded_init (mongoc_apm_command_succeeded_t *event,
220227
event->host = host;
221228
event->server_id = server_id;
222229
event->context = context;
230+
231+
bson_oid_copy_unsafe (service_id, &event->service_id);
223232
}
224233

225234

@@ -254,6 +263,7 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
254263
int64_t operation_id,
255264
const mongoc_host_list_t *host,
256265
uint32_t server_id,
266+
const bson_oid_t *service_id,
257267
bool force_redaction,
258268
void *context)
259269
{
@@ -278,6 +288,8 @@ mongoc_apm_command_failed_init (mongoc_apm_command_failed_t *event,
278288
event->host = host;
279289
event->server_id = server_id;
280290
event->context = context;
291+
292+
bson_oid_copy_unsafe (service_id, &event->service_id);
281293
}
282294

283295

@@ -351,6 +363,19 @@ mongoc_apm_command_started_get_server_id (
351363
}
352364

353365

366+
const bson_oid_t *
367+
mongoc_apm_command_started_get_service_id (
368+
const mongoc_apm_command_started_t *event)
369+
{
370+
if (0 == bson_oid_compare (&event->service_id, &kObjectIdZero)) {
371+
/* serviceId is unset. */
372+
return NULL;
373+
}
374+
375+
return &event->service_id;
376+
}
377+
378+
354379
void *
355380
mongoc_apm_command_started_get_context (
356381
const mongoc_apm_command_started_t *event)
@@ -417,6 +442,19 @@ mongoc_apm_command_succeeded_get_server_id (
417442
}
418443

419444

445+
const bson_oid_t *
446+
mongoc_apm_command_succeeded_get_service_id (
447+
const mongoc_apm_command_succeeded_t *event)
448+
{
449+
if (0 == bson_oid_compare (&event->service_id, &kObjectIdZero)) {
450+
/* serviceId is unset. */
451+
return NULL;
452+
}
453+
454+
return &event->service_id;
455+
}
456+
457+
420458
void *
421459
mongoc_apm_command_succeeded_get_context (
422460
const mongoc_apm_command_succeeded_t *event)
@@ -487,6 +525,19 @@ mongoc_apm_command_failed_get_server_id (
487525
}
488526

489527

528+
const bson_oid_t *
529+
mongoc_apm_command_failed_get_service_id (
530+
const mongoc_apm_command_failed_t *event)
531+
{
532+
if (0 == bson_oid_compare (&event->service_id, &kObjectIdZero)) {
533+
/* serviceId is unset. */
534+
return NULL;
535+
}
536+
537+
return &event->service_id;
538+
}
539+
540+
490541
void *
491542
mongoc_apm_command_failed_get_context (const mongoc_apm_command_failed_t *event)
492543
{

Sources/CLibMongoC/mongoc/mongoc-change-stream.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <CLibMongoC_bson.h>
18+
#include "mongoc-cluster-private.h"
1819
#include "mongoc-change-stream-private.h"
1920
#include "mongoc-collection-private.h"
2021
#include "mongoc-client-private.h"
@@ -239,23 +240,12 @@ _make_cursor (mongoc_change_stream_t *stream)
239240
bson_t reply;
240241
bson_t getmore_opts = BSON_INITIALIZER;
241242
bson_iter_t iter;
242-
mongoc_server_description_t *sd;
243-
uint32_t server_id;
243+
mongoc_server_stream_t *server_stream;
244244

245245
BSON_ASSERT (stream);
246246
BSON_ASSERT (!stream->cursor);
247247
bson_init (&command);
248248
bson_copy_to (&(stream->opts.extra), &command_opts);
249-
sd = mongoc_client_select_server (
250-
stream->client, false /* for_writes */, stream->read_prefs, &stream->err);
251-
if (!sd) {
252-
goto cleanup;
253-
}
254-
server_id = mongoc_server_description_id (sd);
255-
bson_append_int32 (&command_opts, "serverId", 8, server_id);
256-
bson_append_int32 (&getmore_opts, "serverId", 8, server_id);
257-
stream->max_wire_version = sd->max_wire_version;
258-
mongoc_server_description_destroy (sd);
259249

260250
if (bson_iter_init_find (&iter, &command_opts, "sessionId")) {
261251
if (!_mongoc_client_session_from_iter (
@@ -293,6 +283,19 @@ _make_cursor (mongoc_change_stream_t *stream)
293283
goto cleanup;
294284
}
295285

286+
server_stream = mongoc_cluster_stream_for_reads (
287+
&stream->client->cluster, stream->read_prefs, cs, &reply, &stream->err);
288+
if (!server_stream) {
289+
bson_destroy (&stream->err_doc);
290+
bson_copy_to (&reply, &stream->err_doc);
291+
bson_destroy (&reply);
292+
goto cleanup;
293+
}
294+
bson_append_int32 (&command_opts, "serverId", 8, server_stream->sd->id);
295+
bson_append_int32 (&getmore_opts, "serverId", 8, server_stream->sd->id);
296+
stream->max_wire_version = server_stream->sd->max_wire_version;
297+
mongoc_server_stream_cleanup (server_stream);
298+
296299
if (stream->read_concern && !bson_has_field (&command_opts, "readConcern")) {
297300
mongoc_read_concern_append (stream->read_concern, &command_opts);
298301
}

Sources/CLibMongoC/mongoc/mongoc-client-private.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ BSON_BEGIN_DECLS
9494
#define WIRE_VERSION_4_9 12
9595
/* version corresponding to server 5.0 release */
9696
#define WIRE_VERSION_5_0 13
97+
/* first version to support snapshot reads */
98+
#define WIRE_VERSION_SNAPSHOT_READS 13
9799

98100
struct _mongoc_collection_t;
99101

@@ -146,22 +148,10 @@ typedef enum {
146148
BSON_STATIC_ASSERT2 (mongoc_cmd_rw,
147149
MONGOC_CMD_RW == (MONGOC_CMD_READ | MONGOC_CMD_WRITE));
148150

149-
typedef enum { MONGOC_RR_SRV, MONGOC_RR_TXT } mongoc_rr_type_t;
150-
151-
typedef struct _mongoc_rr_data_t {
152-
/* Number of records returned by DNS. */
153-
uint32_t count;
154-
155-
/* Set to lowest TTL found when polling SRV records. */
156-
uint32_t min_ttl;
157-
158-
/* Set to the resulting host list when polling SRV records */
159-
mongoc_host_list_t *hosts;
160-
161-
/* Set to the TXT record when polling for TXT */
162-
char *txt_record_opts;
163-
} mongoc_rr_data_t;
164151

152+
/* TODO (CDRIVER-4052): Move MONGOC_RR_DEFAULT_BUFFER_SIZE and
153+
* _mongoc_client_get_rr to mongoc-topology-private.h or in a separate file.
154+
* There is no reason these should be in mongoc-client. */
165155
#define MONGOC_RR_DEFAULT_BUFFER_SIZE 1024
166156
bool
167157
_mongoc_client_get_rr (const char *service,

Sources/CLibMongoC/mongoc/mongoc-client-session-private.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@ struct _mongoc_transaction_opt_t {
3838
int64_t max_commit_time_ms;
3939
};
4040

41-
typedef enum {
42-
MONGOC_SESSION_NO_OPTS = 0,
43-
MONGOC_SESSION_CAUSAL_CONSISTENCY = (1 << 0),
44-
} mongoc_session_flag_t;
45-
4641
struct _mongoc_session_opt_t {
47-
mongoc_session_flag_t flags;
42+
mongoc_optional_t causal_consistency;
43+
mongoc_optional_t snapshot;
4844
mongoc_transaction_opt_t default_txn_opts;
4945
};
5046

@@ -83,6 +79,9 @@ struct _mongoc_client_session_t {
8379
uint32_t client_generation;
8480
uint32_t server_id;
8581
bson_t *recovery_token;
82+
uint32_t snapshot_time_timestamp;
83+
uint32_t snapshot_time_increment;
84+
bool snapshot_time_set;
8685

8786
/* For testing only */
8887
int64_t with_txn_timeout_ms;
@@ -100,6 +99,7 @@ _mongoc_cluster_time_greater (const bson_t *new, const bson_t *old);
10099
void
101100
_mongoc_client_session_handle_reply (mongoc_client_session_t *session,
102101
bool is_acknowledged,
102+
const char *cmd_name,
103103
const bson_t *reply);
104104

105105
mongoc_server_session_t *
@@ -152,5 +152,12 @@ void
152152
_mongoc_client_session_pin (mongoc_client_session_t *session,
153153
uint32_t server_id);
154154

155+
void
156+
_mongoc_client_session_set_snapshot_time (mongoc_client_session_t *session,
157+
uint32_t t,
158+
uint32_t i);
159+
160+
void
161+
_mongoc_client_session_clear_snapshot_time (mongoc_client_session_t *session);
155162

156163
#endif /* MONGOC_CLIENT_SESSION_PRIVATE_H */

0 commit comments

Comments
 (0)