예제 #1
0
 public ReadOnlyTransaction(Spreads.LMDB.ReadOnlyTransaction tx, DatabasesHolder databasesHolder, IndexesHolder indexesHolder)
     : base(databasesHolder, indexesHolder)
 {
     this.tx = tx;
     this.databasesHolder = databasesHolder;
     this.indexesHolder   = indexesHolder;
 }
 public ReadWriteTransaction(Transaction tx, DatabasesHolder databasesHolder, IndexesHolder indexesHolder)
     : base(databasesHolder, indexesHolder)
 {
     Monitor.Enter(locker);
     this.tx = tx;
     this.databasesHolder = databasesHolder;
     this.indexesHolder   = indexesHolder;
 }
예제 #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
 protected BaseTransaction(DatabasesHolder databasesHolder, IndexesHolder indexesHolder)
 {
     this.databasesHolder = databasesHolder;
     this.indexesHolder   = indexesHolder;
 }