400 likes | 540 Views
Choosing Transaction Models for Enterprise Applications. Jim Tyhurst, Ph.D. Tyhurst Technology Group LLC. Overview. Usage scenarios. Architecture characteristics. Forces that influence design decisions. Transaction models. Infrastructure to handle failures. Resolving conflicts.
E N D
Choosing Transaction Models for Enterprise Applications Jim Tyhurst, Ph.D. Tyhurst Technology Group LLC OOPSLA 2001
Overview • Usage scenarios. • Architecture characteristics. • Forces that influence design decisions. • Transaction models. • Infrastructure to handle failures. • Resolving conflicts. Jim Tyhurst, Ph.D.
Scenario: Concurrent Updates CSR Sales Manager Jim Tyhurst, Ph.D.
Concurrent Updates • Multiple users are updating data. • More than one user may try to update a specific record at the same time. • For example, updating customer data from multiple channels: • Call Center (live Customer Service Rep) • Automated Call Center (Interactive Voice) • Web forms • Applications within the company Jim Tyhurst, Ph.D.
Use Case: Customer Service Rep changes address. Use Case: Sales Manager changes assignment of Account Managers. Customer Record: Name: Bob Region: South East Acct Mgr: Yolanda Concurrent Updates: Example Jim Tyhurst, Ph.D.
Concurrent Updates: Example Original Data Name: Bob Region: South East Acct Mgr: Yolanda Update 1 Update 2 Name: Bob Region: North East Acct Mgr: Andy Name: Bob Region: South East Acct Mgr: Zoe Jim Tyhurst, Ph.D.
Scenario:Independent Updates Jim Tyhurst, Ph.D.
Independent Updates • Multiple users are adding new data. • Each transaction is mutually exclusive of the others. • For example, logging events: • Factory data • Customer calls • Environmental observations Jim Tyhurst, Ph.D.
Overview • Usage scenarios. • Architecture characteristics. • Forces that influence design decisions. • Transaction models. • Infrastructure to handle failures. • Resolving conflicts. Jim Tyhurst, Ph.D.
Fat client. View and model on same layer. Continuous connection to DBMS. Long transactions (pessimistic locking). Client/Server Characteristics Jim Tyhurst, Ph.D.
Fat client. View and model on same layer. Continuous connection to DBMS. Long transactions (pessimistic locking). Thin client. Model on middle tier. Intermittent connection to DBMS. User works outside of a transaction. Client/Server vs. Three-Tier Jim Tyhurst, Ph.D.
Overview • Usage scenarios. • Architecture characteristics. • Forces that influence design decisions. • Transaction models. • Infrastructure to handle failures. • Resolving conflicts. Jim Tyhurst, Ph.D.
Transaction Forces • Designer must map business Tx's to server Tx's. • Shared objects must be modified in a Tx. • View of shared objects should be updated at Tx boundaries. Jim Tyhurst, Ph.D.
Transaction Forces • Failure to commit. • Caused by conflict with another Tx. • Must abort and start a new Tx. • Alternatives: • Retry automatically. • Force user to do rework. • Probability of a commit failure. • Consequences of a commit failure. Jim Tyhurst, Ph.D.
Transaction Forces • Length of Tx • Pessimistic locking ties up resources. • With no locks, risk of commit failure increases with the length of the Tx. • Large number of open Tx's usually degrades performance significantly. Jim Tyhurst, Ph.D.
Overview • Usage scenarios. • Architecture characteristics. • Forces that influence design decisions. • Transaction models. • Infrastructure to handle failures. • Resolving conflicts. Jim Tyhurst, Ph.D.
Transaction Models • Flat Transaction • Nested Transaction • Distributed Transaction • Conversational Transaction • Queued Transaction Jim Tyhurst, Ph.D.
Flat Transaction • All changes occur in a single Tx with no internal structure. • Easy to implement. • Supported by all database systems. Jim Tyhurst, Ph.D.
Nested Transaction • Changes are organized in hierarchical increments. • Each embedded Tx can be rolled back without affecting higher level Tx's or sibling Tx's. • Not supported by many systems. Jim Tyhurst, Ph.D.
Distributed Transaction • Two-phase commit process, so that single Tx can span multiple systems. • Each server verifies that it can commit its portion of the Tx before any server actually performs its portion of the commit. • Useful when the domain model is distributed across servers. Jim Tyhurst, Ph.D.
Conversational Transaction • One business Tx is implemented with a series of data Tx's: • Read data in one Tx. • Modify data outside of Tx. • Submit changes in a second Tx. • Naive implementation leads to "Last Commit Wins". Jim Tyhurst, Ph.D.
Queued Transaction • Submit a Tx Specification to a queue. • Client does not wait for Tx. • Option 1: Single queue reader executes Tx's sequentially as they are read from the queue. • Option 2: Multiple readers execute Tx's. • Works well for independent Tx's. • More difficult to handle failures. Jim Tyhurst, Ph.D.
Transaction Models • Flat Transaction • Nested Transaction • Distributed Transaction • Conversational Transaction • Queued Transaction Jim Tyhurst, Ph.D.
Overview • Usage scenarios. • Architecture characteristics. • Forces that influence design decisions. • Transaction models. • Infrastructure to handle failures. • Resolving conflicts. Jim Tyhurst, Ph.D.
Transaction Failures • Goal:Want to avoid causing the user to perform rework to resubmit a transaction. • Problem:How can a transaction be replayed automatically, rather than simply reporting a failure to the user? Jim Tyhurst, Ph.D.
Avoid Reporting Failure • Avoid failure • Lock an Object • Check Out an Object • Recover from failure • Replay Changes • Transaction Specification • Aspect Change Specification • Dirty Object Pool Jim Tyhurst, Ph.D.
Lock an Object • Reduce the risk of commit failure. • Obtain a write lock on an object before modifying it. • Assures that the locking process is the only one to update an object. • Be careful to avoid deadlock when acquiring multiple locks. Jim Tyhurst, Ph.D.
Check Out an Object • Maintain a "lock" for a long period of time across transactions. • Develop a lock table to hold persistent locks for objects that have been checked out. • Application checks out a copy, makes changes, checks in the changed copy. Jim Tyhurst, Ph.D.
Replay Changes (Specification of) Changes • Keep the changes independent from the view of the repository. • When the view is refreshed, the changes may be replayed. Apply changes View of Database Jim Tyhurst, Ph.D.
Preserving Changes • Problem:How can changes to domain model objects be saved independently from the domain model? • Transaction Specification • Dirty Object Pool Jim Tyhurst, Ph.D.
Transaction Specification • Save the sequence of messages that can be sent to cause the desired changes to occur. • Aspect Change SpecificationArray of messages<receiver, method signature, args> • Array of SQL Commands[c1, c2, ..., cN] Jim Tyhurst, Ph.D.
Dirty Object Pool • Keep a copy of the object in its changed state, where the copy is outside of the database view. • When the database view is refreshed, use the copy to reapply the changes. Dirty Object Pool View of Database Jim Tyhurst, Ph.D.
Overview • Usage scenarios. • Architecture characteristics. • Forces that influence design decisions. • Transaction models. • Infrastructure to handle failures. • Resolving conflicts. Jim Tyhurst, Ph.D.
Resolving Conflicts Business Tx 1 • First Commit Wins • Last Commit Wins • Merge Conflicting Updates Business Tx 2 t0 t1 t2 Jim Tyhurst, Ph.D.
Resolving Conflicts Jim Tyhurst, Ph.D.
First Commit Wins • Primary concern: First set of changes forces second user to start again with revised data. • Easy to detect failure when second user commits, but this maximizes the amount of rework. • Some application servers provide notification for early detection of conflicting changes. Jim Tyhurst, Ph.D.
Last Commit Wins • Primary concern: Avoid rework by user. • Assumes risk of conflict is small and consequences of overwriting data are acceptable. • Replay user's changes in a new transaction, overwriting previously committed changes if necessary. Jim Tyhurst, Ph.D.
Merge Conflicting Updates • Primary Concern: Avoid overwriting previous changes with minimal rework by user. • Option 1: Let user confirm merges. • May be difficult to develop additional user interface. • Option 2: Perform merge automatically with some type of resolution algorithm. Jim Tyhurst, Ph.D.
Overview • Usage scenarios. • Architecture characteristics. • Forces that influence design decisions. • Transaction models. • Infrastructure to handle failures. • Resolving conflicts. Jim Tyhurst, Ph.D.
Conclusion • Three-Tier Architecture often uses Conversational Transaction. • Naive implementation leads to Last Commit Wins, whereas Client/Server typically provides First Commit Wins. • Additional development effort is required to detect and resolve conflicts in overlapping business transactions. Jim Tyhurst, Ph.D.