[CXX-1288] Add method to detect dead tailable cursor Created: 27/Mar/17  Updated: 24/May/17  Resolved: 24/May/17

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: David Golden Assignee: Samuel Rossi (Inactive)
Resolution: Won't Fix Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on CXX-1258 Cursor iterators lose lockstep at cur... Closed

 Description   

Currently, users have no way of knowing that a tailable cursor is "dead" – i.e. that there are no more documents to iterate and the server has returned a cursor_id of zero.

After CDRIVER-2093 is released in libmongoc 1.7.0, we can add a method like can_tail which is always false for non-tailable cursors and for tailable (and tailable-await) cursors passes through the value of mongoc_cursor_more.



 Comments   
Comment by Samuel Rossi (Inactive) [ 24/May/17 ]

From investigating this, it seems that mongoc_get_more will only return false in the case of an error (because the server will never return a cursor id of 0 for a tailable cursor). Because of this, there isn't any need for this method.

Comment by J Rassi [ 14/Apr/17 ]

As an alternative to adding a new method, we can also consider it exceptional behavior for the server to close a tailable cursor. Users would be able to detect this via try/catch.

Comment by David Golden [ 27/Mar/17 ]

We also need to update the tailable cursor example.

A possible way this might be used:

// Endless attempts to tail.
for (;;) {
    auto cursor = _run_tailable_query(&collection);
    while ( cursor->can_tail() ) {
        for ( auto&& doc : cursor ) {
            // do stuff with documents
        }
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
}

Generated at Wed Feb 07 22:02:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.