Presentation Transcript
Transaction Management with EAS: Transaction Management with EAS William B. Heys
Senior Consultant
Stop me at any time for questions: Stop me at any time for questions
Agenda: Agenda Introducing Transactions
Client/Server Transaction Management
Transaction Management with EAS
Component Transaction Properties
TransactionServer Object
Transaction State Primitives
Stateful vs. Stateless Components
Component Deactivation
Connection Management
Transaction Coordinators
Component Design for Transaction Management
Introducing Transactions: Introducing Transactions Transactions comprise one or more SQL statements in a logical group or unit of work
A unit of work is atomic – it must succeed or fail as a whole
Ensures database consistency
All databases updated by an application must be left in a consistent state
Database transactions provide isolation
Changes made by one user are isolated from changes made by other uses running simultaneously
Introducing Transactions: Introducing Transactions Transactions must be designed and managed properly to maximize application concurrency
Otherwise, one user updating a database may cause long-duration locks to be placed on large numbers of rows in the database
Until update locks are released, other uses are unable to access or update these rows
Users may be placed into extended wait periods
To increase concurrency
Minimize scope and duration of transactions
At same time, carefully maintain database consistency
Client/Server Transaction Management: Client/Server Transaction Management In two-tier client/server applications, transaction management is the responsibility of client application
A new database transaction is started when application connects to the database
Transaction Management is scripted
A COMMIT or ROLLBACK issued by the client ends the current transaction and begins a new transaction
Database Transactions: Database Transactions Databases use a combination of logging and row locking to support transactions
All changes made to the database are written to a log file
Deleted Rows – image of deleted row
Changed Rows – image of row before changes
New Rows – primary key of the new row
Database changes remain in “pending” state until the outcome of the transaction is known
Database Transactions: Database Transactions DBMS places locks on updated rows (or pages)
Locks prevent other users or applications from reading or updating a row (or page) while an update is pending to that row (or page)
The result is changes made by one user are isolated from changes made by other users
But concurrency is reduced, waiting is increased
Locks remain until the current transaction is committed or rolled back.
Commit/Rollback Processing: Commit/Rollback Processing When a transaction is committed, its changes are made permanent
All changes made by the application since the transaction began are made permanent
When a transaction is rolled back, its changes are removed
All changes made by the application since the transaction began are reversed – using the log
The database is returned to the original state when the transaction was started
For both Commit and Rollback
All update locks are released
The current transaction ends and a new transaction begins
Transaction Management in EAS: Transaction Management in EAS Responsibility shifts from the client application to EAS (Jaguar)
Jaguar manages transactions quite differently
Deployment-time component property rather than scripting
Database updates performed by multiple components can be grouped into the same atomic unit of work
EAS components can participate in implicit transactions
EAS Transactions are not explicitly controlled using Commit or Rollback requests
Component Transaction Properties: Component Transaction Properties EAS components have a new transaction support property
The transaction support property governs how a component participates in EAS transactions – one of the following values
Transaction Not Supported
Supports Transaction
Requires Transaction
Requires New Transaction
If a component is currently running within an implicit EAS transaction it is a transactional component
Component Transaction Properties: Component Transaction Properties A component can choose not to participate in implicit EAS transactions
Transaction Not Supported
Non-transactional components can issue Commit and Rollback requests explicitly
Not the recommended approach
Component Transaction Properties: Component Transaction Properties Components which only support a transaction may or may not participate in an implicit transaction
Supports Transaction
If invoked by a transactional component (one currently running within an EAS transaction), this component will participate in the invoking component’s transaction
If invoked by a non-transactional component or directly by the client application, this component will not participate in an EAS transaction
Component Transaction Properties: Component Transaction Properties If a component requires a transaction it will always participate in an EAS transaction
Requires Transaction
If invoked by a transactional component (one currently running within an EAS transaction), this component will participate in the invoking component’s transaction
If invoked by a non-transactional component or directly by the client application, this component will create a new EAS transaction
Component Transaction Properties: Component Transaction Properties If a component requires a new transaction it will always create a new EAS transaction
Requires New Transaction
If invoked by a transactional component (one currently running within an EAS transaction), this component will create a new EAS transaction, separate from the invoking component’s transaction
If invoked by a non-transactional component or directly by the client application, this component will create a new EAS transaction
TransactionServer Object: TransactionServer Object Special PowerBuilder service context object
You must create a TransactionServer object to be able to use EAS implicit transaction management
Declare an instance variable of type TransactionServer
Protected TransactionServer its_transaction_server
Create the TransactionServer object in the component’s activate event
this.GetContextService (“TransactionServer”, & its_transaction_server)
Destroy the TransactionServer object in the component’s deactivate event
Transaction State Primitives: Transaction State Primitives Components invoke transaction state primitives to particpate in implicit EAS transactions
Each state primitive has a corresponding PowerBuilder function
CompleteWork – SetComplete()
RollbackWork – SetAbort()
ContinueWork – EnableCommit()
DisableCommit – DisableCommit()
InTransaction – IsInTransaction()
IsRollbackOnly – IsTransactionAborted()
Transaction State Primitives: Transaction State Primitives Transaction state primitives serve two purposes
Used by EAS components in place of SQL Commit or Rollback requests to vote on the success or failure of the implicit transaction
Component can only vote on the outcome of a transaction, it cannot control the outcome
At the end of the transaction, if any no vote is received, the transaction is rolled back. If only yes votes are received, the transaction is committed
Indicates whether the component should be deactivated at the end of the method or remain bound to the client
Transaction State Primitives: Transaction State Primitives
Transaction State Primitives: Transaction State Primitives InTransaction – Allows a component to determine whether the current method is running in a transaction
IsRollbackOnly - Allow a component to determine if the transaction has already been aborted
Stateful vs. Stateless Components: Stateful vs. Stateless Components Stateful components maintain information on behalf of a client - across method invocations
Stateful components must therefore remain bound to a client across method invocations
While bound to a client, the component cannot be shared with or used by other clients
Stateless components are deactivated and unbound from a client following each method call
Stateless components are more scaleable because they can be reused more quickly
Stateful vs. Stateless Components: Stateful vs. Stateless Components Stateful components have many disadvantages
Longer lifetimes
Require more resources
Require more instances to be created for a given set of clients
Tend to cause an increase in network traffic
Retrieve data into a datastore in the component
Bring data from the datastore back to the client
Applications using stateless components are more scaleable
Better able to utilize server clusters
Better load balancing
Automatic failover at the component or server level
Component Deactivation: Component Deactivation Stateless components can support early deactivation - they are automatically deactivated when a method call returns
Early deactivation is only possible if the component is stateless
Set the component deployment-time property for automatic demarcation/deactivation to TRUE
Stateless components in a transaction are also deactivated after invoking a SetComplete or SetAbort request
Component Deactivation: Component Deactivation Stateful components must tell EAS when they can be deactivated
If the stateful component participates in a transaction, the transaction state primitives can be used to cause component deactivation
SetComplete or SetAbort
If a stateful component must remain bound to a client it uses a different set of state primitives for transaction management
EnableCommit or DisableCommit
Connection Management: Connection Management EAS can maintain database connection caches
Connection caches (pooling) enable EAS to logically connect and disconnect from the database
Performance is improved because the number of actual physical connections and disconnections are reduced
Components request connections from the pool or cache
If available, a connection will be reused
If a connection is not available, a new one will be created and physically connected to the database
Connection caching is required for EAS transactions
Transaction Coordinators: Transaction Coordinators EAS supports two transaction coordinators
The default transaction coordinator is the SharedConnection coordinator
Connection caches are required if you are using the SharedConnection coordinator
EAS also supports Microsoft’s Distributed Transaction Coordinator (DTC)
DTC supports transactions spanning multiple database connections (2-phase commits)
Must use ODBC and a DTC-compliant database (Microsoft SQL Server)
Transaction Coordinators: Transaction Coordinators Jaguar will support additional transaction coordinators in the future
Java Transaction Server (JTS)
CORBA Object Transaction Server (OTS)
Jaguar will also support Transarc Encina’s 2-phase commit processing in the future
Component Design: Component Design Component design may be significantly affected by transaction management needs
Consider the example of an ATM
The customer wants to perform a single user transaction to transfer money from one account to another
The system breaks this into multiple database requests
Account balance inquiry
Withdraw money from account one
Deposit money to account two
Write a log record to the audit file
Print a receipt
If either update fails, both must be rolled back
Component Design: Component Design Application
Server Account.getBalances() Select Balance from Savings
Select Balance from Checking
Component Design: Component Design Application
Server Account.Transfer() Update Savings set balance...
Update Checking set balance…
Write Log…
Print Receipt...
Component Design: Component Design How should we design our components?
How many components should we have?
What transaction properties should we set?
Component Design: Component Design Customer Component
Transaction Required
AutoDemarcation TRUE
Transaction Management Customer.Withdraw(Savings) Customer.Deposit(Checking) Customer.WriteLog() Transactions 1 2 3
Component Design: Component Design Customer Component
Requires New Transaction
AutoDemarcation TRUE
Transaction Management Customer.Withdraw(Savings) Customer.Deposit(Checking) Customer.WriteLog() Transactions 1 2 3
Component Design: Component Design Customer Component
Transaction Not Supported
AutoDemarcation TRUE
Transaction Management Customer.Withdraw(Savings) Customer.Deposit(Checking) Customer.WriteLog() Transactions
Component Design: Component Design Customer Component
Transaction Supported
AutoDemarcation TRUE
Transaction Management Customer.Withdraw(Savings) Customer.Deposit(Checking) Customer.WriteLog() Transactions
Component Design: Component Design Transaction Management Savings.Withdraw() Checking.Deposit() Audit.WriteLog() Transactions 1 2 3 Savings Account
Component
Transaction Required AutoDemarcation TRUE Checking Account
Component
Transaction Required
AutoDemarcation TRUE Audit Component
Component
Transaction Required
AutoDemarcation TRUE
Component Design: Component Design Savings Account
Component
Transaction Required AutoDemarcation TRUE Checking Account
Component
Transaction Required
AutoDemarcation TRUE Audit Component
Component
Transaction Required
AutoDemarcation TRUE Transaction Management Savings.Withdraw() Checking.Deposit() Audit.WriteLog() Transactions Customer
Component
New Transaction
Required
or
Transaction
Required
Auto
Demarcation
TRUE
Customer.Transfer() 1
Component Design: Component Design Savings Account
Component
Transaction Supported
AutoDemarcation TRUE Checking Account
Component
Transaction Supported
AutoDemarcation TRUE Audit Component
Component
Transaction Supported
AutoDemarcation TRUE Transaction Management Savings.Withdraw() Checking.Deposit() Audit.WriteLog() Transactions Customer
Component
New Transaction
Required
or
Transaction Required
Auto
Demarcation
TRUE
Customer.Transfer() 1
Component Design: Component Design Savings Account
Component
Transaction Supported
AutoDemarcation TRUE Checking Account
Component
Transaction Supported
AutoDemarcation TRUE Audit Component
Component
Transaction Supported
AutoDemarcation TRUE Transaction Management Savings.Withdraw() Checking.Deposit() Audit.WriteLog() Transactions Customer
Component
Transaction Not Supported
or
Transaction Supported
Auto
Demarcation
TRUE
Customer.Transfer()
Component Design: Component Design Savings Account
Component
NewTrans. Required
AutoDemarcation TRUE Checking Account
Component
New Trans. Required
AutoDemarcation TRUE Audit Component
Component
New Trans. Required
AutoDemarcation TRUE Transaction Management Savings.Withdraw() Checking.Deposit() Audit.WriteLog() Transactions Customer
Component
New Transaction
Required
or
Transaction
Required
or
Transaction Not Supported
or
Transaction Supported
Auto
Demarcation
TRUE
Customer.Transfer() 1 2 3
Component Design: Component Design Savings Account
Component
Trans. Not Supported
AutoDemarcation TRUE Checking Account
Component
Trans. Not Supported
AutoDemarcation TRUE Audit Component
Component
Trans. Not Supported
AutoDemarcation TRUE Transaction Management Savings.Withdraw() Checking.Deposit() Audit.WriteLog() Transactions Customer
Component
New Transaction
Required
or
Transaction
Required
or
Transaction Not Supported
or
Transaction Supported
Auto
Demarcation
TRUE
Customer.Transfer()
Component Design: Component Design Savings Account
Component
Transaction Required
AutoDemarcation TRUE Checking Account
Component
Transaction Required
AutoDemarcation TRUE Audit Component
Component
Transaction Required
AutoDemarcation TRUE Transaction Management Savings.Withdraw() Checking.Deposit() Audit.WriteLog() Transactions Customer
Component
Transaction
Not Supported or
Transaction
Supported
Auto
Demarcation
TRUE
Customer.Transfer() 1 2 3
About the Speaker: CPD Professional Certified PowerBuilder Developer
Since 1994
Advanced CSI
Certified Sybase Instructor (Tools)
Since 1992
Founded Boston PowerBuilder User Group in 1992 About the Speaker
Special Edition Using PowerBuilder 6: Special Edition Using PowerBuilder 6
Special Edition Using PowerBuilder 6: Special Edition Using PowerBuilder 6 ISBN: 0-7897-1437-x
Macmillan (Que) website (www.mcp.com)
Go to Site Search, Book Information and enter ISBN
Amazon.Com (www.amazon.com)
Search on author: Heys, William
SoftPro Bookstore (www.SoftPro.com)
Articles on the Web: Articles on the Web “Improving Application Performance with the PowerBuilder Trace Engine and Application Profiler” published online in Sybase Powerline magazine
“Application Partitioning – Architecting Applications for the Future” published online at PowerCard99, sponsored by Sybase in U.K.
Articles in : Articles in “EASy Does IT: Migrating Applications from Distributed PowerBuilder to Enterprise Application Server 3.0” published in PowerTimes, July-August 1999
“A Brighter future for PowerBuilder and Sybase” Guest editorial published in PowerTimes, July-August 1999
“The New Millennium is Bugging Me, PowerBuilder and the Year 2000 issue” published in PowerTimes, January-February 1999 issue.
Books and Articles by Bill Heys: Books and Articles by Bill Heys Special Edition Using PowerBuilder 5.0. Co-author, published by Que June 1996
“NVO’s How and Why” Posted to Compuserve (Go PBForum) NVO Library Section Filename is NVOHOW.Zip August 1995
PowerBuilder Advisor Columns: PowerBuilder Advisor Columns “How the PowerBuilder 5.0 Foundation Class Libraries Implement a Service-Based Architecture.” November-December 1996
“New Language Features in PowerBuilder 5.0.” September-October 1996
“Managing your PowerBuilder Objects.” May-June 1996
“Encapsulating Your Objects” March-April 1996
“Introduction to Custom Classes” January-February 1996 (Premier Issue)
You can reach me...: William B. Heys
Senior Consultant
+1 (781) 203-3171 direct
+1 (617) 513-0296 cell
bill.heys @ marchFIRST.com
bheys @ attglobal.net
bheys@mediaone.net You can reach me... marchFIRST, Inc.
128 Corporate Center
70 Blanchard Rd., 2nd Flooor
Burlington, MA 01803
+1 (781) 203-3000 tel
+1 (781) 203-3050 fax
www.marchFIRST.com