[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: (ITS#7829) MDB mdb_cursor_del causes records to be skipped



On Fri, 2014-03-28 at 04:58 +0000, armon.dadgar@gmail.com wrote:
> I have a gist demonstrating this: https://gist.github.com/armon/9825666

Some notes about this code:
    // LMDB will return EINVAL(22) for the GET_CURRENT op if
    // there is no further keys. We treat this as no more
    // keys being found.
    if num, ok := err.(mdb.Errno); ok && num == 22 {
        println("errno 22")
        err = mdb.NotFound
    }

The value of EINVAL is OS-dependent, it need not be 22.

EINVAL means you did something wrong, it's a bad idea to
assume it means any particular wrong thing.  For one thing,
mdb might not keep catching that error.  I'd follow up
with a test check that there are indeed no more keys.


That said, mdb_cursor_del() followed by MDB_GET_CURRENT
seems to me a sensible thing to want to do.  So I think
MDB_GET_CURRENT should return MDB_NOTFOUND here.  And maybe
also after cursor_next() returned MDB_NOTFOUND, and on an
empty DB.  OTOH maybe cursors would need to keep more state
to tell this from user errors which should get EINVAL.