Skip to content

Commit c4c2761

Browse files
CXX-3241 deprecated hedged reads (#1387)
--------- Co-authored-by: Ezra Chung <[email protected]>
1 parent e45a609 commit c4c2761

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Changes prior to 3.9.0 are documented as [release notes on GitHub](https://githu
2222
- Support for MacOS 11 (EOL since Nov 2020) and MacOS 12 (EOL since Oct 2021).
2323
- `storage_options()` in `mongocxx::v_noabi::options::index`: use `storage_engine()` instead.
2424
- `base_storage_options` and `wiredtiger_storage_options` in `mongocxx::v_noabi::options::index` are also deprecated.
25+
- `hedge()` in `mongocxx::v_noabi::read_preference`: hedged reads will no longer be supported by MongoDB.
2526

2627
### Changed
2728

src/mongocxx/include/mongocxx/v_noabi/mongocxx/read_preference.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,23 @@ class read_preference {
274274
/// @param hedge
275275
/// The hedge document to set. For example, the document { enabled: true }.
276276
///
277+
/// @deprecated Hedged reads are deprecated in MongoDB Server version 8.0.
278+
///
277279
/// @return A reference to the object on which this member function is being called. This
278280
/// facilitates method chaining.
279281
///
280-
MONGOCXX_ABI_EXPORT_CDECL(read_preference&)
281-
hedge(bsoncxx::v_noabi::document::view_or_value hedge);
282+
MONGOCXX_DEPRECATED MONGOCXX_ABI_EXPORT_CDECL(read_preference&) hedge(
283+
bsoncxx::v_noabi::document::view_or_value hedge);
282284

283285
///
284286
/// Gets the current hedge document to be used for the read preference.
285287
///
288+
/// @deprecated Hedged reads are deprecated in MongoDB Server version 8.0.
289+
///
286290
/// @return A hedge document if one was set.
287291
///
288-
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view> const)
292+
MONGOCXX_DEPRECATED MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::optional<
293+
bsoncxx::v_noabi::document::view> const)
289294
hedge() const;
290295

291296
///

src/mongocxx/test/read_preference.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ TEST_CASE("Read preference methods call underlying mongoc methods", "[read_prefe
199199

200200
SECTION("hedge() calls mongoc_read_prefs_set_hedge") {
201201
/* No hedge should return a disengaged optional. */
202+
BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_BEGIN
202203
REQUIRE(!rp.hedge());
204+
BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_END
203205

204206
read_prefs_set_hedge->visit([&](mongoc_read_prefs_t*, bson_t const* doc) {
205207
bson_iter_t iter;
@@ -209,8 +211,10 @@ TEST_CASE("Read preference methods call underlying mongoc methods", "[read_prefe
209211
called = true;
210212
});
211213

214+
BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_BEGIN
212215
rp.hedge(make_document(kvp("hedge", true)));
213216
REQUIRE((*rp.hedge())["hedge"].get_bool().value == true);
217+
BSONCXX_SUPPRESS_DEPRECATION_WARNINGS_END
214218
REQUIRE(called);
215219
}
216220
}

0 commit comments

Comments
 (0)