320 likes | 447 Vues
This seminar report by Daniel Müller and Marcel Ziswiler provides a comprehensive overview of ACID principles—Atomicity, Consistency, Isolation, and Durability—in transaction management. It explores the Two-Phase Commit (2PC) protocol, an essential mechanism for ensuring reliable transaction processing. Detailed descriptions of transaction states, client and participant views, and exceptions are presented to help clarify the complexities involved in distributed transactions. Additionally, it introduces Mahalo as a transaction management tool within the contexts of Jini and JavaSpaces, offering valuable insights for software developers.
E N D
Jini TransactionPart II Daniel Müller Marcel Ziswiler Seminar Informations- & Kommunikationssysteme
Overview • ACID • 2 Phase Commit • Mahalo • Jini Transaction & JavaSpaces • References Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID 2 Phase Commit Mahalo Jini Transaction & JavaSpaces References ACID • Atomicity • Consistency • Isolation • Durability Daniel Müller Seminar Informations- & Kommunikationssysteme
T = (a := a+5; => Two Phase Commit ACID Atomicity Consistency Isolation Durability Atomicity • All operations of a transaction occur or none of them! T = (a := a+5; b := b+3) Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID Atomicity Consistency Isolation Durability Consistency • Semantic • Not supported ! • Outside of the realm of the transaction itself • Transaction = Tool to allow consistency guarantees • Transaction = A guarantor of consistency Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID Atomicity Consistency Isolation Durability Isolation • Ongoing transactions should not affect each other • Not supported ! Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID Atomicity Consistency Isolation Durability Durability • The result should be persistent • Not supported ! • Durability is a commitment but • Not a guarantee ! • It depends on the application how durable data has to be Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID 2 Phase Commit Mahalo Jini Transaction & JavaSpaces References Two PhaseCommit • Problem • Transaction States • Client’s View • Participant’s View • Transaction Manager’s View • Exceptions • PrepareAndCommit Daniel Müller Seminar Informations- & Kommunikationssysteme
Two Phase Commit Problem Transaction States Client’ View Participant’ s View Transaction Manager’s View Exceptions PrepareAndCommit Problem • Treat a transaction as a single atomic unit • All operations of the transaction succeed or fail • No partial failures • Two Phase Commit Protocol • Can be used in more than traditional transaction systems Daniel Müller Seminar Informations- & Kommunikationssysteme
Two Phase Commit Problem Transaction States Client’ View Participant’ s View Transaction Manager’s View Exceptions PrepareAndCommit TransactionStates • Constants defined for the communication between managers & participants public interface TransactionConstants { int ACTIVE = 1; int VOTING = 2; int PREPARED = 3; int NOTCHANCHED = 4; int COMMITED = 5; int ABORTED = 6; } Daniel Müller Seminar Informations- & Kommunikationssysteme
Two Phase Commit Problem Transaction States Client’ View Participant’ s View Transaction Manager’s View Exceptions PrepareAndCommit Client’sView I ACTIVE create returns otherwise commit VOTING COMMITED participant ABORTED abort cleanup ABORTED Daniel Müller Seminar Informations- & Kommunikationssysteme
Client’sView II • create() ACTIVE • commit() VOTING • abort() ABORTED • Cancel the lease ABORTED • Expire the lease ABORTED Daniel Müller Seminar Informations- & Kommunikationssysteme
Two Phase Commit Problem Transaction States Client’ View Participant’ s View Transaction Manager’s View Exceptions PrepareAndCommit Participant’sView I ACTIVE NOTCHANGED join returns abort prepare cleanup VOTING ABORTED abort abort PREPARED commit COMMITED Daniel Müller Seminar Informations- & Kommunikationssysteme
Participant’s View II • join() ACTIVE • prepare() VOTING • Decide to return one of the following states • NOTCHANGED: read-only (no changes in the state) • PREPARED: changes made & able to roll forward • ABORTED: changes made but can’t guarantee to roll forward Daniel Müller Seminar Informations- & Kommunikationssysteme
Participant’s View III • PREPARED & commit() COMMITED • abort() ABORTED • request the state of the transaction manager int getState(long id); Crash Recovery Daniel Müller Seminar Informations- & Kommunikationssysteme
Two Phase Commit Problem Transaction States Client’ View Participant’ s View Transaction Manager’s View Exceptions PrepareAndCommit TransactionManager’s View I ACTIVE create returns commit otherwise VOTING COMMITED participant ABORTED or timeout abort ABORTED cleanup Daniel Müller Seminar Informations- & Kommunikationssysteme
TransactionManager’s View II • create() ACTIVE • commit() VOTING • Invoke prepare() of all participants • One participant votes ABORTED ABORTED • A participant votes NOTCHANGED Dropped as participant • No one ABORTED & at least one PREPARED COMMITED • abort() ABORTED • Lease cancelled ABORTED • Lease expired ABORTED Daniel Müller Seminar Informations- & Kommunikationssysteme
Two Phase Commit Problem Transaction States Client’ View Participant’ s View Transaction Manager’s View Exceptions PrepareAndCommit Exceptions • UnknownTransactionException • Incorrect transaction ID • Transaction already cleaned up • CannotCommitException • Transaction already ABORTED or COMMITED • CannotAbortException • Transaction already COMMITED • TimeoutExpiredException • Wasn’t able to notify all participants in a given time Daniel Müller Seminar Informations- & Kommunikationssysteme
Two Phase Commit Problem Transaction States Client’ View Participant’ s View Transaction Manager’s View Exceptions PrepareAndCommit prepareAndCommit I • Optimisation / Elimination of the VOTING state • Only one single participant • Only one single participant to prepare()and all others already returned NOTCHANGED Daniel Müller Seminar Informations- & Kommunikationssysteme
prepareAndCommitII public int prepareAndCommit(TransactionManager mgr, long id) throws UnknownTransactionException, RemoteException { int result = prepare(mgr, id); if (result == PREPARED) { commit(mgr, id); result = COMMITED; } return result; } Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID 2 Phase Commit Mahalo Jini Transaction & JavaSpaces References Mahalo • Transaction engine in Sun’s distribution of Jini, as an implementation of a simple transaction manager • An activatable service; it means that it runs under the control of rmid (RMI daemon) Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID 2 Phase Commit Mahalo Jini Transaction & JavaSpaces References Jini Transactions& JavaSpaces • Problem • Example • Solution • Entries under a transaction • ACID revisited Daniel Müller Seminar Informations- & Kommunikationssysteme
JavaSpaces Problem Example Solution Entries under a transaction ACID revisited Problem • Tool for dealing with partial failure • Transactions provide a means of enforcing consistency over a set of (one or more) space-based operations • Consistency: • bundle operations together • Either all complete or none of them Daniel Müller Seminar Informations- & Kommunikationssysteme
JavaSpaces Problem Example Solution Entries under a transaction ACID revisited Example:Web Counter • Problem: Counter lost • Visit a web page • Applet takes a page count entry • Increments its value • Writes it back into the page Daniel Müller Seminar Informations- & Kommunikationssysteme
JavaSpaces Problem Example Solution Entries under a transaction ACID revisited Solution • take & write under a Transaction • .. Transaction txn = trc.transaction; counter = space.take(tmp, txn, Long); counter.increment(); space.write(counter, txn, Lease); .. Daniel Müller Seminar Informations- & Kommunikationssysteme
JavaSpaces Problem Example Solution Entries under a transaction ACID revisited Entries under a Transaction • write entry is only seen within the transaction until it commits • read a entry once read, cannot be taken afterwards, within the same transaction • readIfExists If an entry is taken by another transaction then wait for its return • take removes en entry temporarily from the space Daniel Müller Seminar Informations- & Kommunikationssysteme
JavaSpaces Problem Example Solution Entries under a transaction ACID revisited ACIDRevisited • Atomicity • Consistency • Isolation • Durability Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID Atomicity Consistency Isolation Durability Atomicity • Two Phase Commit • All operations occur ore non of them • Both: Counter was removed from and returned to the space • None: Counter was effectively never removed • Operations are read, write, take, notify Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID Atomicity Consistency Isolation Durability Consistency • Changes do not violate the correctness of the state within the space • Program / Algorithm has to be correct • take and write the counter • increment the value by one Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID Atomicity Consistency Isolation Durability Isolation • Two transactions should not affect each other • take removes the entry temporarily • Deadlock ? Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID Atomicity Consistency Isolation Durability Durability • After commit, changes to a space will survive failures • Problem of the space, not the transaction Daniel Müller Seminar Informations- & Kommunikationssysteme
ACID 2 Phase Commit Mahalo Jini Transaction & JavaSpaces References References • Sun Inc., Jini Technology core platform specification, Version 1.1, Oct. 2000, http://www.sun.com/jini/specs/core1_1.pdf • Scott Oaks & Henry Wong, Jini in a Nutshell, O’Reilly, 2000, http://www.oreilly.com/catalog/jininut • Jan Newmarch, University of Canberra, http://pandonia.canberra.edu.au/java/jini/tutorial • Eric Freeman, Susanne Hupfer, Ken Arnold, JavaSpaces principles, patterns, and practice, Addison Wesley, 1999, http://204.179.152.61/book/0,3828,0201309556,00.html Daniel Müller Seminar Informations- & Kommunikationssysteme