in accord-core/src/main/java/accord/local/cfk/CommandsForKey.java [2156:2271]
private void checkIntegrity()
{
if (isParanoid())
{
Invariants.require(byId.length == 0 || byId[0].compareTo(redundantBefore()) >= 0);
Invariants.require(prunedBeforeById == -1 || (prunedBefore().is(APPLIED) && prunedBefore().is(Write)));
Invariants.require(minUndecidedById < 0 || (byId[minUndecidedById].status().compareTo(InternalStatus.COMMITTED) < 0 && mayExecute(byId[minUndecidedById])));
Invariants.require(maxAppliedWrite() == null || maxUniqueHlc >= maxAppliedWrite().executeAt.hlc());
Invariants.require(maxAppliedPreBootstrapWriteById < 0 || (maxAppliedPreBootstrapWriteById < byId.length && byId[maxAppliedPreBootstrapWriteById].isWrite() && !byId[maxAppliedPreBootstrapWriteById].mayExecute()));
if (maxAppliedWriteByExecuteAt >= 0)
{
Invariants.require(committedByExecuteAt[maxAppliedWriteByExecuteAt].kind() == Write);
Invariants.require(committedByExecuteAt[maxAppliedWriteByExecuteAt].is(APPLIED));
}
if (testParanoia(LINEAR, NONE, LOW))
{
Invariants.requireArgument(SortedArrays.isSortedUnique(byId));
Invariants.requireArgument(SortedArrays.isSortedUnique(committedByExecuteAt, TxnInfo::compareExecuteAt));
for (TxnInfo txn : byId)
{
Invariants.require(mayExecute(txn) == txn.mayExecute());
Invariants.require(txn.hasDeps() || txn.missing() == NO_TXNIDS);
}
for (TxnInfo txn : committedByExecuteAt) Invariants.require(txn.mayExecute());
if (minUndecidedById >= 0) for (int i = 0 ; i < minUndecidedById ; ++i) Invariants.require(byId[i].status().compareTo(InternalStatus.COMMITTED) >= 0 || !mayExecute(byId[i]) || isPreBootstrap(byId[i]));
else for (TxnInfo txn : byId) Invariants.require(txn.status().compareTo(InternalStatus.COMMITTED) >= 0 || !mayExecute(txn) || isPreBootstrap(txn));
if (maxAppliedWriteByExecuteAt >= 0)
{
for (int i = maxAppliedWriteByExecuteAt + 1; i < committedByExecuteAt.length ; ++i)
Invariants.require(committedByExecuteAt[i].kind() != Kind.Write || committedByExecuteAt[i].status().compareTo(APPLIED) < 0);
}
else
{
for (TxnInfo txn : committedByExecuteAt)
Invariants.require(txn.kind() != Kind.Write || txn.status().compareTo(APPLIED) < 0 && mayExecute(txn));
}
LoadingPruned minLoadingPruned = BTree.isEmpty(loadingPruned) ? null : BTree.findByIndex(loadingPruned, 0);
Invariants.require(minLoadingPruned == null|| redundantBefore().compareTo(BTree.findByIndex(loadingPruned, 0)) <= 0);
for (Unmanaged unmanaged : unmanageds)
Invariants.require(unmanaged.waitingUntil.epoch() < bounds.endEpoch);
}
if (testParanoia(SUPERLINEAR, NONE, LOW))
{
for (TxnInfo txn : committedByExecuteAt)
{
Invariants.require(txn == get(txn, byId));
}
for (TxnInfo txn : byId)
{
if (txn.isCommittedAndExecutes())
Invariants.require(Arrays.binarySearch(committedByExecuteAt, txn, TxnInfo::compareExecuteAt) >= 0);
for (TxnId missingId : txn.missing())
{
Invariants.require(txn.witnesses(missingId));
TxnInfo missingInfo = get(missingId, byId);
Invariants.require(missingInfo == null ? missingId.is(UNSTABLE) && find(loadingPruned, missingId) != null : missingInfo.status().compareTo(InternalStatus.COMMITTED) < 0);
Invariants.require(txn.depsKnownBefore().compareTo(missingId) >= 0);
}
if (txn.isCommittedAndExecutes())
Invariants.require(txn == committedByExecuteAt[Arrays.binarySearch(committedByExecuteAt, 0, committedByExecuteAt.length, txn, TxnInfo::compareExecuteAt)]);
}
for (LoadingPruned txn : BTree.<LoadingPruned>iterable(loadingPruned))
{
Invariants.require(indexOf(txn) < 0);
}
int decidedBefore = minUndecidedById < 0 ? byId.length : minUndecidedById;
if (!BTree.isEmpty(loadingPruned))
{
int maxDecidedBefore = Arrays.binarySearch(byId, BTree.findByIndex(loadingPruned, 0));
if (maxDecidedBefore < 0)
maxDecidedBefore = -2 - maxDecidedBefore;
if (maxDecidedBefore < decidedBefore)
decidedBefore = maxDecidedBefore;
}
int appliedBefore = 1 + maxContiguousManagedAppliedIndex(committedByExecuteAt, maxAppliedWriteByExecuteAt, bootstrappedAt());
if (bootstrappedAt() != null)
{
for (int i = 0 ; i < appliedBefore ; ++i)
{
if (committedByExecuteAt[i].compareTo(bootstrappedAt()) < 0) continue;
if (!committedByExecuteAt[i].is(APPLIED))
{
appliedBefore = i;
break;
}
}
}
for (Unmanaged unmanaged : unmanageds)
{
switch (unmanaged.pending)
{
case COMMIT:
{
int byIdIndex = Arrays.binarySearch(byId, unmanaged.waitingUntil);
if (byIdIndex < 0)
byIdIndex = -1 - byIdIndex;
Invariants.require(byIdIndex >= decidedBefore || isAnyPredecessorWaitingOnPruned(loadingPruned, unmanaged.txnId));
break;
}
case APPLY:
{
int byExecuteAtIndex = SortedArrays.binarySearch(committedByExecuteAt, 0, committedByExecuteAt.length, unmanaged.waitingUntil, (f, i) -> f.compareTo(i.executeAt), FAST);
Invariants.require(byExecuteAtIndex >= 0 && byExecuteAtIndex >= appliedBefore);
break;
}
}
}
}
}
}