Distributed Transactions in Java EE Nikolai Tankov SAP Labs Bulgaria January 19th, 2008 Sofia, Bulgaria.

Slides:



Advertisements
Similar presentations
21 Copyright © 2005, Oracle. All rights reserved. Oracle Application Server 10g Transaction Support.
Advertisements

1 Transactions and Web Services. 2 Web Environment Web Service activities form a unit of work, but ACID properties are not always appropriate since Web.
CS542: Topics in Distributed Systems Distributed Transactions and Two Phase Commit Protocol.
Ed Felt & Sriram Srinivasan BEA Systems, Inc. Advanced Distributed Transaction Processing with BEA WebLogic Server ™ 6.0.
COS 461 Fall 1997 Transaction Processing u normal systems lose their state when they crash u many applications need better behavior u today’s topic: how.
Module 20 Troubleshooting Common SQL Server 2008 R2 Administrative Issues.
Database Systems, 8 th Edition Concurrency Control with Time Stamping Methods Assigns global unique time stamp to each transaction Produces explicit.
Transactions Celsina Bignoli Motivations Atomic operations –Group of operation that must all succeed or all fail Network or machine.
© City University London, Dept. of Computing Distributed Systems / Distributed Systems Session 9: Transactions Christos Kloukinas Dept. of Computing.
Transaction Processing Lecture ACID 2 phase commit.
Recovery 10/18/05. Implementing atomicity Note, when a transaction commits, the portion of the system implementing durability ensures the transaction’s.
Transaction Management and Concurrency Control
Chapter 8 : Transaction Management. u Function and importance of transactions. u Properties of transactions. u Concurrency Control – Meaning of serializability.
DBMS Functions Data, Storage, Retrieval, and Update
©Silberschatz, Korth and Sudarshan19.1Database System Concepts Distributed Transactions Transaction may access data at several sites. Each site has a local.
© Chinese University, CSE Dept. Distributed Systems / Distributed Systems Topic 11: Transactions Dr. Michael R. Lyu Computer Science & Engineering.
Version # Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Sponsored by the U.S. Department of Defense © 1999 by Carnegie.
Transaction Management WXES 2103 Database. Content What is transaction Transaction properties Transaction management with SQL Transaction log DBMS Transaction.
COMP 5138 Relational Database Management Systems Semester 2, 2007 Lecture 8A Transaction Concept.
TRANSACTION PROCESSING TECHNIQUES BY SON NGUYEN VIJAY RAO.
Analyzing different protocols for E-business 1 Fatma Sayed Gad Elrab Supervisors Prof. Dr. Ezzat abd El Tawab Korany Dr. Saleh Abdel Shachour El Shehaby.
Transactional Web Services, WS-Transaction and WS-Coordination Based on “WS Transaction Specs,” by Laleci, Introducing WS-Transaction Part 1 & 2, by Little.
Page 1 13/08/2015 The development of Web Transactions Mark Little, Distinguished Engineer, HP.
IS 4506 Database Connectivity.  Overview Two and Three-Tier C/S Architecture ASP Database Connection ODBC - Connection to DBMS Overview of transaction.
Distributed Deadlocks and Transaction Recovery.
Enterprise Java Beans - (EJB)
CS162 Section Lecture 10 Slides based from Lecture and
© jGuru.com EJB Transactions. Transactions Simple Transaction –Transaction = more than one statement which must all succeed (or all fail) together.
Distributed Transactions March 15, Transactions What is a Distributed Transaction?  A transaction that involves more than one server  Network.
Java Transaction API Sean C. Sullivan
Chapter 19 Recovery and Fault Tolerance Copyright © 2008.
Transaction Communications Yi Sun. Outline Transaction ACID Property Distributed transaction Two phase commit protocol Nested transaction.
Transactions1 Unit of work on a database. Transactions2 Transactions, concept Logical unit of work on the database –Examples Transfer money from bank.
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
Distributed Transactions Chapter 13
PAVANI REDDY KATHURI TRANSACTION COMMUNICATION. OUTLINE 0 P ART I : I NTRODUCTION 0 P ART II : C URRENT R ESEARCH 0 P ART III : F UTURE P OTENTIAL 0 R.
Chapter 15 Recovery. Topics in this Chapter Transactions Transaction Recovery System Recovery Media Recovery Two-Phase Commit SQL Facilities.
Distributed Transaction & Long-running transactions Rossen Zhivkov Freelance SharePoint Consultant January 19 th, 2008 Sofia, Bulgaria Krasimir Parushev.
Transaction Services in Component Frameworks Bruce Kessler Comp250CBS March 2, 2004.
Chapter 15 Recovery. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.15-2 Topics in this Chapter Transactions Transaction Recovery System.
Databases Illuminated
DB-16 : JTA Transactions in the RDBMS, What's Going on Down There? Deb Walz Principal Software Engineer.
DB-1: Understanding and Leveraging the Latest ODBC and JDBC Technology What’s new in OpenEdge® 10.1A? Rob Steward Director of Software Development.
XA Transactions.
Distributed Transactions Chapter – Vidya Satyanarayanan.
IM NTU Distributed Information Systems 2004 Distributed Transactions -- 1 Distributed Transactions Yih-Kuen Tsay Dept. of Information Management National.
Marek Prochazka JOTM: Overview and Perspectives
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Revisiting failure detectors Some of you asked questions about implementing consensus using S - how does it differ from reaching consensus using P. Here.
Java Transactions Service Presented by: Dina Sarhan Rana El Hattab.
Distributed Transactions What is a transaction? (A sequence of server operations that must be carried out atomically ) ACID properties - what are these.
4 Copyright © 2004, Oracle. All rights reserved. Managing the Oracle Instance.
Transactions and Security. Contents  Transactions  Transaction Support in EJB  Security  Security Support in EJB.
JTA | Developer Conference JBoss Transactions Ivo Studenský JBoss QA Engineer, Jiří Pechanec JBoss QE Supervisor, Red Hat Sep 10th, 2009.
Distributed Databases – Advanced Concepts Chapter 25 in Textbook.
Prepared by Mehmet Küçüksayan Mustafa Ecmel Özdemir
Recovery in Distributed Systems:
Database System Implementation CSE 507
Two phase commit.
Trafodion Distributed Transaction Management
On transactions, and Atomic Operations
Batches, Transactions, & Errors
Outline Announcements Fault Tolerance.
On transactions, and Atomic Operations
Distributed Transactions
Lecture 20: Intro to Transactions & Logging II
UNIVERSITAS GUNADARMA
Transactions in Distributed Systems
Objectives In this lesson, you will learn about:
Transaction Communication
Presentation transcript:

Distributed Transactions in Java EE Nikolai Tankov SAP Labs Bulgaria January 19th, 2008 Sofia, Bulgaria

Agenda APIs for transaction management in Java EE How TransactionManager works Distributed transactions optimizations Example of 2PC Demo of 2PC and automatic recovery 2 PC issues in some DB-s

Transaction types Local transaction - A transaction that involves only one resource manager (e. g. accesses only one database). Support all the ACID properties (atomicity, consistency, isolation and durability) Distributed transaction - accesses and updates data on two or more networked resources (e. g. RDBMSs). Support all the ACID properties. Short-living transaction – support all the ACID properties. Long-living transaction – do not support ACID properties.

Conceptual View of DTP model Transaction Manager Application Server or Application program javax.transaction.TransactionManager javax.transaction.UserTransaction javax.transaction.TransactionSynchroni zationRegistry ResourceManager1 Message Broker ResourceManager2 DB javax.transaction.xa.*

JTA API is modeled on the X/Open XA standard javax.transaction.TransactionManager – used by the application server itself to control transactions. javax.transaction.UserTransaction – provides the application the ability to control transaction boundaries programmatically. Javax.transaction.TransactionSynchronizationRegistry – introduced in JSR 907. Used from frameworks for association of arbitrary objects with transactions.

javax.transaction.xa.XAResource. start(xid, flags) - Starts work on behalf of a transaction branch specified in xid. end(xid, flags) - Ends the work performed on behalf of a transaction branch. prepare(xid) - Ask the resource manager to prepare the transaction specified in xid for commit. recover – obtain a list of prepared transaction branches which were not commited or rolledback commit(xid, boolean onePhase)- Informs the resource manager to commits the global transaction specified by xid. rollback(xid) – Informs the resource manager to rollbacks the global transaction specified by xid.

javax.transaction.xa.XID interface XID = key for one transaction branch. XID contains: Format ID – int. Must be >0, usually format id is 0 Global transaction id - ID of the distributed transaction. This is byte[] with length up to 64 bytes. Branch Qualifier – ID of the transaction branch. This is byte[] with length up to 64 bytes. Global transaction Id and branch qualifier taken together must be globally unique.

How TransactionManager works Transactions are associated with threads. Transaction objects are invisible for applications. Application server is responsible to obtain XAResource from each resource manager that was used during transaction and enlist it into transaction There is no problem to have stacked transactions. Nested transactions usually are not supported.

How to start distributed transaction Programmatically UserTransaction ut = (new InitialContext()).lookup(“java:comp/UserTransaction”); ut.begin(); … ut.commit() public Foo bar() { In ejb-jar.xml Required

2 phase commit sequence

In-Doubt transactions Transaction becomes in-doubt when one or more RM-s failed to commit due to a system or network error? Reasons for in-doubt transactions Network failure DB crash TransactionManager crush Resolution of in-doubt transactions Automatic – TransactionManager checks periodically for in-doubt transactions and resolves them Manually resolve transactions with DB specific tools.

Heuristics XA_HEURHAZ - the transaction branch may have been heuristically completed XA_HEURMIX - the transaction branch has been heuristically committed and rolled back. XA_HEURCOM - the transaction branch has been heuristically committed XA_HEURRB - the transaction branch has been heuristically rolled back

Requirements for resource managers Keep information about each transaction which is not completed Must be able ensure that commit is possible. If RM votes for commit it must store this promise into durable storage. Implement recover function by listing RM Tlog for in-doubt transactions. Ensure that HeuristicHazard and HeuristicMixed will not happened. Minimize heuristic decisions.

Possible DTP optimizations Last agent optimization (Last resource optimization) Read only optimization One phase commit optimization Local transaction optimization

Last agent optimization It is possible to enlist 0 or 1 resources with Local transaction(LT) support All prepare methods are invoked and after that commit of the LT resource

Read only optimization Resource managers which were used only for read operations are not involved into second commit phase

One phase commit optimization Used when only one XAResource is enlisted into transaction. XAResource.prepare() call is skipped.

Local transaction optimization Local transactions are used if only one resource manager will participate into distributed transaction.

Inbound transaction model Introduced in Java Connector 1.5 Allows a EIS to propagate transaction context to an application server Allows a resource adapter to commit, rollback and recover the transaction branch. Application server is RM for external system

Example uses the 2PC protocol to commit one transaction branch xaConnection = xaDataSource.getXAConnection("user", "password"); xaResource = xaConnection.getXAResource(); connection = xaConnection.getConnection(); stmt = connection.createStatement(); int ret; xid = new MyXid(100, new byte[]{0x01}, new byte[]{0x02}); try { xaResource.start(xid, XAResource.TMNOFLAGS);// be careful with other flags stmt.executeUpdate("insert into test_table values (100)"); xaResource.end(xid, XAResource.TMSUCCESS); try { ret = xaResource.prepare(xid); } catch (XAException e) { // prepare failed, most of the error codes are returned via XAException xaResource.rollback(xid); } if (ret == XAResource.XA_OK) { xaResource.commit(xid, false); } else if(ret != XAResource.XA_RDONLY ){ xaResource.rollback(xid); } } catch (XAException e) { e.printStackTrace(); } finally { stmt.close(); connection.close(); xaConnection.close(); }

Problems with different DB-s Commit from arbitrary XAResource is not working. XAResource instance is closed before close of XAConnection. This problem is valid for all DB2X drivers and does not exist in Oracle, SQL server and MaxDB. It is not possible to have 2 and more connections from one RM that are working in parallel on one transaction. If one connection is started it is not possible to start another connection with same transactionID With default configuration recover is not working on Oracle. All Oracle releases before are not stable. Oracle 8 does not support 2PC with default configuration. Sometimes recover does not return all xids of in-doubt transactions

Thank You! Nikolai Tankov

Additional slides

Tx standards – WS Coordination This specification describes a framework for a coordination service (or coordinator) which consists of the following component services: ■ An Activation service with an operation that enables an application to create a coordination instance or context. ■ A Registration service with an operation that enables an application to register for coordination protocols. ■ A coordination type-specific set of coordination protocols.

Tx standards – WS - Atomic Transaction This specification defines the following protocols for atomic transactions: ■ Completion protocol: initiates commitment processing. Based on each protocol's registered participants, the coordinator begins with Volatile 2PC then proceeds through Durable 2PC. ■ Two-Phase Commit (2PC): The 2PC protocol coordinates registered participants to reach a commit or abort decision, and ensures that all participants are informed of the final result. The 2PC protocol has two variants: ■ Volatile 2PC: Participants managing volatile resources such as a cache should register for this protocol. ■ Durable 2PC: Participants managing durable resources such as a database should register for this protocol. A participant can register for more than one of these protocols by sending multiple Register messages.

Tx standards – WS – Business Activity ■ A coordinator for an AtomicOutcome coordination type must direct all participants to close or all participants to compensate.

Tx standards – WS – Business Activity ■ A coordinator for a MixedOutcome coordination type may direct each individual participant to close or compensate.