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(); }
public RocksPrimaryRepository(RocksDbSharp.RocksDb db, PrimaryIndexGenerator indexGenerator, IIndexOrderProvider indexOrders) { this.Database = db; WriteOptions = new WriteOptions(); this.IndexGenerator = indexGenerator; this.IndexOrders = indexOrders; }
public RocksDbStore(IConfigurationProvider config) { _dir = config.Get("data_dir"); var options = new DbOptions().SetCreateIfMissing(true); _db = RocksDbSharp.RocksDb.Open(options, _dir); }
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); }
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); }
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); } }
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); }
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); } } } }
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()); }
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");
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"); }
/// <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; }
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); }
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(); } } }
public RocksPrimaryRepository(RocksDbSharp.RocksDb db, string entityName) : this(db, new PrimaryIndexGenerator(entityName), new IndexOrderProvider()) { }
public RocksPrimaryRepository(RocksDbSharp.RocksDb db, PrimaryIndexGenerator indexGenerator) : this(db, indexGenerator, new IndexOrderProvider()) { }
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)); }
public byte[] Get(RocksDb db, byte[] key, ColumnFamilyHandle cf = null, ReadOptions options = null) { return(Get(db, key, (ulong)key.GetLongLength(0), cf, options)); }
public static void Put(this RocksDbSharp.RocksDb rocksDb, string key, byte[] value, ColumnFamilyHandle columnFamily) { rocksDb.Put(Encoding.UTF8.GetBytes(key), value, columnFamily); }
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)); }
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)); }
public RocksDbMessageReader(RocksDbSharp.RocksDb db, in PeerId peerId, ColumnFamilyHandle messagesColumnFamily)
public static byte[] Get(this RocksDbSharp.RocksDb rocksDb, string key, ColumnFamilyHandle columnFamily) => rocksDb.Get(Encoding.UTF8.GetBytes(key), columnFamily);