CoreyKaylor / Lightning.NET

.NET library for LMDB key-value store
Other
401 stars 82 forks source link

MapSize for Lightning Environment should be Unsigned Long instead of Long #24

Closed sn0wcat closed 10 years ago

sn0wcat commented 10 years ago

The current version of the Lightning.net seems to have exactly the same issue like for example

https://github.com/Venemo/node-lmdb/issues/13

The following code produces an AccessViolationException after running for a while even though the map size should be sufficient. After changing the parameter to ulong / uintptr the access violation exception was gone.

class Program { private static void Main(string[] args) {

        var path = @"c:\data\lightning";

        if (Directory.Exists(path))
            Directory.Delete(path, true);

        if (!Directory.Exists(path))
            Directory.CreateDirectory(path);

        var env = new LightningEnvironment(@"c:\data\lightning", EnvironmentOpenFlags.WriteMap)
        {
          MapSize = 10L *1024*1024*1024
        };

        env.Open();
        var tx = env.BeginTransaction();

        var db = tx.OpenDatabase();
        tx.Commit();
        tx.Dispose();

        var stopWatch = new Stopwatch();
        stopWatch.Start();
        var key = 0L;
        for (long j = 1L; j < 10000L; j++)
        {

            var t = env.BeginTransaction();
            var cursor = new LightningCursor(db, t);
            Console.WriteLine("Writting chunk {0}", j);
            for (var i = 1L; i < 1000L; i++)
            {
                cursor.Put(Encoding.UTF8.GetBytes(key.ToString("0000000000000000")), Encoding.UTF8.GetBytes(key.ToString("0000000000000000")),
                    LightningDB.PutOptions.AppendData);

                key++;
            }
            cursor.Close();
            cursor.Dispose();
            t.Commit();
            t.Dispose();
        }
        stopWatch.Stop();
        Console.WriteLine("used milliseconds " + stopWatch.ElapsedMilliseconds);

        db.Close();
        env.Close();
    }
}
sn0wcat commented 10 years ago

Hmm...after further testing it seems that the problem is somewhere else, as the access violation exception is still occuring arround 2041 chunk, but not as frequent as befire I guess some debugging will be necessary.

ilyalukyanov commented 10 years ago

Thank your for the issue, i'll try to investigate it on this weekend