Table of Contents
ConsistentCut is a distributed algorithm that splits WAL on 2 global areas - Before
and After
. It guarantees that every transaction committed Before
also will be committed Before
on every other node participated in the transaction. It means that an Ignite nodes can safely recover themself to the consistent Before
state without any coordination with each other.
...
Picture bellow illustrates steps of the algorithm on single node:
lastFinishedCutId
lastFinishedCutId
holds previous ConsistentCutId
, or null.SnapshotOperationRequest
that holds that holds new ConsistentCutId
(goal is to notify every node in a cluster about running incremental snapshot). SnapshotOperationRequest#ConsistentCutId
by DiscoverySPI (by the DistributedProcess).ConsistentCutAwareMessage
#ConsistentCutId
by ConsistentCutAwareMessage#ConsistentCutId
by CommunicationSPI (by transaction messages - Prepare, Finish).ConsistentCutId
, every node: it starts local ConsistentCut: ConsistentCut
lastFinishedCutId
ConsistentCutAwareMessage#
topVer
with ConsistentCutAwareMessage#topVer
with local node order:ConsistentCut
future. ConsistentCut != null
wraps outgoing messages to ConsistentCutAwareMessage
. It contains info:ConsistentCutId
(to start ConsistentCut on remote node, if not yet).txCutId
equals to null then transaction starts committing Before
Consistent Cut started, otherwise After
.ConsistentCutAwareMessage
that makes transaction committed (FinishRequest for 2PC, PrepareResponse for 1PC) sets tx#txCutId = message#txCutId
.committingTxs
:committingTxs
ConsistentCut
committingTx
removedActiveTxs
(IgniteTxManager#activeTx
does).ConsistentCutAwareMessage
(contains ConsistentCutId
).ConsistentCutStartRecord
to WAL ConsistentCutId
.IgniteTxManager#activeTx
. tx#finishFuture
.tx#status == ACTIVE
. It's guaranteed that such transactions belongs After side.committingTxs
removedActiveTxs
(contains transactions that are IgniteTxManager#activeTx
). tx#finishFuture
.committingTxs
removedActiveTxs
to null. DistributedProcess
is running every node wraps outgoing transaction messages (Prepare, Finish) to ConsistentCutAwareMessage (
transaction has not committed yet on sender node)
or ConsistentCutAwareTxFinishMessage (
transaction has committed on a sender node)
. Messages contain info:ConsistentCutId
(to trigger ConsistentCut
on remote node, if not yet).ConsistentCutAwareTxFinishMessage
messages contains additionally txCutId
.
It set on the node that commits first (if it's not null then transaction starts committing After
Consistent Cut):removedActiveTxs
, they just don't land into "before" or "after" set and will be excluded from recovery.removedActiveTxs
if ConsistentCut != null
and removedActiveTxs != null
:removedActiveTxs
IgniteTxManager#activeTx
.ConsistentCutAwareTxFinishMessage
Ignite marks the related transaction with message#txCutId.
For every txCutId
equals tx#txCutId
equals to local, then put transaction ConsistentCutFinishRecord
into WAL with ConsistentCut
future.ConsistentCut
future becomes future becomes null....
tx.finalizationStatus
== RECOVERY_FINISH)....
Ignite transaction protocol includes multiple messages. But only some of them affects meaningful (relating to the algorithm) that change state of transactions (PREPARED, COMMITTED):
...
Those messages are wrapped in ConsistentCutAwareMessage
that is prepared right before sending message on other node. They used the current ConsistentCutId
.
Also some messages require to be combine with additional ConsistentCutId
to check it them on primary/backup node:
GridNearTxFinishRequest / GridDhtTxFinishRequest
GridNearTxPrepareResponse / GridDhtTxPrepareResponse
(for 1PC algorithm).Those messages are filled with txCutId
that is prepared right before transaction starts committing on first committing node. They used the current ConsistentCutId
for this setting. If current ConsistentCutId
is not null, then transaction starts committing after ConsistentCut started and it means that this transaction belongs the After
side.
Code Block | ||||
---|---|---|---|---|
| ||||
class ConsistentCutAwareMessage { /** Original transaction message. */ Message msg; /** Consistent Cut ID. */ UUID cutId; /** Consistent Cut ID after which transaction committed. */ @Nullable UUID txCutId; /** Cluster topology version on which Consistent Cut started. */ long topVer; } |
Also some messages require to be combine with additional ConsistentCutId
to check it them on primary/backup node.
GridNearTxFinishRequest / GridDhtTxFinishRequest
GridNearTxPrepareResponse / GridDhtTxPrepareResponse
(for 1PC algorithm)....
A new field added to IgniteInternalTx
Code Block | ||||
---|---|---|---|---|
| ||||
class IgniteInternalTx {
/**
* @param ID of {@link ConsistentCut} AFTER which this transaction was committed, {@code null} if transaction
* committed BEFORE.
*/
public void cutId(@Nullable UUID id);
} |
Code Block | ||||
---|---|---|---|---|
| ||||
// Class is responsible for managing all stuff related to Consistent Cut. It's an entrypoint for transaction threads to check running consistent cut.
class ConsistentCutManager extends GridCacheSharedManagerAdapter {
// Current Consistent Cut. All transactions threads wraps outgoing messages if this field is not null. */
volatile @Nullable ConsistentCut cut;
// Entrypoint for handling received new Consistent Cut ID.
void handleConsistentCutId(UUID id);
} |
Code Block | ||||
---|---|---|---|---|
| ||||
class ConsistentCutAwareTransactionFinishMessageConsistentCut extends ConsistentCutAwareMessageGridFutureAdapter<WALPointer> { /** Consistent Cut ID after which transaction committed. */ Set<GridCacheVersion> beforeCut; Set<GridCacheVersion> afterCut; @Nullable UUIDSet<IgniteInternalFuture<IgniteInternalTx>> txCutIdremovedActive; } |