in accord-core/src/main/java/accord/local/Cleanup.java [174:230]
private static Cleanup cleanupWithFullRoute(Input input, StoreParticipants participants, TxnId txnId, Timestamp executeAt, SaveStatus saveStatus, Durability durability, RedundantBefore redundantBefore, DurableBefore durableBefore)
{
// We first check if the command is redundant locally, i.e. whether it has been applied to all non-faulty replicas of the local shard
// If not, we don't want to truncate its state else we may make catching up for these other replicas much harder
FullRoute<?> route = Route.castToFullRoute(participants.route());
// we must not use executeAt here if input == PARTIAL because with partial compaction we might be merging the combination of some old executeAt with a later partial status
RedundantStatus redundant = redundantBefore.status(txnId, input == FULL && saveStatus.known.is(ApplyAtKnown) ? executeAt : null, route);
Invariants.require(redundant.none(NOT_OWNED),"Command %s that is being loaded is not owned by this shard on route %s", txnId, route);
if (redundant.none(LOCALLY_REDUNDANT))
return NO;
Cleanup min = cleanupIfUndecidedWithFullRoute(input, txnId, saveStatus, redundant);
if (!redundant.all(TRUNCATE_BEFORE))
{
// TODO (expected): see if we can improve our invariants so we can remove this special-case
if (input != PARTIAL && redundant.all(SHARD_APPLIED) && redundant.all(LOCALLY_DEFUNCT) && !redundant.any(LOCALLY_APPLIED))
return truncate(txnId, min);
return min;
}
Invariants.paranoid(redundant.all(SHARD_APPLIED));
if (saveStatus.compareTo(Vestigial) >= 0)
{
// we can't use durability from an Invalidated record to decide if we can erase/expunge,
// as we don't know that this has been persisted at all shards.
// Similarly, vestigial/erased records don't know their etymology, and may derive from Invalidate
durability = NotDurable;
}
Durability test;
if (durability.compareTo(UniversalOrInvalidated) >= 0) test = durability;
else test = Durability.max(durability, durableBefore.min(txnId, participants.route()));
switch (test)
{
default: throw new UnhandledEnum(durability);
case Local:
case NotDurable:
case ShardUniversal:
// TODO (required): consider how we guarantee not to break recovery of other shards if a majority on this shard are PRE_BOOTSTRAP
// (if the condition is false and we fall through to removing Outcome)
if (participants.doesStillExecute())
return min.atLeast(truncateWithOutcome(txnId, min));
case MajorityOrInvalidated:
case Majority:
return min.atLeast(truncate(txnId, min));
case UniversalOrInvalidated:
case Universal:
if (redundant.all(GC_BEFORE))
return erase(txnId, min);
return truncate(txnId, min);
}
}