Skip to content

Commit 402189f

Browse files
rcsanchez97kevinAlbs
authored andcommitted
CDRIVER-3612 do not accept explicit session for collection count
1 parent 25b8729 commit 402189f

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

src/libmongoc/src/mongoc/mongoc-collection.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,14 @@ mongoc_collection_estimated_document_count (
810810

811811
BSON_ASSERT_PARAM (coll);
812812

813+
if (opts && bson_has_field (opts, "sessionId")) {
814+
bson_set_error (error,
815+
MONGOC_ERROR_COMMAND,
816+
MONGOC_ERROR_COMMAND_INVALID_ARG,
817+
"Collection count must not specify explicit session");
818+
GOTO (done);
819+
}
820+
813821
reply_ptr = reply ? reply : &reply_local;
814822
bson_append_utf8 (&cmd, "count", 5, coll->collection, coll->collectionlen);
815823

@@ -832,6 +840,7 @@ mongoc_collection_estimated_document_count (
832840
}
833841
}
834842

843+
done:
835844
if (!reply) {
836845
bson_destroy (&reply_local);
837846
}

src/libmongoc/tests/test-mongoc-client-session.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,15 @@ run_session_test_bulk_operation (void *ctx)
16261626
}
16271627

16281628

1629+
static void
1630+
run_count_test (session_test_fn_t test_fn)
1631+
{
1632+
/* CDRIVER-3612: mongoc_collection_estimated_document_count does not support
1633+
* explicit sessions */
1634+
_test_implicit_session_lsid (test_fn);
1635+
}
1636+
1637+
16291638
static void
16301639
insert_10_docs (session_test_t *test)
16311640
{
@@ -2846,7 +2855,13 @@ test_session_install (TestSuite *suite)
28462855
add_session_test (
28472856
suite, "/Session/read_write_cmd", test_read_write_cmd, true);
28482857
add_session_test (suite, "/Session/db_cmd", test_db_cmd, false);
2849-
add_session_test (suite, "/Session/count", test_count, true);
2858+
TestSuite_AddFull (suite,
2859+
"/Session/count",
2860+
(void *) run_count_test,
2861+
NULL,
2862+
(void *) test_count,
2863+
test_framework_skip_if_no_cluster_time,
2864+
test_framework_skip_if_no_crypto);
28502865
add_session_test (suite, "/Session/cursor", test_cursor, true);
28512866
add_session_test (suite, "/Session/drop", test_drop, false);
28522867
add_session_test (suite, "/Session/drop_index", test_drop_index, false);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,6 +2621,18 @@ test_estimated_document_count (void)
26212621
ASSERT_OR_PRINT (123 == future_get_int64_t (future), error);
26222622
ASSERT_MATCH (&reply, server_reply);
26232623

2624+
future_destroy (future);
2625+
2626+
/* CDRIVER-3612: ensure that an explicit session triggers a client error */
2627+
future = future_collection_estimated_document_count (
2628+
collection, tmp_bson ("{'sessionId': 123}"), NULL, &reply, &error);
2629+
2630+
ASSERT (-1 == future_get_int64_t (future));
2631+
ASSERT_ERROR_CONTAINS (error,
2632+
MONGOC_ERROR_COMMAND,
2633+
MONGOC_ERROR_COMMAND_INVALID_ARG,
2634+
"Collection count must not specify explicit session");
2635+
26242636
bson_destroy (&reply);
26252637
request_destroy (request);
26262638
future_destroy (future);

src/libmongoc/tests/test-mongoc-retryable-reads.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,19 @@ retryable_reads_test_run_operation (json_test_ctx_t *ctx,
1616
{
1717
bool *explicit_session = (bool *) ctx->config->ctx;
1818
bson_t reply;
19+
bson_iter_t iter;
20+
const char *op_name;
21+
uint32_t op_len;
1922
bool res;
2023

24+
bson_iter_init_find (&iter, operation, "name");
25+
op_name = bson_iter_utf8 (&iter, &op_len);
26+
if (strcmp (op_name, "estimatedDocumentCount") == 0 ||
27+
strcmp (op_name, "count") == 0) {
28+
/* CDRIVER-3612: mongoc_collection_estimated_document_count does not
29+
* support explicit sessions */
30+
*explicit_session = false;
31+
}
2132
res = json_test_operation (ctx,
2233
test,
2334
operation,

0 commit comments

Comments
 (0)