Skip to content

Commit 4cc8a97

Browse files
Annotate and document "hedge" APIs as deprecated
1 parent 0da23b0 commit 4cc8a97

6 files changed

+50
-6
lines changed

src/libmongoc/doc/mongoc_read_prefs_get_hedge.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
mongoc_read_prefs_get_hedge()
44
=============================
55

6+
.. deprecated:: MongoDB Server 8.0
7+
8+
Hedged reads are deprecated in MongoDB version 8.0 and will be removed in
9+
a future release.
10+
611
Synopsis
712
--------
813

src/libmongoc/doc/mongoc_read_prefs_set_hedge.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
mongoc_read_prefs_set_hedge()
44
=============================
55

6+
.. deprecated:: MongoDB Server 8.0
7+
8+
Hedged reads are deprecated in MongoDB version 8.0 and will be removed in
9+
a future release.
10+
611
Synopsis
712
--------
813

src/libmongoc/doc/mongoc_read_prefs_t.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,19 @@ Max Staleness is also supported by sharded clusters of replica sets if all serve
7070
Hedged Reads
7171
------------
7272

73-
When connecting to a sharded cluster running MongoDB 4.4 or later, reads can be sent in parallel to the two "best" hosts. Once one result returns, any other outstanding operations that were part of the hedged read are cancelled.
73+
.. deprecated:: MongoDB Server 8.0
7474

75-
When the read preference mode is ``MONGOC_READ_NEAREST`` and the sharded cluster is running MongoDB 4.4 or later, hedged reads are enabled by default. Additionally, hedged reads may be explicitly enabled or disabled by calling :symbol:`mongoc_read_prefs_set_hedge` with a BSON document, e.g.
75+
Hedged reads are deprecated in MongoDB version 8.0 and will be removed in
76+
a future release.
77+
78+
When connecting to a sharded cluster running MongoDB 4.4 or later, reads can be
79+
sent in parallel to the two "best" hosts. Once one result returns, any other
80+
outstanding operations that were part of the hedged read are cancelled.
81+
82+
When the read preference mode is ``MONGOC_READ_NEAREST`` and the sharded cluster
83+
is running MongoDB 4.4 or later, hedged reads are enabled by default.
84+
Additionally, hedged reads may be explicitly enabled or disabled by calling
85+
:symbol:`mongoc_read_prefs_set_hedge` with a BSON document, e.g.
7686

7787
.. code-block:: none
7888

src/libmongoc/src/mongoc/mongoc-cmd.c

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

1717

18+
#include <mlib/config.h>
1819
#include <mongoc/mongoc-cmd-private.h>
1920
#include <mongoc/mongoc-read-prefs-private.h>
2021
#include <mongoc/mongoc-trace-private.h>
@@ -375,7 +376,10 @@ _mongoc_cmd_parts_assemble_mongos (mongoc_cmd_parts_t *parts, const mongoc_serve
375376
max_staleness_seconds = mongoc_read_prefs_get_max_staleness_seconds (parts->read_prefs);
376377

377378
tags = mongoc_read_prefs_get_tags (parts->read_prefs);
379+
mlib_diagnostic_push ();
380+
mlib_disable_deprecation_warnings ();
378381
hedge = mongoc_read_prefs_get_hedge (parts->read_prefs);
382+
mlib_diagnostic_pop ();
379383
}
380384

381385
if (server_stream->must_use_primary) {

src/libmongoc/src/mongoc/mongoc-read-prefs.c

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

1717

18+
#include <mlib/config.h>
1819
#include <mongoc/mongoc-error-private.h>
1920
#include <mongoc/mongoc-read-prefs-private.h>
2021
#include <mongoc/mongoc-trace-private.h>
@@ -234,7 +235,10 @@ _apply_read_preferences_mongos (const mongoc_read_prefs_t *read_prefs,
234235
max_staleness_seconds = mongoc_read_prefs_get_max_staleness_seconds (read_prefs);
235236

236237
tags = mongoc_read_prefs_get_tags (read_prefs);
238+
mlib_diagnostic_push ();
239+
mlib_disable_deprecation_warnings ();
237240
hedge = mongoc_read_prefs_get_hedge (read_prefs);
241+
mlib_diagnostic_pop ();
238242
}
239243

240244
/* Server Selection Spec says:
@@ -308,7 +312,11 @@ mongoc_read_prefs_append_contents_to_bson (const mongoc_read_prefs_t *read_prefs
308312
if (read_prefs) {
309313
// Other content is only available for non-NULL read_prefs
310314
int64_t max_staleness_seconds = mongoc_read_prefs_get_max_staleness_seconds (read_prefs);
315+
316+
mlib_diagnostic_push ();
317+
mlib_disable_deprecation_warnings ();
311318
const bson_t *hedge = mongoc_read_prefs_get_hedge (read_prefs);
319+
mlib_diagnostic_pop ();
312320
const bson_t *tags = mongoc_read_prefs_get_tags (read_prefs);
313321

314322
if ((flags & MONGOC_READ_PREFS_CONTENT_FLAG_TAGS) && !bson_empty (tags) &&

src/libmongoc/src/mongoc/mongoc-read-prefs.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,40 @@ typedef enum {
4949

5050
MONGOC_EXPORT (mongoc_read_prefs_t *)
5151
mongoc_read_prefs_new (mongoc_read_mode_t read_mode) BSON_GNUC_WARN_UNUSED_RESULT;
52+
5253
MONGOC_EXPORT (mongoc_read_prefs_t *)
5354
mongoc_read_prefs_copy (const mongoc_read_prefs_t *read_prefs) BSON_GNUC_WARN_UNUSED_RESULT;
55+
5456
MONGOC_EXPORT (void)
5557
mongoc_read_prefs_destroy (mongoc_read_prefs_t *read_prefs);
58+
5659
MONGOC_EXPORT (mongoc_read_mode_t)
5760
mongoc_read_prefs_get_mode (const mongoc_read_prefs_t *read_prefs);
61+
5862
MONGOC_EXPORT (void)
5963
mongoc_read_prefs_set_mode (mongoc_read_prefs_t *read_prefs, mongoc_read_mode_t mode);
64+
6065
MONGOC_EXPORT (const bson_t *)
6166
mongoc_read_prefs_get_tags (const mongoc_read_prefs_t *read_prefs);
67+
6268
MONGOC_EXPORT (void)
6369
mongoc_read_prefs_set_tags (mongoc_read_prefs_t *read_prefs, const bson_t *tags);
70+
6471
MONGOC_EXPORT (void)
6572
mongoc_read_prefs_add_tag (mongoc_read_prefs_t *read_prefs, const bson_t *tag);
73+
6674
MONGOC_EXPORT (int64_t)
6775
mongoc_read_prefs_get_max_staleness_seconds (const mongoc_read_prefs_t *read_prefs);
76+
6877
MONGOC_EXPORT (void)
6978
mongoc_read_prefs_set_max_staleness_seconds (mongoc_read_prefs_t *read_prefs, int64_t max_staleness_seconds);
70-
MONGOC_EXPORT (const bson_t *)
71-
mongoc_read_prefs_get_hedge (const mongoc_read_prefs_t *read_prefs);
72-
MONGOC_EXPORT (void)
73-
mongoc_read_prefs_set_hedge (mongoc_read_prefs_t *read_prefs, const bson_t *hedge);
79+
80+
BSON_DEPRECATED ("Hedged reads are deprecated in MongoDB 8.0 and will be removed in a future release")
81+
MONGOC_EXPORT (const bson_t *) mongoc_read_prefs_get_hedge (const mongoc_read_prefs_t *read_prefs);
82+
83+
BSON_DEPRECATED ("Hedged reads are deprecated in MongoDB 8.0 and will be removed in a future release")
84+
MONGOC_EXPORT (void) mongoc_read_prefs_set_hedge (mongoc_read_prefs_t *read_prefs, const bson_t *hedge);
85+
7486
MONGOC_EXPORT (bool)
7587
mongoc_read_prefs_is_valid (const mongoc_read_prefs_t *read_prefs);
7688

0 commit comments

Comments
 (0)