Ejemplo n.º 1
0
 private CachingBin.Page SyncReadPage(long startAddress)
 {
     CachingBin.Page page = new CachingBin.Page(_pageSize);
     LoadPage(page, startAddress);
     page.EnsureEndAddress(_fileLength);
     return(page);
 }
Ejemplo n.º 2
0
 private CachingBin.Page GetPage(long startAddress, IFunction4 producer)
 {
     CachingBin.Page page = ((CachingBin.Page)_cache.Produce(PageAddressFor(startAddress
                                                                            ), producer, _onDiscardPage));
     page.EnsureEndAddress(_fileLength);
     return(page);
 }
Ejemplo n.º 3
0
 /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
 private void FlushPage(CachingBin.Page page)
 {
     if (!page._dirty)
     {
         return;
     }
     WritePageToDisk(page);
 }
Ejemplo n.º 4
0
 /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
 protected virtual void FlushAllPages()
 {
     for (IEnumerator pIter = _cache.GetEnumerator(); pIter.MoveNext();)
     {
         CachingBin.Page p = ((CachingBin.Page)pIter.Current);
         FlushPage(p);
     }
 }
Ejemplo n.º 5
0
 public object Apply(object pageAddress)
 {
     // in case that page is not found in the cache
     CachingBin.Page newPage = ((CachingBin.Page) this._enclosing._pagePool.BorrowObject
                                    ());
     this._enclosing.ResetPageAddress(newPage, ((long)pageAddress));
     return(newPage);
 }
Ejemplo n.º 6
0
		private CachingBin.Page[] NewPagePool(int pageCount)
		{
			CachingBin.Page[] pages = new CachingBin.Page[pageCount];
			for (int i = 0; i < pages.Length; ++i)
			{
				pages[i] = new CachingBin.Page(_pageSize);
			}
			return pages;
		}
Ejemplo n.º 7
0
 private CachingBin.Page[] NewPagePool(int pageCount)
 {
     CachingBin.Page[] pages = new CachingBin.Page[pageCount];
     for (int i = 0; i < pages.Length; ++i)
     {
         pages[i] = new CachingBin.Page(_pageSize);
     }
     return(pages);
 }
Ejemplo n.º 8
0
		/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
		private void LoadPage(CachingBin.Page page, long pos)
		{
			long startAddress = pos - pos % _pageSize;
			page._startAddress = startAddress;
			int count = _bin.Read(page._startAddress, page._buffer, page._bufferSize);
			if (count > 0)
			{
				page._endAddress = startAddress + count;
			}
			else
			{
				page._endAddress = startAddress;
			}
		}
Ejemplo n.º 9
0
		/// <summary>Writes the buffer to cache using pages</summary>
		/// <param name="pos">start position to write</param>
		/// <param name="buffer">source buffer</param>
		/// <param name="length">how many bytes to write</param>
		/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
		public override void Write(long pos, byte[] buffer, int length)
		{
			long startAddress = pos;
			int bytesToWrite = length;
			int bufferOffset = 0;
			while (bytesToWrite > 0)
			{
				// page doesn't need to loadFromDisk if the whole page is dirty
				bool loadFromDisk = (bytesToWrite < _pageSize) || (startAddress % _pageSize != 0);
				CachingBin.Page page = GetPage(startAddress, loadFromDisk);
				int writtenBytes = page.Write(buffer, bufferOffset, startAddress, bytesToWrite);
				bytesToWrite -= writtenBytes;
				startAddress += writtenBytes;
				bufferOffset += writtenBytes;
			}
			long endAddress = startAddress;
			_fileLength = Math.Max(endAddress, _fileLength);
		}
Ejemplo n.º 10
0
		private int ReadInternal(long pos, byte[] buffer, int length, bool syncRead)
		{
			long startAddress = pos;
			int bytesToRead = length;
			int totalRead = 0;
			while (bytesToRead > 0)
			{
				CachingBin.Page page = syncRead ? SyncReadPage(startAddress) : GetPage(startAddress
					, _producerFromDisk);
				int readBytes = page.Read(buffer, totalRead, startAddress, bytesToRead);
				if (readBytes <= 0)
				{
					break;
				}
				bytesToRead -= readBytes;
				startAddress += readBytes;
				totalRead += readBytes;
			}
			return totalRead == 0 ? -1 : totalRead;
		}
Ejemplo n.º 11
0
		private CachingBin.Page SyncReadPage(long startAddress)
		{
			CachingBin.Page page = new CachingBin.Page(_pageSize);
			LoadPage(page, startAddress);
			page.EnsureEndAddress(_fileLength);
			return page;
		}
Ejemplo n.º 12
0
 /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
 private void WritePageToDisk(CachingBin.Page page)
 {
     base.Write(page._startAddress, page._buffer, page.Size());
     page._dirty = false;
 }
Ejemplo n.º 13
0
 private void ResetPageAddress(CachingBin.Page page, long startAddress)
 {
     page._startAddress = startAddress;
     page._endAddress   = startAddress + _pageSize;
 }