-
Notifications
You must be signed in to change notification settings - Fork 82
Transaction framework
The transaction framework ensures that a given set of actions will be performed in order, one after another, on the required peers of the cluster.
The new transaction framework is built around the central store (etcd). A GD2 transaction will have the following characteristics:
- actions will only be performed where required, instead of being done across the whole cluster
- final committing into the store will only be done by the node where the transaction was initiated, instead of being done on all nodes.
A transaction is basically a collection of steps or actions to be performed in order. A transaction object provides the framework with the following,
- a list of nodes that will be a part of the transaction
- a set of transaction steps
Given this information, the GD2 transaction framework will,
- verify if all the listed nodes are online
- run each step on all of the nodes, before proceeding to the next step
- if a step fails, undo the changes done by the step and all previous steps.
The base transaction is basically free-form, allow users to create any order of steps. This keeps it flexible and extensible to create complex transactions.
A step is an action to be performed, most likely a function that needs to be run. A step object provides the following information,
- The function to be run
- The list of nodes the step should be run on.
- An undo function that reverts any changes done by the step.
Each step can have its own list of nodes, so that steps can be targeted to specific nodes and provide more flexibility.
nodes = ["source", "dest"]
checkdest = Step{Func: CanBrickBeCreated, Undo: nil. Nodes:["dest"]}
updateVolume = Step{Func: UpdateVolumeWithNewInfo, Undo: RevertToOldVolume, Nodes[LEADER]}
stopsource = Step{Func:Stopbrick, Undo: StartBrick, Nodes:["source"]}
startdest = Step{Func:Startbrick, Undo: StopBrick, Nodes:["dest"]}
replaceBrick = Txn{Nodes: nodes, Steps:[checkdest, updateVolume, startdest, stopsource]}
res, err = replaceBrick.Perform()