com.bigdata.service
Class CacheOnceMetadataIndex

java.lang.Object
  extended by com.bigdata.service.CacheOnceMetadataIndex
All Implemented Interfaces:
IRangeQuery, IMetadataIndex
Direct Known Subclasses:
CachingMetadataIndex

public class CacheOnceMetadataIndex
extends Object
implements IMetadataIndex

Implementation caches all locators but does not allow stale locators. This is useful for read-historical index views since locators can not become stale for a historical view.

Version:
$Id: CacheOnceMetadataIndex.java 5915 2012-01-30 16:47:10Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected  AbstractScaleOutFederation<?> fed
          The federation.
protected static org.apache.log4j.Logger log
           
protected  MetadataIndex.MetadataIndexMetadata mdmd
          Cached metadata record for the metadata index.
protected  String name
          Name of the scale-out index.
protected  long timestamp
          Timestamp of the view.
 
Fields inherited from interface com.bigdata.btree.IRangeQuery
ALL, CURSOR, DEFAULT, DELETED, FIXED_LENGTH_SUCCESSOR, KEYS, NONE, PARALLEL, READONLY, REMOVEALL, REVERSE, VALS
 
Constructor Summary
CacheOnceMetadataIndex(AbstractScaleOutFederation<?> fed, String name, long timestamp, MetadataIndex.MetadataIndexMetadata mdmd)
          Caches the index partition locators.
 
Method Summary
protected  void cacheLocators(byte[] fromKey, byte[] toKey)
          Bulk copy the partition definitions for the scale-out index into the client.
 PartitionLocator find(byte[] key)
          Find and return the partition spanning the given key.
 PartitionLocator get(byte[] key)
          The partition with that separator key or null (exact match on the separator key).
 MetadataIndex.MetadataIndexMetadata getIndexMetadata()
          The metadata for the metadata index itself.
 IndexMetadata getScaleOutIndexMetadata()
          The metadata template for the scale-out index managed by this metadata index.
 long rangeCount()
          Return the #of tuples in the index.
 long rangeCount(byte[] fromKey, byte[] toKey)
          Return the #of tuples in a half-open key range.
 long rangeCountExact(byte[] fromKey, byte[] toKey)
          Return the exact #of tuples in a half-open key range.
 long rangeCountExactWithDeleted(byte[] fromKey, byte[] toKey)
          Return the exact #of tuples in a half-open key range, including any deleted tuples.
 ITupleIterator rangeIterator()
          Visits all tuples in key order.
 ITupleIterator rangeIterator(byte[] fromKey, byte[] toKey)
          Return an iterator that visits the entries in a half-open key range.
 ITupleIterator rangeIterator(byte[] fromKey, byte[] toKey, int capacity, int flags, IFilter filter)
          Designated variant (the one that gets overridden) for an iterator that visits the entries in a half-open key range.
 void staleLocator(PartitionLocator locator)
          Notification that a locator is stale.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log

fed

protected final AbstractScaleOutFederation<?> fed
The federation.


name

protected final String name
Name of the scale-out index.


timestamp

protected final long timestamp
Timestamp of the view.


mdmd

protected final MetadataIndex.MetadataIndexMetadata mdmd
Cached metadata record for the metadata index.

Constructor Detail

CacheOnceMetadataIndex

public CacheOnceMetadataIndex(AbstractScaleOutFederation<?> fed,
                              String name,
                              long timestamp,
                              MetadataIndex.MetadataIndexMetadata mdmd)
Caches the index partition locators.

Parameters:
name - The name of the scale-out index.
Method Detail

toString

public String toString()
Overrides:
toString in class Object

cacheLocators

protected void cacheLocators(byte[] fromKey,
                             byte[] toKey)
Bulk copy the partition definitions for the scale-out index into the client.

Note: This assumes that the metadata index is NOT partitioned and DOES NOT support delete markers.


staleLocator

public void staleLocator(PartitionLocator locator)
Description copied from interface: IMetadataIndex
Notification that a locator is stale. Caching implementations of this interface will use this notice to update their state from the authoritative metadata index. Non-caching and authoritative implementations just ignore this message.

Specified by:
staleLocator in interface IMetadataIndex
Parameters:
locator - The locator.
Throws:
UnsupportedOperationException - stale locators should not occur for read-historical views!

getIndexMetadata

public final MetadataIndex.MetadataIndexMetadata getIndexMetadata()
Description copied from interface: IMetadataIndex
The metadata for the metadata index itself. Note that the MetadataIndex.MetadataIndexMetadata.getManagedIndexMetadata() returns the template IndexMetadata for the scale-out index partitions.

Specified by:
getIndexMetadata in interface IMetadataIndex
See Also:
IMetadataIndex.getScaleOutIndexMetadata()

getScaleOutIndexMetadata

public final IndexMetadata getScaleOutIndexMetadata()
Description copied from interface: IMetadataIndex
The metadata template for the scale-out index managed by this metadata index.

Specified by:
getScaleOutIndexMetadata in interface IMetadataIndex

get

public PartitionLocator get(byte[] key)
Description copied from interface: IMetadataIndex
The partition with that separator key or null (exact match on the separator key).

Specified by:
get in interface IMetadataIndex
Parameters:
key - The separator key (the first key that would go into that partition).
Returns:
The partition with that separator key or null.

find

public PartitionLocator find(byte[] key)
Description copied from interface: IMetadataIndex
Find and return the partition spanning the given key.

Specified by:
find in interface IMetadataIndex
Parameters:
key - A key (optional). When null the locator for the last index partition will be returned.
Returns:
The partition spanning the given key or null if there are no partitions defined.

rangeCount

public long rangeCount()
Description copied from interface: IRangeQuery
Return the #of tuples in the index.

Note: If the index supports deletion markers then the range count will be an upper bound and may double count tuples which have been overwritten, including the special case where the overwrite is a delete.

Specified by:
rangeCount in interface IRangeQuery
Returns:
The #of tuples in the index.

rangeCount

public long rangeCount(byte[] fromKey,
                       byte[] toKey)
Description copied from interface: IRangeQuery
Return the #of tuples in a half-open key range. The fromKey and toKey need not exist in the B+Tree.

Note: If the index supports deletion markers then the range count will be an upper bound and may double count tuples which have been overwritten, including the special case where the overwrite is a delete.

Specified by:
rangeCount in interface IRangeQuery
Parameters:
fromKey - The lowest key that will be counted (inclusive). When null there is no lower bound.
toKey - The first key that will not be counted (exclusive). When null there is no upper bound.
Returns:
The #of tuples in the half-open key range.

rangeCountExact

public long rangeCountExact(byte[] fromKey,
                            byte[] toKey)
Description copied from interface: IRangeQuery
Return the exact #of tuples in a half-open key range. The fromKey and toKey need not exist in the B+Tree.

Note: If the index supports deletion markers then this operation will require a key-range scan.

Specified by:
rangeCountExact in interface IRangeQuery
Parameters:
fromKey - The lowest key that will be counted (inclusive). When null there is no lower bound.
toKey - The first key that will not be counted (exclusive). When null there is no upper bound.
Returns:
The exact #of tuples in the half-open key range.

rangeCountExactWithDeleted

public long rangeCountExactWithDeleted(byte[] fromKey,
                                       byte[] toKey)
Description copied from interface: IRangeQuery
Return the exact #of tuples in a half-open key range, including any deleted tuples. The fromKey and toKey need not exist in the B+Tree.

When the view is just an AbstractBTree the result is the same as for IRangeQuery.rangeCount(byte[], byte[]), which already reports all tuples regardless of whether or not they are deleted.

When the index is a view with multiple sources, this operation requires a key-range scan where both deleted and undeleted tuples are visited.

Specified by:
rangeCountExactWithDeleted in interface IRangeQuery
Parameters:
fromKey - The lowest key that will be counted (inclusive). When null there is no lower bound.
toKey - The first key that will not be counted (exclusive). When null there is no upper bound.
Returns:
The exact #of deleted and undeleted tuples in the half-open key range.
See Also:
IRangeQuery.rangeCountExact(byte[], byte[])

rangeIterator

public ITupleIterator rangeIterator()
Description copied from interface: IRangeQuery
Visits all tuples in key order. This is identical to
 rangeIterator(null, null)
 

Specified by:
rangeIterator in interface IRangeQuery
Returns:
An iterator that will visit all entries in key order.

rangeIterator

public ITupleIterator rangeIterator(byte[] fromKey,
                                    byte[] toKey,
                                    int capacity,
                                    int flags,
                                    IFilter filter)
Description copied from interface: IRangeQuery
Designated variant (the one that gets overridden) for an iterator that visits the entries in a half-open key range. When toKey EQ fromKey nothing will be visited. It is an error if toKey LT fromKey.

Specified by:
rangeIterator in interface IRangeQuery
Parameters:
fromKey - The first key that will be visited (inclusive lower bound). When null there is no lower bound.
toKey - The first key that will NOT be visited (exclusive upper bound). When null there is no upper bound.
capacity - The #of entries to buffer at a time. This is a hint and MAY be zero (0) to use an implementation specific default capacity. A non-zero value may be used if you know that you want at most N results or if you want to override the default #of results to be buffered before sending them across a network interface. (Note that you can control the default value using IBigdataClient.Options#DEFAULT_CLIENT_RANGE_QUERY_CAPACITY).
flags - A bitwise OR of IRangeQuery.KEYS, IRangeQuery.VALS, etc.
filter - An optional object used to construct a stacked iterator. When IRangeQuery.CURSOR is specified in flags, the base iterator will implement ITupleCursor and the first filter in the stack can safely cast the source iterator to an ITupleCursor. If the outermost filter in the stack does not implement ITupleIterator, then it will be wrapped an ITupleIterator.
See Also:
SuccessorUtil, which may be used to compute the successor of a value before encoding it as a component of a key., BytesUtil#successor(byte[]), which may be used to compute the successor of an encoded key., IFilterConstructor, which may be used to construct an iterator stack performing filtering or other operations.

rangeIterator

public ITupleIterator rangeIterator(byte[] fromKey,
                                    byte[] toKey)
Description copied from interface: IRangeQuery
Return an iterator that visits the entries in a half-open key range. When toKey EQ fromKey nothing will be visited. It is an error if toKey LT fromKey.

Specified by:
rangeIterator in interface IRangeQuery
Parameters:
fromKey - The first key that will be visited (inclusive lower bound). When null there is no lower bound.
toKey - The first key that will NOT be visited (exclusive upper bound). When null there is no upper bound.
See Also:
SuccessorUtil, which may be used to compute the successor of a value before encoding it as a component of a key., BytesUtil#successor(byte[]), which may be used to compute the successor of an encoded key., EntryFilter, which may be used to filter the entries visited by the iterator.


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