1 / 32

Distributed Transaction & Long-running transactions

Distributed Transaction & Long-running transactions. Krasimir Parushev Consultant, ITCE ltd. Rossen Zhivkov Freelance SharePoint Consultant. January 19 th , 2008 Sofia, Bulgaria. What if…. What if you have to update a SQL Server database and Oracle database in one transaction?

halden
Download Presentation

Distributed Transaction & Long-running transactions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Distributed Transaction & Long-running transactions Krasimir ParushevConsultant, ITCE ltd. Rossen ZhivkovFreelance SharePoint Consultant January 19th, 2008Sofia, Bulgaria

  2. What if… • What if you have to update a SQL Server database and Oracle database in one transaction? • What if you have to call two web services in one transaction? • What if you have to implement transaction that lasts for days?

  3. What is… • What is distributed transaction • What is 2-phase commit protocol • What is transaction coordinator • What is resource manager • What is long-running transaction • WS-Coordination, WS-AtomicTransaction, WS-Business Activity • What is BPEL4WS

  4. Roles in Transaction System • Application • Begins the transaction • Makes changes to resources • Can Commit or Abort the transaction • Transaction Manager • Transaction demarcation, participants, and state • Prepare result is made durable • Can Abort the transaction • Resource Managers • Controls changes to resources under the scope of a transaction • Uses a (durable) log for recovery • Can Abort the transaction • Need to participate in 2PC (Atomicity) • Provide Isolation of its resources • Provide Durability of its resources

  5. VB Object VB Object ADO Conn VB Object ADO Conn ADO Conn Local Transactions Application DBMS Activity Lock Manager Transaction Manager Client 1 Activity Client 2 Data Activity Client N

  6. Local Transactions • All updates within a single DBMS • Or other “resource manager” (RM) • DBMS provides transaction demarcation • Begin (start), end (commit), abort (rollback) • DBMS provides transaction manager • DBMS provide lock manager

  7. Computer 2 RM2 -SQL Server Computer 1 RM1 - MSMQ Participating DTC Computer 3 The Coordinating DTC RM3 - ORACLE Participating DTC A Distributed Transaction Data Your Tx COM+ Application RM Proxy Queue RM Proxy RM Proxy Data

  8. Distributed Transactions • Transactions may span multiple RMs • Databases, Queues, etc. • Distributed Transaction Manager • Provides common transaction demarcation • Coordinates commit/abort across RMs • 2 Phase Commit (2PC) Protocol • RMs are “prepared” to either commit or abort • RMs are notified of final outcome • RM recovery • Resource Managers • Need to participate in 2PC (Atomicity) • Provide Isolation of its resources • Provide Durability of its resources

  9. Transaction Manager Dispenses new transactions to clients Tracks the resource managers participating in the transaction Coordinates the transaction outcome Resource Manager A subsystem that allows updates to transaction protected data Transaction Manager File System SQL Server SQL Server Resource Managers Resource Manager Two-Phase Commit

  10. Two-Phase Commit Resource Manager Transaction Manager Prepare Prepare and Force write “Prepared” record to RM log Prepared Force write “Commit” record to TM log Commit Lazy write “Committed” record to RM log and Release locks Committed Lazy write “Committed” record to TM log

  11. Two Phase Commit – Failure Resource Manager Transaction Manager Abort on Failure Prepare Abort on Failure Prepare & Write “Prepared” record to RM log Prepared Will Abort Write “Commit” record to TM log Indoubt on Failure Commit Will Commit Write “Committed” record to RM log & Release locks Commit Committed Commit Write “Committed” record to TM log

  12. LIVE DEMO

  13. MS-DTCDistributed Transaction Coordinator • Windows NT Service • Two Phase Commit (2PC) and Recovery • Infrastructure • COM Interfaces (a.k.a., DTC proxy) • Used for App  TM, TM RM communication • Local TM, remote TM, TM failover • Supported Resource Managers (RM) • SQL Server, MSMQ, BizTalk, COM+ CRM, … • Oracle, DB2, …

  14. SQL Server And Dist Tx • Client initiated distributed transaction • Existing DTC transaction is passed to SQL Server using data access API • ODBC • SQL_ATTR_ENLIST_IN_DTC connection attribute • OLE-DB • ITransactionJoin::JoinTransaction • ADO • Only implicit via MTS/COM+ • System.Data.SqlClient • v1.1 SqlConnection.EnlistDistributedTransaction • System.Transactions • Later… • DB-Library – dbenlisttrans • COM+, System.EnterpriseServices, WCF

  15. Application NT NT MS DTC MS DTC SQL Server SQL Server SQL Server And Dist. Tx… • Server initiated • BEGIN DISTRIBUTED TRANSACTION • Linked Server call • Extended Stored Procedures • X-Transactions • Partitioned Tables

  16. Using distributed transactions in .NET System.Transactions • System.Transactions = API for programming local & distributed transactions • Enlisting resources in distributed transactions • Ambient Transactions • Transaction Promotion • Transaction Flow

  17. Transaction Flow

  18. Transactions from .NET application

  19. Custom Resource Managers • Why to write own resource managers • Incorporate custom resources in distributed transactions • Implement logic for two-phase commit steps (Prepare, Commit, Rollback) • Volatile resource managers • Transactional variables • Transactional collections • Transactional files…. • Sample

  20. Transactional NTFS & Registry • Kernel Transaction Memory • Kernel objects in transaction (distributed / local) • Allows atomic operations for: • Many operations on single file • Operations for multiple files • Operations for many computers • Registry modifications • Sample

  21. Windows Communication Foundation • What is WCF? • Web services + WSE + WS-specifications + MSMQ + EnterpriseServices(COM+) + Remoting • Reliable messaging • Securable services • Protocols support • New abstraction level • Data Abstraction • Communication Abstraction

  22. WCF and Transactions • WCF services & other resource managers can be executed within the scope of distributed transaction • Transactable Services • In the Internet – using WS-AtomicTransaction • In the Intranet - DTC, OleTransaction protocol, System.Transaction • MSDTC and WS-AtomicTransactions • Transaction Flow

  23. Incorporate web services in distributed transactions using WCF

  24. Long-running transactions • The business scenario • We ”cannot” lock the service sessions (and the underlying database) for that long time • Are ACID properties maintained? • Is it OK to hold locks for days • Compensation actions • Logic to “undo” the effects from previously committed action

  25. LIVE DEMO : Long-running transactions

  26. WS-* specifications • WS-Coordination • Distribution of the transaction context • WS-AtomicTransaction • Pure ACID for short transactions with 2PC or similar • Locking resources • WS-Business Activity • Long living transactions • To coordinate large work implemented by several small WS-AtomicTransaction services • Compensations • SOAP “compensate” message

  27. Business Process Execution Language For Web Services - BPEL4WS • What is BPEL4WS: • Orchestrating web services to implement business process • Complex transactions modeled as … WORKFLOW • Provides sequences, branches, iterations, etc • Bound to local scope • Use WS-BusinessActivity to incorporate distributed scopes

  28. Comparison: Distributed vs. Long-running • Transaction trees • In distributed transactions: • Parent NEVER commits before the child commits (2PC) • Parent / Child hold locks till end of transaction • In long-running transactions: • Parent can commit independently of the child transaction • If Child then rollbacks, parent executes compensation logic • Parent / Child release locks immediately after commit

  29. Workflow Foundation • Business Processes orchestration • Support for Distributed transactions via TransactionScope • Support for Long-running transactions via Compensations • Persistence and Tracking • Integration with WCF & Web Services • Published as WCF/web service • Utilizes WCF/Web service

  30. Implement long-running transactions in Windows Workflow Foundation

  31. Summary • Distributed Transactions • 2-Phase Commit Protocol • SQL Server 2005 & Distributed transactions • .NET & Distributed Transactions • Custom Resource Managers • Distributed Transactions in Web Services • Windows Communications Foundation & WS-AtomicTransaction • Long-running transactions • Workflow Foundation • BPEL4WS & WS-BusinessActivity • Next steps

  32. Thank You for you time Rossen Zhivkovrzhivkov@gmail.com Krasimir Parushevkrasimir@itce.com

More Related