public void ReadBlockFromDisk(Algorithm.Collection.ICollectionOnDisk parent, List <Algorithm.BTree.BTreeItemOnDisk> items, System.Func <int, bool> readCallback) { var sortedBlocks = new Sop.Collections.Generic.SortedDictionary <long, int>(); var dataSegments = new Sop.Collections.Generic.SortedDictionary <long, long>(); for (int i = 0; i < items.Count; i++) { var address = GetId(items[i].Value.DiskBuffer); sortedBlocks.Add(address, i); } dataSegments.Clear(); //detect contiguous blocks & read these data blocks as a bigger segment for optimal reading. KeyValuePair <long, int> lastEntry; List <KeyValuePair <long, int> > blockAddresses = new List <KeyValuePair <long, int> >(); foreach (var entry in sortedBlocks) { lastEntry = entry; var address = entry.Key; blockAddresses.Add(entry); if (!Algorithm.BTree.IndexedBlockRecycler.DetectAndMerge(dataSegments, address, items[entry.Value].Value.DiskBuffer.contiguousBlockCount * (int)parent.DataBlockSize, MaxSegmentSize)) { _readAheadBuffer.Clear(); dataSegments.MoveFirst(); _readAheadBuffer.Read(parent.FileStream, dataSegments.CurrentKey, (int)dataSegments.CurrentValue); foreach (var addr in blockAddresses) { var rab = new DataBlockReadBufferLogic(_readAheadBuffer); var block = ReadBlockFromDisk(parent, addr.Key, false); items[addr.Value].Value.DiskBuffer = block; // process(deserialize the Object) the read blocks... readCallback(addr.Value); _readAheadBuffer = rab; } blockAddresses.Clear(); dataSegments.Clear(); dataSegments.Add(address, items[entry.Value].Value.DiskBuffer.contiguousBlockCount * (int)parent.DataBlockSize); } } // process last data segment... if (dataSegments.Count > 0) { _readAheadBuffer.Clear(); dataSegments.MoveFirst(); _readAheadBuffer.Read(parent.FileStream, dataSegments.CurrentKey, (int)dataSegments.CurrentValue); foreach (var addr in blockAddresses) { var rab = new DataBlockReadBufferLogic(_readAheadBuffer); var block = ReadBlockFromDisk(parent, addr.Key, false); items[addr.Value].Value.DiskBuffer = block; // process(deserialize the Object) the read blocks... readCallback(addr.Value); _readAheadBuffer = rab; } } }
public object Clone() { var r = new DataBlockReadBufferLogic { _readBufferSize = _readBufferSize, _readBufferDataAddress = _readBufferDataAddress }; if (_readBuffer == null) { return(r); } r._readBuffer = new byte[_readBuffer.Length]; _readBuffer.CopyTo(r._readBuffer, 0); return(r); }
public DataBlockReadBufferLogic(DataBlockReadBufferLogic source) { this._readBuffer = source._readBuffer; this._readBufferDataAddress = source._readBufferDataAddress; this._readBufferSize = source._readBufferSize; }