Beispiel #1
0
        public void Open()
        {
            if (!Directory.Exists(_folder))
            {
                Directory.CreateDirectory(_folder);
            }
            _env = LmdbEnv.CreateDb(_folder, 1 * 1024 * 1024);

            using (var tx = _env.Write()) {
                var dto = Lmdb.GetBuffer(tx, 0);
                if (dto == null)
                {
                    SetNewBuffer(tx, 0);
                }
                else
                {
                    _buffer = new Buffer(dto, _folder);
                    _buffer.OpenOrCreate();
                }


                var meta = Lmdb.GetCellarMeta(tx, 0, Lmdb.NewCellarDto());
                _maxKeySize = meta.GetCellarMaxKeySize();
                _maxValSize = meta.GetCellarMaxValSize();

                tx.Commit();
            }
        }
Beispiel #2
0
        // called to flush all in-flight data
        public void Checkpoint(string name, long position)
        {
            _buffer.Flush();

            using (var tx = _env.Write()) {
                var bufferDto = _buffer.GetState();
                //Console.WriteLine("Checkpoint buffer at {0}+{1}", bufferDto.GetBufferStartPos(), bufferDto.GetBufferPos());
                Lmdb.SetBuffer(tx, 0, bufferDto);
                Lmdb.SetStreamPosition(tx, name, position);

                Lmdb.SetCellarMeta(tx, 0, Lmdb.NewCellarDto()
                                   .SetCellarMaxKeySize(_maxKeySize)
                                   .SetCellarMaxValSize(_maxValSize));

                tx.Commit();
            }
        }