Esempio n. 1
0
        public bool RemoveById(ByteBuffer keyBytes, bool throwWhenNotFound)
        {
            ResetKeyPrefix();
            if (_kvtr.Find(keyBytes) != FindResult.Exact)
            {
                if (throwWhenNotFound)
                {
                    throw new BTDBException("Not found record to delete.");
                }
                return(false);
            }
            var valueBytes = _kvtr.GetValue();

            _kvtr.EraseCurrent();

            if (_hasSecondaryIndexes)
            {
                RemoveSecondaryIndexes(keyBytes, valueBytes);
            }

            _relationInfo.FreeContent(_transaction, valueBytes);

            _modificationCounter.MarkModification();
            return(true);
        }
Esempio n. 2
0
        public void InternalDelete(object obj)
        {
            var o     = (IDBObject)obj;
            var oid   = o.Oid;
            var taken = false;

            try
            {
                _keyValueTrProtector.Start(ref taken);
                _keyValueTr.SetKeyPrefix(ObjectDB.AllObjectsPrefix);
                var key = new byte[PackUnpack.LengthVUInt(oid)];
                int ofs = 0;
                PackUnpack.PackVUInt(key, ref ofs, oid);
                if (_keyValueTr.FindExactKey(key))
                {
                    _keyValueTr.EraseCurrent();
                }
            }
            finally
            {
                if (taken)
                {
                    _keyValueTrProtector.Stop();
                }
            }
            _objCache.TryRemove(oid);
            _dirtyObjSet.TryRemove(oid);
        }
Esempio n. 3
0
        public bool Remove(TKey key)
        {
            var keyBytes = KeyToByteArray(key);

            _modificationCounter++;
            if (_keyValueTr.EraseCurrent(keyBytes))
            {
                NotifyRemoved();
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        public bool Remove(TKey key)
        {
            var keyBytes = KeyToByteArray(key);

            _keyValueTrProtector.Start();
            _modificationCounter++;
            _keyValueTr.SetKeyPrefix(_prefix);
            if (_keyValueTr.Find(keyBytes) != FindResult.Exact)
            {
                return(false);
            }
            _keyValueTr.EraseCurrent();
            NotifyRemoved();
            return(true);
        }
Esempio n. 5
0
        public bool Remove(TKey key)
        {
            var keyBytes = KeyToByteArray(key);

            _keyValueTrProtector.Start();
            _modificationCounter++;
            _keyValueTr.SetKeyPrefix(_prefix);
            var found = _keyValueTr.FindExactKey(keyBytes);

            if (found)
            {
                _keyValueTr.EraseCurrent();
                NotifyRemoved();
            }
            return(found);
        }
Esempio n. 6
0
        public void Delete(object @object)
        {
            if (@object == null)
            {
                throw new ArgumentNullException(nameof(@object));
            }
            var indirect = @object as IIndirect;

            if (indirect != null)
            {
                if (indirect.Oid != 0)
                {
                    Delete(indirect.Oid);
                    return;
                }
                Delete(indirect.ValueAsObject);
                return;
            }
            var tableInfo = AutoRegisterType(@object.GetType());
            DBObjectMetadata metadata;

            if (_objSmallMetadata != null)
            {
                if (!_objSmallMetadata.TryGetValue(@object, out metadata))
                {
                    _objSmallMetadata.Add(@object, new DBObjectMetadata(0, DBObjectState.Deleted));
                    return;
                }
            }
            else if (_objBigMetadata != null)
            {
                if (!_objBigMetadata.TryGetValue(@object, out metadata))
                {
                    _objBigMetadata.Add(@object, new DBObjectMetadata(0, DBObjectState.Deleted));
                    return;
                }
            }
            else
            {
                return;
            }
            if (metadata.Id == 0 || metadata.State == DBObjectState.Deleted)
            {
                return;
            }
            metadata.State = DBObjectState.Deleted;
            _keyValueTrProtector.Start();
            _keyValueTr.SetKeyPrefix(ObjectDB.AllObjectsPrefix);
            if (_keyValueTr.FindExactKey(BuildKeyFromOid(metadata.Id)))
            {
                _keyValueTr.EraseCurrent();
            }
            tableInfo.CacheSingletonContent(_transactionNumber + 1, null);
            if (_objSmallCache != null)
            {
                _objSmallCache.Remove(metadata.Id);
            }
            else
            {
                _objBigCache?.Remove(metadata.Id);
            }
            _dirtyObjSet?.Remove(metadata.Id);
        }
Esempio n. 7
0
 public void EraseCurrent()
 {
     LogSimpleOperation(KVReplayOperation.EraseCurrent);
     _tr.EraseCurrent();
 }
 public void EraseCurrent()
 {
     EraseCurrentCount++;
     _keyValueDBTransaction.EraseCurrent();
 }
Esempio n. 9
0
        void DoRandomWork()
        {
            var opCounter = 0;
            var random    = new Random();

            using (var stream = CreateTestStream())
                //using (IKeyValueDB db = new KeyValueDBReplayProxy(new KeyValueDB(), new PositionLessStreamWriter(new PositionLessStreamProxy("btdb.log"))))
                using (IKeyValueDB db = new KeyValueDB())
                {
                    db.Open(stream, false);
                    IKeyValueDBTransaction tr = db.StartTransaction();
                    while (opCounter < 100000)
                    {
                        if (opCounter % 1000 == 0)
                        {
                            Console.WriteLine(string.Format("Operation {0}", opCounter));
                            Console.WriteLine(tr.CalculateStats().ToString());
                        }
                        opCounter++;
                        var action = random.Next(100);
                        if (action < 10)
                        {
                            if (action > 1)
                            {
                                //Console.WriteLine("Commit");
                                tr.Commit();
                            }
                            else
                            {
                                //Console.WriteLine("Rollback");
                            }
                            tr.Dispose();
                            tr = db.StartTransaction();
                        }
                        else if (action < 50 || tr.GetKeyIndex() < 0)
                        {
                            var key = new byte[random.Next(1, 1000)];
                            random.NextBytes(key);
                            //Console.WriteLine(string.Format("CreateKey {0}", key.Length));
                            tr.CreateKey(key);
                        }
                        else if (action < 60)
                        {
                            //Console.WriteLine("EraseCurrent");
                            tr.EraseCurrent();
                        }
                        else if (action < 65)
                        {
                            //Console.WriteLine("FindNextKey");
                            tr.FindNextKey();
                        }
                        else if (action < 70)
                        {
                            //Console.WriteLine("FindPreviousKey");
                            tr.FindPreviousKey();
                        }
                        else
                        {
                            var value = new byte[random.Next(1, 100000)];
                            random.NextBytes(value);
                            //Console.WriteLine(string.Format("SetValue {0}", value.Length));
                            tr.SetValue(value);
                        }
                    }
                    tr.Dispose();
                }
        }