public class HTree extends AbstractHTree implements IIndexLocalCounter
AbstractHTree.HTreePageStateException| Modifier and Type | Field and Description |
|---|---|
protected AtomicLong |
counter
The mutable counter exposed by #getCounter()}.
|
protected long |
nentries
The #of entries in the
HTree. |
protected long |
nleaves
The #of
BucketPages in the HTree. |
protected long |
nnodes
The #of
DirectoryPage in the HTree. |
protected long |
recordVersion
The value of the record version number that will be assigned to the next
node or leaf written onto the backing store.
|
addressBits, bucketSlots, DEBUG, dumpLog, error, ERROR_CLOSED, ERROR_ERROR_STATE, ERROR_LESS_THAN_ZERO, ERROR_READ_ONLY, ERROR_TOO_LARGE, ERROR_TOO_SMALL, ERROR_TRANSIENT, INFO, log, MAX_ADDRESS_BITS, metadata, MIN_ADDRESS_BITS, ndistinctOnWriteRetentionQueue, nodeSer, readOnly, root, store, writeRetentionQueue| Constructor and Description |
|---|
HTree(IRawStore store,
Checkpoint checkpoint,
IndexMetadata metadata,
boolean readOnly)
Required constructor form for
HTree and any derived subclasses. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_reopen()
This method is responsible for setting up the root leaf (either new or
read from the store), the bloom filter, etc.
|
HTree |
asReadOnly()
Returns an immutable view of this
HTree. |
boolean |
contains(byte[] key)
Return
true iff there is at least one tuple in the hash tree
having the specified key. |
boolean |
contains(int key) |
boolean |
contains(Object obj) |
static HTree |
create(IRawStore store,
HTreeIndexMetadata metadata)
Create a new
HTree or derived class. |
static HTree |
createTransient(HTreeIndexMetadata metadata)
|
BaseIndexStats |
dumpPages(boolean recursive,
boolean visitLeaves)
Reports statistics for the index.
|
protected void |
fireDirtyEvent()
Fire an event to the listener (iff set).
|
boolean |
flush()
Flush the nodes of the
BTree to the backing store. |
Checkpoint |
getCheckpoint()
Returns the most recent
ICheckpoint record. |
ICounter |
getCounter()
Returns an
ICounter. |
IDirtyListener |
getDirtyListener()
Return the
IDirtyListener. |
long |
getEntryCount()
The #of tuples in the
HTree. |
long |
getLastCommitTime()
The timestamp associated with the last
IAtomicStore.commit() in
which writes buffered by this index were made restart-safe on the backing
store. |
long |
getLeafCount()
The #of
BucketPages in the HTree (not buddy hash buckets,
but the pages on which they appear). |
long |
getMetadataAddr()
The address at which the most recent
IndexMetadata record was
written. |
long |
getNodeCount()
The #of
DirectoryPages in the HTree (not buddy hash
tables, but the pages on which they appear). |
long |
getRecordVersion()
The value of the record version number that will be assigned to the next
node or leaf written onto the backing store.
|
long |
getRevisionTimestamp() |
long |
getRootAddr()
The address of the last written root of the persistent data structure
-or-
0L if there is no root. |
long |
handleCommit(long commitTime)
Flush dirty state to the store in preparation for an atomic commit and
return the address from which the persistence capable data structure may
be reloaded.
|
byte[] |
insert(byte[] key,
byte[] value)
Insert a tuple into the hash tree.
|
void |
insert(int key,
byte[] val) |
void |
insert(Object obj) |
protected void |
insertRawTuple(com.bigdata.htree.BucketPage src,
int slot)
Insert a tuple into the hash tree.
|
void |
invalidate(Throwable t)
Mark an
ICommitter as invalid. |
static HTree |
load(IRawStore store,
long addrCheckpoint,
boolean readOnly)
Load an instance of a
HTree or derived class from the store. |
protected com.bigdata.htree.AbstractPage |
locatePageForKey(byte[] key) |
ITupleIterator |
lookupAll(byte[] key)
Return an iterator which will visit each tuple in the index having the
specified key.
|
ITupleIterator |
lookupAll(int key)
Return an iterator which will visit each tuple in the index having the
specified key.
|
byte[] |
lookupFirst(byte[] key)
Return the first value for the key.
|
byte[] |
lookupFirst(int key)
Return the first value for the key.
|
boolean |
needsCheckpoint()
Return true iff changes would be lost unless the B+Tree is flushed to the
backing store using
writeCheckpoint(). |
long |
rangeCount()
The #of index entries.
|
protected int |
recycle(long addr)
Recycle (aka delete) the allocation.
|
byte[] |
remove(byte[] key)
Removes a single entry matching the key supplied.
|
void |
removeAll()
Remove all entries in the index.
|
int |
removeAll(byte[] key) |
protected void |
setCheckpoint(Checkpoint checkpoint)
Sets the
checkpoint and initializes the mutable fields from the
checkpoint record. |
void |
setDirtyListener(IDirtyListener listener)
Set or clear the listener (there can be only one).
|
void |
setIndexMetadata(HTreeIndexMetadata indexMetadata)
Method updates the index metadata associated with this
BTree. |
void |
setLastCommitTime(long lastCommitTime)
Sets the lastCommitTime.
|
long |
writeCheckpoint()
Checkpoint operation must
#flush() dirty nodes, dirty persistent
data structures, etc, write a new Checkpoint record on the
backing store, save a reference to the current Checkpoint, and
return the address of that Checkpoint record. |
Checkpoint |
writeCheckpoint2()
Checkpoint operation must
#flush() dirty nodes, dirty persistent
data structures, etc, write a new Checkpoint record on the
backing store, save a reference to the current Checkpoint, and
return the address of that Checkpoint record. |
assertNotReadOnly, assertNotTransient, checkConsistency, checkConsistency, close, decodeRecordAddr, dump, dump, encodeRecordAddr, getAddressBits, getBtreeCounters, getCounters, getHeight, getIndexMetadata, getNodeSerializer, getReadLockCount, getRoot, getStore, isBalanced, isOpen, isReadOnly, isTransient, rangeIterator, readLock, readNodeOrLeaf, reopen, scan, setBTreeCounters, toString, touch, values, writeLock, writeNodeOrLeaf, writeNodeRecursive, writeNodeRecursiveCallersThread, writeNodeRecursiveConcurrentprotected long nnodes
protected long nleaves
protected long nentries
protected long recordVersion
protected AtomicLong counter
Note: This is protected so that it will be visible to
Checkpoint which needs to write the actual value store in this
counter into its serialized record (without the partition identifier).
public HTree(IRawStore store, Checkpoint checkpoint, IndexMetadata metadata, boolean readOnly)
HTree and any derived subclasses.
This constructor is used both to create a new HTree, and to load
a HTree from the store using a Checkpoint record.store - The store.checkpoint - A Checkpoint record for that HTree.metadata - The metadata record for that HTree.readOnly - When true the HTree will be immutable.HTree#create(IRawStore, IndexMetadata),
load(IRawStore, long, boolean)public final long getNodeCount()
AbstractHTreeDirectoryPages in the HTree (not buddy hash
tables, but the pages on which they appear).getNodeCount in interface ISimpleTreeIndexAccessgetNodeCount in class AbstractHTreepublic final long getLeafCount()
AbstractHTreeBucketPages in the HTree (not buddy hash buckets,
but the pages on which they appear).getLeafCount in interface ISimpleTreeIndexAccessgetLeafCount in class AbstractHTreepublic final long getEntryCount()
AbstractHTreeHTree.getEntryCount in interface ISimpleTreeIndexAccessgetEntryCount in class AbstractHTreepublic final Checkpoint getCheckpoint()
ICheckpointProtocolICheckpoint record.getCheckpoint in interface ICheckpointProtocolICheckpoint record and never
null.public final long getRecordVersion()
ICheckpointProtocolgetRecordVersion in interface ICheckpointProtocolpublic final long getMetadataAddr()
ICheckpointProtocolIndexMetadata record was
written.getMetadataAddr in interface ICheckpointProtocolpublic final long getRootAddr()
ICheckpointProtocol0L if there is no root. A 0L return may be
an indication that an empty data structure will be created on demand.getRootAddr in interface ICheckpointProtocolpublic boolean needsCheckpoint()
writeCheckpoint().
Note: In order to avoid needless checkpoints this method will return
false if:
null, indicating that the index
is closed (in which case there are no buffered writes);Checkpoint.getRootAddr(), and the
counter value agrees Checkpoint.getCounter().true true iff changes would be lost unless the
B+Tree was flushed to the backing store using
writeCheckpoint().public final void setIndexMetadata(HTreeIndexMetadata indexMetadata)
BTree.
The new metadata record will be written out as part of the next index
writeCheckpoint().
Note: this method should be used with caution.
indexMetadata - The new metadata description for the BTree.IllegalArgumentException - if the new value is nullIllegalArgumentException - if the new IndexMetadata record has already been
written on the store - see
IndexMetadata.getMetadataAddr()UnsupportedOperationException - if the index is read-only.public long handleCommit(long commitTime)
ICommitterhandleCommit in interface ICommittercommitTime - The timestamp assigned to the commit.public void invalidate(Throwable t)
ICommitterICommitter as invalid. This will prevent it from allowing
any writes through to the backing store.invalidate in interface ICommittert - A cause (required).https://jira.blazegraph.com/browse/BLZG-1953public ICounter getCounter()
ICounter. The ICounter is mutable iff the
BTree is mutable. All ICounters returned by this method
report and increment the same underlying counter.
Note: When the BTree is part of a scale-out index then the
counter will assign values within a namespace defined by the partition
identifier.
getCounter in interface IIndexLocalCounterprotected void setCheckpoint(Checkpoint checkpoint)
checkpoint and initializes the mutable fields from the
checkpoint record. In order for this operation to be atomic, the caller
must be synchronized on the HTree or otherwise guaranteed to have
exclusive access, e.g., during the ctor or when the HTree is
mutable and access is therefore required to be single-threaded.protected void _reopen()
AbstractHTreeAbstractHTree.reopen() once AbstractHTree.root has been show to be
null with double-checked locking. When invoked in this
context, the caller is guaranteed to hold a lock on this. This is
done to ensure that at most one thread gets to re-open the index from the
backing store._reopen in class AbstractHTreepublic final long getLastCommitTime()
AbstractHTreeIAtomicStore.commit() in
which writes buffered by this index were made restart-safe on the backing
store. The lastCommitTime is set when the index is loaded from the
backing store and updated after each commit. It is ZERO (0L) when
HTree is first created and will remain ZERO (0L) until the
HTree is committed. If the backing store does not support atomic
commits, then this value will always be ZERO (0L).getLastCommitTime in interface ICheckpointProtocolgetLastCommitTime in class AbstractHTreepublic final long getRevisionTimestamp()
public final void setLastCommitTime(long lastCommitTime)
ICheckpointProtocol
Note: The lastCommitTime is set by a combination of the
AbstractJournal and Name2Addr based on the actual
commitTime of the commit during which an Name2Addr.Entry for that index was
last committed. It is set for both historical index reads and unisolated
index reads using Name2Addr.Entry.commitTime. The lastCommitTime for an
unisolated index will advance as commits are performed with that index.
setLastCommitTime in interface ICheckpointProtocollastCommitTime - The timestamp of the last committed state of this index.public final IDirtyListener getDirtyListener()
ICheckpointProtocolIDirtyListener.getDirtyListener in interface ICheckpointProtocolpublic final void setDirtyListener(IDirtyListener listener)
ICheckpointProtocolsetDirtyListener in interface ICheckpointProtocollistener - The listener.protected final void fireDirtyEvent()
public final boolean flush()
BTree to the backing store. After invoking
this method the root of the BTree will be clean.
Note: This does NOT flush all persistent state. See
writeCheckpoint() which also handles the optional bloom filter,
the IndexMetadata, and the Checkpoint record itself.
true if anything was written.public HTree asReadOnly()
HTree. If BTree is
already read-only, then this instance is returned. Otherwise, a
read-only BTree is loaded from the last checkpoint and returned.IllegalStateException - If the BTree is dirty.public final long writeCheckpoint()
#flush() dirty nodes, dirty persistent
data structures, etc, write a new Checkpoint record on the
backing store, save a reference to the current Checkpoint, and
return the address of that Checkpoint record.
Note: A checkpoint by itself is NOT an atomic commit. The commit protocol
is at the store level and uses Checkpoints to ensure that the
state of the persistence capable data structure is current on the backing
store.
writeCheckpoint in interface ICheckpointProtocolCheckpoint record for the
persistence capable was written onto the store. The data
structure can be reloaded from this Checkpoint record.#load(IRawStore, long)public final Checkpoint writeCheckpoint2()
#flush() dirty nodes, dirty persistent
data structures, etc, write a new Checkpoint record on the
backing store, save a reference to the current Checkpoint, and
return the address of that Checkpoint record.
Note: A checkpoint by itself is NOT an atomic commit. The commit protocol
is at the store level and uses Checkpoints to ensure that the
state of the persistence capable data structure is current on the backing
store.
writeCheckpoint2 in interface ICheckpointProtocolCheckpoint record for the persistent data structure
which was written onto the store. The persistent data structure
can be reloaded from this Checkpoint record.#load(IRawStore, long)public boolean contains(Object obj)
public boolean contains(int key)
public boolean contains(byte[] key)
true iff there is at least one tuple in the hash tree
having the specified key.key - The key.true iff the hash tree contains at least one tuple
with that key.IllegalArgumentException - if the key is null.
TODO Parallel to insert(), consider a contains() signature
which permits testing for a specific value as well. Maybe
in a wrapper class?public byte[] lookupFirst(int key)
key - The key.null if there are
no tuples in the index having that key. Note that the return
value is not diagnostic if the application allows
null values into the index.public byte[] lookupFirst(byte[] key)
key - The key.null if there are
no tuples in the index having that key. Note that the return
value is not diagnostic if the application allows
null values into the index.public ITupleIterator lookupAll(int key)
key - The key.null.public ITupleIterator lookupAll(byte[] key)
key - The key.null.public void insert(Object obj)
public void insert(int key,
byte[] val)
public byte[] insert(byte[] key,
byte[] value)
key - The key.value - The value.null (always).
TODO If the application wants to restrict the hash tree to such
that it does not contain duplicate tuples then it must first
search in the tree for an exact match (key and value). It is
easier to do that from within the insert logic so expand the
method signature to pass an insert enum {ALLDUPS,DUPKEYS,NODUPS}.protected void insertRawTuple(com.bigdata.htree.BucketPage src,
int slot)
src - The source BucketPage srcslot - The slot in the source BucketPage whose tuple will be
inserted (really copied).public byte[] remove(byte[] key)
key - public int removeAll(byte[] key)
protected com.bigdata.htree.AbstractPage locatePageForKey(byte[] key)
public void removeAll()
ISimpleIndexAccessremoveAll in interface ISimpleIndexAccesspublic long rangeCount()
AbstractHTreerangeCount in interface ISimpleIndexAccessrangeCount in class AbstractHTreeIRangeQuery.rangeCount()public BaseIndexStats dumpPages(boolean recursive, boolean visitLeaves)
ICheckpointProtocoldumpPages in interface ICheckpointProtocolrecursive - When true, also collects statistics on the pages
(nodes and leaves) using a low-level approach.visitLeaves - When true and recursive:=true then the
leaves of the index are also visited.public static HTree create(IRawStore store, HTreeIndexMetadata metadata)
HTree or derived class. This method works by writing
the IndexMetadata record on the store and then loading the
HTree from the IndexMetadata record.store - The store.metadata - The metadata record.HTree.IllegalStateException - If you attempt to create two HTree objects from the
same metadata record since the metadata address will have
already been noted on the IndexMetadata object. You
can use IndexMetadata.clone() to obtain a new copy of
the metadata object with the metadata address set to
0L.IllegalStateException - if the IndexTypeEnum in the supplied
IndexMetadata object is not
IndexTypeEnum.BTree.load(IRawStore, long, boolean)public static HTree createTransient(HTreeIndexMetadata metadata)
HTree or derived class that is fully transient (NO
backing IRawStore).
Fully transient HTrees provide the functionality of a HTree
without a backing persistence store. Internally, reachable nodes and
leaves of the transient HTree use hard references to ensure that
remain strongly reachable. Deleted nodes and leaves simply clear their
references and will be swept by the garbage collector shortly thereafter.
Operations which attempt to write on the backing store will fail.
While nodes and leaves are never persisted, the keys and values of the
transient HTree are unsigned byte[]s. This means that application
keys and values are always converted into unsigned byte[]s before being
stored in the HTree. Hence if an object that is inserted into
the HTree and then looked up using the HTree API, you
WILL NOT get back the same object reference.
Note: CLOSING A TRANSIENT INDEX WILL DISCARD ALL DATA!
metadata - The metadata record.HTree.public static HTree load(IRawStore store, long addrCheckpoint, boolean readOnly)
HTree or derived class from the store. The
HTree or derived class MUST declare a constructor with the
following signature:
className(IRawStore store, Checkpoint checkpoint, IndexMetadata metadata, boolean readOnly)
store - The store.addrCheckpoint - The address of a Checkpoint record for the index.readOnly - When true the BTree will be marked as
read-only. Marking has some advantages relating to the locking
scheme used by Node.getChild(int) since the root node
is known to be read-only at the time that it is allocated as
per-child locking is therefore in place for all nodes in the
read-only BTree. It also results in much higher
concurrency for AbstractBTree.touch(AbstractNode).HTree or derived class loaded from that
Checkpoint record.IllegalArgumentException - if store is null.protected int recycle(long addr)
BTreeCounters.addr - The address to be recycled.IAddressManager.NULL.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.