コード例 #1
0
ファイル: RocksDbStorage.cs プロジェクト: ocoanet/Zebus
        public void Start()
        {
            var options = new DbOptions().SetCreateIfMissing()
                          .SetCreateMissingColumnFamilies()
                          .SetMaxBackgroundCompactions(4)
                          .SetMaxBackgroundFlushes(2)
                          .SetBytesPerSync(1024 * 1024);

            var columnFamilies = new ColumnFamilies
            {
                { "Messages", ColumnFamilyOptions() },
                { "Peers", ColumnFamilyOptions() },
                { "Acks", ColumnFamilyOptions() }
            };

            _db = RocksDbSharp.RocksDb.Open(options, _databaseDirectoryPath, columnFamilies);

            _messagesColumnFamily = _db.GetColumnFamily("Messages");
            _peersColumnFamily    = _db.GetColumnFamily("Peers");
            _acksColumnFamily     = _db.GetColumnFamily("Acks");

            ColumnFamilyOptions ColumnFamilyOptions() => new ColumnFamilyOptions().SetCompression(CompressionTypeEnum.rocksdb_no_compression)
            .SetLevelCompactionDynamicLevelBytes(true)
            .SetArenaBlockSize(16 * 1024);

            LoadAllOutOfOrderAcks();
        }
コード例 #2
0
        public RocksPrimaryRepository(RocksDbSharp.RocksDb db, PrimaryIndexGenerator indexGenerator, IIndexOrderProvider indexOrders)
        {
            this.Database = db;

            WriteOptions        = new WriteOptions();
            this.IndexGenerator = indexGenerator;
            this.IndexOrders    = indexOrders;
        }
コード例 #3
0
ファイル: RocksDbStore.cs プロジェクト: crazyants/resin
        public RocksDbStore(IConfigurationProvider config)
        {
            _dir = config.Get("data_dir");

            var options = new DbOptions().SetCreateIfMissing(true);

            _db = RocksDbSharp.RocksDb.Open(options, _dir);
        }
コード例 #4
0
        public RocksDbKeyValueRepository(string folder, DataStoreSerializer dataStoreSerializer)
        {
            Directory.CreateDirectory(folder);
            this.dataStoreSerializer = dataStoreSerializer;

            // Open a connection to a new DB and create if not found
            var options = new DbOptions().SetCreateIfMissing(true);

            this.rocksdb = DB.Open(options, folder);
        }
コード例 #5
0
 public SingleColumnFamilyAdapter(string name, RocksDbSharp.RocksDb db, WriteOptions writeOptions, Func <byte[], byte[], int> keyComparator, ColumnFamilyHandle columnFamilyHandle)
 {
     this.name               = name;
     this.db                 = db;
     this.writeOptions       = writeOptions;
     this.keyComparator      = keyComparator;
     this.columnFamilyHandle = columnFamilyHandle;
     flushOptions            = new();
     flushOptions.SetWaitForFlush(true);
 }
コード例 #6
0
 public ulong Get(RocksDb db, byte[] key, ulong keyLength, byte[] buffer, ulong offset, ulong length, ColumnFamilyHandle cf = null, ReadOptions options = null)
 {
     unsafe
     {
         var ptr = Native.Instance.rocksdb_writebatch_wi_get_from_batch_and_db(Handle, db.Handle, (options ?? RocksDb.DefaultReadOptions).Handle, key, keyLength, out ulong valLength, cf);
         valLength = Math.Min(length, valLength);
         Marshal.Copy(ptr, buffer, (int)offset, (int)valLength);
         Native.Instance.rocksdb_free(ptr);
         return(valLength);
     }
 }
コード例 #7
0
        public RocksDbChainStore(Network network, DataFolder dataFolder, ChainIndexer chainIndexer)
        {
            this.network        = network;
            this.ChainIndexer   = chainIndexer;
            this.nearTipHeaders = new MemoryCountCache <uint256, BlockHeader>(601);
            this.recentHeaders  = new MemoryCountCache <uint256, BlockHeader>(100);
            this.locker         = new object();

            // Open a connection to a new DB and create if not found
            var options = new DbOptions().SetCreateIfMissing(true);

            this.rocksdb = DB.Open(options, dataFolder.ChainPath);
        }
コード例 #8
0
        private void LoadPrunedTip(RocksDbSharp.RocksDb rocksdb)
        {
            if (this.PrunedTip == null)
            {
                lock (this.blockRepository.Locker)

                {
                    byte[] row = rocksdb.Get(DBH.Key(RocksdbBlockRepository.CommonTableName, prunedTipKey));
                    if (row != null)
                    {
                        this.PrunedTip = this.dataStoreSerializer.Deserialize <HashHeightPair>(row);
                    }
                }
            }
        }
コード例 #9
0
        public RocksdbBlockRepository(Network network, string folder, ILoggerFactory loggerFactory, DataStoreSerializer dataStoreSerializer)
        {
            Guard.NotNull(network, nameof(network));
            Guard.NotEmpty(folder, nameof(folder));

            Directory.CreateDirectory(folder);
            var options = new DbOptions().SetCreateIfMissing(true);

            this.rocksdb = DB.Open(options, folder);
            this.Locker  = new object();

            this.logger              = loggerFactory.CreateLogger(this.GetType().FullName);
            this.network             = network;
            this.dataStoreSerializer = dataStoreSerializer;
            this.genesisTransactions = network.GetGenesis().Transactions.ToDictionary(k => k.GetHash());
        }
コード例 #10
0
        private void Start()
        {
            var options = new DbOptions().SetCreateIfMissing()
                          .SetCreateMissingColumnFamilies()
                          .SetMaxBackgroundCompactions(4)
                          .SetMaxBackgroundFlushes(2)
                          .SetBytesPerSync(1024 * 1024);

            var columnFamilies = new ColumnFamilies
            {
                { "Peers", ColumnFamilyOptions() },
                { "Subscriptions", ColumnFamilyOptions() }
            };

            _db = RocksDbSharp.RocksDb.Open(options, DatabaseFilePath, columnFamilies);

            _peersColumnFamily         = _db.GetColumnFamily("Peers");
            _subscriptionsColumnFamily = _db.GetColumnFamily("Subscriptions");
コード例 #11
0
ファイル: BenchmarkDatabases.cs プロジェクト: zyhong/DBTrie
 public void Setup()
 {
     folder = @"BenchData";
     Directory.CreateDirectory($@"BenchData");
     Directory.CreateDirectory($@"{folder}\trie");
     trie = DBTrieEngine.OpenFromFolder($@"{folder}\trie").Result;
     ldb  = new DB(new Options {
         CreateIfMissing = true
     }, $@"{folder}\ldb");
     Directory.CreateDirectory($@"{folder}\litedb");
     litedb = new LiteDatabase(new ConnectionString()
     {
         Filename = $@"{folder}\litedb\db"
     });
     this.litedbCol = litedb.GetCollection <LiteDbEntity>("tbl");
     trx            = trie.OpenTransaction().Result;
     tbl            = trx.GetTable("tbl");
     rocksdb        = rdb.RocksDb.Open(new rdb.DbOptions().SetCreateIfMissing(true), $@"{folder}\rocksdb");
 }
コード例 #12
0
        /// <summary>
        /// Initializes a new instance of the object.
        /// </summary>
        /// <param name="network">Specification of the network the node runs on - RegTest/TestNet/MainNet.</param>
        /// <param name="folder"><see cref="RocksDbProvenBlockHeaderRepository"/> folder path to the DBreeze database files.</param>
        /// <param name="loggerFactory">Factory to create a logger for this type.</param>
        /// <param name="dataStoreSerializer">The serializer to use for <see cref="IBitcoinSerializable"/> objects.</param>
        public RocksDbProvenBlockHeaderRepository(Network network, string folder, ILoggerFactory loggerFactory,
                                                  DataStoreSerializer dataStoreSerializer)
        {
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(folder, nameof(folder));
            this.dataStoreSerializer = dataStoreSerializer;

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);

            Directory.CreateDirectory(folder);

            // Open a connection to a new DB and create if not found
            var options = new DbOptions().SetCreateIfMissing(true);

            this.rocksdb = DB.Open(options, folder);

            this.locker = new object();

            this.network = network;
        }
コード例 #13
0
        public RocksDbCoindb(Network network, string folder, IDateTimeProvider dateTimeProvider,
                             ILoggerFactory loggerFactory, INodeStats nodeStats, DataStoreSerializer dataStoreSerializer)
        {
            Guard.NotNull(network, nameof(network));
            Guard.NotEmpty(folder, nameof(folder));

            this.dataStoreSerializer = dataStoreSerializer;

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);

            // Open a connection to a new DB and create if not found
            var options = new DbOptions().SetCreateIfMissing(true);

            this.rocksdb = DB.Open(options, folder);

            this.network            = network;
            this.performanceCounter = new BackendPerformanceCounter(dateTimeProvider);

            nodeStats.RegisterStats(this.AddBenchStats, StatsType.Benchmark, this.GetType().Name, 400);
        }
コード例 #14
0
        public static IEnumerable <KeyValuePair <byte[], byte[]> > Search(this RocksDbSharp.RocksDb database, byte[] indexKey, bool distinct, bool isSubKey)
        {
            Dictionary <ByteArray, bool> dictionary = new Dictionary <ByteArray, bool>();

            using (var iterator = database.NewIterator())
            {
                var it = iterator.Seek(indexKey);
                while (it.Valid())
                {
                    var iterKey = it.Key();
                    if (!iterKey.ContainsSequence32(indexKey))
                    {
                        break;
                    }

                    if (isSubKey)
                    {
                        var key = it.Value();

                        if (key == null || key.Length == 0)
                        {
                            continue;
                        }

                        if (distinct)
                        {
                            var bKey = new ByteArray(key);
                            if (dictionary.ContainsKey(bKey))
                            {
                                continue;
                            }
                            dictionary[bKey] = true;
                        }

                        var value = database.Get(key);
                        if (value == null || value.Length == 0)
                        {
                            continue;
                        }

                        yield return(new KeyValuePair <byte[], byte[]>(key, value));
                    }
                    else
                    {
                        if (distinct)
                        {
                            var bKey = new ByteArray(iterKey);
                            if (dictionary.ContainsKey(bKey))
                            {
                                continue;
                            }
                            dictionary[bKey] = true;
                        }

                        var value = it.Value();
                        if (value == null || value.Length == 0)
                        {
                            continue;
                        }

                        yield return(new KeyValuePair <byte[], byte[]>(iterKey, value));
                    }

                    it = it.Next();
                }
            }
        }
コード例 #15
0
 public RocksPrimaryRepository(RocksDbSharp.RocksDb db, string entityName)
     : this(db, new PrimaryIndexGenerator(entityName), new IndexOrderProvider())
 {
 }
コード例 #16
0
 public RocksPrimaryRepository(RocksDbSharp.RocksDb db, PrimaryIndexGenerator indexGenerator)
     : this(db, indexGenerator, new IndexOrderProvider())
 {
 }
コード例 #17
0
 public string Get(RocksDb db, string key, ColumnFamilyHandle cf = null, ReadOptions options = null, Encoding encoding = null)
 {
     return(Native.Instance.rocksdb_writebatch_wi_get_from_batch_and_db(Handle, db.Handle, (options ?? RocksDb.DefaultReadOptions).Handle, key, cf, encoding ?? defaultEncoding));
 }
コード例 #18
0
 public byte[] Get(RocksDb db, byte[] key, ColumnFamilyHandle cf = null, ReadOptions options = null)
 {
     return(Get(db, key, (ulong)key.GetLongLength(0), cf, options));
 }
コード例 #19
0
 public static void Put(this RocksDbSharp.RocksDb rocksDb, string key, byte[] value, ColumnFamilyHandle columnFamily)
 {
     rocksDb.Put(Encoding.UTF8.GetBytes(key), value, columnFamily);
 }
コード例 #20
0
 public ulong Get(RocksDb db, byte[] key, byte[] buffer, ulong offset, ulong length, ColumnFamilyHandle cf = null, ReadOptions options = null)
 {
     return(Get(db, key, (ulong)key.GetLongLength(0), buffer, offset, length, cf, options));
 }
コード例 #21
0
 public byte[] Get(RocksDb db, byte[] key, ulong keyLength, ColumnFamilyHandle cf = null, ReadOptions options = null)
 {
     return(Native.Instance.rocksdb_writebatch_wi_get_from_batch_and_db(Handle, db.Handle, (options ?? RocksDb.DefaultReadOptions).Handle, key, keyLength, cf));
 }
コード例 #22
0
ファイル: RocksDbMessageReader.cs プロジェクト: ocoanet/Zebus
 public RocksDbMessageReader(RocksDbSharp.RocksDb db, in PeerId peerId, ColumnFamilyHandle messagesColumnFamily)
コード例 #23
0
 public static byte[] Get(this RocksDbSharp.RocksDb rocksDb, string key, ColumnFamilyHandle columnFamily) => rocksDb.Get(Encoding.UTF8.GetBytes(key), columnFamily);