Search code examples
c#lmdb

LMDB, overwrote the key-value but MDB_MAP_FULL


I understood LMDB use the copy-on-write strategy. But how can i clean the old garbage? I overwrote the item using the same key name, I expected the previous item data removed automatically but it seems not. I set the map-size 10,485,760 and made an item sized 4,194,304. This program crashes on the 3rd launch by issuing MDB_MAP_FULL.

static void Main(string[] args)
{
    using (LightningEnvironment env = new LightningEnvironment(@"d:\test"))
    {
        env.MapSize = 10485760;
        env.MaxDatabases = 1;
        env.Open();

        using (var tx = env.BeginTransaction())
        using (var db = tx.OpenDatabase("first", new DatabaseConfiguration { Flags = DatabaseOpenFlags.Create }))
        {
            byte[] data = new byte[1024 * 1024 * 4];
            tx.Put(db, Encoding.UTF8.GetBytes("big"), data);
            tx.Commit();
        }
    }
}

Solution

  • It means map size is full when you trying to add the key. Lmdb mapsize increases when you are trying to write a element even if it is duplicate. So, catch the exception of map size full and increase the map size of environment by some 10 percentage or any factor and add the element which you are trying to add