Esempio n. 1
0
        /// <summary>
        /// Remove from in-memory blocks the block referenced
        /// by DataAddress.
        /// NOTE: this function is invoked when Rolling back changes
        /// </summary>
        /// <param name="dataAddress"></param>
        /// <param name="transaction"> </param>
        internal virtual bool RemoveInMemory(long dataAddress,
                                             Transaction.ITransactionLogger transaction)
        {
            //** current block
            if (currentDataBlock != null &&
                (currentDataBlock.DataAddress == -1 || currentDataBlock.IsBlockOfThis(dataAddress)))
            {
                currentEntry             = currentDataBlock = null;
                _currentEntryDataAddress = -1;
            }
            //** MRU
            RemoveFromCache(transaction);

            if (DataBlockDriver.HeaderData.RecycledSegment != null)
            {
                if (dataAddress >= DataBlockDriver.HeaderData.RecycledSegment.StartBlockAddress &&
                    dataAddress <= (DataBlockDriver.HeaderData.RecycledSegment.StartBlockAddress +
                                    DataBlockDriver.HeaderData.RecycledSegment.Count * (int)DataBlockSize))
                {
                    DataBlockDriver.HeaderData.RecycledSegment = null;
                }
            }

            //** take care of deleted blocks list...
            if (deletedBlocks is CollectionOnDisk)
            {
                ((CollectionOnDisk)deletedBlocks).RemoveInMemory(dataAddress, transaction);
            }

            //** Header and DiskBuffer
            return(DiskBuffer.DataAddress == -1 ||
                   DiskBuffer.IsBlockOfThis(dataAddress) ||
                   HeaderData.DiskBuffer.DataAddress == -1 ||
                   HeaderData.DiskBuffer.IsBlockOfThis(dataAddress));
        }
Esempio n. 2
0
        public object Clone()
        {
            var r = new HeaderData
            {
                _count                    = _count,
                _isDirty                  = _isDirty,
                DataBlockSize             = DataBlockSize,
                DiskBuffer                = (Sop.DataBlock)DiskBuffer.Clone(),
                EndAllocatableAddress     = EndAllocatableAddress,
                HintSizeOnDisk            = HintSizeOnDisk,
                IsModifiedInTransaction   = IsModifiedInTransaction,
                NextAllocatableAddress    = NextAllocatableAddress,
                OccupiedBlocksHead        = (Sop.DataBlock)OccupiedBlocksHead.Clone(),
                OccupiedBlocksTail        = (Sop.DataBlock)OccupiedBlocksTail.Clone(),
                OnDiskLeftoverSegmentSize = OnDiskLeftoverSegmentSize,
                StartAllocatableAddress   = StartAllocatableAddress
            };

            if (RecycledSegment != null)
            {
                r.RecycledSegment = (DeletedBlockInfo)RecycledSegment.Clone();
            }
            if (RecycledSegmentBeforeTransaction != null)
            {
                r.RecycledSegmentBeforeTransaction = (DeletedBlockInfo)RecycledSegmentBeforeTransaction.Clone();
            }
            return(r);
        }
Esempio n. 3
0
        public object Clone()
        {
            DeletedBlockInfo r = new DeletedBlockInfo();

            r.Count             = Count;
            r.StartBlockAddress = StartBlockAddress;
            r.IsDirty           = IsDirty;
            r.HintSizeOnDisk    = HintSizeOnDisk;
            r.EndBlockAddress   = EndBlockAddress;
            if (DiskBuffer != null)
            {
                r.DiskBuffer = (Sop.DataBlock)DiskBuffer.Clone();
            }
            return(r);
        }
Esempio n. 4
0
        protected EditorViewModel(IEditorDocument document, IEditorBuffer viewBuffer = null)
        {
            Check.ArgumentNull(nameof(document), document);

            DiskBuffer = document.EditorBuffer;
            DiskBuffer.AddService(this);

            ViewBuffer = viewBuffer ?? DiskBuffer;
            if (viewBuffer != null)
            {
                ViewBuffer.AddService(this);
            }

            _document = document;
        }
Esempio n. 5
0
        /// <summary>
        /// Register current collection's state
        /// </summary>
        public virtual void RegisterChange(bool partialRegister = false)
        {
            IsDirty = true;
            _registerCallCount++;
            if (_registerCallCount == 1)
            {
                if (DiskBuffer == null)
                {
                    throw new InvalidOperationException("'DiskBuffer' is null.");
                }

                bool stateSerialized = false;
                if (!partialRegister || DiskBuffer.SizeOccupied == 0)
                {
                    stateSerialized = true;
                    DiskBuffer.ClearData();
                    OnDiskBinaryWriter.WriteObject(File, this, DiskBuffer);
                }
                if (!ChangeRegistry)
                {
                    _registerCallCount = 0;
                    if (!partialRegister || stateSerialized)
                    {
                        Blocks.Add(DataBlockDriver.GetId(DiskBuffer), DiskBuffer);  //90;
                    }
                    //DataBlockDriver.MruManager.Add(DataBlockDriver.GetId(DiskBuffer), DiskBuffer);
                }
                else
                {
                    DataBlockDriver.SetDiskBlock(this, DiskBuffer, true);
                    if (_registerCallCount > 1)
                    {
                        _registerCallCount = 0;
                        //IsDirty = true;
                        RegisterChange(partialRegister);
                    }
                    _registerCallCount = 0;
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Close the Collection
        /// </summary>
        public virtual void Close()
        {
            bool miscCollsClosed = false;

            if (IsOpen)
            {
                if (!IsCloned)
                {
                    OnCommit();
                }
                if (IsDirty && !IsCloned && DataAddress >= 0 && Count > 0)
                {
                    Flush();
                }
                if (deletedBlocks != null)
                {
                    deletedBlocks.Close();
                }
                miscCollsClosed = true;
                if (DataBlockDriver != null)
                {
                    if (!IsCloned)
                    {
                        //DataBlocksPool.RemoveFromPool(this.DataBlockDriver.MruManager);
                        //this.DataBlockDriver.MruManager.Clear();
                        DataBlockDriver.HeaderData.Clear();
                    }
                }
                if (Parent == null)
                {
                    if (OnDiskBinaryWriter != null)
                    {
                        OnDiskBinaryWriter.Close();
                        OnDiskBinaryWriter = null;
                    }
                    if (OnDiskBinaryReader != null)
                    {
                        OnDiskBinaryReader.Close();
                        OnDiskBinaryReader = null;
                    }
                }
                if (Blocks != null)
                {
                    Blocks.Clear();
                }
                currentDataBlock         = null;
                currentEntry             = null;
                _currentEntryDataAddress = -1;
                isOpen = false;
            }
            if (_fileStream != null)
            {
                _fileStream.Close();
                _fileStream = null;
            }
            if (!miscCollsClosed)
            {
                if (deletedBlocks != null)
                {
                    deletedBlocks.Close();
                }
            }
            if (_isUnloading)
            {
                _isUnloading = false;
            }
            long da = DiskBuffer.DataAddress;

            DiskBuffer.Initialize();
            DiskBuffer.DataAddress = da;
        }
Esempio n. 7
0
 public override string ToString()
 {
     return(DiskBuffer.ToString());
 }