Skip to content

Commit 5ede743

Browse files
committed
back out bulkwrite changes
1 parent 9b6ea84 commit 5ede743

File tree

6 files changed

+46
-150
lines changed

6 files changed

+46
-150
lines changed

src/libmongoc/src/mongoc/mongoc-bulkwrite.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,15 @@ mongoc_bulkwrite_execute (mongoc_bulkwrite_t *self, const mongoc_bulkwriteopts_t
15611561
goto fail;
15621562
}
15631563

1564+
if (_mongoc_cse_is_enabled (self->client)) {
1565+
_mongoc_set_error (&error,
1566+
MONGOC_ERROR_COMMAND,
1567+
MONGOC_ERROR_COMMAND_INVALID_ARG,
1568+
"bulkWrite does not currently support automatic encryption");
1569+
_bulkwriteexception_set_error (ret.exc, &error);
1570+
goto fail;
1571+
}
1572+
15641573
const mongoc_ss_log_context_t ss_log_context = {
15651574
.operation = "bulkWrite", .has_operation_id = true, .operation_id = self->operation_id};
15661575

@@ -1686,11 +1695,8 @@ mongoc_bulkwrite_execute (mongoc_bulkwrite_t *self, const mongoc_bulkwriteopts_t
16861695
}
16871696
}
16881697

1689-
const int32_t maxWriteBatchSize = mongoc_server_stream_max_write_batch_size (ss);
1698+
int32_t maxWriteBatchSize = mongoc_server_stream_max_write_batch_size (ss);
16901699
int32_t maxMessageSizeBytes = mongoc_server_stream_max_msg_size (ss);
1691-
if (_mongoc_cse_is_enabled (self->client)) {
1692-
maxMessageSizeBytes = MONGOC_REDUCED_MAX_MSG_SIZE_FOR_FLE;
1693-
}
16941700
// `ops_doc_offset` is an offset into the `ops` document sequence. Counts the number of documents sent.
16951701
size_t ops_doc_offset = 0;
16961702
// `ops_byte_offset` is an offset into the `ops` document sequence. Counts the number of bytes sent.

src/libmongoc/src/mongoc/mongoc-crypt.c

+10-15
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ _state_machine_destroy (_state_machine_t *state_machine)
310310
bson_free (state_machine);
311311
}
312312

313-
/* State handler MONGOCRYPT_CTX_NEED_MONGO_COLLINFO{_WITH_DB} */
313+
/* State handler MONGOCRYPT_CTX_NEED_MONGO_COLLINFO */
314314
static bool
315-
_state_need_mongo_collinfo (_state_machine_t *state_machine, bool with_db, bson_error_t *error)
315+
_state_need_mongo_collinfo (_state_machine_t *state_machine, bson_error_t *error)
316316
{
317317
mongoc_database_t *db = NULL;
318318
mongoc_cursor_t *cursor = NULL;
@@ -336,13 +336,7 @@ _state_need_mongo_collinfo (_state_machine_t *state_machine, bool with_db, bson_
336336
}
337337

338338
bson_append_document (&opts, "filter", -1, &filter_bson);
339-
const char *db_name = with_db ? mongocrypt_ctx_mongo_db (state_machine->ctx) : state_machine->db_name;
340-
if (!db_name) {
341-
_ctx_check_error (state_machine->ctx, error, true);
342-
goto fail;
343-
}
344-
db = mongoc_client_get_database (state_machine->collinfo_client, db_name);
345-
339+
db = mongoc_client_get_database (state_machine->collinfo_client, state_machine->db_name);
346340
cursor = mongoc_database_find_collections_with_opts (db, &opts);
347341
if (mongoc_cursor_error (cursor, error)) {
348342
goto fail;
@@ -1084,7 +1078,7 @@ _state_machine_run (_state_machine_t *state_machine, bson_t *result, bson_error_
10841078
_ctx_check_error (state_machine->ctx, error, true);
10851079
goto fail;
10861080
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
1087-
if (!_state_need_mongo_collinfo (state_machine, false, error)) {
1081+
if (!_state_need_mongo_collinfo (state_machine, error)) {
10881082
goto fail;
10891083
}
10901084
break;
@@ -1118,9 +1112,12 @@ _state_machine_run (_state_machine_t *state_machine, bson_t *result, bson_error_
11181112
goto success;
11191113
break;
11201114
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB:
1121-
if (!_state_need_mongo_collinfo (state_machine, true, error)) {
1122-
goto fail;
1123-
}
1115+
_mongoc_set_error (error,
1116+
MONGOC_ERROR_CLIENT_SIDE_ENCRYPTION,
1117+
MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_STATE,
1118+
"MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB is "
1119+
"unimplemented");
1120+
goto fail;
11241121
break;
11251122
}
11261123
}
@@ -1403,8 +1400,6 @@ _mongoc_crypt_new (const bson_t *kms_providers,
14031400
crypt->kmsid_to_tlsopts = mcd_mapof_kmsid_to_tlsopts_new ();
14041401
crypt->handle = mongocrypt_new ();
14051402
mongocrypt_setopt_retry_kms (crypt->handle, true);
1406-
mongocrypt_setopt_use_need_mongo_collinfo_with_db_state (crypt->handle);
1407-
14081403
if (!mongocrypt_setopt_enable_multiple_collinfo (crypt->handle)) {
14091404
_crypt_check_error (crypt->handle, error, true);
14101405
goto fail;

src/libmongoc/tests/client_side_encryption_prose/limits-encryptedFields.json

-14
This file was deleted.

src/libmongoc/tests/client_side_encryption_prose/limits-qe-doc.json

-3
This file was deleted.

src/libmongoc/tests/test-mongoc-client-side-encryption.c

+18-114
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "TestSuite.h"
18-
#include "bson/bson.h"
1917
#include "json-test.h"
20-
#include <mongoc/mongoc.h>
21-
2218
#include "test-libmongoc.h"
2319

2420
#include <common-bson-dsl-private.h>
@@ -344,15 +340,14 @@ _command_started (const mongoc_apm_command_started_t *event)
344340
limits_apm_ctx_t *ctx;
345341

346342
ctx = (limits_apm_ctx_t *) mongoc_apm_command_started_get_context (event);
347-
const char *cmd_name = mongoc_apm_command_started_get_command_name (event);
348-
if (0 == strcmp ("insert", cmd_name) || 0 == strcmp ("bulkWrite", cmd_name)) {
343+
if (0 == strcmp ("insert", mongoc_apm_command_started_get_command_name (event))) {
349344
ctx->num_inserts++;
350345
}
351346
}
352347

353348
/* Prose Test 4: BSON Size Limits and Batch Splitting */
354349
static void
355-
test_bson_size_limits_and_batch_splitting (bool with_qe)
350+
test_bson_size_limits_and_batch_splitting (void *unused)
356351
{
357352
/* Expect an insert of two documents over 2MiB to split into two inserts but
358353
* still succeed. */
@@ -375,6 +370,8 @@ test_bson_size_limits_and_batch_splitting (bool with_qe)
375370
const int exceeds_2mib_after_encryption = size_2mib - 2000;
376371
const int exceeds_16mib_after_encryption = size_16mib - 2000;
377372

373+
BSON_UNUSED (unused);
374+
378375
/* Do the test setup. */
379376

380377
/* Drop and create db.coll configured with limits-schema.json */
@@ -426,7 +423,6 @@ test_bson_size_limits_and_batch_splitting (bool with_qe)
426423
coll = mongoc_client_get_collection (client, "db", "coll");
427424
/* End of setup */
428425

429-
/* Case 1 */
430426
/* Insert { "_id": "over_2mib_under_16mib", "unencrypted": <the string "a"
431427
* repeated 2097152 times> } */
432428
docs[0] = BCON_NEW ("_id", "over_2mib_under_16mib");
@@ -445,23 +441,6 @@ test_bson_size_limits_and_batch_splitting (bool with_qe)
445441
ASSERT_OR_PRINT (mongoc_collection_insert_one (coll, docs[0], NULL /* opts */, NULL /* reply */, &error), error);
446442
bson_destroy (docs[0]);
447443

448-
/* Check that inserting close to, but not exceeding, 16MiB, passes */
449-
docs[0] = bson_new ();
450-
bson_append_utf8 (docs[0], "_id", -1, "under_16mib", -1);
451-
bson_append_utf8 (docs[0], "unencrypted", -1, as, exceeds_16mib_after_encryption);
452-
ASSERT_OR_PRINT (mongoc_collection_insert_one (coll, docs[0], NULL /* opts */, NULL /* reply */, &error), error);
453-
bson_destroy (docs[0]);
454-
455-
/* but.. exceeding 16 MiB fails */
456-
docs[0] = get_bson_from_json_file ("./src/libmongoc/tests/client_side_encryption_prose/limits-doc.json");
457-
bson_append_utf8 (docs[0], "_id", -1, "under_16mib", -1);
458-
bson_append_utf8 (docs[0], "unencrypted", -1, as, exceeds_16mib_after_encryption);
459-
BSON_ASSERT (!mongoc_collection_insert_one (coll, docs[0], NULL /* opts */, NULL /* reply */, &error));
460-
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 2, "too large");
461-
bson_destroy (docs[0]);
462-
463-
/* Case 2: collection bulkWrite */
464-
465444
/* Insert two documents that each exceed 2MiB but no encryption occurs.
466445
* Expect the bulk write to succeed and run as two separate inserts.
467446
*/
@@ -495,73 +474,20 @@ test_bson_size_limits_and_batch_splitting (bool with_qe)
495474
bson_destroy (docs[0]);
496475
bson_destroy (docs[1]);
497476

498-
if (with_qe) {
499-
/* Case 3: client bulkWrite */
500-
mongoc_bulkwriteopts_t *bw_opts = mongoc_bulkwriteopts_new ();
501-
mongoc_bulkwriteopts_set_verboseresults (bw_opts, true);
477+
/* Check that inserting close to, but not exceeding, 16MiB, passes */
478+
docs[0] = bson_new ();
479+
bson_append_utf8 (docs[0], "_id", -1, "under_16mib", -1);
480+
bson_append_utf8 (docs[0], "unencrypted", -1, as, exceeds_16mib_after_encryption);
481+
ASSERT_OR_PRINT (mongoc_collection_insert_one (coll, docs[0], NULL /* opts */, NULL /* reply */, &error), error);
482+
bson_destroy (docs[0]);
502483

503-
bson_t *corpus_encryptedFields =
504-
get_bson_from_json_file ("./src/libmongoc/tests/client_side_encryption_prose/limits-encryptedFields.json");
505-
bson_t *coll_opts = BCON_NEW ("encryptedFields", BCON_DOCUMENT (corpus_encryptedFields));
506-
mongoc_database_t *db = mongoc_client_get_database (client, "db");
507-
(void) mongoc_collection_drop (coll, NULL);
508-
// Create a newly named collection to avoid cached previous JSON Schema.
509-
mongoc_collection_t *coll2 = mongoc_database_create_collection (db, "coll2", coll_opts, &error);
510-
ASSERT_OR_PRINT (coll2, error);
511-
mongoc_collection_destroy(coll2);
512-
513-
/* Insert two documents that each exceed 2MiB but no encryption occurs.
514-
* Expect two separate bulkWrite commands.
515-
*/
516-
docs[0] = BCON_NEW ("_id", "over_2mib_3");
517-
bson_append_utf8 (docs[0], "unencrypted", -1, as, size_2mib - 1500);
518-
docs[1] = BCON_NEW ("_id", "over_2mib_4");
519-
bson_append_utf8 (docs[1], "unencrypted", -1, as, size_2mib - 1500);
520-
521-
ctx.num_inserts = 0;
522-
mongoc_bulkwrite_t *bw = mongoc_client_bulkwrite_new (client);
523-
ASSERT_OR_PRINT (mongoc_bulkwrite_append_insertone (bw, "db.coll2", docs[0], NULL, &error), error);
524-
ASSERT_OR_PRINT (mongoc_bulkwrite_append_insertone (bw, "db.coll2", docs[1], NULL, &error), error);
525-
526-
mongoc_bulkwritereturn_t bwr = mongoc_bulkwrite_execute (bw, bw_opts);
527-
ASSERT_NO_BULKWRITEEXCEPTION (bwr);
528-
ASSERT_CMPINT (ctx.num_inserts, ==, 2);
529-
bson_destroy (docs[0]);
530-
bson_destroy (docs[1]);
531-
mongoc_bulkwrite_destroy (bw);
532-
mongoc_bulkwriteresult_destroy (bwr.res);
533-
mongoc_bulkwriteexception_destroy (bwr.exc);
534-
535-
/* Insert two documents that each exceed 2MiB after encryption occurs. Expect
536-
* the bulk write to succeed and run as two separate inserts.
537-
*/
538-
539-
540-
docs[0] = get_bson_from_json_file ("./src/libmongoc/tests/client_side_encryption_prose/limits-qe-doc.json");
541-
bson_append_utf8 (docs[0], "_id", -1, "encryption_exceeds_2mib_3", -1);
542-
bson_append_utf8 (docs[0], "foo", -1, as, exceeds_2mib_after_encryption - 1500);
543-
docs[1] = get_bson_from_json_file ("./src/libmongoc/tests/client_side_encryption_prose/limits-qe-doc.json");
544-
bson_append_utf8 (docs[1], "_id", -1, "encryption_exceeds_2mib_4", -1);
545-
bson_append_utf8 (docs[1], "foo", -1, as, exceeds_2mib_after_encryption - 1500);
546-
547-
ctx.num_inserts = 0;
548-
bw = mongoc_client_bulkwrite_new (client);
549-
ASSERT_OR_PRINT (mongoc_bulkwrite_append_insertone (bw, "db.coll2", docs[0], NULL, &error), error);
550-
ASSERT_OR_PRINT (mongoc_bulkwrite_append_insertone (bw, "db.coll2", docs[1], NULL, &error), error);
551-
552-
bwr = mongoc_bulkwrite_execute (bw, bw_opts);
553-
ASSERT_NO_BULKWRITEEXCEPTION (bwr);
554-
ASSERT_CMPINT (ctx.num_inserts, ==, 2);
555-
bson_destroy (docs[0]);
556-
bson_destroy (docs[1]);
557-
mongoc_bulkwrite_destroy (bw);
558-
mongoc_bulkwriteresult_destroy (bwr.res);
559-
mongoc_bulkwriteexception_destroy (bwr.exc);
560-
mongoc_bulkwriteopts_destroy (bw_opts);
561-
bson_destroy (corpus_encryptedFields);
562-
bson_destroy (coll_opts);
563-
mongoc_database_destroy (db);
564-
}
484+
/* but.. exceeding 16 MiB fails */
485+
docs[0] = get_bson_from_json_file ("./src/libmongoc/tests/client_side_encryption_prose/limits-doc.json");
486+
bson_append_utf8 (docs[0], "_id", -1, "under_16mib", -1);
487+
bson_append_utf8 (docs[0], "unencrypted", -1, as, exceeds_16mib_after_encryption);
488+
BSON_ASSERT (!mongoc_collection_insert_one (coll, docs[0], NULL /* opts */, NULL /* reply */, &error));
489+
ASSERT_ERROR_CONTAINS (error, MONGOC_ERROR_SERVER, 2, "too large");
490+
bson_destroy (docs[0]);
565491

566492
bson_free (as);
567493
bson_destroy (kms_providers);
@@ -575,20 +501,6 @@ test_bson_size_limits_and_batch_splitting (bool with_qe)
575501
mongoc_auto_encryption_opts_destroy (opts);
576502
}
577503

578-
static void
579-
test_bson_size_limits_and_batch_splitting_no_qe (void *unused)
580-
{
581-
BSON_UNUSED (unused);
582-
test_bson_size_limits_and_batch_splitting (false);
583-
}
584-
585-
static void
586-
test_bson_size_limits_and_batch_splitting_qe (void *unused)
587-
{
588-
BSON_UNUSED (unused);
589-
test_bson_size_limits_and_batch_splitting (true);
590-
}
591-
592504
typedef struct {
593505
bson_t *last_cmd;
594506
} _datakey_and_double_encryption_ctx_t;
@@ -6995,19 +6907,11 @@ test_client_side_encryption_install (TestSuite *suite)
69956907
test_framework_skip_if_no_auth /* requires auth for error check */);
69966908
TestSuite_AddFull (suite,
69976909
"/client_side_encryption/bson_size_limits_and_batch_splitting",
6998-
test_bson_size_limits_and_batch_splitting_no_qe,
6910+
test_bson_size_limits_and_batch_splitting,
69996911
NULL,
70006912
NULL,
70016913
test_framework_skip_if_no_client_side_encryption,
70026914
test_framework_skip_if_max_wire_version_less_than_8);
7003-
TestSuite_AddFull (suite,
7004-
"/client_side_encryption/bson_size_limits_and_batch_splitting_qe",
7005-
test_bson_size_limits_and_batch_splitting_qe,
7006-
NULL,
7007-
NULL,
7008-
test_framework_skip_if_no_client_side_encryption,
7009-
test_framework_skip_if_max_wire_version_less_than_25,
7010-
test_framework_skip_if_single);
70116915
TestSuite_AddFull (suite,
70126916
"/client_side_encryption/views_are_prohibited",
70136917
test_views_are_prohibited,

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

+8
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,14 @@ test_crud_install (TestSuite *suite)
15191519
test_framework_skip_if_max_wire_version_less_than_25 // require server 8.0
15201520
);
15211521

1522+
TestSuite_AddFull (suite,
1523+
"/crud/prose_test_13",
1524+
prose_test_13,
1525+
NULL /* dtor */,
1526+
NULL /* ctx */,
1527+
test_framework_skip_if_max_wire_version_less_than_25, // require server 8.0
1528+
test_framework_skip_if_no_client_side_encryption);
1529+
15221530
TestSuite_AddFull (suite,
15231531
"/crud/prose_test_15",
15241532
prose_test_15,

0 commit comments

Comments
 (0)