public override void ApplySlotChanges(IVisitable slotChangeTree, int slotChangeCount
     , Slot reservedSlot)
 {
     if (slotChangeCount > 0)
     {
         var transactionLogSlot = SlotLongEnoughForLog(slotChangeCount, reservedSlot)
             ? reservedSlot
             : AllocateSlot(true, slotChangeCount);
         var buffer = new StatefulBuffer(_container.SystemTransaction(), transactionLogSlot
             );
         buffer.WriteInt(transactionLogSlot.Length());
         buffer.WriteInt(slotChangeCount);
         AppendSlotChanges(buffer, slotChangeTree);
         buffer.Write();
         var commitHook = _container.CommitHook();
         FlushDatabaseFile();
         _container.WriteTransactionPointer(transactionLogSlot.Address());
         FlushDatabaseFile();
         if (WriteSlots(slotChangeTree))
         {
             FlushDatabaseFile();
         }
         _container.WriteTransactionPointer(0);
         commitHook.Run();
         FlushDatabaseFile();
         if (transactionLogSlot != reservedSlot)
         {
             FreeSlot(transactionLogSlot);
         }
     }
     FreeSlot(reservedSlot);
 }
Esempio n. 2
0
 // _key, _slot._address, _slot._length 
 public override object Read(ByteArrayBuffer buffer)
 {
     var id = buffer.ReadInt();
     var slot = new Slot
         (buffer.ReadInt(), buffer.ReadInt());
     return new IdSlotTree(id, slot);
 }
        private long IdSystemUsage()
        {
            IIdSystem idSystem = _db.IdSystem();
            long      usage    = 0;

            while (idSystem is BTreeIdSystem)
            {
                IIdSystem parentIdSystem = ((IIdSystem)FieldValue(idSystem, "_parentIdSystem"));
                usage += BTreeUsage(_db.SystemTransaction(), parentIdSystem, (BTree)FieldValue(idSystem
                                                                                               , "_bTree"), _slots);
                PersistentIntegerArray persistentState = (PersistentIntegerArray)FieldValue(idSystem
                                                                                            , "_persistentState");
                int persistentStateId = persistentState.GetID();
                Db4objects.Db4o.Internal.Slots.Slot persistentStateSlot = parentIdSystem.CommittedSlot
                                                                              (persistentStateId);
                _slots.Add(persistentStateSlot);
                usage   += persistentStateSlot.Length();
                idSystem = parentIdSystem;
            }
            if (idSystem is InMemoryIdSystem)
            {
                Db4objects.Db4o.Internal.Slots.Slot idSystemSlot = ((Db4objects.Db4o.Internal.Slots.Slot
                                                                     )FieldValue(idSystem, "_slot"));
                usage += idSystemSlot.Length();
                _slots.Add(idSystemSlot);
            }
            return(usage);
        }
Esempio n. 4
0
 /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
 private DatabaseIdentityIDAndUUID ReadDatabaseIdentityIDAndUUID
     (ObjectContainerBase container, ClassMetadata classMetadata, Slot oldSlot, bool
         checkClass)
 {
     if (DTrace.enabled)
     {
         DTrace.RereadOldUuid.LogLength(oldSlot.Address(), oldSlot.Length());
     }
     var reader = container.DecryptedBufferByAddress(oldSlot.Address(), oldSlot
         .Length());
     if (checkClass)
     {
         var realClass = ClassMetadata.ReadClass(container, reader);
         if (realClass != classMetadata)
         {
             return null;
         }
     }
     if (classMetadata.SeekToField(container.Transaction, reader, this) == HandlerVersion
         .Invalid)
     {
         return null;
     }
     return new DatabaseIdentityIDAndUUID(reader.ReadInt(), reader.ReadLong
         ());
 }
Esempio n. 5
0
 public void Apply(object idSlot)
 {
     Db4objects.Db4o.Internal.Slots.Slot slot = ((Db4objects.Db4o.Internal.Slots.Slot)
                                                     ((Pair)idSlot).second);
     usage.value += slot.Length();
     this._enclosing._slots.Add(slot);
 }
Esempio n. 6
0
 public virtual void SlotFreed(Slot slot)
 {
     if (_slotFreedCallback == null)
     {
         return;
     }
     _slotFreedCallback.Apply(slot);
 }
		public virtual void TestAllocateSlot()
		{
			Slot slot = new Slot(1, 15);
			_nonBlocked.Free(slot);
			Slot allocatedSlot = _nonBlocked.AllocateSlot(8);
			int expectedAllocatedSlotLength = _blockConverter.BlockAlignedBytes(8);
			Slot expectedSlot = new Slot(1, expectedAllocatedSlotLength);
			Assert.AreEqual(expectedSlot, allocatedSlot);
		}
Esempio n. 8
0
 public override ByteArrayBuffer GetByteLoad()
 {
     var address = _payLoad.ReadInt();
     var length = _payLoad.Length() - (Const4.IntLength);
     var slot = new Slot(address, length);
     _payLoad.RemoveFirstBytes(Const4.IntLength);
     _payLoad.UseSlot(slot);
     return _payLoad;
 }
Esempio n. 9
0
		// do nothing
		public override void Free(Slot slot)
		{
			int address = slot.Address();
			if (address <= 0)
			{
				throw new ArgumentException();
			}
			int length = slot.Length();
			if (DTrace.enabled)
			{
				DTrace.FreespacemanagerRamFree.LogLength(address, length);
			}
			_finder._key = address;
			FreeSlotNode sizeNode;
			FreeSlotNode addressnode = (FreeSlotNode)Tree.FindSmaller(_freeByAddress, _finder
				);
			if ((addressnode != null) && ((addressnode._key + addressnode._peer._key) == address
				))
			{
				sizeNode = addressnode._peer;
				RemoveFromFreeBySize(sizeNode);
				sizeNode._key += length;
				FreeSlotNode secondAddressNode = (FreeSlotNode)Tree.FindGreaterOrEqual(_freeByAddress
					, _finder);
				if ((secondAddressNode != null) && (address + length == secondAddressNode._key))
				{
					sizeNode._key += secondAddressNode._peer._key;
					RemoveFromBothTrees(secondAddressNode._peer);
				}
				sizeNode.RemoveChildren();
				AddToFreeBySize(sizeNode);
			}
			else
			{
				addressnode = (FreeSlotNode)Tree.FindGreaterOrEqual(_freeByAddress, _finder);
				if ((addressnode != null) && (address + length == addressnode._key))
				{
					sizeNode = addressnode._peer;
					RemoveFromBothTrees(sizeNode);
					sizeNode._key += length;
					addressnode._key = address;
					addressnode.RemoveChildren();
					sizeNode.RemoveChildren();
					_freeByAddress = Tree.Add(_freeByAddress, addressnode);
					AddToFreeBySize(sizeNode);
				}
				else
				{
					if (CanDiscard(length))
					{
						return;
					}
					AddFreeSlotNodes(address, length);
				}
			}
			SlotFreed(slot);
		}
Esempio n. 10
0
		private bool HandledAsReAdd(Slot slot)
		{
			if (!Slot.IsNull(slot))
			{
				return false;
			}
			_clazz.AddToIndex(_transaction, _id);
			return true;
		}
Esempio n. 11
0
		public sealed override ByteArrayBuffer GetByteLoad()
		{
			int address = _payLoad.ReadInt();
			int length = _payLoad.Length() - (Const4.IntLength);
			Slot slot = new Slot(address, length);
			_payLoad.RemoveFirstBytes(Const4.IntLength);
			_payLoad.UseSlot(slot);
			return this._payLoad;
		}
Esempio n. 12
0
 public void UseSlot(Db4objects.Db4o.Internal.Slots.Slot slot)
 {
     _address = slot.Address();
     _offset  = 0;
     if (slot.Length() > _buffer.Length)
     {
         _buffer = new byte[slot.Length()];
     }
     _length = slot.Length();
 }
Esempio n. 13
0
		public virtual void TestIndexMarshalling()
		{
			ByteArrayBuffer reader = new ByteArrayBuffer(2 * Const4.IntLength);
			Slot original = new Slot(unchecked((int)(0xdb)), unchecked((int)(0x40)));
			StringHandler().WriteIndexEntry(Context(), reader, original);
			reader._offset = 0;
			Slot retrieved = (Slot)StringHandler().ReadIndexEntry(Context(), reader);
			Assert.AreEqual(original.Address(), retrieved.Address());
			Assert.AreEqual(original.Length(), retrieved.Length());
		}
Esempio n. 14
0
 public virtual void TestToNonBlockedLength()
 {
     int[] blocks = {0, 1, 8, 9};
     int[] bytes = {0, 8, 64, 72};
     for (var i = 0; i < blocks.Length; i++)
     {
         var blockedSlot = new Slot(0, blocks[i]);
         var byteSlot = new Slot(0, bytes[i]);
         Assert.AreEqual(byteSlot, blockConverter.ToNonBlockedLength(blockedSlot));
     }
 }
Esempio n. 15
0
 public virtual void TestToBlockedLength()
 {
     int[] bytes = {0, 1, 2, 7, 8, 9, 16, 17, 799, 800, 801};
     int[] blocks = {0, 1, 1, 1, 1, 2, 2, 3, 100, 100, 101};
     for (var i = 0; i < bytes.Length; i++)
     {
         var byteSlot = new Slot(0, bytes[i]);
         var blockedSlot = new Slot(0, blocks[i]);
         Assert.AreEqual(blockedSlot, blockConverter.ToBlockedLength(byteSlot));
     }
 }
Esempio n. 16
0
 public virtual void DelayedFree(Slot slot, bool freeToSystemFreeSpaceSystem)
 {
     if (freeToSystemFreeSpaceSystem)
     {
         _freeToSystemFreespaceSystem.Add(slot);
     }
     else
     {
         _freeToUserFreespaceSystem.Add(slot);
     }
 }
		private void AssertAllocateSlot(int freeSlotSize, int requiredSlotSize, int expectedSlotSize
			)
		{
			Slot slot = new Slot(1, freeSlotSize);
			_nonBlocked.Free(slot);
			Slot allocatedSlot = _nonBlocked.AllocateSlot(requiredSlotSize);
			int expectedAllocatedSlotLength = _blockConverter.BlockAlignedBytes(expectedSlotSize
				);
			Slot expectedSlot = new Slot(1, expectedAllocatedSlotLength);
			Assert.AreEqual(expectedSlot, allocatedSlot);
		}
Esempio n. 18
0
		private void ReadThis()
		{
			SystemData systemData = _container.SystemData();
			_slot = systemData.IdSystemSlot();
			if (!Slot.IsNull(_slot))
			{
				ByteArrayBuffer buffer = _container.ReadBufferBySlot(_slot);
				_childId = buffer.ReadInt();
				_idGenerator.Read(buffer);
				_ids = (IdSlotTree)new TreeReader(buffer, new IdSlotTree(0, null)).Read();
			}
		}
 private void FreeSlot(Slot slot)
 {
     if (slot == null)
     {
         return;
     }
     if (_container.FreespaceManager() == null)
     {
         return;
     }
     _container.FreespaceManager().FreeSafeSlot(slot);
 }
Esempio n. 20
0
		protected override void Free(IFreespaceManager freespaceManager, Slot slot)
		{
			if (slot.IsNull())
			{
				return;
			}
			if (_freed == null)
			{
				_freed = new Collection4();
			}
			_freed.Add(slot);
		}
Esempio n. 21
0
 public virtual Tree Free(LocalObjectContainer file, Tree treeRoot, Slot
     slot)
 {
     file.Free(_slot.Address(), _slot.Length());
     if (RemoveReferenceIsLast())
     {
         if (treeRoot != null)
         {
             return treeRoot.RemoveNode(this);
         }
     }
     PointTo(slot);
     return treeRoot;
 }
Esempio n. 22
0
        private long ClassMetadataUsage()
        {
            Db4objects.Db4o.Internal.Slots.Slot classRepositorySlot = Slot(_db.ClassCollection
                                                                               ().GetID());
            _slots.Add(classRepositorySlot);
            long        usage       = classRepositorySlot.Length();
            IEnumerator classIdIter = _db.ClassCollection().Ids();

            while (classIdIter.MoveNext())
            {
                int curClassId = (((int)classIdIter.Current));
                Db4objects.Db4o.Internal.Slots.Slot classSlot = Slot(curClassId);
                _slots.Add(classSlot);
                usage += classSlot.Length();
            }
            return(usage);
        }
Esempio n. 23
0
        private static long BTreeUsage(Transaction transaction, IIdSystem idSystem, BTree
                                       btree, ISlotMap slotMap)
        {
            IEnumerator nodeIter = btree.AllNodeIds(transaction);

            Db4objects.Db4o.Internal.Slots.Slot btreeSlot = idSystem.CommittedSlot(btree.GetID
                                                                                       ());
            slotMap.Add(btreeSlot);
            long usage = btreeSlot.Length();

            while (nodeIter.MoveNext())
            {
                int curNodeId = ((int)nodeIter.Current);
                Db4objects.Db4o.Internal.Slots.Slot slot = idSystem.CommittedSlot(curNodeId);
                slotMap.Add(slot);
                usage += slot.Length();
            }
            return(usage);
        }
Esempio n. 24
0
		public SlotDetail(Slot slot)
		{
			this._slot = slot;
		}
Esempio n. 25
0
		public virtual void NotifyDeleted(IFreespaceManager freespaceManager)
		{
			if (DTrace.enabled)
			{
				DTrace.NotifySlotDeleted.Log(_key);
			}
			Operation(SlotChange.SlotChangeOperation.delete);
			FreePreviouslyModifiedSlot(freespaceManager);
			_newSlot = Slot.Zero;
		}
Esempio n. 26
0
		public virtual void NotifySlotCreated(Slot slot)
		{
			if (DTrace.enabled)
			{
				DTrace.NotifySlotCreated.Log(_key);
				DTrace.NotifySlotCreated.LogLength(slot);
			}
			Operation(SlotChange.SlotChangeOperation.create);
			_newSlot = slot;
		}
Esempio n. 27
0
		protected virtual void Free(IFreespaceManager freespaceManager, Slot slot)
		{
			if (slot.IsNull())
			{
				return;
			}
			if (freespaceManager == null)
			{
				return;
			}
			freespaceManager.Free(slot);
		}
Esempio n. 28
0
		protected virtual void FreePreviouslyModifiedSlot(IFreespaceManager freespaceManager
			)
		{
			if (Slot.IsNull(_newSlot))
			{
				return;
			}
			Free(freespaceManager, _newSlot);
			_newSlot = null;
		}
Esempio n. 29
0
		public virtual void NotifySlotUpdated(IFreespaceManager freespaceManager, Slot slot
			)
		{
			if (DTrace.enabled)
			{
				DTrace.NotifySlotUpdated.LogLength(_key, slot);
			}
			FreePreviouslyModifiedSlot(freespaceManager);
			_newSlot = slot;
			Operation(SlotChange.SlotChangeOperation.update);
		}
Esempio n. 30
0
		public override object Read(ByteArrayBuffer reader)
		{
			SlotChange change = new SlotChange(reader.ReadInt());
			Slot newSlot = new Slot(reader.ReadInt(), reader.ReadInt());
			change.NewSlot(newSlot);
			return change;
		}
		public virtual void SlotFreed(Slot slot)
		{
		}
		public virtual void Free(Slot slot)
		{
			_listener.OnFree(slot);
		}
Esempio n. 33
0
 public Pointer4(int id, Slot slot)
 {
     _id   = id;
     _slot = slot;
 }
Esempio n. 34
0
 public StatefulBuffer(Db4objects.Db4o.Internal.Transaction trans, Db4objects.Db4o.Internal.Slots.Slot
                       slot) : this(trans, slot.Address(), slot.Length())
 {
 }
Esempio n. 35
0
		public abstract void ApplySlotChanges(IVisitable slotChangeTree, int slotChangeCount
			, Slot reservedSlot);
Esempio n. 36
0
			private bool IsValid(Slot slot)
			{
				return !Slot.IsNull(slot);
			}
Esempio n. 37
0
		private void NewSlot(Slot slot)
		{
			_newSlot = slot;
		}