Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
 public long GetCheckpoint(string name, long dv = default(long))
 {
     using (var env = LmdbEnv.CreateDb(_folder, 1024 * 1024, EnvironmentOpenFlags.ReadOnly)) {
         using (var tx = env.Read()) {
             return(Lmdb.GetStreamPosition(tx, name, dv));
         }
     }
 }
Ejemplo n.º 3
0
        public override void Run()
        {
            if (!Directory.Exists(DatabasePath))
            {
                Console.WriteLine("Path not found {0}", DatabasePath);
                Environment.Exit(1);
            }
            var outPath = DatabasePath.TrimEnd('/') + ".pack";

            if (Directory.Exists(outPath))
            {
                Directory.Delete(outPath, true);
            }
            Directory.CreateDirectory(outPath);


            using (var db = LmdbEnv.CreateDb(DatabasePath, 0, EnvironmentOpenFlags.ReadOnly)) {
                using (var tx = db.Read()) {
                    var stats = tx.GetUsedSize();

                    Console.WriteLine("Entry count: {0}. Size: {1}", stats.EntryCount,
                                      Print.Bytes(stats.UsedBytes));
                }

                db.CopyTo(outPath, true);
            }

            var inFile = Path.Combine(outPath, "data.mdb");

            Console.WriteLine("Packed into {0}", Print.Bytes(new FileInfo(inFile).Length));

            var outFile = Path.Combine(outPath, "data.mdb.gzip");

            using (var input = File.OpenRead(inFile))
                using (var output = File.Create(outFile))
                    using (var gz = new GZipStream(output, CompressionLevel.Optimal)) {
                        input.CopyTo(gz);
                    }


            Console.WriteLine("Gzipped into {0}", Print.Bytes(new FileInfo(outFile).Length));
        }
Ejemplo n.º 4
0
        void LoadData()
        {
            if (!Directory.Exists(_folder))
            {
                return;
            }



            using (var env = LmdbEnv.CreateDb(_folder, 1024 * 1024, EnvironmentOpenFlags.ReadOnly)) {
                using (var tx = env.Read()) {
                    _chunks  = Lmdb.ListChunks(tx).Select(c => c.Value).ToArray();
                    _buffer  = Lmdb.GetBuffer(tx, 0);
                    _cellar  = Lmdb.GetCellarMeta(tx, 0, new Lmdb.CellarDto());
                    ByteSize = Cellar.EstimateSize(tx).ByteSize;
                }
            }

            _maxKeySize   = _cellar.GetCellarMaxKeySize();
            _maxValueSize = _cellar.GetCellarMaxValSize();
        }