Skip to content

Commit 340b1f4

Browse files
authored
CDRIVER-5780 Support QE with Client.bulkWrite (#2043)
1 parent 9ad30a4 commit 340b1f4

File tree

7 files changed

+442
-86
lines changed

7 files changed

+442
-86
lines changed

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,15 +1569,6 @@ mongoc_bulkwrite_execute(mongoc_bulkwrite_t *self, const mongoc_bulkwriteopts_t
15691569
goto fail;
15701570
}
15711571

1572-
if (_mongoc_cse_is_enabled(self->client)) {
1573-
_mongoc_set_error(&error,
1574-
MONGOC_ERROR_COMMAND,
1575-
MONGOC_ERROR_COMMAND_INVALID_ARG,
1576-
"bulkWrite does not currently support automatic encryption");
1577-
_bulkwriteexception_set_error(ret.exc, &error);
1578-
goto fail;
1579-
}
1580-
15811572
const mongoc_ss_log_context_t ss_log_context = {
15821573
.operation = "bulkWrite", .has_operation_id = true, .operation_id = self->operation_id};
15831574

@@ -1703,8 +1694,11 @@ mongoc_bulkwrite_execute(mongoc_bulkwrite_t *self, const mongoc_bulkwriteopts_t
17031694
}
17041695
}
17051696

1706-
int32_t maxWriteBatchSize = mongoc_server_stream_max_write_batch_size(ss);
1697+
const int32_t maxWriteBatchSize = mongoc_server_stream_max_write_batch_size(ss);
17071698
int32_t maxMessageSizeBytes = mongoc_server_stream_max_msg_size(ss);
1699+
if (_mongoc_cse_is_enabled(self->client)) {
1700+
maxMessageSizeBytes = MONGOC_REDUCED_MAX_MSG_SIZE_FOR_FLE;
1701+
}
17081702
// `ops_doc_offset` is an offset into the `ops` document sequence. Counts the number of documents sent.
17091703
size_t ops_doc_offset = 0;
17101704
// `ops_byte_offset` is an offset into the `ops` document sequence. Counts the number of bytes sent.

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ _state_machine_destroy(_state_machine_t *state_machine)
319319
bson_free(state_machine);
320320
}
321321

322-
/* State handler MONGOCRYPT_CTX_NEED_MONGO_COLLINFO */
322+
/* State handler MONGOCRYPT_CTX_NEED_MONGO_COLLINFO{_WITH_DB} */
323323
static bool
324-
_state_need_mongo_collinfo(_state_machine_t *state_machine, bson_error_t *error)
324+
_state_need_mongo_collinfo(_state_machine_t *state_machine, const char *db_name, bson_error_t *error)
325325
{
326326
mongoc_database_t *db = NULL;
327327
mongoc_cursor_t *cursor = NULL;
@@ -345,7 +345,12 @@ _state_need_mongo_collinfo(_state_machine_t *state_machine, bson_error_t *error)
345345
}
346346

347347
bson_append_document(&opts, "filter", -1, &filter_bson);
348-
db = mongoc_client_get_database(state_machine->collinfo_client, state_machine->db_name);
348+
if (!db_name) {
349+
_ctx_check_error(state_machine->ctx, error, true);
350+
goto fail;
351+
}
352+
db = mongoc_client_get_database(state_machine->collinfo_client, db_name);
353+
349354
cursor = mongoc_database_find_collections_with_opts(db, &opts);
350355
if (mongoc_cursor_error(cursor, error)) {
351356
goto fail;
@@ -1085,7 +1090,7 @@ _state_machine_run(_state_machine_t *state_machine, bson_t *result, bson_error_t
10851090
_ctx_check_error(state_machine->ctx, error, true);
10861091
goto fail;
10871092
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO:
1088-
if (!_state_need_mongo_collinfo(state_machine, error)) {
1093+
if (!_state_need_mongo_collinfo(state_machine, state_machine->db_name, error)) {
10891094
goto fail;
10901095
}
10911096
break;
@@ -1118,14 +1123,16 @@ _state_machine_run(_state_machine_t *state_machine, bson_t *result, bson_error_t
11181123
case MONGOCRYPT_CTX_DONE:
11191124
goto success;
11201125
break;
1121-
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB:
1122-
_mongoc_set_error(error,
1123-
MONGOC_ERROR_CLIENT_SIDE_ENCRYPTION,
1124-
MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_STATE,
1125-
"MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB is "
1126-
"unimplemented");
1127-
goto fail;
1128-
break;
1126+
case MONGOCRYPT_CTX_NEED_MONGO_COLLINFO_WITH_DB: {
1127+
const char *db_name = mongocrypt_ctx_mongo_db(state_machine->ctx);
1128+
if (!db_name) {
1129+
_ctx_check_error(state_machine->ctx, error, true);
1130+
goto fail;
1131+
}
1132+
if (!_state_need_mongo_collinfo(state_machine, db_name, error)) {
1133+
goto fail;
1134+
}
1135+
} break;
11291136
}
11301137
}
11311138

@@ -1407,6 +1414,8 @@ _mongoc_crypt_new(const bson_t *kms_providers,
14071414
crypt->kmsid_to_tlsopts = mcd_mapof_kmsid_to_tlsopts_new();
14081415
crypt->handle = mongocrypt_new();
14091416
mongocrypt_setopt_retry_kms(crypt->handle, true);
1417+
mongocrypt_setopt_use_need_mongo_collinfo_with_db_state(crypt->handle);
1418+
14101419
if (!mongocrypt_setopt_enable_multiple_collinfo(crypt->handle)) {
14111420
_crypt_check_error(crypt->handle, error, true);
14121421
goto fail;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "LOCALAAAAAAAAAAAAAAAAA==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "foo",
11+
"bsonType": "string"
12+
}
13+
]
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"foo": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
3+
}

0 commit comments

Comments
 (0)