Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Global serializability wikipedia , lookup
Clusterpoint wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Object-relational impedance mismatch wikipedia , lookup
Versant Object Database wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Commitment ordering wikipedia , lookup
Distributed Transaction & Long-running transactions Krasimir Parushev Consultant, ITCE ltd. Rossen Zhivkov Freelance SharePoint Consultant January 19th, 2008 Sofia, Bulgaria 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? 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, WSBusiness Activity What is BPEL4WS 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 Local Transactions Client 1 VB Object ADO Conn Lock Manager Transaction Manager Activity Client 2 ADO Conn VB Object Activity Client N Data ADO Conn VB Object Activity Application DBMS 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 A Distributed Transaction RM2 -SQL Server RM1 - MSMQ Your Tx COM+ Application RM Proxy Queue RM Proxy The Coordinating DTC Computer 1 Data Participating ComputerDTC 2 RM Proxy RM3 - ORACLE Data Participating ComputerDTC 3 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 Two-Phase Commit Transaction Manager Dispenses new transactions to clients Tracks the resource managers participating in the transaction Coordinates the transaction outcome Transaction Manager Resource Manager A subsystem that allows updates to transaction protected data SQL Server File System Resource Managers SQL Server Resource Manager Two-Phase Commit Transaction Manager Resource Manager Prepare Prepared Force write “Commit” record to TM log Lazy write “Committed” record to TM log Prepare and Force write “Prepared” record to RM log Commit Committed Lazy write “Committed” record to RM log and Release locks Commit Abort on Failure Committed Will Will Commit Abort Commit Write “Committed” record to TM log Resource Manager Prepared Indoubt on Failure Write “Commit” record to TM log Prepare Commit Transaction Manager Abort on Failure Two Phase Commit – Failure Prepare & Write “Prepared” record to RM log Write “Committed” record to RM log & Release locks LIVE DEMO MS-DTC Distributed 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, … 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 SQL Server And Dist. Tx… Server initiated BEGIN DISTRIBUTED TRANSACTION Linked Server call Extended Stored Procedures X-Transactions Application Partitioned Tables MS DTC MS DTC SQL Server NT SQL Server NT 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 Transaction Flow Transaction A Code block with no ambient transaction ----- -- - - -- -- --- –- – - - ---- -- –-- –- - –-- ------ -- - - –- –- – scope 1 {Required} scope 2 {Required} Transaction B scope 3 scope 4 {RequiresNew} {Suppress} Transactions from .NET application 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 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 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 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 Incorporate web services in distributed transactions using WCF 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 LIVE DEMO : Long-running transactions 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 WSAtomicTransaction services Compensations SOAP “compensate” message 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 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 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 Implement long-running transactions in Windows Workflow Foundation 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 & WSAtomicTransaction Long-running transactions Workflow Foundation BPEL4WS & WS-BusinessActivity Next steps Thank You for you time Rossen Zhivkov [email protected] Krasimir Parushev [email protected]