com.bigdata.btree
Class Checkpoint

java.lang.Object
  extended by com.bigdata.btree.Checkpoint
All Implemented Interfaces:
Externalizable, Serializable
Direct Known Subclasses:
MetadataIndex.MetadataIndexCheckpoint

public class Checkpoint
extends Object
implements Externalizable

A checkpoint record is written each time the btree is flushed to the store.

Note: In order to create a btree use BTree.create(IRawStore, IndexMetadata) to write the initial IndexMetadata record and the initial check point on the store. It will then load the BTree from the Checkpoint record and you can start using the index.

Version:
$Id: Checkpoint.java 5499 2011-11-03 19:49:10Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form

Nested Class Summary
static class Checkpoint.IndexTypeEnum
          Type safe enumeration of index types.
 
Constructor Summary
Checkpoint()
          De-serialization ctor.
Checkpoint(BTree btree)
          Creates a Checkpoint record from a BTree.
Checkpoint(HTree htree)
          Creates a Checkpoint record from an HTree.
Checkpoint(IndexMetadata metadata)
          Create the first checkpoint record for a new BTree from a IndexMetadata record.
Checkpoint(IndexMetadata metadata, Checkpoint oldCheckpoint)
          Create the first checkpoint record for an existing BTree when it is propagated on overflow onto a new backing IRawStore.
 
Method Summary
 long getBloomFilterAddr()
          Address of the IBloomFilter.
 long getCheckpointAddr()
          The address used to read this Checkpoint record from the store.
 long getCounter()
          Return the value of the B+Tree local counter stored in the Checkpoint record.
 long getEntryCount()
          The #of index entries (aka tuple count).
 int getGlobalDepth()
          The global depth of the root directory (HTree only).
 int getHeight()
          The height of a B+Tree.
 Checkpoint.IndexTypeEnum getIndexType()
          The type of index for this checkpoint record.
 long getLeafCount()
          The #of leaves (B+Tree) or hash buckets (HTree).
 long getMetadataAddr()
          Address that can be used to read the IndexMetadata record for the index from the store.
 long getNodeCount()
          The #of non-leaf nodes (B+Tree) or directories (HTree).
 long getRecordVersion()
          Return the value of the next record version number to be assigned that is stored in the Checkpoint record.
 long getRootAddr()
          Address of the root node or leaf of the BTree.
 boolean hasCheckpointAddr()
          Return true iff the checkpoint address is defined.
static Checkpoint load(IRawStore store, long addrCheckpoint)
          Read a Checkpoint record from a store.
 void readExternal(ObjectInput in)
           
 String toString()
          A human readable representation of the state of the Checkpoint record.
 void write(IRawStore store)
          Write the Checkpoint record on the store, setting addrCheckpoint as a side effect.
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Checkpoint

public Checkpoint()
De-serialization ctor.


Checkpoint

public Checkpoint(IndexMetadata metadata)
Create the first checkpoint record for a new BTree from a IndexMetadata record. The root of the BTree will NOT exist (its address will be 0L). Once written on the store the Checkpoint record may be used to obtain a corresponding instance of a BTree object.

Parameters:
metadata - The index metadata record.

Checkpoint

public Checkpoint(IndexMetadata metadata,
                  Checkpoint oldCheckpoint)
Create the first checkpoint record for an existing BTree when it is propagated on overflow onto a new backing IRawStore. The counter is propagated to the new Checkpoint but otherwise the initialization is as if for an empty BTree.

Parameters:
metadata - The index metadata record.
oldCheckpoint - The last Checkpoint for the index on the old backing store. The counter is propagated to the new Checkpoint record.

Checkpoint

public Checkpoint(BTree btree)
Creates a Checkpoint record from a BTree.

Pre-conditions:

Note: if the root is null then the root is assumed to be clean and the root address from the last Checkpoint record is used. Otherwise the address of the root is used (in which case it MUST be defined).

Parameters:
btree - The btree.

Checkpoint

public Checkpoint(HTree htree)
Creates a Checkpoint record from an HTree.

Pre-conditions:

Note: if the root is null then the root is assumed to be clean and the root address from the last Checkpoint record is used. Otherwise the address of the root is used (in which case it MUST be defined).

Parameters:
htree - The HTree.
Method Detail

getCheckpointAddr

public final long getCheckpointAddr()
The address used to read this Checkpoint record from the store.

Note: This is set as a side-effect by write(IRawStore).

Throws:
IllegalStateException - if the Checkpoint record has not been written on a store.

hasCheckpointAddr

public final boolean hasCheckpointAddr()
Return true iff the checkpoint address is defined.


getMetadataAddr

public final long getMetadataAddr()
Address that can be used to read the IndexMetadata record for the index from the store.


getRootAddr

public final long getRootAddr()
Address of the root node or leaf of the BTree.

Returns:
The address of the root -or- 0L iff the btree does not have a root.

getBloomFilterAddr

public final long getBloomFilterAddr()
Address of the IBloomFilter.

Returns:
The address of the bloom filter -or- 0L iff the btree does not have a bloom filter.

getHeight

public final int getHeight()
The height of a B+Tree. ZERO(0) means just a root leaf. Values greater than zero give the #of levels of abstract nodes. There is always one layer of leaves which is not included in this value.

Returns:
The global depth and ZERO (0) unless the checkpoint record is for an Checkpoint.IndexTypeEnum.BTree

getGlobalDepth

public final int getGlobalDepth()
The global depth of the root directory (HTree only).

Returns:
The global depth and ZERO (0) unless the checkpoint record is for an Checkpoint.IndexTypeEnum.HTree

getNodeCount

public final long getNodeCount()
The #of non-leaf nodes (B+Tree) or directories (HTree).


getLeafCount

public final long getLeafCount()
The #of leaves (B+Tree) or hash buckets (HTree).


getEntryCount

public final long getEntryCount()
The #of index entries (aka tuple count).


getCounter

public final long getCounter()
Return the value of the B+Tree local counter stored in the Checkpoint record.


getRecordVersion

public final long getRecordVersion()
Return the value of the next record version number to be assigned that is stored in the Checkpoint record. This number is incremented each time a node or leaf is written onto the backing store. The initial value is ZERO (0). The first value assigned to a node or leaf will be ZERO (0).


getIndexType

public Checkpoint.IndexTypeEnum getIndexType()
The type of index for this checkpoint record.


toString

public final String toString()
A human readable representation of the state of the Checkpoint record.

Overrides:
toString in class Object

write

public final void write(IRawStore store)
Write the Checkpoint record on the store, setting addrCheckpoint as a side effect.

Parameters:
store -
Throws:
IllegalStateException - if the Checkpoint record has already been written.

load

public static Checkpoint load(IRawStore store,
                              long addrCheckpoint)
Read a Checkpoint record from a store.

Parameters:
store - The store.
addrCheckpoint - The address from which to read the Checkpoint record. This address is set on the Checkpoint record as a side-effect.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException


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