Skip to content

Commit ae91cf1

Browse files
CDRIVER-5636 make trimFactor and sparsity optional (#1677)
* add spec test * add prose test * distinguish between 0 and unset for `sparsity` and `trimFactor` * update version libmongocrypt * update docs --------- Co-authored-by: Ezra Chung <[email protected]>
1 parent 75ec9c3 commit ae91cf1

File tree

6 files changed

+544
-14
lines changed

6 files changed

+544
-14
lines changed

.evergreen/scripts/compile-libmongocrypt.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ compile_libmongocrypt() {
1010
# `.evergreen/scripts/kms-divergence-check.sh` to ensure that there is no
1111
# divergence in the copied files.
1212

13-
# TODO: once 1.10.2 is released (containing MONGOCRYPT-706) replace the following with:
14-
# git clone -q --depth=1 https://github.com/mongodb/libmongocrypt --branch 1.10.2 || return
13+
# TODO: once 1.11.0 is released (containing MONGOCRYPT-698) replace the following with:
14+
# git clone -q --depth=1 https://github.com/mongodb/libmongocrypt --branch 1.11.0 || return
1515
{
1616
git clone -q https://github.com/mongodb/libmongocrypt || return
17-
# Check out commit containing MONGOCRYPT-706
18-
git -C libmongocrypt checkout 06dedd42351b9adce146eaa0e971e793d8676e49
17+
# Check out commit containing MONGOCRYPT-698
18+
git -C libmongocrypt checkout 14ccd9ce8a030158aec07f63e8139d34b95d88e6
1919
}
2020

2121
declare -a crypt_cmake_flags=(

src/libmongoc/doc/mongoc_client_encryption_encrypt_range_opts_set_sparsity.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ Synopsis
1414
1515
.. versionadded:: 1.24.0
1616

17-
Sets sparsity for explicit encryption. Sparsity is required for explicit encryption of range indexes.
17+
Sets sparsity for explicit encryption.
1818
Only applies when the algorithm set by :symbol:`mongoc_client_encryption_encrypt_opts_set_algorithm()` is "Range".
1919
It is an error to set sparsity when algorithm is not "Range".
2020

21+
Sparsity may be used to tune performance. When omitted, a default value is used.
22+
2123
Sparsity must match the value set in the encryptedFields of the destination collection.
2224
It is an error to set a different value.
2325

src/libmongoc/doc/mongoc_client_encryption_encrypt_range_opts_set_trim_factor.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ Synopsis
1414
1515
.. versionadded:: 1.28.0
1616

17-
Sets trim factor for explicit encryption. Trim factor is required for explicit encryption of range indexes.
17+
Sets trim factor for explicit encryption.
1818
Only applies when the algorithm set by :symbol:`mongoc_client_encryption_encrypt_opts_set_algorithm()` is "Range".
1919
It is an error to set trim factor when algorithm is not "Range".
2020

21+
The trim factor may be used to tune performance. When omitted, a default value is used.
22+
2123
Trim factor must match the value set in the encryptedFields of the destination collection.
2224
It is an error to set a different value.
2325

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,14 @@ struct _mongoc_client_encryption_encrypt_range_opts_t {
424424
bson_value_t value;
425425
bool set;
426426
} max;
427-
int32_t trim_factor;
428-
int64_t sparsity;
427+
struct {
428+
int32_t value;
429+
bool set;
430+
} trim_factor;
431+
struct {
432+
int64_t value;
433+
bool set;
434+
} sparsity;
429435
struct {
430436
int32_t value;
431437
bool set;
@@ -555,15 +561,17 @@ mongoc_client_encryption_encrypt_range_opts_set_trim_factor (mongoc_client_encry
555561
int32_t trim_factor)
556562
{
557563
BSON_ASSERT_PARAM (range_opts);
558-
range_opts->trim_factor = trim_factor;
564+
range_opts->trim_factor.set = true;
565+
range_opts->trim_factor.value = trim_factor;
559566
}
560567

561568
void
562569
mongoc_client_encryption_encrypt_range_opts_set_sparsity (mongoc_client_encryption_encrypt_range_opts_t *range_opts,
563570
int64_t sparsity)
564571
{
565572
BSON_ASSERT_PARAM (range_opts);
566-
range_opts->sparsity = sparsity;
573+
range_opts->sparsity.set = true;
574+
range_opts->sparsity.value = sparsity;
567575
}
568576

569577
void
@@ -998,11 +1006,11 @@ append_bson_range_opts (bson_t *bson_range_opts, const mongoc_client_encryption_
9981006
if (opts->range_opts->precision.set) {
9991007
BSON_ASSERT (BSON_APPEND_INT32 (bson_range_opts, "precision", opts->range_opts->precision.value));
10001008
}
1001-
if (opts->range_opts->sparsity) {
1002-
BSON_ASSERT (BSON_APPEND_INT64 (bson_range_opts, "sparsity", opts->range_opts->sparsity));
1009+
if (opts->range_opts->sparsity.set) {
1010+
BSON_ASSERT (BSON_APPEND_INT64 (bson_range_opts, "sparsity", opts->range_opts->sparsity.value));
10031011
}
1004-
if (opts->range_opts->trim_factor) {
1005-
BSON_ASSERT (BSON_APPEND_INT32 (bson_range_opts, "trimFactor", opts->range_opts->trim_factor));
1012+
if (opts->range_opts->trim_factor.set) {
1013+
BSON_ASSERT (BSON_APPEND_INT32 (bson_range_opts, "trimFactor", opts->range_opts->trim_factor.value));
10061014
}
10071015
}
10081016

0 commit comments

Comments
 (0)