Skip to content

Commit b266c16

Browse files
authored
CDRIVER-629 remove MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED (#1940)
1 parent ab59ef0 commit b266c16

9 files changed

+14
-44
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Unreleased (2.0.0)
4646
* The associated Windows-only option `CYRUS_PLUGIN_PATH_PREFIX` is removed.
4747
* Support for the deprecated `minPoolSize` URI option is removed along with associated API: `MONGOC_URI_MINPOOLSIZE` and `mongoc_client_pool_min_size`.
4848
* Support for LibreSSL (the CMake option `ENABLE_SSL=LIBRESSL`) is removed. Associated API is removed (`MONGOC_ENABLE_SSL_LIBRESSL` and `mongoc_stream_tls_libressl_new`).
49+
* `MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED` (value -1) is removed. Use `MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED` (value 0) which is handled equivalently. If specified in a URI, replace: `mongodb://host/?w=-1` with `mongodb://host/?w=0`.
4950
* The deprecated CMake option `ENABLE_AUTOMATIC_INIT_AND_CLEANUP` is removed. See [Initialization and cleanup](https://mongoc.org/libmongoc/1.30.2/init-cleanup.html) for expected use of `mongoc_init()` and `mongoc_cleanup()`.
5051

5152
### Forwarding headers (`#include <bson.h>` and `#include <mongoc.h>`)

src/libmongoc/doc/mongoc_write_concern_get_w.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Fetches the ``w`` parameter of the write concern.
2424
Returns
2525
-------
2626

27-
Returns an integer containing the w value. If wmajority is set, this would be MONGOC_WRITE_CONCERN_W_MAJORITY.
27+
Returns an integer containing the ``w`` value. If wmajority is set, this would be ``MONGOC_WRITE_CONCERN_W_MAJORITY``.
2828

src/libmongoc/doc/mongoc_write_concern_set_w.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Parameters
1515
----------
1616

1717
* ``write_concern``: A :symbol:`mongoc_write_concern_t`.
18-
* ``w``: A positive ``int32_t`` or zero.
18+
* ``w``: Use ``MONGOC_WRITE_CONCERN_W_DEFAULT``, ``MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED``, ``MONGOC_WRITE_CONCERN_W_MAJORITY``, or a positive integer.
1919

2020
Description
2121
-----------
2222

2323
Sets the ``w`` value for the write concern. See :symbol:`mongoc_write_concern_t` for more information on this setting.
2424

25-
Unacknowledged writes are not causally consistent. If you execute a write operation with a :symbol:`mongoc_write_concern_t` on which you have called :symbol:`mongoc_write_concern_set_w` with a value of 0, the write does not participate in causal consistency, even when executed with a :symbol:`mongoc_client_session_t`.
25+
Unacknowledged writes are not causally consistent. If you execute a write operation with a :symbol:`mongoc_write_concern_t` on which you have called :symbol:`mongoc_write_concern_set_w` with a value of ``MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED``, the write does not participate in causal consistency, even when executed with a :symbol:`mongoc_client_session_t`.
2626

2727
Beginning in version 1.9.0, this function can now alter the write concern after
2828
it has been used in an operation. Previously, using the struct with an operation

src/libmongoc/doc/mongoc_write_concern_t.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ n Block until a write has been propaga
3737
Deprecations
3838
------------
3939

40-
The write concern ``MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED`` (value -1) is a deprecated synonym for ``MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED`` (value 0), and will be removed in the next major release.
41-
4240
:symbol:`mongoc_write_concern_set_fsync` is deprecated.
4341

4442
.. only:: html

src/libmongoc/src/mongoc/mongoc-uri.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,8 +2135,7 @@ _mongoc_uri_build_write_concern (mongoc_uri_t *uri, bson_error_t *error)
21352135
storeStrRef (w_str),
21362136
case (
21372137
// Special W options:
2138-
when (anyOf (eq (int32, MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED),
2139-
eq (int32, MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED)),
2138+
when (eq (int32, MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED),
21402139
// These conflict with journalling:
21412140
if (eval (mongoc_write_concern_get_journal (write_concern)),
21422141
then (error ("Journal conflicts with w value"))),

src/libmongoc/src/mongoc/mongoc-write-concern.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,8 @@ bool
374374
mongoc_write_concern_is_acknowledged (const mongoc_write_concern_t *write_concern)
375375
{
376376
if (write_concern) {
377-
return (((write_concern->w != MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED) &&
378-
(write_concern->w != MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED)) ||
379-
write_concern->fsync_ == true || mongoc_write_concern_get_journal (write_concern));
377+
return (((write_concern->w != MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED)) || write_concern->fsync_ == true ||
378+
mongoc_write_concern_get_journal (write_concern));
380379
}
381380
return true;
382381
}
@@ -400,8 +399,7 @@ mongoc_write_concern_is_valid (const mongoc_write_concern_t *write_concern)
400399

401400
/* Journal or fsync should require acknowledgement. */
402401
if ((write_concern->fsync_ == true || mongoc_write_concern_get_journal (write_concern)) &&
403-
(write_concern->w == MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED ||
404-
write_concern->w == MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED)) {
402+
(write_concern->w == MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED)) {
405403
return false;
406404
}
407405

@@ -511,7 +509,7 @@ _mongoc_write_concern_new_from_iter (const bson_iter_t *iter, bson_error_t *erro
511509
if (BSON_ITER_IS_KEY (&inner, "w")) {
512510
if (BSON_ITER_HOLDS_INT32 (&inner)) {
513511
w = bson_iter_int32 (&inner);
514-
if (w < MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED) {
512+
if (w < MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED) {
515513
goto fail;
516514
}
517515

src/libmongoc/src/mongoc/mongoc-write-concern.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ BSON_BEGIN_DECLS
2727

2828

2929
#define MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED 0
30-
#define MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED -1 /* deprecated */
3130
#define MONGOC_WRITE_CONCERN_W_DEFAULT -2
3231
#define MONGOC_WRITE_CONCERN_W_MAJORITY -3
3332
#define MONGOC_WRITE_CONCERN_W_TAG -4

src/libmongoc/tests/test-mongoc-uri.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,11 +1544,6 @@ test_mongoc_uri_new_with_error (void)
15441544
ASSERT_ERROR_CONTAINS (
15451545
error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, "Journal conflicts with w value [w=0]");
15461546

1547-
error = BSON_ERROR_INIT;
1548-
ASSERT (!mongoc_uri_new_with_error ("mongodb://localhost/db?journal=true&w=-1", &error));
1549-
ASSERT_ERROR_CONTAINS (
1550-
error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, "Journal conflicts with w value [w=-1]");
1551-
15521547
error = BSON_ERROR_INIT;
15531548
ASSERT (!mongoc_uri_new_with_error ("mongodb://localhost/db?w=-5", &error));
15541549
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_COMMAND, MONGOC_ERROR_COMMAND_INVALID_ARG, "Unsupported w value [w=-5]");
@@ -2085,8 +2080,8 @@ test_mongoc_uri_write_concern (void)
20852080
},
20862081
{
20872082
.uri = "mongodb://localhost/?" MONGOC_URI_W "=-1",
2088-
.parses = true,
2089-
.w = MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED,
2083+
.parses = false,
2084+
.log_msg = "Unsupported w value [w=-1]",
20902085
},
20912086
{
20922087
.uri = "mongodb://localhost/?" MONGOC_URI_W "=0",
@@ -2176,12 +2171,6 @@ test_mongoc_uri_write_concern (void)
21762171
.w = MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED,
21772172
.log_msg = "Journal conflicts with w value [" MONGOC_URI_W "=0]",
21782173
},
2179-
{
2180-
.uri = "mongodb://localhost/?" MONGOC_URI_W "=-1&" MONGOC_URI_JOURNAL "=true",
2181-
.parses = false,
2182-
.w = MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED,
2183-
.log_msg = "Journal conflicts with w value [" MONGOC_URI_W "=-1]",
2184-
},
21852174
{0}};
21862175

21872176
for (int i = 0; tests[i].uri; i++) {

src/libmongoc/tests/test-mongoc-write-concern.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,9 @@ test_write_concern_fsync_and_journal_w1_and_validity (void)
196196
ASSERT (mongoc_write_concern_journal_is_set (write_concern));
197197
mongoc_write_concern_set_journal (write_concern, false);
198198

199-
/* w=-1 does not need GLE and is valid */
200-
mongoc_write_concern_set_w (write_concern, MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED);
201-
ASSERT (!mongoc_write_concern_is_acknowledged (write_concern));
199+
/* w=-1 is considered valid (server is expected to error) */
200+
mongoc_write_concern_set_w (write_concern, -1);
202201
ASSERT (mongoc_write_concern_is_valid (write_concern));
203-
ASSERT (mongoc_write_concern_journal_is_set (write_concern));
204-
205-
/* fsync=true needs GLE, but it conflicts with w=-1 */
206-
mongoc_write_concern_set_fsync (write_concern, true);
207-
ASSERT (mongoc_write_concern_is_acknowledged (write_concern));
208-
ASSERT (!mongoc_write_concern_is_valid (write_concern));
209-
ASSERT (mongoc_write_concern_journal_is_set (write_concern));
210-
211-
/* journal=true needs GLE, but it conflicts with w=-1 */
212-
mongoc_write_concern_set_fsync (write_concern, false);
213-
mongoc_write_concern_set_journal (write_concern, true);
214-
ASSERT (mongoc_write_concern_is_acknowledged (write_concern));
215-
ASSERT (mongoc_write_concern_journal_is_set (write_concern));
216202

217203
/* fsync=true with w=default needs GLE and is valid */
218204
mongoc_write_concern_set_journal (write_concern, false);
@@ -311,7 +297,7 @@ test_write_concern_from_iterator (void)
311297
_test_write_concern_from_iterator ("{'writeConcern': {'w': 1}}", true, false);
312298
_test_write_concern_from_iterator ("{'writeConcern': {'j': true}}", true, false);
313299
_test_write_concern_from_iterator ("{'writeConcern': {'j': false}}", true, false);
314-
_test_write_concern_from_iterator ("{'writeConcern': {'w': -1}}", true, false);
300+
_test_write_concern_from_iterator ("{'writeConcern': {'w': -1}}", false, false);
315301
_test_write_concern_from_iterator ("{'writeConcern': {'w': -2}}", false, false);
316302
_test_write_concern_from_iterator ("{'writeConcern': {'w': -3}}", false, false);
317303
_test_write_concern_from_iterator ("{'writeConcern': {'w': -4}}", false, false);

0 commit comments

Comments
 (0)