コード例 #1
0
        private static void StoreFile(string path)
        {
            string key   = path;
            string value = String.Empty;

            byte[] buffer = File.ReadAllBytes(path);

            LMDBEnvironment _env;
            string          dir = "c:\\temp\\cache_net10B";

            _env = new LMDBEnvironment(dir);
            _env.MaxDatabases = 2;
            _env.MapSize      = 10485760 * 100;
            _env.Open();

            DateTime dtStart = DateTime.Now;
            var      tx      = _env.BeginTransaction();
            var      db      = tx.OpenDatabase("DB", new DatabaseConfiguration {
                Flags = DatabaseOpenFlags.Create
            });
            var enc = System.Text.Encoding.UTF8;

            tx.Put(db, enc.GetBytes(key), buffer);
            tx.Commit();
            db.Dispose();

            DateTime dtStop = DateTime.Now;
            TimeSpan ts     = dtStop - dtStart;
            string   str    = String.Format("Time elapsed for set:{0} ms", ts.TotalMilliseconds);

            Logger.LogInfo(str);

            _env.Dispose();
        }
コード例 #2
0
        public LmdbHelperTests()
        {
            _directory   = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            _env         = LMDBEnvironment.Create(_directory, disableAsync: true);
            _env.MapSize = 100 * 1024 * 1024;
            _env.Open();

            _writer = new StreamWriter(new FileStream($"trace_{_correlationId}.log", FileMode.OpenOrCreate))
            {
                AutoFlush = true
            };

            if (OutputTraceLog)
            {
                TheTrace.Tracer = (level, s, os) =>
                {
                    lock (_lock)
                    {
                        var message = $"{DateTime.Now.ToString("yyyy-MM-dd:HH-mm-ss.fff")}\t{_correlationId}\t{level}\t{(os.Length == 0 ? s : string.Format(s, os))}";
                        try
                        {
                            _writer.WriteLine(message);
                        }
                        catch
                        {
                        }
                    }
                };
            }
        }
コード例 #3
0
        private DatabaseContext(string pathToDatabase, long mapSize, bool unsafeAsync, int hashTablesCount)
        {
            HashTablesCount = hashTablesCount;

            // Check if current process is 64 bit one (needed for lmdb to run)
            if (!Environment.Is64BitProcess)
            {
                throw new BadRuntimeException();
            }

            var lmdbOpenFlags = LMDBEnvironmentFlags.NoMemInit;

            if (unsafeAsync)
            {
                lmdbOpenFlags = lmdbOpenFlags | LMDBEnvironmentFlags.MapAsync | LMDBEnvironmentFlags.NoLock | LMDBEnvironmentFlags.WriteMap;
            }
            environment              = LMDBEnvironment.Create(pathToDatabase, lmdbOpenFlags, disableAsync: true);
            environment.MapSize      = mapSize;
            environment.MaxDatabases = HashTablesCount + 5;
            environment.MaxReaders   = 1000;
            environment.Open();

            // Open all database to make sure they exists and to hold their handles
            var configuration = new DatabaseConfig(DbFlags.Create | DbFlags.IntegerKey);

            var tracksDatabase          = environment.OpenDatabase("tracks", configuration);
            var subFingerprintsDatabase = environment.OpenDatabase("subFingerprints", configuration);

            var hashTables      = new Database[hashTablesCount];
            var hashTableConfig = new DatabaseConfig(
                DbFlags.Create
                | DbFlags.DuplicatesSort
                | DbFlags.IntegerKey
                | DbFlags.IntegerDuplicates
                );

            for (var i = 0; i < hashTablesCount; i++)
            {
                hashTables[i] = environment.OpenDatabase($"HashTable{i}", hashTableConfig);
            }

            databasesHolder = new DatabasesHolder(tracksDatabase, subFingerprintsDatabase, hashTables);

            // Open all databases for indexes
            var isrcIndex                  = environment.OpenDatabase("isrcIndex", new DatabaseConfig(DbFlags.Create));
            var titleArtistIndex           = environment.OpenDatabase("titleArtistIndex", new DatabaseConfig(DbFlags.Create | DbFlags.DuplicatesSort));
            var tracksSubfingerprintsIndex = environment.OpenDatabase("tracksSubfingerprintsIndex", new DatabaseConfig(
                                                                          DbFlags.Create
                                                                          | DbFlags.DuplicatesSort
                                                                          | DbFlags.IntegerKey
                                                                          | DbFlags.IntegerDuplicates
                                                                          ));

            indexesHolder = new IndexesHolder(isrcIndex, titleArtistIndex, tracksSubfingerprintsIndex);
        }
コード例 #4
0
        private static LMDBEnvironment CreateEnv()
        {
            Logger.LogInfo("CreateEnv");

            DateTime dt = DateTime.Now;

            LMDBEnvironment env;
            string          dir = "c:\\temp\\mycache_"
                                  + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString();

            env = new LMDBEnvironment(dir);

            env.MaxDatabases = 2;
            env.MapSize      = 10485760 * 10;
            env.Open();
            return(env);
        }
コード例 #5
0
        /// <summary>
        /// Creates a new
        /// </summary>
        /// <param name="directory">directory where the data and snapshots kept</param>
        /// <param name="mapSize">Default is 100 MB</param>
        public LmdbPersister(string directory, long mapSize = 100 * 1024 * 1024, Guid?seedId = null)
        {
            _directory = directory;
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            _env         = LMDBEnvironment.Create(directory, disableAsync: true);
            _env.MapSize = mapSize;
            _env.Open();

            _snapMgr = new SnapshotManager(_directory);

            _logDb = _env.OpenDatabase(Databases.Log, new DatabaseConfig(DbFlags.Create | DbFlags.DuplicatesSort)
            {
                DupSortPrefix = 64
            });
            _stateDb = _env.OpenDatabase(Databases.State, new DatabaseConfig(DbFlags.Create));

            LoadState(seedId);
        }