com.bigdata.journal
Class DiskBackedBufferStrategy

java.lang.Object
  extended by com.bigdata.rawstore.AbstractRawStore
      extended by com.bigdata.rawstore.AbstractRawWormStore
          extended by com.bigdata.journal.AbstractBufferStrategy
              extended by com.bigdata.journal.BasicBufferStrategy
                  extended by com.bigdata.journal.DiskBackedBufferStrategy
All Implemented Interfaces:
IBufferStrategy, IDiskBasedStrategy, IAddressManager, IMRMW, IMROW, IRawStore, IStoreSerializer, IWORM
Direct Known Subclasses:
DirectBufferStrategy, MappedBufferStrategy

public abstract class DiskBackedBufferStrategy
extends BasicBufferStrategy
implements IDiskBasedStrategy

Abstract base class for implementations that use a direct buffer as a write through cache to an image on the disk. This covers both the BufferMode.Direct, where we use explicit IO operations, and the BufferMode.Mapped, where we memory-map the image. Common features shared by these implementations deal mainly with initialization of a new disk image.

Version:
$Id: DiskBackedBufferStrategy.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
TODO:
write tests of the disk-only mode operations when overflowing an int32 extent., consider a read buffer that uses a weak value cache backed by an LRU hard reference cache, which in turn evicts buffers back to a pool for reuse. The pool would bin buffers by size, keep no more than some #of buffers of a given size, and offer a service to allocate buffers of no less than a given capacity. This might reduce heap churn by recycling buffers in addition to providing minimizing the need to hit the OS disk cache, the disk buffers, or the disk platter.

Field Summary
protected  IReopenChannel opener
          Used to re-open the FileChannel in this class.
 
Fields inherited from class com.bigdata.journal.BasicBufferStrategy
extent, userExtent
 
Fields inherited from class com.bigdata.journal.AbstractBufferStrategy
bufferMode, ERR_ADDRESS_IS_NULL, ERR_ADDRESS_NOT_WRITTEN, ERR_BAD_RECORD_SIZE, ERR_BUFFER_EMPTY, ERR_BUFFER_NULL, ERR_INT32, ERR_NOT_OPEN, ERR_READ_ONLY, ERR_RECORD_LENGTH_ZERO, ERR_TRUNCATE, initialExtent, log, maximumExtent, nextOffset, WARN
 
Fields inherited from class com.bigdata.rawstore.AbstractRawWormStore
am
 
Fields inherited from class com.bigdata.rawstore.AbstractRawStore
serializer
 
Fields inherited from interface com.bigdata.rawstore.IAddressManager
NULL
 
Method Summary
 void close()
          Closes the file.
 void deleteResources()
          Deletes the backing file(s) (if any) and clears any records for the store from the IGlobalLRU.
 void force(boolean metadata)
          Forces the data to disk.
 FileChannel getChannel()
          The channel used to read and write on the file.
 File getFile()
          The backing file.
 int getHeaderSize()
          The size of the file header in bytes.
 RandomAccessFile getRandomAccessFile()
          The object used to read and write on that file.
 boolean isStable()
          True iff backed by stable storage.
 ByteBuffer read(long addr)
          The backing file is fully buffered so it does not need to be open for a read to succeed.
 ByteBuffer readRootBlock(boolean rootBlock0)
          Read the specified root block from the backing file.
 long transferTo(RandomAccessFile out)
          Note: This is synchronized so that concurrent writers must block during this operation.
 void writeRootBlock(IRootBlockView rootBlock, ForceEnum forceOnCommit)
          Write the root block onto stable storage (ie, flush it through to disk).
 
Methods inherited from class com.bigdata.journal.BasicBufferStrategy
getBufferView, getCounters, getExtent, getUserExtent, truncate, write
 
Methods inherited from class com.bigdata.journal.AbstractBufferStrategy
assertOpen, closeForWrites, destroy, getBufferMode, getInitialExtent, getMaximumExtent, getNextOffset, getResourceMetadata, getUUID, isOpen, isReadOnly, overflow, size, transferFromDiskTo
 
Methods inherited from class com.bigdata.rawstore.AbstractRawWormStore
getAddressManager, getByteCount, getOffset, getOffsetBits, packAddr, toAddr, toString, unpackAddr
 
Methods inherited from class com.bigdata.rawstore.AbstractRawStore
deserialize, deserialize, deserialize, serialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.bigdata.journal.IBufferStrategy
closeForWrites, getBufferMode, getCounters, getExtent, getInitialExtent, getMaximumExtent, getNextOffset, getUserExtent, truncate
 
Methods inherited from interface com.bigdata.rawstore.IRawStore
destroy, getResourceMetadata, getUUID, isFullyBuffered, isOpen, isReadOnly, size, write
 
Methods inherited from interface com.bigdata.rawstore.IAddressManager
getByteCount, getOffset, packAddr, toAddr, toString, unpackAddr
 
Methods inherited from interface com.bigdata.rawstore.IStoreSerializer
deserialize, deserialize, deserialize, serialize
 

Field Detail

opener

protected final IReopenChannel opener
Used to re-open the FileChannel in this class.

Method Detail

getHeaderSize

public final int getHeaderSize()
Description copied from interface: IDiskBasedStrategy
The size of the file header in bytes.

Specified by:
getHeaderSize in interface IBufferStrategy
Specified by:
getHeaderSize in interface IDiskBasedStrategy

getFile

public final File getFile()
Description copied from interface: IDiskBasedStrategy
The backing file.

Specified by:
getFile in interface IDiskBasedStrategy
Specified by:
getFile in interface IRawStore

getRandomAccessFile

public final RandomAccessFile getRandomAccessFile()
Description copied from interface: IDiskBasedStrategy
The object used to read and write on that file.

Specified by:
getRandomAccessFile in interface IDiskBasedStrategy

getChannel

public final FileChannel getChannel()
Description copied from interface: IDiskBasedStrategy
The channel used to read and write on the file.

Specified by:
getChannel in interface IDiskBasedStrategy

isStable

public final boolean isStable()
Description copied from interface: IRawStore
True iff backed by stable storage.

Specified by:
isStable in interface IRawStore

force

public void force(boolean metadata)
Forces the data to disk.

Specified by:
force in interface IRawStore
Parameters:
metadata - If true, then force both the file contents and the file metadata to disk.

close

public void close()
Closes the file.

Specified by:
close in interface IRawStore
Overrides:
close in class BasicBufferStrategy

deleteResources

public void deleteResources()
Description copied from interface: IRawStore
Deletes the backing file(s) (if any) and clears any records for the store from the IGlobalLRU.

Specified by:
deleteResources in interface IRawStore

readRootBlock

public ByteBuffer readRootBlock(boolean rootBlock0)
Description copied from interface: IBufferStrategy
Read the specified root block from the backing file.

Specified by:
readRootBlock in interface IBufferStrategy

writeRootBlock

public void writeRootBlock(IRootBlockView rootBlock,
                           ForceEnum forceOnCommit)
Description copied from interface: IBufferStrategy
Write the root block onto stable storage (ie, flush it through to disk).

Specified by:
writeRootBlock in interface IBufferStrategy
Parameters:
rootBlock - The root block. Which root block is indicated by IRootBlockView.isRootBlock0().

transferTo

public long transferTo(RandomAccessFile out)
                throws IOException
Description copied from class: BasicBufferStrategy
Note: This is synchronized so that concurrent writers must block during this operation.

Specified by:
transferTo in interface IBufferStrategy
Overrides:
transferTo in class BasicBufferStrategy
Parameters:
out - The file to which the buffer contents will be transferred.
Returns:
The #of bytes written.
Throws:
IOException

read

public ByteBuffer read(long addr)
The backing file is fully buffered so it does not need to be open for a read to succeed. However, we use this as an opportunity to transparently re-open the FileChannel if it has been closed asynchronously or in response to an interrupt (that is, if we discover that the channel is closed but AbstractBufferStrategy.isOpen() still returns true).

Specified by:
read in interface IRawStore
Overrides:
read in class BasicBufferStrategy
Parameters:
addr - A long integer that encodes both the offset from which the data will be read and the #of bytes to be read. See IAddressManager.toAddr(int, long).
Returns:
The data read. The buffer will be flipped to prepare for reading (the position will be zero and the limit will be the #of bytes read).


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.