public void WriteNodeToBatch(ulong id, IHashTrieNode node, RocksDbAtomicWrite tx) { var prefix = EntryPrefix.PersistentHashMap.BuildPrefix(id); tx.Put(prefix, NodeSerializer.ToBytes(node)); var hashPrefix = EntryPrefix.VersionByHash.BuildPrefix(node.Hash); tx.Put(hashPrefix, UInt64Utils.ToBytes(id)); }
public void CommitNodes() { RocksDbAtomicWrite tx = new RocksDbAtomicWrite(_dbContext); foreach (var item in _nodeCache) { tx.Put(EntryPrefix.PersistentHashMap.BuildPrefix(item.Key), NodeSerializer.ToBytes(item.Value)); Console.WriteLine("Adding node to DB : " + item.Key); } ulong nodesCnt = UInt64Utils.FromBytes(_dbContext.Get(EntryPrefix.NodesDownloadedTillNow.BuildPrefix())); nodesCnt += (ulong)_nodeCache.Count; tx.Put(EntryPrefix.NodesDownloadedTillNow.BuildPrefix(), UInt64Utils.ToBytes(nodesCnt)); tx.Commit(); _nodeCache.Clear(); }
public void CommitIds() { RocksDbAtomicWrite tx = new RocksDbAtomicWrite(_dbContext); foreach (var item in _idCache) { tx.Put(EntryPrefix.VersionByHash.BuildPrefix(HexUtils.HexToBytes(item.Key)), UInt64Utils.ToBytes(item.Value)); } tx.Commit(); _idCache.Clear(); }
private void Save(byte[] key, byte[] content, bool tryCommit = true) { batch.Put(key, content); var keyHash = key.Keccak(); _memDb[keyHash] = content; DbShrinkUtils.UpdateCounter(); if (tryCommit && DbShrinkUtils.CycleEnded()) { Commit(); } }
public void AddAndRemoveTransaction(TransactionReceipt txToAdd, TransactionReceipt txToRemove) { /* write transaction to storage */ var batch = new RocksDbAtomicWrite(_rocksDbContext); var prefixTx = EntryPrefix.TransactionByHash.BuildPrefix(txToRemove.Hash); batch.Delete(prefixTx); prefixTx = EntryPrefix.TransactionByHash.BuildPrefix(txToAdd.Hash); batch.Put(prefixTx, txToAdd.ToByteArray()); /* add transaction to pool */ var pool = GetTransactionPool(); pool.Remove(txToRemove.Hash); if (!pool.Contains(txToAdd.Hash)) { pool.Add(txToAdd.Hash); } prefixTx = EntryPrefix.TransactionPool.BuildPrefix(); batch.Put(prefixTx, pool.TransactionHashListToByteArray()); batch.Commit(); }
public void SetVersion(uint repository, ulong version, RocksDbAtomicWrite tx) { tx.Put(EntryPrefix.StorageVersionIndex.BuildPrefix(repository), version.ToBytes().ToArray()); }