public abstract class AbstractChunkedTupleIterator<E> extends Object implements ITupleIterator<E>
ResultSet
at a time. This
introduces the concept of a continuationQuery()
so that the iterator
can materialize the tuples using a sequence of queries that progresses
through the index until all tuples in the key range have been visited.Modifier and Type | Class and Description |
---|---|
class |
AbstractChunkedTupleIterator.ResultSetTuple
|
Modifier and Type | Field and Description |
---|---|
protected int |
capacity
This controls the #of results per data service query.
|
protected static boolean |
DEBUG |
protected static String |
ERR_NO_KEYS
Error message used by
#getKey() when the iterator was not
provisioned to request keys from the data service. |
protected static String |
ERR_NO_VALS
Error message used by
#getValue() when the iterator was not
provisioned to request values from the data service. |
protected boolean |
exhausted
When true, the entire key range specified by the client has been visited
and the iterator is exhausted (i.e., all done).
|
protected IFilter |
filter
Optional filter.
|
protected int |
flags
These flags control whether keys and/or values are requested.
|
protected byte[] |
fromKey
The first key to visit -or- null iff no lower bound.
|
protected static boolean |
INFO |
protected int |
lastVisited
The index of the last entry visited in the current
ResultSet . |
protected byte[] |
lastVisitedKeyInPriorResultSet
This gets set by
continuationQuery() to the value of the key for
the then current tuple . |
protected static org.apache.log4j.Logger |
log |
protected int |
nqueries
The #of range query operations executed.
|
protected long |
nvisited
The #of enties visited so far.
|
protected ResultSet |
rset
The current result set.
|
protected byte[] |
toKey
The first key to NOT visit -or- null iff no upper bound.
|
Constructor and Description |
---|
AbstractChunkedTupleIterator(byte[] fromKey,
byte[] toKey,
int capacity,
int flags,
IFilter filter) |
Modifier and Type | Method and Description |
---|---|
protected void |
continuationQuery()
Issues a "continuation" query against the same index.
|
protected void |
deleteBehind() |
protected abstract void |
deleteBehind(int n,
Iterator<byte[]> keys)
Batch delete the index entries identified by keys and clear the
list.
|
protected abstract void |
deleteLast(byte[] key)
Delete the index entry identified by key.
|
void |
flush()
Method flushes any queued deletes.
|
protected long |
getCommitTime()
The timestamp returned by the initial
ResultSet . |
protected int |
getDefaultCapacity()
The capacity used by default when the caller specified
0
as the capacity for the iterator. |
int |
getQueryCount()
The #of queries issued so far.
|
protected abstract boolean |
getReadConsistent()
When
true the getCommitTime() will be used to
ensure that continuationQuery() s run against the same commit
point for the local index partition thereby producing a read
consistent view even when the iterator is ITx.READ_COMMITTED . |
protected long |
getReadTime()
Return the timestamp used for
continuationQuery() s. |
protected abstract ResultSet |
getResultSet(long timestamp,
byte[] fromKey,
byte[] toKey,
int capacity,
int flags,
IFilter filter)
Abstract method must return the next
ResultSet based on the
supplied parameter values. |
protected abstract long |
getTimestamp()
The timestamp for the operation as specified by the ctor (this is used
for remote index queries but when running against a local index).
|
long |
getVisitedCount()
The #of entries visited so far (not the #of entries scanned, which can be
much greater if a filter is in use).
|
boolean |
hasNext()
There are three levels at which we need to test in order to determine if
the total iterator is exhausted.
|
ITuple<E> |
next()
Advance the iterator and return the
ITuple from which you can
extract the data and metadata for next entry. |
protected void |
rangeQuery()
Issues the original range query.
|
protected abstract IBlock |
readBlock(int sourceIndex,
long addr)
Return an object that may be used to read the block from the backing
store per the contract for
ITuple.readBlock(long) |
void |
remove()
Queues a request to remove the entry under the most recently visited key.
|
protected static final transient org.apache.log4j.Logger log
protected static final transient boolean INFO
protected static final transient boolean DEBUG
protected static final transient String ERR_NO_KEYS
#getKey()
when the iterator was not
provisioned to request keys from the data service.protected static final transient String ERR_NO_VALS
#getValue()
when the iterator was not
provisioned to request values from the data service.protected final byte[] fromKey
protected final byte[] toKey
protected final int capacity
protected final int flags
protected final IFilter filter
protected int nqueries
protected ResultSet rset
Note: A result set will be empty if there are no entries (after filtering) that lie within the key range in a given index partition. It is possible for any of the result sets to be empty. Consider a case of static partitioning of an index into N partitions. When the index is empty, a range query of the entire index will still query each of the N partitions. However, since the index is empty none of the partitions will have any matching entries and all result sets will be empty.
rangeQuery()
,
continuationQuery()
protected long nvisited
protected int lastVisited
protected boolean exhausted
protected byte[] lastVisitedKeyInPriorResultSet
continuationQuery()
to the value of the key for
the then current tuple
. This is used by remove()
in
the edge case where lastVisited
is -1
because a
continuation query has been issued but next()
has not yet been
invoked. It is cleared by next()
so that it does not hang
around.public AbstractChunkedTupleIterator(byte[] fromKey, byte[] toKey, int capacity, int flags, IFilter filter)
protected abstract long getTimestamp()
protected long getCommitTime()
ResultSet
.protected abstract boolean getReadConsistent()
true
the getCommitTime()
will be used to
ensure that continuationQuery()
s run against the same commit
point for the local index partition thereby producing a read
consistent view even when the iterator is ITx.READ_COMMITTED
.
When false
continuationQuery()
s will use
whatever value is returned by getTimestamp()
. Read-consistent
semantics for a partitioned index are achieved using the timestamp
returned by IIndexStore.getLastCommitTime()
rather than
ITx.READ_COMMITTED
.protected final long getReadTime()
continuationQuery()
s. The value
returned depends on whether or not getReadConsistent()
is
true
. When consistent reads are required the timestamp
will be the ResultSet.getCommitTime()
for the initial
ResultSet
. Otherwise it is the value returned by
getTimestamp()
.IllegalStateException
- if getReadConsistent()
is true
and
the initial ResultSet
has not been read since the
commitTime for that ResultSet
is not yet available.public int getQueryCount()
public long getVisitedCount()
protected int getDefaultCapacity()
0
as the capacity for the iterator.protected abstract ResultSet getResultSet(long timestamp, byte[] fromKey, byte[] toKey, int capacity, int flags, IFilter filter)
ResultSet
based on the
supplied parameter values.timestamp
- fromKey
- toKey
- capacity
- flags
- filter
- protected void rangeQuery()
protected void continuationQuery()
ResultSet
but
ResultSet.isExhausted()
is [false], indicating that there is more
data available.public boolean hasNext()
ResultSet
. If not and
the ResultSet
is NOT exhausted
,
then we issue a continuationQuery()
against the same index
partition. If the ResultSet
is
exhausted
, then we test to see whether
or not we have visited all index partitions. If so, then the iterator is
exhausted. Otherwise we issue a range query against the
#nextPartition()
.public ITuple<E> next()
ITupleIterator
ITuple
from which you can
extract the data and metadata for next entry.
Note: An ITupleIterator
s will generally return the same
ITuple
reference on on each invocation of this method. The caller
is responsible for copying out any data or metadata of interest before
calling ITupleIterator.next()
again. See TupleFilter
which is aware of
this and can be used to stack filters safely.
public void remove()
ResultSet
is exhausted and then a batch delete will be done for the queue.public void flush()
flush()
under these
circumstances will result in some buffered deletes never being applied.protected void deleteBehind()
protected abstract void deleteBehind(int n, Iterator<byte[]> keys)
n
- The #of keys to be deleted.keys
- The keys to be deleted.protected abstract void deleteLast(byte[] key)
key
- A key.protected abstract IBlock readBlock(int sourceIndex, long addr)
ITuple.readBlock(long)
sourceIndex
- The value from ITuple.getSourceIndex()
.addr
- The value supplied to ITuple.readBlock(long)
.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.