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

Re: LMDB: Compare function implementation



Venkat Murty wrote:
Hi all,
I am inserting a non-zero length key into a database where I provide a
compare function. But I am seeing that MDB_val->mv_size = 0 in the compare
function. Is that possible?

If you saw it, then it must be possible...

Branch pages all start with an empty key.


More details (LMDB 0.9.11 Release):

I have a database where I want to delete all elements that have the same prefix.


void eraseElements (KeyPrefix prefix, MDB_txn *txn, MDB_dbi database)
{
   MDB_val k;

   k.mv_data = &prefix;
   k.mv_size  = sizeof (KeyPrefix);

   MDB_val v;

   MDB_cursor *cur;
   mdb_cursor_open (txn, database, &cur);
   while (! mdb_cursor_get (cur, &k, &v, MDB_SET_RANGE))

This loop is rather inefficient. Should just initialize once with SET_RANGE, and then loop using NEXT.
   {
       if (memcmp (&prefix, k.mv_data, sizeof (KeyPrefix)) != 0) break;
       mdb_cursor_del (cur, 0);

         k.mv_data = &prefix;
         k.mv_size  = sizeof (KeyPrefix);
     }
     mdb_cursor_close (cur);
}


Relevant stack trace
   DB::compare (a, b) and b->mv_size == 0
   mdb_cursor_set(mc, key, data, op=MDB_SET_RANGE, exactp=0x0) at mdb.c:5348
   mdb_cursor_get(mc,key,data,op=MDB_SET_RANGE) at mdb.c:5655
   eraseElements(..)



--
  -- Howard Chu
  CTO, Symas Corp.           http://www.symas.com
  Director, Highland Sun     http://highlandsun.com/hyc/
  Chief Architect, OpenLDAP  http://www.openldap.org/project/