Skip to content

Commit 4249c97

Browse files
authored
CDRIVER-4557 add int64 connection_id functions (#1246)
* add connection_id_int64 functions * deprecate int32 connection_id functions * replace use of int32 with connection_id with int64 * add deprecation notes to documentation * document connection_id with int64 * add warning when int64 is out of int32 range
1 parent 95d7a18 commit 4249c97

12 files changed

+199
-16
lines changed

src/libmongoc/doc/mongoc_apm_command_failed_get_server_connection_id.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Synopsis
1010
1111
int32_t
1212
mongoc_apm_command_failed_get_server_connection_id (
13-
const mongoc_apm_command_failed_t *event);
13+
const mongoc_apm_command_failed_t *event)
14+
BSON_GNUC_DEPRECATED_FOR (
15+
"mongoc_apm_command_failed_get_server_connection_id_int64");
1416
1517
Returns this event's context.
1618

@@ -19,6 +21,12 @@ distinct from the server ID (:symbol:`mongoc_apm_command_failed_get_server_id`)
1921
and is returned by the hello or legacy hello response as "connectionId" from the
2022
server on 4.2+.
2123

24+
Deprecated
25+
----------
26+
27+
This function is deprecated. Please use
28+
:symbol:`mongoc_apm_command_failed_get_server_connection_id_int64` in new code.
29+
2230
Parameters
2331
----------
2432

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
:man_page: mongoc_apm_command_failed_get_server_connection_id_int64
2+
3+
mongoc_apm_command_failed_get_server_connection_id_int64()
4+
==========================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
int64_t
12+
mongoc_apm_command_failed_get_server_connection_id_int64 (
13+
const mongoc_apm_command_failed_t *event);
14+
15+
Returns this event's context.
16+
17+
Returns the server connection ID for the command. The server connection ID is
18+
distinct from the server ID (:symbol:`mongoc_apm_command_failed_get_server_id`)
19+
and is returned by the hello or legacy hello response as "connectionId" from the
20+
server on 4.2+.
21+
22+
Parameters
23+
----------
24+
25+
* ``event``: A :symbol:`mongoc_apm_command_failed_t`.
26+
27+
Returns
28+
-------
29+
30+
The server connection ID as a positive integer or -1 if it is not available.
31+
32+
.. seealso::
33+
34+
| :doc:`Introduction to Application Performance Monitoring <application-performance-monitoring>`
35+

src/libmongoc/doc/mongoc_apm_command_failed_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ An event notification sent when the driver fails to execute a MongoDB command.
3030
mongoc_apm_command_failed_get_server_id
3131
mongoc_apm_command_failed_get_service_id
3232
mongoc_apm_command_failed_get_server_connection_id
33+
mongoc_apm_command_failed_get_server_connection_id_int64
3334

3435
.. seealso::
3536

src/libmongoc/doc/mongoc_apm_command_started_get_server_connection_id.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ Synopsis
1010
1111
int32_t
1212
mongoc_apm_command_started_get_server_connection_id (
13-
const mongoc_apm_command_started_t *event);
13+
const mongoc_apm_command_started_t *event)
14+
BSON_GNUC_DEPRECATED_FOR (
15+
"mongoc_apm_command_started_get_server_connection_id_int64");
1416
1517
Returns the server connection ID for the command. The server connection ID is
1618
distinct from the server ID (:symbol:`mongoc_apm_command_started_get_server_id`)
1719
and is returned by the hello or legacy hello response as "connectionId" from the
1820
server on 4.2+.
1921

22+
Deprecated
23+
----------
24+
25+
This function is deprecated. Please use
26+
:symbol:`mongoc_apm_command_started_get_server_connection_id_int64` in new code.
27+
2028
Parameters
2129
----------
2230

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
:man_page: mongoc_apm_command_started_get_server_connection_id_int64
2+
3+
mongoc_apm_command_started_get_server_connection_id_int64()
4+
===========================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
int64_t
12+
mongoc_apm_command_started_get_server_connection_id_int64 (
13+
const mongoc_apm_command_started_t *event);
14+
15+
Returns the server connection ID for the command. The server connection ID is
16+
distinct from the server ID (:symbol:`mongoc_apm_command_started_get_server_id`)
17+
and is returned by the hello or legacy hello response as "connectionId" from the
18+
server on 4.2+.
19+
20+
Parameters
21+
----------
22+
23+
* ``event``: A :symbol:`mongoc_apm_command_started_t`.
24+
25+
Returns
26+
-------
27+
28+
The server connection ID as a positive integer or -1 if it is not available.
29+
30+
.. seealso::
31+
32+
| :doc:`Introduction to Application Performance Monitoring <application-performance-monitoring>`
33+

src/libmongoc/doc/mongoc_apm_command_started_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ An event notification sent when the driver begins executing a MongoDB command.
3333
mongoc_apm_command_started_get_server_id
3434
mongoc_apm_command_started_get_service_id
3535
mongoc_apm_command_started_get_server_connection_id
36+
mongoc_apm_command_started_get_server_connection_id_int64
3637

src/libmongoc/doc/mongoc_apm_command_succeeded_get_server_connection_id.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ Synopsis
1010
1111
int32_t
1212
mongoc_apm_command_succeeded_get_server_connection_id (
13-
const mongoc_apm_command_succeeded_t *event);
13+
const mongoc_apm_command_succeeded_t *event)
14+
BSON_GNUC_DEPRECATED_FOR (
15+
"mongoc_apm_command_succeeded_get_server_connection_id_int64");
1416
1517
Returns the server connection ID for the command. The server connection ID is
1618
distinct from the server ID
1719
(:symbol:`mongoc_apm_command_succeeded_get_server_id`) and is returned by the
1820
hello or legacy hello response as "connectionId" from the server on 4.2+.
1921

22+
Deprecated
23+
----------
24+
25+
This function is deprecated. Please use
26+
:symbol:`mongoc_apm_command_succeeded_get_server_connection_id_int64` in new code.
27+
2028
Parameters
2129
----------
2230

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
:man_page: mongoc_apm_command_succeeded_get_server_connection_id_int64
2+
3+
mongoc_apm_command_succeeded_get_server_connection_id_int64()
4+
=============================================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
int64_t
12+
mongoc_apm_command_succeeded_get_server_connection_id_int64 (
13+
const mongoc_apm_command_succeeded_t *event);
14+
15+
Returns the server connection ID for the command. The server connection ID is
16+
distinct from the server ID
17+
(:symbol:`mongoc_apm_command_succeeded_get_server_id`) and is returned by the
18+
hello or legacy hello response as "connectionId" from the server on 4.2+.
19+
20+
Parameters
21+
----------
22+
23+
* ``event``: A :symbol:`mongoc_apm_command_succeeded_t`.
24+
25+
Returns
26+
-------
27+
28+
The server connection ID as a positive integer or -1 if it is not available.
29+
30+
.. seealso::
31+
32+
| :doc:`Introduction to Application Performance Monitoring <application-performance-monitoring>`
33+

src/libmongoc/doc/mongoc_apm_command_succeeded_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ An event notification sent when the driver successfully executes a MongoDB comma
3333
mongoc_apm_command_succeeded_get_server_id
3434
mongoc_apm_command_succeeded_get_service_id
3535
mongoc_apm_command_succeeded_get_server_connection_id
36+
mongoc_apm_command_succeeded_get_server_connection_id_int64
3637

src/libmongoc/src/mongoc/mongoc-apm.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,26 @@ mongoc_apm_command_started_get_server_connection_id (
392392
{
393393
if (event->server_connection_id > INT32_MAX ||
394394
event->server_connection_id < INT32_MIN) {
395+
MONGOC_WARNING (
396+
"Server connection ID %" PRId64
397+
" is outside of int32 range. Returning -1. Use "
398+
"mongoc_apm_command_started_get_server_connection_id_int64.",
399+
event->server_connection_id);
395400
return MONGOC_NO_SERVER_CONNECTION_ID;
396401
}
397402

398403
return (int32_t) event->server_connection_id;
399404
}
400405

401406

407+
int64_t
408+
mongoc_apm_command_started_get_server_connection_id_int64 (
409+
const mongoc_apm_command_started_t *event)
410+
{
411+
return event->server_connection_id;
412+
}
413+
414+
402415
void *
403416
mongoc_apm_command_started_get_context (
404417
const mongoc_apm_command_started_t *event)
@@ -484,13 +497,26 @@ mongoc_apm_command_succeeded_get_server_connection_id (
484497
{
485498
if (event->server_connection_id > INT32_MAX ||
486499
event->server_connection_id < INT32_MIN) {
500+
MONGOC_WARNING (
501+
"Server connection ID %" PRId64
502+
" is outside of int32 range. Returning -1. Use "
503+
"mongoc_apm_command_succeeded_get_server_connection_id_int64.",
504+
event->server_connection_id);
487505
return MONGOC_NO_SERVER_CONNECTION_ID;
488506
}
489507

490508
return (int32_t) event->server_connection_id;
491509
}
492510

493511

512+
int64_t
513+
mongoc_apm_command_succeeded_get_server_connection_id_int64 (
514+
const mongoc_apm_command_succeeded_t *event)
515+
{
516+
return event->server_connection_id;
517+
}
518+
519+
494520
void *
495521
mongoc_apm_command_succeeded_get_context (
496522
const mongoc_apm_command_succeeded_t *event)
@@ -580,13 +606,26 @@ mongoc_apm_command_failed_get_server_connection_id (
580606
{
581607
if (event->server_connection_id > INT32_MAX ||
582608
event->server_connection_id < INT32_MIN) {
609+
MONGOC_WARNING (
610+
"Server connection ID %" PRId64
611+
" is outside of int32 range. Returning -1. Use "
612+
"mongoc_apm_command_failed_get_server_connection_id_int64.",
613+
event->server_connection_id);
583614
return MONGOC_NO_SERVER_CONNECTION_ID;
584615
}
585616

586617
return (int32_t) event->server_connection_id;
587618
}
588619

589620

621+
int64_t
622+
mongoc_apm_command_failed_get_server_connection_id_int64 (
623+
const mongoc_apm_command_failed_t *event)
624+
{
625+
return event->server_connection_id;
626+
}
627+
628+
590629
void *
591630
mongoc_apm_command_failed_get_context (const mongoc_apm_command_failed_t *event)
592631
{

src/libmongoc/src/mongoc/mongoc-apm.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ mongoc_apm_command_started_get_service_id (
104104
const mongoc_apm_command_started_t *event);
105105
MONGOC_EXPORT (int32_t)
106106
mongoc_apm_command_started_get_server_connection_id (
107+
const mongoc_apm_command_started_t *event)
108+
BSON_GNUC_DEPRECATED_FOR (
109+
"mongoc_apm_command_started_get_server_connection_id_int64");
110+
MONGOC_EXPORT (int64_t)
111+
mongoc_apm_command_started_get_server_connection_id_int64 (
107112
const mongoc_apm_command_started_t *event);
108113
MONGOC_EXPORT (void *)
109114
mongoc_apm_command_started_get_context (
@@ -137,6 +142,11 @@ mongoc_apm_command_succeeded_get_service_id (
137142
const mongoc_apm_command_succeeded_t *event);
138143
MONGOC_EXPORT (int32_t)
139144
mongoc_apm_command_succeeded_get_server_connection_id (
145+
const mongoc_apm_command_succeeded_t *event)
146+
BSON_GNUC_DEPRECATED_FOR (
147+
"mongoc_apm_command_succeeded_get_server_connection_id_int64");
148+
MONGOC_EXPORT (int64_t)
149+
mongoc_apm_command_succeeded_get_server_connection_id_int64 (
140150
const mongoc_apm_command_succeeded_t *event);
141151
MONGOC_EXPORT (void *)
142152
mongoc_apm_command_succeeded_get_context (
@@ -172,6 +182,11 @@ mongoc_apm_command_failed_get_service_id (
172182
const mongoc_apm_command_failed_t *event);
173183
MONGOC_EXPORT (int32_t)
174184
mongoc_apm_command_failed_get_server_connection_id (
185+
const mongoc_apm_command_failed_t *event)
186+
BSON_GNUC_DEPRECATED_FOR (
187+
"mongoc_apm_command_failed_get_server_connection_id_int64");
188+
MONGOC_EXPORT (int64_t)
189+
mongoc_apm_command_failed_get_server_connection_id_int64 (
175190
const mongoc_apm_command_failed_t *event);
176191
MONGOC_EXPORT (void *)
177192
mongoc_apm_command_failed_get_context (

src/libmongoc/tests/unified/entity-map.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ typedef struct command_callback_funcs_t {
227227
apm_func_int64_t get_operation_id;
228228
apm_func_bson_oid_t get_service_id;
229229
apm_func_host_list_t get_host;
230-
apm_func_int32_t get_server_connection_id;
230+
apm_func_int64_t get_server_connection_id;
231231
apm_func_serialize_t serialize;
232232
} command_callback_funcs_t;
233233

@@ -310,10 +310,10 @@ store_event_serialize_started (bson_t *doc,
310310
"connectionId",
311311
mongoc_apm_command_started_get_host (apm_command)->host_and_port);
312312

313-
BSON_APPEND_INT32 (
313+
BSON_APPEND_INT64 (
314314
doc,
315315
"serverConnectionId",
316-
mongoc_apm_command_started_get_server_connection_id (apm_command));
316+
mongoc_apm_command_started_get_server_connection_id_int64 (apm_command));
317317

318318
{
319319
const bson_oid_t *const service_id =
@@ -355,10 +355,10 @@ store_event_serialize_failed (bson_t *doc,
355355
"connectionId",
356356
mongoc_apm_command_failed_get_host (apm_command)->host_and_port);
357357

358-
BSON_APPEND_INT32 (
358+
BSON_APPEND_INT64 (
359359
doc,
360360
"serverConnectionId",
361-
mongoc_apm_command_failed_get_server_connection_id (apm_command));
361+
mongoc_apm_command_failed_get_server_connection_id_int64 (apm_command));
362362

363363
{
364364
const bson_oid_t *const service_id =
@@ -403,10 +403,11 @@ store_event_serialize_succeeded (
403403
"connectionId",
404404
mongoc_apm_command_succeeded_get_host (apm_command)->host_and_port);
405405

406-
BSON_APPEND_INT32 (
406+
BSON_APPEND_INT64 (
407407
doc,
408408
"serverConnectionId",
409-
mongoc_apm_command_succeeded_get_server_connection_id (apm_command));
409+
mongoc_apm_command_succeeded_get_server_connection_id_int64 (
410+
apm_command));
410411

411412
{
412413
const bson_oid_t *const service_id =
@@ -498,8 +499,8 @@ command_started (const mongoc_apm_command_started_t *started)
498499
.get_service_id =
499500
(apm_func_bson_oid_t) mongoc_apm_command_started_get_service_id,
500501
.get_host = (apm_func_host_list_t) mongoc_apm_command_started_get_host,
501-
.get_server_connection_id =
502-
(apm_func_int32_t) mongoc_apm_command_started_get_server_connection_id,
502+
.get_server_connection_id = (apm_func_int64_t)
503+
mongoc_apm_command_started_get_server_connection_id_int64,
503504
.serialize = (apm_func_serialize_t) store_event_serialize_started,
504505
};
505506

@@ -523,8 +524,8 @@ command_failed (const mongoc_apm_command_failed_t *failed)
523524
.get_service_id =
524525
(apm_func_bson_oid_t) mongoc_apm_command_failed_get_service_id,
525526
.get_host = (apm_func_host_list_t) mongoc_apm_command_failed_get_host,
526-
.get_server_connection_id =
527-
(apm_func_int32_t) mongoc_apm_command_failed_get_server_connection_id,
527+
.get_server_connection_id = (apm_func_int64_t)
528+
mongoc_apm_command_failed_get_server_connection_id_int64,
528529
.serialize = (apm_func_serialize_t) store_event_serialize_failed,
529530
};
530531

@@ -548,8 +549,8 @@ command_succeeded (const mongoc_apm_command_succeeded_t *succeeded)
548549
.get_service_id =
549550
(apm_func_bson_oid_t) mongoc_apm_command_succeeded_get_service_id,
550551
.get_host = (apm_func_host_list_t) mongoc_apm_command_succeeded_get_host,
551-
.get_server_connection_id = (apm_func_int32_t)
552-
mongoc_apm_command_succeeded_get_server_connection_id,
552+
.get_server_connection_id = (apm_func_int64_t)
553+
mongoc_apm_command_succeeded_get_server_connection_id_int64,
553554
.serialize = (apm_func_serialize_t) store_event_serialize_succeeded,
554555
};
555556

0 commit comments

Comments
 (0)