Skip to content

Commit fbf2ab4

Browse files
committed
CDRIVER-966 get/set_max_await_time_ms
A new option available with the MongoDB 3.2 "getMore" command, only for tailable cursors with awaitData.
1 parent b7f7805 commit fbf2ab4

15 files changed

+280
-26
lines changed

NEWS

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
mongo-c-driver 1.3.0
22
====================
33

4-
54
* mongoc_collection_find_and_modify () will now apply the mongoc_collection_t
65
write_concern_t when talking to MongoDB 3.2+.
76

87
* To explain a query plan with MongoDB 3.2+, you must now call the "explain"
98
command. Including the "$explain" key in a mongoc_collection_find query no
109
longer works. See the mongoc_collection_find documentation page for details.
1110

12-
mongo-c-driver 1.2.2
13-
====================
11+
* Various get/setters on cursor
12+
- mongoc_cursor_get_max_await_time_ms
13+
- mongoc_cursor_set_max_await_time_ms
14+
1415

1516
mongo-c-driver 1.2.1
1617
====================

build/autotools/versions.ldscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ LIBMONGOC_1.3 {
268268
mongoc_bulk_operation_set_bypass_document_validation;
269269
mongoc_bulk_operation_set_flags;
270270
mongoc_collection_find_and_modify_with_opts;
271+
mongoc_cursor_get_max_await_time_ms;
272+
mongoc_cursor_set_max_await_time_ms;
271273
mongoc_find_and_modify_opts_destroy;
272274
mongoc_find_and_modify_opts_new;
273275
mongoc_find_and_modify_opts_set_bypass_document_validation;

build/cmake/libmongoc-ssl.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ mongoc_cursor_get_batch_size
8989
mongoc_cursor_get_hint
9090
mongoc_cursor_get_host
9191
mongoc_cursor_get_id
92+
mongoc_cursor_get_max_await_time_ms
9293
mongoc_cursor_is_alive
9394
mongoc_cursor_more
9495
mongoc_cursor_next
9596
mongoc_cursor_set_batch_size
97+
mongoc_cursor_set_max_await_time_ms
9698
mongoc_database_add_user
9799
mongoc_database_command
98100
mongoc_database_command_simple

build/cmake/libmongoc.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ mongoc_cursor_get_batch_size
8787
mongoc_cursor_get_hint
8888
mongoc_cursor_get_host
8989
mongoc_cursor_get_id
90+
mongoc_cursor_get_max_await_time_ms
9091
mongoc_cursor_is_alive
9192
mongoc_cursor_more
9293
mongoc_cursor_next
9394
mongoc_cursor_set_batch_size
95+
mongoc_cursor_set_max_await_time_ms
9496
mongoc_database_add_user
9597
mongoc_database_command
9698
mongoc_database_command_simple

doc/cursors.page

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ print_all_documents (mongoc_collection_t *collection)
6464
<output>{ "ts" : { "$timestamp" : { "t" : 1400023818, "i" : 1 } }, "h" : -8458503739429355503, "v" : 2, "op" : "i", "ns" : "test.test", "o" : { "_id" : { "$oid" : "5372ab0a25164be923d10d50" } } }</output></screen>
6565

6666
<note style="tip"><p>The line of output is a sample from performing <code>db.test.insert({})</code> from the mongo shell on the given replicaSet.</p></note>
67+
<p>See also <code xref="mongoc_cursor_set_max_await_time_ms">mongoc_cursor_set_max_await_time_ms</code>.</p>
6768

6869
</section>
6970

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<page xmlns="http://projectmallard.org/1.0/"
3+
type="topic"
4+
style="function"
5+
xmlns:api="http://projectmallard.org/experimental/api/"
6+
xmlns:ui="http://projectmallard.org/experimental/ui/"
7+
id="mongoc_cursor_get_max_await_time_ms">
8+
<info>
9+
<link type="guide" xref="mongoc_cursor_t" group="function"/>
10+
</info>
11+
<title>mongoc_cursor_get_max_await_time_ms()</title>
12+
13+
<section id="synopsis">
14+
<title>Synopsis</title>
15+
<synopsis><code mime="text/x-csrc"><![CDATA[uint32_t
16+
mongoc_cursor_get_max_await_time_ms (mongoc_cursor_t *cursor);
17+
]]></code></synopsis>
18+
</section>
19+
20+
<section id="parameters">
21+
<title>Parameters</title>
22+
<table>
23+
<tr><td><p>cursor</p></td><td><p>A <code xref="mongoc_cursor_t">mongoc_cursor_t</code>.</p></td></tr>
24+
</table>
25+
</section>
26+
27+
<section id="description">
28+
<title>Description</title>
29+
<p>Retrieve the value set with <code xref="mongoc_cursor_set_max_await_time_ms">mongoc_cursor_set_max_await_time_ms</code>.</p>
30+
</section>
31+
32+
</page>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0"?>
2+
<page xmlns="http://projectmallard.org/1.0/"
3+
type="topic"
4+
style="function"
5+
xmlns:api="http://projectmallard.org/experimental/api/"
6+
xmlns:ui="http://projectmallard.org/experimental/ui/"
7+
id="mongoc_cursor_set_max_await_time_ms">
8+
<info>
9+
<link type="guide" xref="mongoc_cursor_t" group="function"/>
10+
</info>
11+
<title>mongoc_cursor_set_max_await_time_ms()</title>
12+
13+
<section id="synopsis">
14+
<title>Synopsis</title>
15+
<synopsis><code mime="text/x-csrc"><![CDATA[void
16+
mongoc_cursor_set_max_await_time_ms (mongoc_cursor_t *cursor,
17+
uint32_t max_await_time_ms);
18+
]]></code></synopsis>
19+
</section>
20+
21+
<section id="parameters">
22+
<title>Parameters</title>
23+
<table>
24+
<tr><td><p>cursor</p></td><td><p>A <code xref="mongoc_cursor_t">mongoc_cursor_t</code>.</p></td></tr>
25+
<tr><td><p>max_await_time_ms</p></td><td><p>A timeout in milliseconds.</p></td></tr>
26+
</table>
27+
</section>
28+
29+
<section id="description">
30+
<title>Description</title>
31+
<p>The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. Only applies if the is cursor created from <code xref="mongoc_collection_find">mongoc_collection_find</code> with the <link xref="mongoc_query_flags_t">query flags</link> MONGOC_QUERY_TAILABLE_CURSOR and MONGOC_QUERY_AWAIT_DATA, and the server is MongoDB 3.2 or later.</p>
32+
<p>The <code>max_await_time_ms</code> cannot be changed after the first call to <code xref="mongoc_cursor_next">mongoc_cursor_next</code>.</p>
33+
</section>
34+
35+
<section id="seealso">
36+
<title>See Also</title>
37+
<p><link xref="cursors#tailable">Tailable Cursors.</link></p>
38+
</section>
39+
40+
</page>

src/libmongoc.symbols

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ mongoc_cursor_get_batch_size
9292
mongoc_cursor_get_hint
9393
mongoc_cursor_get_host
9494
mongoc_cursor_get_id
95+
mongoc_cursor_get_max_await_time_ms
9596
mongoc_cursor_is_alive
9697
mongoc_cursor_more
9798
mongoc_cursor_next
9899
mongoc_cursor_set_batch_size
100+
mongoc_cursor_set_max_await_time_ms
99101
mongoc_database_add_user
100102
mongoc_database_command
101103
mongoc_database_command_simple

src/mongoc/mongoc-cursor-cursorid.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@ _mongoc_cursor_prepare_getmore_command (mongoc_cursor_t *cursor,
157157
if (cursor->batch_size) {
158158
bson_append_int32 (command, "batchSize", 9, cursor->batch_size);
159159
}
160+
161+
/* Find, getMore And killCursors Commands Spec: "In the case of a tailable
162+
cursor with awaitData == true the driver MUST provide a Cursor level
163+
option named maxAwaitTimeMS (See CRUD specification for details). The
164+
maxTimeMS option on the getMore command MUST be set to the value of the
165+
option maxAwaitTimeMS. If no maxAwaitTimeMS is specified, the driver
166+
SHOULD not set maxTimeMS on the getMore command."
167+
*/
168+
if (cursor->flags & MONGOC_QUERY_TAILABLE_CURSOR &&
169+
cursor->flags & MONGOC_QUERY_AWAIT_DATA &&
170+
cursor->max_await_time_ms) {
171+
bson_append_int32 (command, "maxTimeMS", 9, cursor->max_await_time_ms);
172+
}
160173
}
161174

162175

src/mongoc/mongoc-cursor-private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct _mongoc_cursor_t
7373
uint32_t limit;
7474
uint32_t count;
7575
uint32_t batch_size;
76+
uint32_t max_await_time_ms;
7677

7778
char ns [140];
7879
uint32_t nslen;

0 commit comments

Comments
 (0)