I understand the 2 phase commit architecture. Let there be 2 slaves and 1 master and the all prepare phases went fine. When the master askede slave 1 to commit, the commit was fine. When master asked slave 2 to commit, it failed. So the master now needs to rollback the entire transaction. My queston is how slave 1 will now rollbakc since it has already committed? From my knowledge, commits are full and final. There maybe save points or journals on disk to restore state but that may require DBA assistance.
Reference on SO - Can a transaction be rolled back after it's committed and connection is closed?
That is normally not possible. The prepare phase of a two-phase commit should do everything necessary to make the transaction durable, except making it visible to others. After a prepare has been completed successfully a commit should always be possible. Once a two-phase commit has been committed it cannot be backed out.
If a commit of an already prepared transaction fails (eg because the resource is temporarily unavailable), then the resource manager should be able to recover the transaction and retry the commit. If this is not possible, then the resource doesn't support true two-phase commit and is probably faking it (for example by ignoring the prepare call).
So the successful commit should not be rolled back, but the failed commit should be retried!