SortedDataInterface::newCursor() needs to place the position to the beginning of the cursor?

43 views
Skip to first unread message

Siying Dong

unread,
Oct 22, 2014, 5:37:09 PM10/22/14
to mongo...@googlegroups.com
Hi,

I realized that there is no clear document of SortedDataInterface::newCursor() to say whether the storage engine needs to place the cursor to the beginning position. In current rocks storage engine, it is always placed to the beginning cursor. However, in most cases _locate() is called after newCursor(), so it is an wasteful, sometimes expensive process. I try to remove seeking logic inside rocks's newCursor(), all the JS core tests still pass. Can you clearly document the expected behavior for newCursor() so that we know what we can think of what we need to do to avoid this costs?

Thanks,

Siying

Max Hirschhorn

unread,
Oct 27, 2014, 1:23:15 PM10/27/14
to mongo...@googlegroups.com
Hi Siying,

Newly constructed cursors do not need to be positioned at a particular entry of the index. The documentation for SortedDataInterface (including newCursor) was updated in commit 147f75df6b.

Best,
Max H.


--
You received this message because you are subscribed to the Google Groups "mongodb-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-dev...@googlegroups.com.
To post to this group, send email to mongo...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-dev.
For more options, visit https://groups.google.com/d/optout.

John Esmet

unread,
Oct 27, 2014, 3:06:58 PM10/27/14
to mongo...@googlegroups.com
Great. Does that further mean a newly constructed cursor may (and should) return EOF before the first call to locate()? The code probably doesn't actually expect this but I want to make sure.

Example:

c = newCursor();
c->isEOF(); // true since we did not locate, underlying cursor is 'uninitialized'
c->locate(someKey); // initializes cursor, seeks to key
c->isEOF(); // depends on the locate() call

Mathias Stearn

unread,
Oct 27, 2014, 3:38:22 PM10/27/14
to mongodb-dev
After construction, a SortedDataInterface::Cursor is in an unspecified state. It is invalid for a consumer to call anything other than locate() or customLocate() on a newly created Cursor. Implementations are allowed but not required to check for misuses of the API.

In your example, that means that the first isEOF() call is invalid and your impl can do whatever it likes.

Siying Dong

unread,
Nov 3, 2014, 2:01:23 PM11/3/14
to mongo...@googlegroups.com
Thank you for your answer. That's great!
Reply all
Reply to author
Forward
0 new messages