private void RemoveMessageFromStorage(LightningTransaction tx, string queueName, params Message[] messages)
        {
            var db = OpenDatabase(tx, queueName);

            foreach (var message in messages)
            {
                tx.Delete(db, message.Id.MessageIdentifier.ToByteArray());
            }
        }
Exemple #2
0
 private void DeleteImpl(IEnumerable <TKey> keys)
 {
     foreach (var key in keys.Select(_settings.SerializeKey))
     {
         if (_tx.ContainsKey(_db, key))
         {
             _tx.Delete(_db, key);
         }
     }
 }
        public void DatabaseDeleteShouldRemoveItem()
        {
            var key   = "key";
            var value = "value";

            _txn.Put(_db, key, value);

            _txn.Delete(_db, key);

            Assert.False(_txn.ContainsKey(_db, key));
        }
Exemple #4
0
 public static void TryDelete(this LightningTransaction tx, LightningDatabase db, byte[] key)
 {
     try {
         tx.Delete(db, key);
     } catch (LightningException ex) {
         if (ex.StatusCode != Lmdb.MDB_NOTFOUND)
         {
             throw;
         }
     }
 }
Exemple #5
0
        public void DatabaseDeleteShouldRemoveItem()
        {
            //arrange
            var key   = "key";
            var value = "value";

            _txn.Put(_db, key, value);

            //act
            _txn.Delete(_db, key);

            //assert
            Assert.IsFalse(_txn.ContainsKey(_db, key));
        }
        public StorageResult <TValue> DeleteDocument <TKey, TValue>(ITransaction transaction, string collection, TKey key)
        {
            StorageResult <TValue> result = new StorageResult <TValue>();

            if (string.IsNullOrEmpty(collection))
            {
                throw new ArgumentException("Collection name can not be null or empty.");
            }

            if (!CollectionExists(collection))
            {
                throw new ArgumentException("Specified collection not found in " + GetFileInfo() + " Collection = " + collection);
            }

            ValidateTransaction(transaction);
            LightningTransaction lmdbTransaction = (LightningTransaction)transaction.InnerObject;

            byte[] keyBytes   = _environment.ConverterStore.GetToBytes <TKey>().Convert(_collectionTable[collection].Collection, key);
            byte[] valueBytes = lmdbTransaction.Get(_collectionTable[collection].Collection, keyBytes);

            long size = CaclulateSize(keyBytes, valueBytes);

            result.Document = _environment.ConverterStore.GetFromBytes <TValue>().Convert(_collectionTable[collection].Collection, valueBytes);
            try
            {
                lmdbTransaction.Delete(_collectionTable[collection].Collection, keyBytes);
                ((LMDBTransaction)transaction).ChangeSize(-size);
                _collectionTable[collection].DecrementTemporaryStats(size);

                result.Status = StoreResult.Success;
                return(result);
            }
            catch (LightningException le)
            {
                //todo temp fix consider success if doc not found
                if (le.StatusCode == LMDBErrorCodes.MDB_NOTFOUND)
                {
                    if (LoggerManager.Instance.StorageLogger != null && LoggerManager.Instance.StorageLogger.IsWarnEnabled)
                    {
                        LoggerManager.Instance.StorageLogger.Warn("LMDB.DeleteDocument", "Error Deleting Document." + GetFileInfo() + le);
                    }
                    result.Status = StoreResult.Success;
                    return(result);
                }
                result.Status = HandleException(le);
                return(result);
            }
        }
 private void MoveToQueue(LightningTransaction tx, string queueName, Message message)
 {
     try
     {
         var idBytes  = message.Id.MessageIdentifier.ToByteArray();
         var original = OpenDatabase(tx, message.Queue);
         var newDb    = OpenDatabase(tx, queueName);
         tx.Delete(original, idBytes).ThrowOnError();
         tx.Put(newDb, idBytes, message.Serialize()).ThrowOnError();
     }
     catch (LightningException ex)
     {
         tx.Dispose();
         if (ex.StatusCode == (int)MDBResultCode.NotFound)
         {
             throw new QueueDoesNotExistException("Queue doesn't exist", ex);
         }
         throw;
     }
 }
Exemple #8
0
 public void Delete(byte[] key)
 {
     _tx.Delete(_db, key);
 }
Exemple #9
0
        public static void Delete(this LightningTransaction tx, LightningDatabase db, string key)
        {
            var enc = System.Text.Encoding.UTF8;

            tx.Delete(db, enc.GetBytes(key));
        }