com.bigdata.journal
Class TemporaryRawStore

java.lang.Object
  extended by com.bigdata.rawstore.AbstractRawStore
      extended by com.bigdata.rawstore.AbstractRawWormStore
          extended by com.bigdata.journal.TemporaryRawStore
All Implemented Interfaces:
ICounterSetAccess, IAddressManager, IMRMW, IMROW, IRawStore, IWORM
Direct Known Subclasses:
TemporaryStore

public class TemporaryRawStore
extends AbstractRawWormStore
implements IMRMW

A non-restart-safe store for temporary data that buffers data in memory until the write cache overflows (or is flushed to the disk) and then converts to a disk-based store. The backing file (if any) is released when the temporary store is close()d.

Version:
$Id: TemporaryRawStore.java 2356 2010-01-28 17:36:13Z martyncutcher $
Author:
Bryan Thompson
See Also:
BufferMode.Temporary, DiskOnlyStrategy

Field Summary
 
Fields inherited from class com.bigdata.rawstore.AbstractRawWormStore
am
 
Fields inherited from interface com.bigdata.rawstore.IAddressManager
NULL
 
Constructor Summary
TemporaryRawStore()
          Create a TemporaryRawStore.
TemporaryRawStore(int offsetBits)
          Create a TemporaryRawStore.
TemporaryRawStore(long maximumExtent, int offsetBits, File file)
          Create a TemporaryRawStore with the specified configuration.
 
Method Summary
protected  void assertOpen()
           
 void close()
          Close the store and delete the associated file, if any.
 void delete(long addr)
          The default implementation is a NOP.
 void deleteResources()
          Note: This operation is a NOP since close() always deletes the backing file and deleteResources() requires that the store is closed as a pre-condition.
 void destroy()
          Simply delegates to close() since close() always deletes the backing file for a temporary store.
protected  void finalize()
          Closes the store if it gets GCd.
 void force(boolean metadata)
          Force the data to stable storage.
 DiskOnlyStrategy getBufferStrategy()
           
 CounterSet getCounters()
          Return performance counters.
 File getFile()
          The backing file -or- null if there is no backing file for the store.
 int getMaxRecordSize()
          The maximum length of a record that may be written on the store.
 IResourceMetadata getResourceMetadata()
          Note: Temporary stores do not have persistent resource descriptions.
protected static File getTempFile()
          Return an empty File created using the temporary file name mechanism.
static File getTempFile(File tmpDir)
          Return an empty File created using the temporary file name mechanism in the specified directory.
 UUID getUUID()
          The UUID of this TemporaryRawStore.
 boolean isFullyBuffered()
          Return false since the temporary store is (at least in principle) backed by disk.
 boolean isOpen()
          true iff the store is open.
 boolean isReadOnly()
          true iff the store does not allow writes.
 boolean isStable()
          Always returns false since the store will be deleted as soon as it is closed.
 ByteBuffer read(long addr)
          Read the data (unisolated).
 long size()
          The #of application data bytes written on the store (does not count any headers or root blocks that may exist for the store).
 String toString()
           
 long write(ByteBuffer data)
          Write the data (unisolated).
 
Methods inherited from class com.bigdata.rawstore.AbstractRawWormStore
getAddressManager, getByteCount, getOffset, getOffsetBits, getPhysicalAddress, toAddr, toString
 
Methods inherited from class com.bigdata.rawstore.AbstractRawStore
abortContext, delete, detachContext, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TemporaryRawStore

public TemporaryRawStore()
Create a TemporaryRawStore.


TemporaryRawStore

public TemporaryRawStore(int offsetBits)
Create a TemporaryRawStore.

Parameters:
offsetBits - This determines the capacity of the store file and the maximum length of a record. The value is passed through to WormAddressManager.WormAddressManager(int).

TemporaryRawStore

public TemporaryRawStore(long maximumExtent,
                         int offsetBits,
                         File file)
Create a TemporaryRawStore with the specified configuration.

Parameters:
maximumExtent - The maximum extent allowed for the TemporaryRawStore -or- ZERO (0L) iff no limit should be imposed.
offsetBits - This determines the capacity of the store file and the maximum length of a record. The value is passed through to WormAddressManager.WormAddressManager(int).
file - The name of the backing file. The file will be created on demand if it does not exist. It will be an error if the file exists and has a non-zero size at that time. The file will be registered with the JVM for for "delete on exit" and will be deleted regardless as soon as the store is closed.
Method Detail

getTempFile

protected static File getTempFile()
Return an empty File created using the temporary file name mechanism. The file name will begin with bigdata and end with .tmp. The file is marked for eventual deletion.


getTempFile

public static File getTempFile(File tmpDir)
Return an empty File created using the temporary file name mechanism in the specified directory. The directory will be created if it does not exist and the caller has sufficient permissions. The file name will begin with bigdata and end with .tmp. The file is marked for eventual deletion.

Parameters:
tmpDir - The directory within which to create the temporary file.

getUUID

public final UUID getUUID()
The UUID of this TemporaryRawStore. This is reported as part of getResourceMetadata() and may also be used to ensure that ILocatableResources created on a TemporaryStore are placed within a unique namespace.

Specified by:
getUUID in interface IRawStore

finalize

protected void finalize()
                 throws Throwable
Closes the store if it gets GCd.

Overrides:
finalize in class Object
Throws:
Throwable

toString

public String toString()
Overrides:
toString in class Object

getFile

public final File getFile()
Description copied from interface: IRawStore
The backing file -or- null if there is no backing file for the store.

Specified by:
getFile in interface IRawStore

close

public void close()
Close the store and delete the associated file, if any.

Specified by:
close in interface IRawStore

deleteResources

public void deleteResources()
Note: This operation is a NOP since close() always deletes the backing file and deleteResources() requires that the store is closed as a pre-condition.

Specified by:
deleteResources in interface IRawStore

getResourceMetadata

public final IResourceMetadata getResourceMetadata()
Note: Temporary stores do not have persistent resource descriptions.

Specified by:
getResourceMetadata in interface IRawStore

getBufferStrategy

public final DiskOnlyStrategy getBufferStrategy()

destroy

public final void destroy()
Simply delegates to close() since close() always deletes the backing file for a temporary store.

Specified by:
destroy in interface IRawStore
See Also:
IRawStore.deleteResources()

force

public final void force(boolean metadata)
Description copied from interface: IRawStore
Force the data to stable storage. While this is NOT sufficient to guarantee an atomic commit, the data must be forced to disk as part of an atomic commit protocol.

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

size

public final long size()
Description copied from interface: IRawStore
The #of application data bytes written on the store (does not count any headers or root blocks that may exist for the store).

Specified by:
size in interface IRawStore

assertOpen

protected final void assertOpen()

isOpen

public final boolean isOpen()
Description copied from interface: IRawStore
true iff the store is open.

Specified by:
isOpen in interface IRawStore
Returns:
true iff the store is open.

isReadOnly

public final boolean isReadOnly()
Description copied from interface: IRawStore
true iff the store does not allow writes.

Specified by:
isReadOnly in interface IRawStore

isStable

public final boolean isStable()
Always returns false since the store will be deleted as soon as it is closed.

Specified by:
isStable in interface IRawStore

isFullyBuffered

public final boolean isFullyBuffered()
Return false since the temporary store is (at least in principle) backed by disk.

Specified by:
isFullyBuffered in interface IRawStore

read

public final ByteBuffer read(long addr)
Description copied from interface: IRawStore
Read the data (unisolated).

Specified by:
read in interface IRawStore
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).

write

public final long write(ByteBuffer data)
Description copied from interface: IRawStore
Write the data (unisolated).

Specified by:
write in interface IRawStore
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.

getMaxRecordSize

public final int getMaxRecordSize()
The maximum length of a record that may be written on the store.


getCounters

public CounterSet getCounters()
Description copied from interface: ICounterSetAccess
Return performance counters.

Specified by:
getCounters in interface ICounterSetAccess

delete

public void delete(long addr)
Description copied from class: AbstractRawStore
The default implementation is a NOP.

Specified by:
delete in interface IRawStore
Overrides:
delete in class AbstractRawStore
Parameters:
addr - A long integer formed using Addr that encodes both the offset at which the data was written and the #of bytes that were written.


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