com.bigdata.journal
Class MappedBufferStrategy

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.MappedBufferStrategy
All Implemented Interfaces:
ICounterSetAccess, IBufferStrategy, IDiskBasedStrategy, IAddressManager, IMRMW, IMROW, IRawStore, IWORM

public class MappedBufferStrategy
extends DiskBackedBufferStrategy

Memory-mapped journal strategy (this mode is NOT recommended).

Note: the use of FileLock with a memory-mapped file is NOT recommended by the JDK as this combination is not permitted on some platforms.

Note: Extension and truncation of a mapped file are not possible with the JDK since there is no way to guarentee that the mapped file will be unmapped in a timely manner. Journals that handle IJournal#overflow() should trigger overflow just a bit earlier for a MappedByteBuffer in an attempt to avoid running out of space in the journal. If a transaction can not be committed due to overflow, it could be re-committed after handling the overflow event (e.g., throw a "CommitRetryException").

The mapped mode has nearly the performance of the transient mode in some tests. However the use of mapped files might not prove worth the candle due to the difficulties with resource deallocation for this strategy and the good performance of some alternative strategies. There are also some other issues that have shown up in some of the tests suites -- look carefully if you are going to pursue this!

Version:
$Id: MappedBufferStrategy.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038, BufferMode.Mapped

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_BUFFER_OVERRUN, ERR_MAX_EXTENT, ERR_NOT_OPEN, ERR_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 interface com.bigdata.rawstore.IAddressManager
NULL
 
Method Summary
 void close()
          The file channel is closed, but according to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038 there is no way to guarentee when the mapped file will be released.
 void deleteResources()
          Overrides the default behavior so that an exception is NOT thrown if the file can not be deleted.
 void force(boolean metadata)
          Force the data to disk.
 boolean isFullyBuffered()
          True iff the store is fully buffered (all reads are against memory).
 void truncate(long newExtent)
          Note: Extension and truncation of a mapped file are not possible with the JDK since there is no way to guarentee that the mapped file will be unmapped in a timely manner.
 
Methods inherited from class com.bigdata.journal.DiskBackedBufferStrategy
delete, getChannel, getFile, getHeaderSize, getRandomAccessFile, isStable, read, readRootBlock, setNextOffset, transferTo, writeRootBlock
 
Methods inherited from class com.bigdata.journal.BasicBufferStrategy
getBufferView, getCounters, getExtent, getUserExtent, write
 
Methods inherited from class com.bigdata.journal.AbstractBufferStrategy
abort, assertOpen, closeForWrites, commit, destroy, getBufferMode, getInitialExtent, getMaximumExtent, getMaxRecordSize, getMetaBitsAddr, getMetaStartAddr, getMinimumExtension, getNextOffset, getResourceMetadata, getUUID, isOpen, isReadOnly, overflow, requiresCommit, size, transferFromDiskTo, useChecksums
 
Methods inherited from class com.bigdata.rawstore.AbstractRawWormStore
getAddressManager, getByteCount, getOffset, getOffsetBits, getPhysicalAddress, toAddr, toString
 
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
abort, closeForWrites, commit, getAddressManager, getBufferMode, getCounters, getExtent, getInitialExtent, getMaximumExtent, getMaxRecordSize, getMetaBitsAddr, getMetaStartAddr, getNextOffset, getOffsetBits, getUserExtent, requiresCommit, useChecksums
 
Methods inherited from interface com.bigdata.rawstore.IRawStore
destroy, getResourceMetadata, getUUID, isOpen, isReadOnly, size, write
 
Methods inherited from interface com.bigdata.rawstore.IAddressManager
getByteCount, getOffset, getPhysicalAddress, toAddr, toString
 

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.


force

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

Specified by:
force in interface IRawStore
Overrides:
force in class DiskBackedBufferStrategy
Parameters:
metadata - If true, then force both the file contents and the file metadata to disk.
See Also:
MappedByteBuffer.force()

close

public void close()
The file channel is closed, but according to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038 there is no way to guarentee when the mapped file will be released.

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

deleteResources

public void deleteResources()
Overrides the default behavior so that an exception is NOT thrown if the file can not be deleted. Since Java can not provide for synchronous unmap of memory-mapped files, we can not delete the backing file immediately. Instead, we mark the file for "deleteOnExit" and let the VM attempt to clean it up when it exits.

Specified by:
deleteResources in interface IRawStore
Overrides:
deleteResources in class DiskBackedBufferStrategy

truncate

public void truncate(long newExtent)
Note: Extension and truncation of a mapped file are not possible with the JDK since there is no way to guarentee that the mapped file will be unmapped in a timely manner.

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.
Throws:
UnsupportedOperationException - Always thrown.


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