Presentation is loading. Please wait.

Presentation is loading. Please wait.

Gert E.R. Drapers Software Architect Microsoft Corporation

Similar presentations


Presentation on theme: "Gert E.R. Drapers Software Architect Microsoft Corporation"— Presentation transcript:

1 Gert E.R. Drapers Software Architect Microsoft Corporation
8/2/2018 2:44 PM DAT459 SQL Server And Distributed Transactions – Architecture And Internals Gert E.R. Drapers Software Architect Microsoft Corporation © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

2 Agenda “Distributed” Transactions 101 Architecture Overview
8/2/2018 2:44 PM Agenda “Distributed” Transactions 101 Architecture Overview Client Initiated Distributed Transactions Server Initiated Distributed Transactions XA and JDBC integration Oracle integration Monitoring Distributed Transactions © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

3 Why Transactions? Correctness (programming model) ACID properties
8/2/2018 2:44 PM Why Transactions? Correctness (programming model) ACID properties Atomicity All changes happen or nothing happens Consistency Data is transformed from one correct state to another Isolation Concurrent updaters are prevented from interfering with one another Durability Committed changes remain permanent despite failures © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

4 Roles Transaction System
8/2/2018 2:44 PM Roles 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 Manager Controls changes to resources under the scope of a transaction Uses a (durable) log for recovery © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

5 Isolation Goal: Maximize concurrency without unwanted interactions
8/2/2018 2:44 PM Isolation Goal: Maximize concurrency without unwanted interactions Higher isolation provides better consistency Lower isolation provides better concurrency Concurrency anomalies Lost Updates (can overwrite uncommitted changes) Dirty Reads (can read uncommitted changes) Unrepeatable Reads (changing commits) Phantoms (insert/delete anomalies) DBMS defines its isolation rules Read (shared) locks and write (exclusive) locks Lock granularity: File, page, record, … © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

6 8/2/2018 2:44 PM Degrees of isolation Whether or not these problems occur depends on a transaction’s degree of isolation Degree 1 2 2.999 3 Common Name Chaos Read Uncommitted Read Committed Repeatable Read Serializable A.K.A. Browse Cursor Stability Isolated Lost Updates? Yes No No No No Dirty Reads? Yes Yes No No No Unrepeatable Reads? Yes Yes Yes No No Phantoms? Yes Yes Yes Yes No © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

7 8/2/2018 2:44 PM Two-Phase Commit (2PC) The two-phase commit protocol ensures that all transaction participants agree to either Commit the transaction and make its effects permanent Rollback the transaction and to undo its effects It provides the “Atomicity” property of “ACID” It is only needed when two or more parties participate in a transaction Two-phase commit must work despite process, system, or communication failures © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

8 Two-Phase Commit Transaction Manager Resource Manager
8/2/2018 2:44 PM Two-Phase Commit 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 SQL Server Transaction Manager File System Resource Managers Resource Manager © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

9 Two-Phase Commit Transaction Manager Resource Manager Prepare
8/2/2018 2:44 PM Two-Phase Commit Transaction Manager Resource 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 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

10 Two Phase Commit – Failure
8/2/2018 2:44 PM Two Phase Commit – Failure Transaction Manager Resource Manager Abort on Failure Prepare Abort on Failure Prepare & Write “Prepared” record to RM log Prepared Will Abort Write “Commit” record to TM log on Failure Indoubt Commit Commit Will Write “Committed” record to RM log & Release locks Commit Committed Write “Committed” record to TM log Commit © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

11 MS-DTC Distributed Transaction Coordinator
8/2/2018 2:44 PM 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, … © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

12 Local Transactions Data Client 1 Transaction Manager Lock Manager
8/2/2018 2:44 PM Local Transactions Application DBMS Activity VB Object ADO Conn Client 1 Transaction Manager Lock Manager Activity ADO Conn Client 2 VB Object Data Activity Client N VB Object ADO Conn © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

13 Local Transactions All updates within a single DBMS
8/2/2018 2:44 PM 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 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

14 Distributed Transactions
8/2/2018 2:44 PM 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 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

15 A Distributed Transaction
8/2/2018 2:44 PM A Distributed Transaction Computer 2 RM2 -SQL Server Participating DTC Computer 1 The Coordinating DTC RM1 - MSMQ Data Your Tx COM+ Application RM Proxy Queue RM Proxy RM Proxy Computer 3 RM3 - ORACLE Participating DTC Data © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

16 SQL Server And Dist Tx Client initiated distributed transaction
8/2/2018 2:44 PM 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.0 only implicit via System.EnterpriseServices v1.1 SqlConnection.EnlistDistributedTransaction DB-Library – dbenlisttrans MTS, COM+, System.EnterpriseServices © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

17 8/2/2018 2:44 PM OLE Transactions Used by application programmers and resource manager developers ITransactionDispenser is used to initiate transactions ITransaction is used to commit or abort transactions OLE Transactions MS DTC implements the OLE Transactions standard OLE Transactions describes the interfaces between transactional applications, transaction coordinators, and transactional resource managers It defines the interfaces which transactional applications invoke to begin, commit, and abort distributed transactions. It defines the interfaces implemented and used by transactional resource managers such as SQL Server to perform two-phase commit. It defines the role of the transaction manager (coordinator) in guaranteeing atomic transaction outcome. Model Summary The application calls DtcGetTransactionManager to connect to MS DTC. DtcGetTransactionManager returns a pointer to the ITransactionDispenser interface. The application invokes ITransactionDispenser::BeginTransaction and obtains a transaction object which represents the transaction. The application associates the transaction with the ODBC or DB-Library connections to the SQL Server database. For DB-Library connections, the application calls dbenlistxact for each connection. For ODBC connections, the application calls SQLSetConnectOption for each connection Each of the SQL Server’s enlists on the MS DTC transaction The application then updates, inserts, or deletes records in one or more SQL Server databases. The application calls ITransaction::Commit on the transaction object MS DTC uses the two phase commit protocol to coordinate the transaction outcome with all of the enlisted SQL Server databases. Normally, the transaction commits. If a failure occurs during the two phase commit protocol or if the application calls ITransaction::Abort on the transaction object, then the transaction is aborted and the effects of the transaction are undone from all of the SQL Server databases. © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

18 SQL Server And Dist. Tx… Server initiated
8/2/2018 2:44 PM SQL Server And Dist. Tx… Server initiated BEGIN DISTRIBUTED TRANSACTION Linked Server call Extended Stored Procedures srv_getdtcaxct NT SQL Server MS DTC Application © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

19 MS-DTC SQL Server Settings
8/2/2018 2:44 PM MS-DTC SQL Server Settings sp_configure “remote proc trans”, {0|1} Server-wide option for automatically starting MS DTC transactions for server to server RPCs SET REMOTE_PROC_TRANSACTIONS ON|OFF Session-wide option for automatically starting MS DTC transactions for server to server RPCs sp_configure “remote conn timeout”, <n> Timeout on server to server RPCs before automatically dropping the connection Connection will only be closed if there is no MS DTC transaction active for the connection Overview SQL Server is capable of automatically initiating MS DTC transactions. This is controlled using either a SQL server level option or a SQL session level option. SQL Server Option This is a server wide option which controls the default setting of the session level option. New sessions started after altering the server option will take the setting of the server level option. sp_configure “remote proc trans”, {0|1} SQLSession Option When the session level option is ON, SQL automatically initiates an MS DTC transaction whenever a remote stored procedure is invoked. The value of the session option can be controlled using the the SET statement. SET REMOTE_PROCEDURE_TRANSACTIONS {ON|OFF} The default value of the session level option is set based upon the value of the server wide option. Timeout Option SQL Server allows control of the timeout valuefor server to server RPC connections. For high volumes of distributed transactions, a larger timeout period eliminates the need for constant re-establishment of server to server connections The timeout period is configurable with a server configuration parameter: sp_configure “remote conn timeout”, <n> where <n> specifies the timeout inactivity period, in minutes. Connection will only be closed if there is no DTC transaction active for the connection. © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

20 Transact-SQL Explicit
8/2/2018 2:44 PM Transact-SQL Explicit BEGIN DISTRIBUTED TRANSACTION This Transact-SQL call explicitly initiates an MS-DTC transaction If a stored procedure calls a remote stored procedure, both stored procedures are protected by the MS-DTC transaction Overview Using MS DTC from SQL Server is very simple. An application can begin an MS DTC transaction explicitly using the Transact-SQL BEGIN DISTRIBUTED TRANSACTION statement. The COMMIT TRANSACTION or ROLLBACK TRANSACTION statements areused to commit or abort the MS DTC transaction. Remote Stored Procedure Invocation If a stored procedure running under the protection of an MS DTC transaction calls a remote stored procedure, the remote stored procedure will also run under the protection of the MS DTC transaction. If that remote stored procedure calls yet another remote stored procedure, it too will run under the protection of the MS DTC transaction. Failure to propagate an MS DTC transaction to a remote server will cause the entiretransaction to abort. Savepoints The existing SQL Server SAVE TRAN statement is unchanged. A rollback of an MS DTC transaction will take all servers back to the state they were in when the MS DTC transaction was started. An application can perform partial rollbacks to named savepoints on individual servers without affecting the MS DTC transaction. BEGIN DISTRIBUTED TRANSACTION INSERT INTO ACCOUNTS VALUES (100,20) EXEC RMTBRANCH.ACCOUNTS.DBO.DEPOSIT 100,20 COMMIT TRANSACTION © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

21 Transact-SQL Implicit
8/2/2018 2:44 PM Transact-SQL Implicit SQL Server can implicitly initiate an MS-DTC transaction when one is needed This is controlled using two SQL Server options Session-level option SET REMOTE_PROC_TRANSACTIONS ON Server-level option sp_configure “remote proc trans”, 1 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

22 X-Database Transactions
8/2/2018 2:44 PM X-Database Transactions Cross-database transactions on the same SQL Server Operations between two or more database result in a internal distributed transaction Does not require DTC © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

23 Client Two-Phase Commit
8/2/2018 2:44 PM Client Two-Phase Commit DB-Library-based Should no longer be used Does not scale © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

24 8/2/2018 2:44 PM XA Transactions Transactions can be coordinated by an XA compliant TP Monitor: Tuxedo, TopEnd, Encina, etc. SQL Server can act as an XA compliant resource manager Other XA compliant databases can be updated in the same transaction NT NT or UNIX SQL Server Application TP Monitor MS DTC Oracle Sybase Informix XA OLE Tx © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

25 8/2/2018 2:44 PM JDBC XA Integration Microsoft JDBC driver can enlist SQL Server in an Java originated JTA transaction By default not enabled, need to run INSTJDBC.SQL script to register xp_jdbc_open, xp_jdbc_close, xp_jdbc_start, xp_jdbc_end, xp_jdbc_prepare, xp_jdbc_commit, xp_jdbc_rollback, xp_jdbc_forget, xp_jdbc_recover Located in: C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\SQLServer JTA Relies on XA switch library © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

26 Oracle Integration Oracle 7.x relies on MTXOCI.DLL
8/2/2018 2:44 PM Oracle Integration Oracle 7.x relies on MTXOCI.DLL Oracle 8i, 9i and 10g should be using the Oracle provided DTC integration plumbing, named “Oracle Services for MTS” No need to use MTXOCI8.DLL © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

27 Oracle Integration… 8/2/2018 2:44 PM
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

28 Transaction Monitoring
8/2/2018 2:44 PM Transaction Monitoring SQL Server Trace/Profiler DTCTransaction event class (19) EventSubClass, BinaryData, TextData SQLTransaction event class (50) EventSubClass, TransactionID, ObjectName, TextData Performance Monitor Distributed Transaction Coordinator Aborted Transactions Aborted Transactions/sec Active Transactions Active Transactions Maximum Committed Transactions Committed Transactions/sec Force Aborted Transactions Force Committed Transactions In Doubt Transactions Response Time – Average Response Time – Maximum Response Time – Minimum Transactions/sec © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

29 Transaction Monitoring…
8/2/2018 2:44 PM Transaction Monitoring… DTC Trace %windir%\system32\msdtc\trace\ msdtcvtr.bat Requires TRACEFMT.EXE (Platform SDK) Component Services A.k.a., COM+ Explorer MTS Spy/COM+ Spy Platform SDK © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

30 MS-DTC Log Sizing Rules: How many concurrent transactions?
8/2/2018 2:44 PM MS-DTC Log Sizing Rules: Log Record ~144 bytes (depends on number of RM’s involved in transaction) MS-DTC uses a circular transaction log Default Log Size is 4MB DTC start rejecting new transactions when the current log space used is larger than the total Log Size / 8 How many concurrent transactions? 4MB / 144 bytes = 30000tx / 8 = ~ 3640 concurrent tx © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

31 Troubleshooting MS-DTC
8/2/2018 2:44 PM Troubleshooting MS-DTC Setup (reinstall) Q – HOWTO: Reinstall MS DTC for a Nonclustered Windows NT 4.0 Server Q – HOWTO: Reinstall MS DTC for a Nonclustered Windows 2000 Server Communication DTCPING (see Q306843) Firewall Q HOWTO: Troubleshoot MS DTC Firewall Issues © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

32 SQL Server ResourceMgrID
8/2/2018 2:44 PM SQL Server ResourceMgrID HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer REG_SZ ResourceMgrID GUID that UNIQUELY identifies this SQL Server instance Reason for SQL Server SYSPREP or images based installs to fail Needs to be duplicated on cluster nodes, otherwise transactions can not recover! © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

33 Information Q306843 HOWTO: Troubleshoot MS DTC Firewall Issues
8/2/2018 2:44 PM Information Q HOWTO: Troubleshoot MS DTC Firewall Issues Q INFO: Names and IP Addresses an MS DTC Client Must Have Q HOWTO: Set Up a Local MS DTC to Point to a Remote MS DTC Q INFO: Log Files Used by Distributed Transaction Coordinator Q MS DTC Leaks Handles If There Is Long String in TIP Transaction (Windows 2000 post service pack 2 hotfix rollup 19) Q How to Troubleshoot MSDTC Event ID 4209 © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

34 8/2/2018 2:44 PM Information… Q INFO: Two-Phase Commit is Not Supported over TCP/IP for DB2OLEDB Q HOWTO: Avoid COM/MTS Object Activation Delay on MSCS Q MSDTC Disaster Recovery Techniques Q INFO: The "msdtc -remove" Command Shows Errors Q INFO: COM+ and MTS Always Use SERIALIZABLE Transaction Isolation Q INF: Limited Support for Savepoint in Distributed Transactions Q BUG: DTC Transactions Fail When SQL Runs in Lightweight Pooling Q INF: FAQs – SQL Server 7.0 – FailoveR © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

35 Please fill out a session evaluation on CommNet
8/2/2018 2:44 PM Please fill out a session evaluation on CommNet Q1: Overall satisfaction with the session Q2: Usefulness of the information Q3: Presenter’s knowledge of the subject Q4: Presenter’s presentation skills Q5: Effectiveness of the presentation © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

36 Discussion E-Mail: gertd@microsoft.com http://SQLDev.Net
8/2/2018 2:44 PM Discussion © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

37 © 2004 Microsoft Corporation. All rights reserved.
8/2/2018 2:44 PM © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.


Download ppt "Gert E.R. Drapers Software Architect Microsoft Corporation"

Similar presentations


Ads by Google