User Tools

Site Tools


tutorial:transfer-api_transactions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:transfer-api_transactions [2023/07/19 13:48] – [Implementing support for transactions] technici4ntutorial:transfer-api_transactions [2023/07/19 14:00] (current) – [Nested transactions] technici4n
Line 110: Line 110:
 Here is the branching graph for that first example: Here is the branching graph for that first example:
  
-{{https://i.imgur.com/qW0ROX3.png}}+{{:tutorial:transaction_graph_1.png?nolink&400|}}
  
 ==== Nested transactions ==== ==== Nested transactions ====
Line 152: Line 152:
 Here is the corresponding graph: Here is the corresponding graph:
  
-{{https://i.imgur.com/n4jZ9FH.png}}+{{:tutorial:transaction_graph_2.png?nolink|}}
  
 === Transaction vs TransactionContext === === Transaction vs TransactionContext ===
Line 245: Line 245:
  
 Now that we have been through this background knowledge, here is how the ''SnapshotParticipant'' operates: Now that we have been through this background knowledge, here is how the ''SnapshotParticipant'' operates:
-When ''updateSnapshots'' is called: +  * When ''updateSnapshots'' is called: 
-  If we already have a snapshot for this transaction, do nothing. +    If we already have a snapshot for this transaction, do nothing. 
-  Otherwise call ''createSnapshot'' to save a snapshot, and add a close callback. +    Otherwise call ''createSnapshot'' to save a snapshot, and add a close callback. 
-When a transaction is aborted: +  When a transaction is aborted: 
-  We are guaranteed to have a snapshot for that transaction due to how state is managed. +    We are guaranteed to have a snapshot for that transaction due to how state is managed. 
-  Call ''readSnapshot'' to revert the state changes. +    Call ''readSnapshot'' to revert the state changes. 
-When a transaction is committed: +  When a transaction is committed: 
-  If this is an outer (= not nested) transaction, the change is confirmed. +    If this is an outer (= not nested) transaction, the change is confirmed. 
-    We know that something probably changed, otherwise we would not have a registered close callback. +      We know that something probably changed, otherwise we would not have a registered close callback. 
-    Call ''addOuterCloseCallback''. The callback will call ''onFinalCommit''+      Call ''addOuterCloseCallback''. The callback will call ''onFinalCommit''
-  If this is a nested transaction, we need to deal with the snapshot: +    If this is a nested transaction, we need to deal with the snapshot: 
-    If the parent transaction already has an older snapshot, discard the more recent snapshot. +      If the parent transaction already has an older snapshot, discard the more recent snapshot. 
-    Otherwise the snapshot is moved to the parent transaction.+      Otherwise the snapshot is moved to the parent transaction.
  
 Hopefully that gives an overview of what is happening under the hood. You should now be ready to read [[https://github.com/FabricMC/fabric/blob/1.20.1/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/transaction/base/SnapshotParticipant.java|the source code of SnapshotParticipant]]. Hopefully that gives an overview of what is happening under the hood. You should now be ready to read [[https://github.com/FabricMC/fabric/blob/1.20.1/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/transaction/base/SnapshotParticipant.java|the source code of SnapshotParticipant]].
  
tutorial/transfer-api_transactions.1689774490.txt.gz · Last modified: 2023/07/19 13:48 by technici4n