The idea behind the two-phase commit protocol is that during the first phase, each resource manager only agrees that it can proceed with the commit. The resource manager can only do that if it has stored the transaction's updates to the log. If it says it can commit, and then fails, it uses the log to finish the commit processing when it recovers.
In the case of a single transaction manager, the two-phase commit protocol is straightforward:
The two-phase commit protocol is defined in terms of a coordinator and participants. In the case where there are resource managers on more than one node, one of the transaction managers (the coordinator) is held responsible for directing the overall two-phase commit. If a given transaction includes resource managers from other nodes, the transaction managers from those nodes become participants in the two-phase commit. The prime transaction manager sees the secondary transaction managers as resources. They, in turn, ask their resource managers (and any transaction managers that are subordinate to them for this transaction) to prepare and to commit.
The transaction managers and resource managers thus form a tree. This is called the tree-of-processes model. The "Request to Prepare", "Commit" and "Abort" messages move down this tree and the "Prepared" and "Done" messages move up. Each transaction manager at an interior node of this tree is responsible for managing the sub-tree below it.