Package com.yahoo.documentapi
Class ProgressToken
java.lang.Object
com.yahoo.documentapi.ProgressToken
Token to use to keep track of progress for visiting. Can be used to resume
visiting if visiting has been aborted for any reason.
- Author:
- Thomas Gundersen, vekterli
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
When a bucket has its state kept by the progress token, we need to discern between active buckets (i.e. those that have been returned byVisitorIterator.getNext()
but have not yet been update()'d) and pending buckets (i.e. those that have been update()'d and may be returned by getNext() at some point)static final record
For consistent bucket key ordering, we need to ensure that reverse bucket IDs that have their MSB set actually are compared as being greater than those that don't.static enum
Any bucket kept track of by aProgressToken
instance may be in one of two states: pending or active. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.yahoo.document.BucketId
static final com.yahoo.document.BucketId
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a progress token.ProgressToken
(byte[] serialized) ProgressToken
(int distributionBits) ProgressToken
(String serialized) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFailedBucket
(com.yahoo.document.BucketId superbucket, com.yahoo.document.BucketId progress, String errorMsg) static long
bucketToKey
(long id) boolean
static ProgressToken
fromSerializedString
(String serializedString) long
long
int
Map<com.yahoo.document.BucketId,
com.yahoo.document.BucketId> Get all failed buckets and their progress.long
long
long
boolean
boolean
boolean
isEmpty()
boolean
boolean
static long
keyToBucketId
(long key) static long
makeNthBucketKey
(long n, int distributionBits) Directly generate a bucket Id key for then
th bucket in reverse sorted order.double
Calculate an estimate on how far we've managed to iterate over both the superbuckets and the sub-buckets.double
progressFraction
(com.yahoo.document.BucketId superbucket, com.yahoo.document.BucketId progress) byte[]
Returns a string (base64) encoding of the serial form of this tokenvoid
setInconsistentState
(boolean inconsistentState) toString()
The format of the bucket progress output is as follows:
-
Field Details
-
NULL_BUCKET
public static final com.yahoo.document.BucketId NULL_BUCKET -
FINISHED_BUCKET
public static final com.yahoo.document.BucketId FINISHED_BUCKET
-
-
Constructor Details
-
ProgressToken
public ProgressToken()Creates a progress token. -
ProgressToken
public ProgressToken(int distributionBits) -
ProgressToken
-
ProgressToken
public ProgressToken(byte[] serialized)
-
-
Method Details
-
serialize
public byte[] serialize() -
serializeToString
Returns a string (base64) encoding of the serial form of this token -
fromSerializedString
-
addFailedBucket
public void addFailedBucket(com.yahoo.document.BucketId superbucket, com.yahoo.document.BucketId progress, String errorMsg) -
getFailedBuckets
Get all failed buckets and their progress. Not thread safe.- Returns:
- Unmodifiable map of all failed buckets
-
makeNthBucketKey
public static long makeNthBucketKey(long n, int distributionBits) Directly generate a bucket Id key for then
th bucket in reverse sorted order.- Parameters:
n
- a number in the range [0, 2**distributionBits
)distributionBits
- Distribution bit count for the generated key- Returns:
- A value where, if you had generated 2**
distributionBits
BucketId
s with incremental numerical IDs and then sorted them on their reverse bit-order keys, the returned key would be equal to the nth element in the resulting sorted sequence.
-
getDistributionBitCount
public int getDistributionBitCount() -
getActiveBucketCount
public long getActiveBucketCount() -
getBucketCursor
public long getBucketCursor() -
getFinishedBucketCount
public long getFinishedBucketCount() -
getTotalBucketCount
public long getTotalBucketCount() -
getPendingBucketCount
public long getPendingBucketCount() -
hasPending
public boolean hasPending() -
hasActive
public boolean hasActive() -
isFinished
public boolean isFinished() -
isEmpty
public boolean isEmpty() -
getFirstErrorMsg
-
containsFailedBuckets
public boolean containsFailedBuckets() -
isInconsistentState
public boolean isInconsistentState() -
setInconsistentState
public void setInconsistentState(boolean inconsistentState) -
toString
The format of the bucket progress output is as follows:VDS bucket progress file (n% completed)\n distribution bit count\n current bucket cursor\n number of finished buckets\n total number of buckets\n hex-of-superbucket:hex-of-progress\n ... repeat above line for each pending bucket ...
Note that unlike earlier versions of ProgressToken, the bucket IDs are not prefixed with '0x'. -
percentFinished
public double percentFinished()Calculate an estimate on how far we've managed to iterate over both the superbuckets and the sub-buckets. Runs in O(n+m) time, where n is the number of active buckets and m is the number of pending buckets. Both these values should be fairly small in practice, however. Method is synchronized, as legacy code treats this as an atomic read.- Returns:
- A value in the range [0, 100] estimating the progress.
-
bucketToKey
public static long bucketToKey(long id) -
keyToBucketId
public static long keyToBucketId(long key) -
progressFraction
public double progressFraction(com.yahoo.document.BucketId superbucket, com.yahoo.document.BucketId progress) - Parameters:
superbucket
- The superbucket of whichprogress
is a sub-bucketprogress
- The sub-bucket for which a fractional progress should be calculated- Returns:
- a value in [0, 1] specifying how far the (sub-bucket) has reached in its superbucket. This is calculated by looking at the bucket's split factor.
-