Skip to content

Commit 44c345e

Browse files
Shraya Ramanihanumantmk
authored andcommitted
CDRIVER-470 added wiredtiger index options
Closes #126
1 parent 08cbe76 commit 44c345e

File tree

8 files changed

+122
-14
lines changed

8 files changed

+122
-14
lines changed

build/autotools/versions.ldscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ LIBMONGOC_1.1 {
229229
mongoc_database_find_collections;
230230
mongoc_index_opt_geo_get_default;
231231
mongoc_index_opt_geo_init;
232+
mongoc_index_opt_wt_get_default;
233+
mongoc_index_opt_wt_init;
232234
mongoc_rand_add;
233235
mongoc_rand_seed;
234236
mongoc_rand_status;

build/cmake/libmongoc-ssl.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ mongoc_index_opt_geo_get_default
140140
mongoc_index_opt_geo_init
141141
mongoc_index_opt_get_default
142142
mongoc_index_opt_init
143+
mongoc_index_opt_wt_get_default
144+
mongoc_index_opt_wt_init
143145
mongoc_init
144146
mongoc_log
145147
mongoc_log_default_handler

build/cmake/libmongoc.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ mongoc_index_opt_geo_get_default
138138
mongoc_index_opt_geo_init
139139
mongoc_index_opt_get_default
140140
mongoc_index_opt_init
141+
mongoc_index_opt_wt_get_default
142+
mongoc_index_opt_wt_init
141143
mongoc_init
142144
mongoc_log
143145
mongoc_log_default_handler

src/libmongoc.symbols

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ mongoc_index_opt_geo_get_default
139139
mongoc_index_opt_geo_init
140140
mongoc_index_opt_get_default
141141
mongoc_index_opt_init
142+
mongoc_index_opt_wt_get_default
143+
mongoc_index_opt_wt_init
142144
mongoc_init
143145
mongoc_log
144146
mongoc_log_default_handler

src/mongoc/mongoc-collection.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,11 @@ mongoc_collection_create_index (mongoc_collection_t *collection,
789789
bson_t ar;
790790
bson_t doc;
791791
bson_t reply;
792+
bson_t storage_doc;
793+
bson_t wt_doc;
792794
const mongoc_index_opt_geo_t *geo_opt;
795+
const mongoc_index_opt_storage_t *storage_opt;
796+
const mongoc_index_opt_wt_t *wt_opt;
793797
char *alloc_name = NULL;
794798
bool ret = false;
795799

@@ -862,6 +866,21 @@ mongoc_collection_create_index (mongoc_collection_t *collection,
862866
BSON_APPEND_DOUBLE (&doc, "bucketSize", geo_opt->haystack_bucket_size);
863867
}
864868
}
869+
870+
if (opt->storage_options) {
871+
storage_opt = opt->storage_options;
872+
switch (storage_opt->type) {
873+
case MONGOC_INDEX_STORAGE_OPT_WIREDTIGER:
874+
wt_opt = (mongoc_index_opt_wt_t *)storage_opt;
875+
BSON_APPEND_DOCUMENT_BEGIN (&doc, "storageEngine", &storage_doc);
876+
BSON_APPEND_DOCUMENT_BEGIN (&storage_doc, "wiredtiger", &wt_doc);
877+
BSON_APPEND_UTF8 (&wt_doc, "configString", wt_opt->config_str);
878+
bson_append_document_end (&storage_doc, &wt_doc);
879+
bson_append_document_end (&doc, &storage_doc);
880+
break;
881+
}
882+
}
883+
865884
bson_append_document_end (&ar, &doc);
866885
bson_append_array_end (&cmd, &ar);
867886

src/mongoc/mongoc-index.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static mongoc_index_opt_t gMongocIndexOptDefault = {
3232
0,
3333
-1,
3434
-1,
35+
NULL,
3536
NULL
3637
};
3738

@@ -43,6 +44,11 @@ static mongoc_index_opt_geo_t gMongocIndexOptGeoDefault = {
4344
2
4445
};
4546

47+
static mongoc_index_opt_wt_t gMongocIndexOptWTDefault = {
48+
{ MONGOC_INDEX_STORAGE_OPT_WIREDTIGER },
49+
""
50+
};
51+
4652
const mongoc_index_opt_t *
4753
mongoc_index_opt_get_default (void)
4854
{
@@ -55,6 +61,12 @@ mongoc_index_opt_geo_get_default (void)
5561
return &gMongocIndexOptGeoDefault;
5662
}
5763

64+
const mongoc_index_opt_wt_t *
65+
mongoc_index_opt_wt_get_default (void)
66+
{
67+
return &gMongocIndexOptWTDefault;
68+
}
69+
5870
void
5971
mongoc_index_opt_init (mongoc_index_opt_t *opt)
6072
{
@@ -70,3 +82,10 @@ mongoc_index_opt_geo_init (mongoc_index_opt_geo_t *opt)
7082

7183
memcpy (opt, &gMongocIndexOptGeoDefault, sizeof *opt);
7284
}
85+
86+
void mongoc_index_opt_wt_init (mongoc_index_opt_wt_t *opt)
87+
{
88+
BSON_ASSERT(opt);
89+
90+
memcpy (opt, &gMongocIndexOptWTDefault, sizeof *opt);
91+
}

src/mongoc/mongoc-index.h

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,47 @@ typedef struct
3838

3939
typedef struct
4040
{
41-
bool is_initialized;
42-
bool background;
43-
bool unique;
44-
const char *name;
45-
bool drop_dups;
46-
bool sparse;
47-
int32_t expire_after_seconds;
48-
int32_t v;
49-
const bson_t *weights;
50-
const char *default_language;
51-
const char *language_override;
52-
mongoc_index_opt_geo_t *geo_options;
53-
void *padding[7];
41+
int type;
42+
} mongoc_index_opt_storage_t;
43+
44+
typedef enum
45+
{
46+
MONGOC_INDEX_STORAGE_OPT_MMAPV1,
47+
MONGOC_INDEX_STORAGE_OPT_WIREDTIGER,
48+
} mongoc_index_storage_opt_type_t;
49+
50+
typedef struct
51+
{
52+
mongoc_index_opt_storage_t base;
53+
const char* config_str;
54+
void *padding[8];
55+
} mongoc_index_opt_wt_t;
56+
57+
typedef struct
58+
{
59+
bool is_initialized;
60+
bool background;
61+
bool unique;
62+
const char *name;
63+
bool drop_dups;
64+
bool sparse;
65+
int32_t expire_after_seconds;
66+
int32_t v;
67+
const bson_t *weights;
68+
const char *default_language;
69+
const char *language_override;
70+
mongoc_index_opt_geo_t *geo_options;
71+
mongoc_index_opt_storage_t *storage_options;
72+
void *padding[6];
5473
} mongoc_index_opt_t;
5574

5675

5776
const mongoc_index_opt_t *mongoc_index_opt_get_default (void) BSON_GNUC_CONST;
5877
const mongoc_index_opt_geo_t *mongoc_index_opt_geo_get_default (void) BSON_GNUC_CONST;
78+
const mongoc_index_opt_wt_t *mongoc_index_opt_wt_get_default (void) BSON_GNUC_CONST;
5979
void mongoc_index_opt_init (mongoc_index_opt_t *opt);
6080
void mongoc_index_opt_geo_init (mongoc_index_opt_geo_t *opt);
61-
81+
void mongoc_index_opt_wt_init (mongoc_index_opt_wt_t *opt);
6282

6383
BSON_END_DECLS
6484

tests/test-mongoc-collection.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,47 @@ test_index_geo (void)
637637
mongoc_client_destroy(client);
638638
}
639639

640+
static void
641+
test_index_storage (void)
642+
{
643+
mongoc_collection_t *collection;
644+
mongoc_database_t *database;
645+
mongoc_client_t *client;
646+
mongoc_index_opt_t opt;
647+
mongoc_index_opt_wt_t wt_opt;
648+
bson_error_t error;
649+
bool r;
650+
bson_t keys;
651+
652+
mongoc_index_opt_init (&opt);
653+
mongoc_index_opt_wt_init (&wt_opt);
654+
655+
client = mongoc_client_new (gTestUri);
656+
ASSERT (client);
657+
658+
database = get_test_database (client);
659+
ASSERT (database);
660+
661+
collection = get_test_collection (client, "test_storage_index");
662+
ASSERT (collection);
663+
664+
/* Create a simple index */
665+
bson_init (&keys);
666+
bson_append_int32 (&keys, "hello", -1, 1);
667+
668+
/* Add storage option to the index */
669+
wt_opt.base.type = MONGOC_INDEX_STORAGE_OPT_WIREDTIGER;
670+
wt_opt.config_str = "block_compressor=zlib";
671+
672+
opt.storage_options = (mongoc_index_opt_storage_t *)&wt_opt;
673+
674+
r = mongoc_collection_create_index (collection, &keys, &opt, &error);
675+
ASSERT (r);
676+
677+
mongoc_collection_destroy (collection);
678+
mongoc_database_destroy (database);
679+
mongoc_client_destroy (client);
680+
}
640681

641682
static void
642683
test_count (void)
@@ -1336,6 +1377,7 @@ test_collection_install (TestSuite *suite)
13361377
TestSuite_Add (suite, "/Collection/index", test_index);
13371378
TestSuite_Add (suite, "/Collection/index_compound", test_index_compound);
13381379
TestSuite_Add (suite, "/Collection/index_geo", test_index_geo);
1380+
TestSuite_Add (suite, "/Collection/index_storage", test_index_storage);
13391381
TestSuite_Add (suite, "/Collection/regex", test_regex);
13401382
TestSuite_Add (suite, "/Collection/update", test_update);
13411383
TestSuite_Add (suite, "/Collection/remove", test_remove);

0 commit comments

Comments
 (0)