in accord-core/src/main/java/accord/local/cfk/CommandsForKey.java [1248:1335]
public boolean visit(TxnId testTxnId,
Kinds testKind,
TestStartedAt testStartedAt,
Timestamp testStartedAtTimestamp,
ComputeIsDep computeIsDep,
Predicate<SummaryStatus> testStatus,
AllCommandVisitor visitor)
{
int start, end, loadingIndex = 0;
// if this is null the TxnId is known in byId
// otherwise, it must be non-null and represents the transactions (if any) that have requested it be loaded due to being pruned
TxnId prunedBefore = prunedBefore();
TxnId[] loadingFor = null;
{
int insertPos = Arrays.binarySearch(byId, testStartedAtTimestamp);
if (insertPos < 0)
{
loadingFor = NOT_LOADING_PRUNED;
insertPos = -1 - insertPos;
if (computeIsDep != IGNORE && testTxnId.compareTo(prunedBefore) < 0)
loadingFor = loadingPrunedFor(loadingPruned, testTxnId, NOT_LOADING_PRUNED);
}
switch (testStartedAt)
{
default: throw new UnhandledEnum(testStartedAt);
case STARTED_BEFORE: start = 0; end = insertPos; break;
case STARTED_AFTER: start = insertPos; end = byId.length; break;
case ANY: start = 0; end = byId.length;
}
}
for (int i = start; i < end ; ++i)
{
TxnInfo txn = byId[i];
if (!txn.is(testKind)) continue;
SummaryStatus summaryStatus = txn.summaryStatus();
if (summaryStatus == null || (testStatus != null && !testStatus.test(summaryStatus))) continue;
Timestamp executeAt = txn.executeAt;
IsDep dep = null;
if (computeIsDep != IGNORE)
{
if (!txn.hasDeps() || (summaryStatus == SummaryStatus.ACCEPTED ? txn : executeAt).compareTo(testTxnId) <= 0)
{
dep = NOT_ELIGIBLE;
}
else
{
boolean hasAsDep;
if (loadingFor == null)
{
TxnId[] missing = txn.missing();
hasAsDep = missing == NO_TXNIDS || Arrays.binarySearch(txn.missing(), testTxnId) < 0;
}
else if (loadingFor == NOT_LOADING_PRUNED)
{
hasAsDep = false;
}
else
{
// we could use expontentialSearch and moving index for improved algorithmic complexity,
// but since should be rarely taken path probably not worth code complexity
loadingIndex = SortedArrays.exponentialSearch(loadingFor, loadingIndex, loadingFor.length, txn);
if (loadingIndex >= 0)
{
hasAsDep = !loadingFor[loadingIndex].is(UNSTABLE);
++loadingIndex;
}
else
{
hasAsDep = false;
loadingIndex = -1 - loadingIndex;
}
}
if (txn.compareTo(ACCEPTED) >= 0) dep = hasAsDep ? IS_STABLE_DEP : IS_NOT_STABLE_DEP;
else if (txn.is(PrivilegedCoordinatorWithDeps)) dep = hasAsDep ? IS_COORD_DEP : IS_NOT_COORD_DEP;
else dep = NOT_ELIGIBLE;
}
}
if (!visitor.visit(key, txn.plainTxnId(), executeAt, summaryStatus, dep, txn.isDurable() ? Majority : NotDurable))
return false;
}
return true;
}