Esempio n. 1
0
 public byte[] this[byte[] key]
 {
     get
     {
         UpdateReadMetrics();
         return(_db.Get(key));
     }
     set
     {
         UpdateWriteMetrics();
         if (_currentBatch != null)
         {
             if (value == null)
             {
                 _currentBatch.Delete(key);
             }
             else
             {
                 _currentBatch.Put(key, value);
             }
         }
         else
         {
             if (value == null)
             {
                 _db.Remove(key);
             }
             else
             {
                 _db.Put(key, value);
             }
         }
     }
 }
Esempio n. 2
0
 public byte[] this[byte[] key]
 {
     get
     {
         UpdateReadMetrics();
         return(_rocksDb.Get(key, _columnFamily));
     }
     set
     {
         UpdateWriteMetrics();
         if (_mainDb.CurrentBatch != null)
         {
             if (value == null)
             {
                 _mainDb.CurrentBatch.Delete(key, _columnFamily);
             }
             else
             {
                 _mainDb.CurrentBatch.Put(key, value, _columnFamily);
             }
         }
         else
         {
             if (value == null)
             {
                 _rocksDb.Remove(key, _columnFamily, _mainDb.WriteOptions);
             }
             else
             {
                 _rocksDb.Put(key, value, _columnFamily, _mainDb.WriteOptions);
             }
         }
     }
 }
Esempio n. 3
0
        public byte[] this[byte[] key]
        {
            get
            {
                switch (_dbInstance)
                {
                case DbInstance.DiscoveryNodes:
                    Metrics.DiscoveryNodesDbReads++;
                    break;

                case DbInstance.Peers:
                    Metrics.PeersDbReads++;
                    break;
                }

                if (_currentBatch != null)
                {
                    return(_currentBatch.Get(key));
                }

                return(_db.Get(key));
            }
            set
            {
                switch (_dbInstance)
                {
                case DbInstance.DiscoveryNodes:
                    Metrics.DiscoveryNodesDbWrites++;
                    break;

                case DbInstance.Peers:
                    Metrics.PeersDbWrites++;
                    break;
                }

                if (_currentBatch != null)
                {
                    if (value == null)
                    {
                        _currentBatch.Delete(key);
                    }
                    else
                    {
                        _currentBatch.Put(key, value);
                    }
                }
                else
                {
                    if (value == null)
                    {
                        _db.Remove(key);
                    }
                    else
                    {
                        _db.Put(key, value);
                    }
                }
            }
        }
Esempio n. 4
0
 public byte[] this[byte[] key]
 {
     get
     {
         return(Db.Get(key));
     }
     set
     {
         UpdateWriteMetrics();
         if (CurrentBatch != null)
         {
             if (value == null)
             {
                 CurrentBatch.Delete(key);
             }
             else
             {
                 CurrentBatch.Put(key, value);
             }
         }
         else
         {
             if (value == null)
             {
                 Db.Remove(key, null, WriteOptions);
             }
             else
             {
                 Db.Put(key, value, null, WriteOptions);
             }
         }
     }
 }
Esempio n. 5
0
        /// <inheritdoc/>
        public override bool DeleteTransaction(TxId txid)
        {
            byte[] key = TxKey(txid);

            if (!(_txIndexDb.Get(key) is byte[] txDbNameBytes))
            {
                return(false);
            }

            _rwTxLock.EnterWriteLock();
            try
            {
                string txDbName = RocksDBStoreBitConverter.GetString(txDbNameBytes);
                if (!_txDbCache.TryGetValue(txDbName, out RocksDb txDb))
                {
                    txDb = RocksDBUtils.OpenRocksDb(_options, TxDbPath(txDbName));
                    _txDbCache.AddOrUpdate(txDbName, txDb);
                }

                _txCache.Remove(txid);
                _txIndexDb.Remove(key);
                txDb.Remove(key);

                return(true);
            }
            finally
            {
                _rwTxLock.ExitWriteLock();
            }
        }
Esempio n. 6
0
        /// <inheritdoc/>
        public override bool DeleteBlock(HashDigest <SHA256> blockHash)
        {
            byte[] key = BlockKey(blockHash);

            if (!(_blockIndexDb.Get(key) is byte[] blockDbNameByte))
            {
                return(false);
            }

            _rwBlockLock.EnterWriteLock();
            try
            {
                string blockDbName = RocksDBStoreBitConverter.GetString(blockDbNameByte);
                if (!_blockDbCache.TryGetValue(blockDbName, out RocksDb blockDb))
                {
                    blockDb = RocksDBUtils.OpenRocksDb(_options, BlockDbPath(blockDbName));
                    _blockDbCache.AddOrUpdate(blockDbName, blockDb);
                }

                _blockCache.Remove(blockHash);
                _blockIndexDb.Remove(key);
                blockDb.Remove(key);
                return(true);
            }
            finally
            {
                _rwBlockLock.ExitWriteLock();
            }
        }
Esempio n. 7
0
 /// <inheritdoc/>
 public override void UnstageTransactionIds(ISet <TxId> txids)
 {
     foreach (TxId txId in txids)
     {
         byte[] key = StagedTxKey(txId);
         _stagedTxDb.Remove(key);
     }
 }
        public static void Remove(this RocksDb db, byte table, byte[] key)
        {
            Span <byte> dbkey = stackalloc byte[key.Length + 1];

            dbkey[0] = table;
            key.AsSpan().CopyTo(dbkey.Slice(1));

            db.Remove(dbkey.ToArray());
        }
Esempio n. 9
0
 public bool DeleteGraph(string id, GraphType type)
 {
     if (!ContainsGraph(id, type))
     {
         return(false);
     }
     _db.Remove(MakeKey(id, type));
     return(true);
 }
Esempio n. 10
0
 /// <summary>
 /// Remove value from Rocksdb
 /// </summary>
 /// <param name="Key">Search Key</param>
 /// <returns></returns>
 bool DeleteDb(string Key)
 {
     try {
         db.Remove(Key);
         return(true);
     } catch (Exception exc) {
         Log.Error(exc, $"DeleteDb(key:{Key})");
         return(false);
     }
 }
Esempio n. 11
0
        /// <inheritdoc cref="BaseStore.ForkBlockIndexes(Guid, Guid, BlockHash)"/>
        public override void ForkBlockIndexes(
            Guid sourceChainId,
            Guid destinationChainId,
            BlockHash branchpoint
            )
        {
            BlockHash?genesisHash = IterateIndexes(sourceChainId, 0, 1).FirstOrDefault();

            if (genesisHash is null || branchpoint.Equals(genesisHash))
            {
                return;
            }

            ColumnFamilyHandle srcCf  = GetColumnFamily(_chainDb, sourceChainId);
            ColumnFamilyHandle destCf = GetColumnFamily(_chainDb, destinationChainId);

            foreach (Iterator k in IterateDb(_chainDb, IndexKeyPrefix, destinationChainId))
            {
                _chainDb.Remove(k.Key(), destCf);
            }

            long bpIndex = GetBlockIndex(branchpoint).Value;

            if (GetPreviousChainInfo(srcCf) is { } chainInfo&&
                chainInfo.Item2 == bpIndex)
            {
                ForkBlockIndexes(chainInfo.Item1, destinationChainId, branchpoint);
                return;
            }

            _chainDb.Put(PreviousChainIdKey, sourceChainId.ToByteArray(), destCf);
            _chainDb.Put(
                PreviousChainIndexKey,
                RocksDBStoreBitConverter.GetBytes(bpIndex),
                destCf
                );
            _chainDb.Put(
                IndexCountKey,
                RocksDBStoreBitConverter.GetBytes(bpIndex + 1),
                destCf
                );
            AddFork(srcCf, destinationChainId);
        }
Esempio n. 12
0
 public void Delete(byte[]?key)
 {
     if (disposed || db.Handle == IntPtr.Zero)
     {
         throw new ObjectDisposedException(nameof(RocksDbStore));
     }
     if (readOnly)
     {
         throw new InvalidOperationException("read only");
     }
     db.Remove(key ?? Array.Empty <byte>(), columnFamily, writeOptions);
 }
Esempio n. 13
0
        public void AddLogEntryByFollower(StateLogEntrySuggestion suggestion)
        {
            //remove all log bigger than this,(clear no committed logs)
            var key  = GetKey(suggestion.StateLogEntry.Term, suggestion.StateLogEntry.Index);
            var iter = db.NewIterator();

            iter.Seek(key);
            while (iter.Valid())
            {
                iter.Next();
                if (iter.Valid())
                {
                    db.Remove(iter.Key());
                }
                else
                {
                    break;
                }
            }
            //add this one
            AddLogEntry(suggestion);
            //update commit status
            if (suggestion.IsCommitted)
            {
                if (this.LastCommittedIndexTerm > suggestion.StateLogEntry.Term ||
                    (
                        this.LastCommittedIndexTerm == suggestion.StateLogEntry.Term &&
                        this.LastCommittedIndex > suggestion.StateLogEntry.Index
                    ))
                {
                    //Should be not possible
                }
                else
                {
                    this.LastCommittedIndex     = suggestion.StateLogEntry.Index;
                    this.LastCommittedIndexTerm = suggestion.StateLogEntry.Term;
                }
            }
        }
Esempio n. 14
0
        /// <inheritdoc/>
        public override bool DeleteBlock(HashDigest <SHA256> blockHash)
        {
            byte[] key = BlockKey(blockHash);

            if (_blockDb.Get(key) is null)
            {
                return(false);
            }

            _blockCache.Remove(blockHash);
            _blockDb.Remove(key);

            return(true);
        }
Esempio n. 15
0
        /// <inheritdoc/>
        public override bool DeleteTransaction(TxId txid)
        {
            byte[] key = TxKey(txid);

            if (_txDb.Get(key) is null)
            {
                return(false);
            }

            _txCache.Remove(txid);
            _txDb.Remove(key);

            return(true);
        }
Esempio n. 16
0
        public void create_rocksdb_test()
        {
            Parallel.ForEach(Enumerable.Range(1, 10), i => {
                // Using strings below, but can also use byte arrays for both keys and values
                // much care has been taken to minimize buffer copying
                _rocksDb.Put($"key{i}", "value");
                string value = _rocksDb.Get($"key{i}");
                Assert.AreEqual("value", value);
                _rocksDb.Remove($"key{i}");
            });


            _rocksDb.Dispose();
        }
Esempio n. 17
0
 /// <inheritdoc/>
 public override void UnstageTransactionIds(ISet <TxId> txids)
 {
     try
     {
         foreach (TxId txId in txids)
         {
             byte[] key = StagedTxKey(txId);
             _stagedTxDb.Remove(key);
         }
     }
     catch (Exception e)
     {
         LogUnexpectedException(nameof(UnstageTransactionIds), e);
     }
 }
Esempio n. 18
0
        /// <inheritdoc cref="BaseStore.DeleteBlock(BlockHash)"/>
        public override bool DeleteBlock(BlockHash blockHash)
        {
            byte[] key = BlockKey(blockHash);

            if (!(_blockIndexDb.Get(key) is byte[] blockDbNameByte))
            {
                return(false);
            }

            _rwBlockLock.EnterWriteLock();
            try
            {
                string  blockDbName = RocksDBStoreBitConverter.GetString(blockDbNameByte);
                RocksDb blockDb;
                lock (_blockDbCache)
                {
                    if (!_blockDbCache.TryGetValue(blockDbName, out blockDb))
                    {
                        blockDb = RocksDBUtils.OpenRocksDb(_options, BlockDbPath(blockDbName));
                        _blockDbCache.AddOrUpdate(blockDbName, blockDb);
                    }
                }

                _blockCache.Remove(blockHash);
                _blockIndexDb.Remove(key);
                blockDb.Remove(key);
                return(true);
            }
            catch (Exception e)
            {
                LogUnexpectedException(nameof(DeleteBlock), e);
            }
            finally
            {
                _rwBlockLock.ExitWriteLock();
            }

            return(false);
        }
Esempio n. 19
0
        public void RemoveBytes(string key, ColumnFamilyHandle cf = null, WriteOptions writeOptions = null)
        {
            var eKey = Encoding.UTF8.GetBytes(key);

            _db.Remove(eKey);
        }
Esempio n. 20
0
 public void Remove(string K)
 {
     db.Remove(K);
 }
Esempio n. 21
0
 public void Delete(byte[] key)
 {
     _ThrowIfNotInitialized();
     _rocksDb.Remove(key, null, _writeOptions);
 }
Esempio n. 22
0
        public byte[] this[byte[] key]
        {
            get
            {
                switch (_dbInstance)
                {
                case DbInstance.State:
                    Metrics.StateDbReads++;
                    break;

                case DbInstance.Storage:
                    Metrics.StorageDbReads++;
                    break;

                case DbInstance.BlockInfo:
                    Metrics.BlockInfosDbReads++;
                    break;

                case DbInstance.Block:
                    Metrics.BlocksDbReads++;
                    break;

                case DbInstance.Code:
                    Metrics.CodeDbReads++;
                    break;

                case DbInstance.Receipts:
                    Metrics.ReceiptsDbReads++;
                    break;

                case DbInstance.Other:
                    Metrics.OtherDbReads++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (_currentBatch != null)
                {
                    throw new NotSupportedException("Index not needed, am I right?");
                    //return _currentBatch.Get(key);
                }

                return(_db.Get(key));
            }
            set
            {
                switch (_dbInstance)
                {
                case DbInstance.State:
                    Metrics.StateDbWrites++;
                    break;

                case DbInstance.Storage:
                    Metrics.StorageDbWrites++;
                    break;

                case DbInstance.BlockInfo:
                    Metrics.BlockInfosDbWrites++;
                    break;

                case DbInstance.Block:
                    Metrics.BlocksDbWrites++;
                    break;

                case DbInstance.Code:
                    Metrics.CodeDbWrites++;
                    break;

                case DbInstance.Receipts:
                    Metrics.ReceiptsDbWrites++;
                    break;

                case DbInstance.Other:
                    Metrics.OtherDbWrites++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (_currentBatch != null)
                {
                    if (value == null)
                    {
                        _currentBatch.Delete(key);
                    }
                    else
                    {
                        _currentBatch.Put(key, value);
                    }
                }
                else
                {
                    if (value == null)
                    {
                        _db.Remove(key);
                    }
                    else
                    {
                        _db.Put(key, value);
                    }
                }
            }
        }
Esempio n. 23
0
 //Remove
 public void Remove(string txid, int n)
 {
     db.Remove(txid + n);
 }
Esempio n. 24
0
 public void Delete(byte[] key)
 {
     _keyValueDb.Remove(key);
 }
Esempio n. 25
0
 public void Delete(byte table, byte[] key)
 {
     db.Remove(key ?? Array.Empty <byte>(), GetFamily(table), Options.WriteDefault);
 }
Esempio n. 26
0
 /// <inheritdoc cref="BaseStore.DeleteTxIdBlockHashIndex(TxId, BlockHash)"/>
 public override void DeleteTxIdBlockHashIndex(TxId txId, BlockHash blockHash)
 {
     _txIdBlockHashIndexDb.Remove(
         TxIdBlockHashIndexKey(txId, blockHash)
         );
 }
Esempio n. 27
0
 private void Remove_Internal(byte[] key)
 {
     _db.Remove(key, cf: GetPartition());
 }
Esempio n. 28
0
 public void Delete(byte table, byte[] key)
 {
     db.Remove(key, GetFamily(table), Options.WriteDefault);
 }
Esempio n. 29
0
 public void Delete(byte[] key)
 {
     db.Remove(key);
 }
Esempio n. 30
0
        public byte[] this[byte[] key]
        {
            get
            {
                switch (_dbInstance)
                {
                case DbInstance.State:
                    Metrics.StateDbReads++;
                    break;

                case DbInstance.BlockInfos:
                    Metrics.BlockInfosDbReads++;
                    break;

                case DbInstance.Blocks:
                    Metrics.BlocksDbReads++;
                    break;

                case DbInstance.Code:
                    Metrics.CodeDbReads++;
                    break;

                case DbInstance.Receipts:
                    Metrics.ReceiptsDbReads++;
                    break;

                case DbInstance.PendingTxs:
                    Metrics.PendingTxsDbReads++;
                    break;

                case DbInstance.Trace:
                    Metrics.TraceDbReads++;
                    break;

                case DbInstance.Other:
                    Metrics.OtherDbReads++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                return(_db.Get(key));
            }
            set
            {
                switch (_dbInstance)
                {
                case DbInstance.State:
                    Metrics.StateDbWrites++;
                    break;

                case DbInstance.BlockInfos:
                    Metrics.BlockInfosDbWrites++;
                    break;

                case DbInstance.Blocks:
                    Metrics.BlocksDbWrites++;
                    break;

                case DbInstance.Code:
                    Metrics.CodeDbWrites++;
                    break;

                case DbInstance.Receipts:
                    Metrics.ReceiptsDbWrites++;
                    break;

                case DbInstance.PendingTxs:
                    Metrics.PendingTxsDbWrites++;
                    break;

                case DbInstance.Trace:
                    Metrics.TraceDbWrites++;
                    break;

                case DbInstance.Other:
                    Metrics.OtherDbWrites++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (_currentBatch != null)
                {
                    if (value == null)
                    {
                        _currentBatch.Delete(key);
                    }
                    else
                    {
                        _currentBatch.Put(key, value);
                    }
                }
                else
                {
                    if (value == null)
                    {
                        _db.Remove(key);
                    }
                    else
                    {
                        _db.Put(key, value);
                    }
                }
            }
        }