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

Re: LMDB - growing the database



Is this is a safe heuristic ? I query this self-written functionbefore every mdb_put to see if it might fail because of space problems. If it could fail, then I just commit the transaction, grow the database and keep on doing mdb_put's. It worked so far, but that doesn't mean much :)

Basically my guess is, that the size of the data and key with some overhead and some rounding are what is needed for transaction pages and data pages and I figure growing the btree would possibly add one more page:


/* (nat) this is supposed to be a conservative heuristic */
int
mdb_can_put( MDB_txn *txn, MDB_dbi dbi,
    MDB_val *key, MDB_val *data, unsigned int flags)
{
   MDB_env    *env;
   size_t     pgsize;
   size_t     size;
   pgno_t     pgno;
   int        num;

   env    = txn->mt_env;
   pgsize = env->me_psize - PAGEHDRSZ;
   size   = key->mv_size + 16 + data->mv_size + 16;    /* 15 for alignment/overhead voodoo */
   num    = (size + pgsize - 1) / pgsize;              /* size for data */
   
   if( txn->mt_dirty_room < num)
      return( MDB_TXN_FULL);
   
   pgno = txn->mt_next_pgno;
   num  = num * 2 + 1;   /* figure num data, num txn (?), one for btree expansion */
   if( pgno + num >= env->me_maxpg)
      return( MDB_MAP_FULL);
   return( 0);
}

Ciao
   Nat!
---------------------------------------------------
Die Jugend von heute liebt den Luxus, hat schlechte 
Manieren und verachtet die Autorität. Sie wider-
sprechen ihren Eltern, legen die Beine übereinander 
und tyrannisieren ihre Lehrer. -- Sokrates