com.bigdata.journal
Class DirectBufferStrategy

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
                      extended by com.bigdata.journal.DirectBufferStrategy
All Implemented Interfaces:
IBufferStrategy, IDiskBasedStrategy, IAddressManager, IMRMW, IMROW, IRawStore, IStoreSerializer, IWORM

public class DirectBufferStrategy
extends DiskBackedBufferStrategy

Direct buffer strategy uses a direct ByteBuffer as a write through cache and writes through to disk for persistence.

Version:
$Id: DirectBufferStrategy.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
BufferMode.Direct
TODO:
modify to support aio (asynchronous io). aio can be supported with a 2nd thread that writes behind from the cache to the file. force() will need to be modified to wait until the aio thread has caught up to the nextOffset (i.e., has written all data that is dirty on the buffer).

Field Summary
 
Fields inherited from class com.bigdata.journal.DiskBackedBufferStrategy
opener
 
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
 boolean isFullyBuffered()
          True iff the store is fully buffered (all reads are against memory).
 void truncate(long newExtent)
          Note: This is synchronized since it MAY be invoked directly while concurrent writers are running and not just from AbstractBufferStrategy.overflow(long).
 long write(ByteBuffer data)
          Extends the basic behavior to write through to the backing file.
 
Methods inherited from class com.bigdata.journal.DiskBackedBufferStrategy
close, deleteResources, force, getChannel, getFile, getHeaderSize, getRandomAccessFile, isStable, read, readRootBlock, transferTo, writeRootBlock
 
Methods inherited from class com.bigdata.journal.BasicBufferStrategy
getBufferView, getCounters, getExtent, getUserExtent
 
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
 
Methods inherited from interface com.bigdata.rawstore.IRawStore
destroy, getResourceMetadata, getUUID, isOpen, isReadOnly, size
 
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
 

Method Detail

isFullyBuffered

public boolean isFullyBuffered()
Description copied from interface: IRawStore
True iff the store is fully buffered (all reads are against memory). Implementations MAY change the value returned by this method over the life cycle of the store, e.g., to conserve memory a store may drop or decrease its buffer if it is backed by disk.

Note: This does not guarantee that the OS will not swap the buffer onto disk.


write

public long write(ByteBuffer data)
Extends the basic behavior to write through to the backing file.

Note: ClosedChannelException can be thrown out of this method. This exception is an indication that the backing channel was closed while a writer was still running.

Note: ClosedByInterruptException can be thrown out of this method (wrapped as a RuntimeException). This exception is an indication that a writer was interrupted. This will occur if you are using ExecutorService.shutdownNow() on a service that is running one or more writers. In such cases this should not be considered an error but the expected result of interrupting the writer.

However, note that ClosedByInterruptException means that the channel was actually closed when the writer was interrupted. This means that you basically can not interrupt running writers without having to re-open the channel.

Specified by:
write in interface IRawStore
Overrides:
write in class BasicBufferStrategy
Parameters:
data - The data. The bytes from the current Buffer.position() to the Buffer.limit() will be written and the Buffer.position() will be advanced to the Buffer.limit() . The caller may subsequently modify the contents of the buffer without changing the state of the store (i.e., the data are copied into the store).
Returns:
A long integer formed that encodes both the offset from which the data may be read and the #of bytes to be read. See IAddressManager.

truncate

public void truncate(long newExtent)
Description copied from class: BasicBufferStrategy
Note: This is synchronized since it MAY be invoked directly while concurrent writers are running and not just from AbstractBufferStrategy.overflow(long).

Specified by:
truncate in interface IBufferStrategy
Overrides:
truncate in class BasicBufferStrategy
Parameters:
newExtent - The new extent of the journal. This value represent the total extent of the journal, including any root blocks together with the user extent.


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