com.bigdata.btree
Class IndexSegmentStore

java.lang.Object
  extended by com.bigdata.rawstore.AbstractRawStore
      extended by com.bigdata.btree.IndexSegmentStore
All Implemented Interfaces:
IAddressManager, IRawStore, IStoreSerializer

public class IndexSegmentStore
extends AbstractRawStore

A read-only store backed by a file containing a single IndexSegment.

Version:
$Id: IndexSegmentStore.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected  IBigdataFederation<?> fed
          Optional.
protected  File file
          The file containing the index segment.
protected  ReentrantLock lock
          A lock used to make open and close operations atomic.
protected static org.apache.log4j.Logger log
          Logger.
protected static String mode
          The mode that will be used to open the file .
 
Fields inherited from class com.bigdata.rawstore.AbstractRawStore
serializer
 
Fields inherited from interface com.bigdata.rawstore.IAddressManager
NULL
 
Constructor Summary
IndexSegmentStore(File file)
          Open a read-only store containing an IndexSegment, but does not load the IndexSegment from the store.
IndexSegmentStore(File file, IBigdataFederation<?> fed)
          Constructor variant that accepts an IBigdataFederation reference and will report out Events.
 
Method Summary
protected  void bufferIndexNodes()
          Attempts to read the index nodes into buf_nodes.
 void close()
          Closes the file and releases the internal buffers.
 void deleteResources()
          Deletes the backing file(s) (if any) and clears any records for the store from the IGlobalLRU.
 void destroy()
          Atomically closes the store (iff open) and then deletes the backing file.
protected  void finalize()
          Closes out the IndexSegmentStore iff it is still open.
 void force(boolean metadata)
          Force the data to stable storage.
 IndexSegmentAddressManager getAddressManager()
          Used to correct decode region-based addresses.
 int getByteCount(long addr)
          The length of the datum in bytes.
 IndexSegmentCheckpoint getCheckpoint()
          A read-only view of the checkpoint record for the index segment.
 CounterSet getCounters()
          Reports performance counters.
 File getFile()
          The backing file -or- null if there is no backing file for the store.
 IndexMetadata getIndexMetadata()
          The IndexMetadata record for the IndexSegment.
 long getOffset(long addr)
          The offset on the store at which the datum is stored.
 IResourceMetadata getResourceMetadata()
          A description of this store in support of the scale-out architecture.
 UUID getUUID()
          Return the UUID which identifies this IRawStore.
 boolean isFullyBuffered()
          Return false since the leaves are not fully buffered even if the nodes are fully buffered.
 boolean isNodesFullyBuffered()
          Return true if the nodes of the IndexSegment are fully buffered in memory.
 boolean isOpen()
          true iff the store is open.
 boolean isReadOnly()
          true iff the store does not allow writes.
 boolean isStable()
          True iff backed by stable storage.
 IndexSegment loadIndexSegment()
          Load the IndexSegment.
 void packAddr(DataOutput out, long addr)
          Pack the address onto the output stream.
 ByteBuffer read(long addr)
          Read a record from the IndexSegmentStore.
protected  BloomFilter readBloomFilter()
          Reads the bloom filter directly from the file.
 void reopen()
          Re-open a (possibly closed) store.
 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).
 long toAddr(int nbytes, long offset)
          Converts a byte count and offset into a long integer.
 String toString()
           
 String toString(long addr)
          A human readable representation of the address.
 long unpackAddr(DataInput in)
          Unpack the address from the input stream.
 long write(ByteBuffer data)
          Write the data (unisolated).
 
Methods inherited from class com.bigdata.rawstore.AbstractRawStore
deserialize, deserialize, deserialize, serialize
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log
Logger.


mode

protected static final String mode
The mode that will be used to open the file .

See Also:
Constant Field Values

file

protected final File file
The file containing the index segment.


fed

protected final IBigdataFederation<?> fed
Optional. When defined, Events are reported out.


lock

protected final ReentrantLock lock
A lock used to make open and close operations atomic.

Constructor Detail

IndexSegmentStore

public IndexSegmentStore(File file)
Open a read-only store containing an IndexSegment, but does not load the IndexSegment from the store.

Note: If an exception is thrown then the backing file will be closed.

Note: Normally access to IndexSegmentStores is mediated by the StoreManager which imposes a canonicalizing weak value cache to ensure that we do not double-open an IndexSegmentStore.

Parameters:
file - The file
Throws:
RuntimeException - if there is a problem.
RootBlockException - if the root block is invalid.
See Also:
loadIndexSegment()

IndexSegmentStore

public IndexSegmentStore(File file,
                         IBigdataFederation<?> fed)
Constructor variant that accepts an IBigdataFederation reference and will report out Events.

Parameters:
file -
fed -
Method Detail

getAddressManager

public final IndexSegmentAddressManager getAddressManager()
Used to correct decode region-based addresses. The IndexSegmentBuilder encodes region-based addresses using IndexSegmentRegion. Those addresses are then transparently decoded by this class. The IndexSegment itself knows nothing about this entire slight of hand.

Specified by:
getAddressManager in class AbstractRawStore

getCheckpoint

public final IndexSegmentCheckpoint getCheckpoint()
A read-only view of the checkpoint record for the index segment.


getUUID

public final UUID getUUID()
Description copied from interface: IRawStore
Return the UUID which identifies this IRawStore. This supports both IRawStore.getResourceMetadata() and the LRUNexus.


getIndexMetadata

public final IndexMetadata getIndexMetadata()
The IndexMetadata record for the IndexSegment.

Note: The IndexMetadata.getPartitionMetadata() always reports that LocalPartitionMetadata.getResources() is null. This is because the BTree on the AbstractJournal defines the index partition view and each IndexSegment generally participates in MANY views - one per commit point on each AbstractJournal where the IndexSegment is part of an index partition view.


finalize

protected void finalize()
                 throws Exception
Closes out the IndexSegmentStore iff it is still open.

Note: The IndexSegment has hard reference to the IndexSegmentStore but not the other way around. Therefore an IndexSegment will be swept before its store is finalized.

Overrides:
finalize in class Object
Throws:
Exception

toString

public String toString()
Overrides:
toString in class Object

getResourceMetadata

public IResourceMetadata getResourceMetadata()
Description copied from interface: IRawStore
A description of this store in support of the scale-out architecture.


reopen

public void reopen()
Re-open a (possibly closed) store. This operation should succeed if the backing file is still accessible.

Note: If an exception is thrown then the backing file will be closed.

Throws:
RootBlockException - if the root block is invalid.
RuntimeException - if there is a problem, including a FileNotFoundException.
See Also:
close()

loadIndexSegment

public IndexSegment loadIndexSegment()
Load the IndexSegment. The IndexSegment (or derived class) MUST provide a public constructor with the following signature: className(IndexSegmentFileStore store)

Note: Normally access to IndexSegments is mediated by the StoreManager which imposes a canonicalizing weak value cache to ensure that we do not double-open an IndexSegment.

Parameters:
store - The store.
Returns:
The IndexSegment or derived class loaded from that store.

isOpen

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

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.


isStable

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


isFullyBuffered

public final boolean isFullyBuffered()
Return false since the leaves are not fully buffered even if the nodes are fully buffered.


isNodesFullyBuffered

public boolean isNodesFullyBuffered()
Return true if the nodes of the IndexSegment are fully buffered in memory. The result is consistent as of the time that this method examines the state of the IndexSegmentStore.


getFile

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


close

public void close()
Closes the file and releases the internal buffers. This operation will quietly succeed if the IndexSegmentStore is already closed. This operation may be reversed by reopen() as long as the backing file remains available. A read on a closed IndexSegmentStore will transparently reopen() the store as long as the backing file remains available. destroy() provides an atomic "close and delete" operation.


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.


destroy

public void destroy()
Atomically closes the store (iff open) and then deletes the backing file. Any records for the store are cleared from the IGlobalLRU.

See Also:
IRawStore.deleteResources()

write

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

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.

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.

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).


getCounters

public CounterSet getCounters()
Description copied from interface: IRawStore
Reports performance counters.


read

public ByteBuffer read(long addr)
Read a record from the IndexSegmentStore. If the request is in the node region and the nodes have been buffered then this uses a slice on the node buffer. Otherwise this reads through to the backing file.

Note: An LRU disk cache is a poor choice for the leaves. Since the btree already maintains a cache of the recently touched leaf objects, a recent read against the disk is the best indication that we have that we will NOT want to read that region again soon.

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).

bufferIndexNodes

protected void bufferIndexNodes()
                         throws IOException
Attempts to read the index nodes into buf_nodes.

Note: If the nodes could not be buffered then reads against the nodes will read through to the backing file.

Throws:
IOException

readBloomFilter

protected BloomFilter readBloomFilter()
                               throws IOException
Reads the bloom filter directly from the file.

Returns:
The bloom filter -or- null if the bloom filter was not constructed when the IndexSegment was built.
Throws:
IOException

getByteCount

public final int getByteCount(long addr)
Description copied from interface: IAddressManager
The length of the datum in bytes.

Parameters:
addr - The opaque identifier that is the within store locator for some datum.
Returns:
The offset of that datum.

getOffset

public final long getOffset(long addr)
Description copied from interface: IAddressManager
The offset on the store at which the datum is stored. While this is often the offset of a byte into a file on disk, implementations MAY assign offsets using other strategies.

Parameters:
addr - The opaque identifier that is the within store locator for some datum.
Returns:
The offset of that datum.

packAddr

public final void packAddr(DataOutput out,
                           long addr)
                    throws IOException
Description copied from interface: IAddressManager
Pack the address onto the output stream.

Parameters:
out - The output stream.
addr - The opaque identifier that is the within store locator for some datum.
Throws:
IOException

toAddr

public final long toAddr(int nbytes,
                         long offset)
Description copied from interface: IAddressManager
Converts a byte count and offset into a long integer.

Parameters:
nbytes - The byte count.
offset - The byte offset.
Returns:
The long integer.

toString

public final String toString(long addr)
Description copied from interface: IAddressManager
A human readable representation of the address.

Parameters:
addr - The opaque identifier that is the within store locator for some datum.
Returns:
A human readable representation.

unpackAddr

public final long unpackAddr(DataInput in)
                      throws IOException
Description copied from interface: IAddressManager
Unpack the address from the input stream.

Parameters:
in - The input stream.
Returns:
The opaque identifier that is the within store locator for some datum.
Throws:
IOException


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