SlideShare a Scribd company logo
1 of 38
Download to read offline
2/21/2012 1
9. Queued Transaction
Processing
CSEP 545 Transaction Processing
Philip A. Bernstein
Copyright ©2012 Philip A. Bernstein
2/21/2012 2
Outline
1. Introduction
2. Transactional Semantics
3. Queue Manager
4. Message-Oriented Middleware
Appendices
A. Marshaling
B. Microsoft Message Queue
2/21/2012 3
9.1 Introduction
• Direct TP - a client sends a request to a server, waits
(synchronously) for the server to run the transaction
and possibly return a reply (e.g., RPC)
• Problems with Direct TP
– Server or client-server communications is down
when the client wants to send the request
– Client or client-server communications is down
when the server wants to send the reply
– If the server fails, how does the client find out what
happened to its outstanding requests?
– Load balancing across many servers
– Priority-based scheduling of busy servers
2/21/2012 4
Persistent Queuing
• Queuing - controlling work requests by moving
them through persistent transactional queues
• Benefits of queuing
– Client can send a request to an unavailable server
– Server can send a reply to an unavailable client
– Since the queue is persistent, a client can (in principle)
find out the state of a request
– Can dequeue requests based on priority
– Can have many servers feed off a single queue
Client Server
Enqueue Dequeue
2/21/2012 5
Other Benefits
• Queue manager as a protocol gateway
– Need to support multiple protocols in just one system
environment
– Can be a trusted client of other systems to bridge security
barriers
• Explicit traffic control, without message loss
• Safe place to do message translation between
application formats
2/21/2012 6
9.2 Transaction Semantics Server View
• The queue is a transactional resource manager
• Server dequeues request within a transaction
• If the transaction aborts, the dequeue is undone,
so the request is returned to the queue
Start
Dequeue(Req, Q1)
process request Req
Enqueue(Reply, Q2)
Commit
Client
Server’s request queue
Client’s
reply queue
Server ProgramQ1
Q2
2/21/2012 7
Transaction Semantics
Server View (cont’d)
• Server program is usually a workflow controller.
• It functions as a dispatcher to
– get a request,
– call the appropriate transaction server, and
– return the reply to the client.
• Abort-count limit and error queue to deal with
requests that repeatedly lead to an aborted
transaction.
2/21/2012 8
• Client runs one transaction to enqueue a request and
a second transaction to dequeue the reply
Transaction Semantics - Client View
Txn1: Start
get input
construct request
Enqueue(Request, Q1)
Commit
Txn3: Start
Dequeue(Reply, Q2)
decode reply
process output
Commit
Q1
Q2
Txn2: Start
Dequeue(Req, Q1)
process request Req
Enqueue(Reply, Q2)
Commit
2/21/2012 9
Transaction Semantics
Client View (cont’d)
• Client transactions are very light weight
• Still, every request now requires 3 transactions,
two on the client and one on the server
– Moreover, if the queue manager is an independent
resource manager (rather than being part of the
database system), then Transaction 2 requires
two phase commit
• So queuing’s benefits come at a cost
2/21/2012 10
Client Recovery
• If a client times out waiting for a reply, it can
determine the state of the request from the queues
– Request is in Q1, reply is in Q2, or request is executing
• Assume each request has a globally unique ID
• If client fails and then recovers, a request could be
in one of 4 states:
– A. Txn1 didn’t commit – no message in either queue.
– B. Txn1 committed but server’s Txn2 did not –
request is either in request queue or being processed
– C. Txn2 committed but Txn3 did not – reply is in the
reply queue
– D. Txn3 committed – no message in either queue
2/21/2012 11
Client Recovery (2)
• So, if the client knows the request id R, it can
determine state C and maybe state B.
• What if no queued message has the id R?
Could be in state A, B, or D.
• Can further clarify matters if the client has a local
database that can run 2-phase commit with the
queue manager.
– Use the local database to store the state of the request.
2/21/2012 12
Transaction Semantics - Client View
Txn1: Start
R = LastRequest
Enqueue(Request Q, R)
LastEnqueuedID=R.ID
Commit
Txn3: Start
R = Dequeue(Reply Q)
decode reply & process output
LastDequeuedID=R.ID
Commit
Q1
Q2
Txn2: Start
Req=Dequeue(RequestQ)
process request Req
Enqueue(ReplyQ, reply)
Commit
Txn0: Start
get input & construct request R
LastRequest = R
Commit
2/21/2012 13
Client Recovery (3)
• If client fails and then recovers, a request R could
be in one of 4 states:
– A. Txn1 didn’t commit – Local DB says R is
NotSubmitted.
– B. Txn1 committed but server’s Txn2 did not – Local
DB says R is Submitted and R is either in request queue
or being processed
– C. Txn2 committed but Txn3 did not – Local DB says R
is Submitted and R’s reply is in the reply queue
– D. Txn3 committed – Local DB says R is Done
• To distinguish B and C, client first checks request
queue (if desired) and then polls reply queue.
2/21/2012 14
Persistent Sessions
• Suppose client doesn’t have a local database that
runs 2PC with the queue manager.
• The queue manager can help by persistently
remembering each client’s last operation, which is
returned when the client connects to a queue …
amounts to a persistent session.
2/21/2012 15
Client Recovery with Persistent Sessions
// Let R be id of client’s last request
// Assume client ran Txn0 for R before Txn1
Client connects to request and reply queues;
If (id of last request enqueued  R) { resubmit request }
elseif (id of last reply message dequeued  R)
{ dequeue (and wait for) reply with id R }
else // R was fully processed, nothing to recover
• Now client can figure out
• A – if last enqueued request is not R
• D – if last dequeued reply is R
• B – no evidence of R and not in states A, C, or D.
2/21/2012 16
Non-Undoable Operations
• How to handle non-undoable non-idempotent
operations in txn3 ?
Txn3: Start
Dequeue(Reply for R, Q2)
decode reply & process output
State(R) = “Done”
Commit
Crash!
=> R was processed.
But Txn3 aborts.
So R is back on Q2.
• If the operation is undoable, then undo it.
• If it’s idempotent, it’s safe to repeat it.
• If it’s neither, it had better be testable.
2/21/2012 17
Testable Operations
• Testable operations
– After the operation runs, there is a test operation that
the client can execute to tell whether the operation ran
– Typically, the non-undoable operation returns a
description of the state of the device (before-state) and
then changes the state of the device
– The test operation returns a description of the state of
the device.
– E.g., State description can be a unique
ticket/check/form number under the print head
2/21/2012 18
Recovery Procedure for State C
To process a reply
1. Start a transaction
2. Dequeue the reply
3. If there’s an earlier logged device state for this
reply and it differs from the current device state,
then ask the operator whether to abort this txn
4. Persistently log the current device state with
the reply’s ID. This operation is permanent
whether or not this transaction commits.
5. Perform the operation on the physical device
6. Commit
Log
2/21/2012 19
Optimizations
• In effect, the previous procedure makes the action
“process output” idempotent.
• If “process output” sent a message, it may not be
testable, so make sure it’s idempotent!
– If txn3 is sending a receipt, label it by the serial number
of the request, so it can be sent twice
• Log device state as part of Dequeue operation
(saves an I/O).
– i.e., run step 3 before step 2.
2/21/2012 20
9.3 Queue Manager
• A queue supports most file-oriented operations
– Create and destroy queue database
– Create and destroy queue
– Show and modify queue’s attributes (e.g. security)
– Open-scan and get-next-element
– Enqueue and Dequeue
• Next element or element identified by index
• Inside or outside a transaction
– Read element
2/21/2012 21
Queue Manager (cont’d)
• Also has some communication types of operations
– Start and stop queue
– Volatile queues (lost in a system failure)
– Persistent sessions (explained earlier)
• System management operations
– Monitor load
– Report on failures and recoveries
2/21/2012 22
Example of Enqueue Parameters
(IBM Websphere MQ)
• System-generated and application-assigned message Ids
• Name of destination queue and reply queue (optional)
• Flag indicating if message is persistent
• Message type - datagram, request, reply, report
• Message priority
• Correlation id to link reply to request
• Expiry time
• Application-defined format type and code page (for I18N)
• Report options - confirm on arrival (when enqueued)?,
on delivery (when dequeued)?, on expiry?, on exception?
2/21/2012 23
Priority Ordering
• Prioritize queue elements
• Dequeue by priority
• Abort makes strict priority-ordered dequeue too
expensive
– Could never have two elements of different priorities
dequeued and uncommitted concurrently
• But some systems require it for legal reasons
– Stock trades must be processed in timestamp order
2/21/2012 24
Routing
• Forwarding of messages between queues
– Transactional, to avoid lost messages
– Batch forwarding of messages, for better throughput
– Can be implemented as an ordinary transaction server
• Often, a lightweight client implementation supports
a client queue,
– Captures messages when client is disconnected, and
– Forwards them when communication to queue server is
re-established
• Implies system mgmt requirement to display
topology of forwarding links
2/21/2012 25
State of the Art
• All app servers support some form of queuing
• A new trend is to add queuing to the SQL DBMS
– Oracle & SQL Server have it.
– Avoids 2PC for Txn2, allows queries, ….
• Queuing is hard to build well.
– It’s a product or major sub-system, not just a feature.
• Lots of queuing products with small market share.
• Some major ones are
– IBM’s MQSeries
– Oracle Streams AQ
– Oracle BEA MessageQ
– Microsoft Message Queuing
9.4 Message-Oriented Middleware
• Publish-Subscribe
• Message Broker
• Message Bus
2/21/2012 26
Publish-Subscribe
• Using queues, each message has one recipient
• Some apps need to send to multiple recipients
– E.g., notify changes of stock price, flight schedule
• Publish-subscribe paradigm allows many
recipients per message
– Subscribers sign up for message types, by name (e.g.
“Reuters”) or predicate (type=“Msft” and price > 33)
• Similar to queues
– Send and receiver are decoupled
– Send or receive within a transaction
– Subscribers can push (dispatch) or pull (dequeue)2/21/2012 27
Publish-Subscribe (cont’d)
• Hence, often supported by queue managers
• E.g., Java Messaging Service (JMS) defines
both peer-to-peer and pub-sub interfaces
2/21/2012 28
Data Streams
AKA Complex Event Processing
• Treat a message stream like a table in a SQL database
• A query retrieves messages within a time window
– Distinguish message-time from event-time
• An evolution of pub-sub and of SQL databases
• Applications – sensors, financial markets, intelligence,
gaming, telecom, mobile commerce, ….
• Products are from startups & major vendors
2/21/2012 29
– Microsoft Stream Insight
– IBM InfoSphere Streams
– Oracle Complex Event Proc.
– StreamBase
Broker and Bus Middleware
• Messaging technology is often used to integrate
independent applications.
– Broker-based: Enterprise Application Integration
(EAI)
– Bus-based: Enterprise Server Bus (ESB)
• These functions are often combined with queuing
and/or pub-sub.
2/21/2012 30
Broker-Based
2/21/2012 31
Client
Uniform
Function
Interface
Protocol
AdaptorParameter
Translation
Message Broker
Protocol
Adaptor
     
TP System
TP Application
TP System
TP Application
• The Broker bridges wire protocols, invocation
mechanisms, and parameter formats
Bus-Based
2/21/2012 32
Client
TP System
TP Application
Protocol Adaptor
  
TP System
TP Application
Protocol Adaptor
• All apps support the same protocol and invocation
mechanism
• Client or broker functions still needed for
translating parameter formats
Trends
• There is much variety in message-oriented
middleware
• Probably this will continue, followed by
some shakeout
2/21/2012 33
2/21/2012 34
Appendix A: Marshaling
• Caller of Enqueue and Dequeue needs to marshal and
unmarshal data into variables
• Instead, use the automatic marshaling of RPC
• Here’s how RPC works:
App Proxy Runtime Runtime Stub App
call P
return
to caller
pack
argu-
ments
unpack
results
send
receive
receive
send
unpack
argu-
ments
pack
results
P
work
return
wait
Client’s System Server’s System
Call
packet
Return
packet
2/21/2012 35
Adapting RPC Marshaling for Queues
App Proxy Runtime Runtime Stub App
call P
return
to app
pack
argu-
ments
unpack
results
enqueue
request
dequeue
reply
dequeue
request
enqueue
reply
unpack
argu-
ments
pack
results
P
work
return
wait
Client’s System Server’s Systemserver
request
queue
client
reply
queue
• In effect, use queuing as a transport for RPC
• Example – Queued Component in MSMQ
2/21/2012 36
Appendix B : Microsoft Message Queuing
(MSMQ) [from 2003]
• Clients enqueue/dequeue to queue servers
– API - Open/Close, Send/Receive
– Each queue is named in the Active Directory
– Additional functions: Create/Delete queue, Locate queue, Set/Get
queue properties, Set/Get queue security
• Send/Receive can be
– Transactional on persistent queues (transparently gets transaction
context), using DTC
– Non-transactional on persistent/volatile queues
• Independent client has a local persistent queue store.
– Processes ops locally, asynchronously sends to a server
– Dependent client issues RPC to a queue server
(easier to administer, fewer resources required)
2/21/2012 37
MSMQ Servers
Open Send Rec’v Close
API
Application
1
Application
2
Information
Server
Client Proxy
Server
Queue
Manager
‘A’ ‘B’ ‘C’ Sys Sys
Routing
Server
MSMQ Server
• Stores messages
• Dynamic min-cost routing
• Volatile or persistent (txnal)
store and forward
• Support local / dependent
clients and forwarding from
servers / independent clients
• Provides MSMQ Explorer
– Topologies, routing, mgmt
• Security via ACLs, journals,
public key authentication
2/21/2012 38
MSMQ Interoperation
• Exchange Connector - Send and receive messages
and forms through Exchange Server and MSMQ
• MAPI transport - Send and receive messages and
forms through MAPI and MSMQ
• Via Level 8 Systems,
– Clients - MVS, AS/400, VMS, HP-Unix, Sun-Solaris,
AIX, OS/2 clients
– Interoperates with IBM MQSeries

More Related Content

What's hot

Transaction & Concurrency Control
Transaction & Concurrency ControlTransaction & Concurrency Control
Transaction & Concurrency ControlRavimuthurajan
 
Transaction conccurency
Transaction conccurencyTransaction conccurency
Transaction conccurencyEsraa Farrag
 
Two phase commit protocol in dbms
Two phase commit protocol in dbmsTwo phase commit protocol in dbms
Two phase commit protocol in dbmsDilouar Hossain
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency ControlDilum Bandara
 
Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Peter R. Egli
 
DBMS Unit III Material
DBMS Unit III MaterialDBMS Unit III Material
DBMS Unit III MaterialArthyR3
 
Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemorySHIKHA GAUTAM
 
Trafodion Distributed Transaction Management
Trafodion Distributed Transaction ManagementTrafodion Distributed Transaction Management
Trafodion Distributed Transaction ManagementRohit Jain
 
Transaction Processing Monitors
Transaction Processing MonitorsTransaction Processing Monitors
Transaction Processing MonitorssuZZal123
 
Dbms ii mca-ch11-recovery-2013
Dbms ii mca-ch11-recovery-2013Dbms ii mca-ch11-recovery-2013
Dbms ii mca-ch11-recovery-2013Prosanta Ghosh
 

What's hot (16)

Transaction & Concurrency Control
Transaction & Concurrency ControlTransaction & Concurrency Control
Transaction & Concurrency Control
 
6 two phasecommit
6 two phasecommit6 two phasecommit
6 two phasecommit
 
Transaction conccurency
Transaction conccurencyTransaction conccurency
Transaction conccurency
 
Two phase commit protocol in dbms
Two phase commit protocol in dbmsTwo phase commit protocol in dbms
Two phase commit protocol in dbms
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency Control
 
Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)
 
DBMS Unit III Material
DBMS Unit III MaterialDBMS Unit III Material
DBMS Unit III Material
 
Distributed Transaction
Distributed TransactionDistributed Transaction
Distributed Transaction
 
Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
 
2 pc
2 pc2 pc
2 pc
 
Trafodion Distributed Transaction Management
Trafodion Distributed Transaction ManagementTrafodion Distributed Transaction Management
Trafodion Distributed Transaction Management
 
Transaction Processing monitor
Transaction Processing monitorTransaction Processing monitor
Transaction Processing monitor
 
Transaction Processing Monitors
Transaction Processing MonitorsTransaction Processing Monitors
Transaction Processing Monitors
 
Dbms
DbmsDbms
Dbms
 
Distributed DBMS - Unit 9 - Distributed Deadlock & Recovery
Distributed DBMS - Unit 9 - Distributed Deadlock & RecoveryDistributed DBMS - Unit 9 - Distributed Deadlock & Recovery
Distributed DBMS - Unit 9 - Distributed Deadlock & Recovery
 
Dbms ii mca-ch11-recovery-2013
Dbms ii mca-ch11-recovery-2013Dbms ii mca-ch11-recovery-2013
Dbms ii mca-ch11-recovery-2013
 

Viewers also liked

16 greg hope_com_wics
16 greg hope_com_wics16 greg hope_com_wics
16 greg hope_com_wicsashish61_scs
 
Project description2012
Project description2012Project description2012
Project description2012ashish61_scs
 
3 concurrency controlone_v3
3 concurrency controlone_v33 concurrency controlone_v3
3 concurrency controlone_v3ashish61_scs
 
08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlickashish61_scs
 
14 scaleabilty wics
14 scaleabilty wics14 scaleabilty wics
14 scaleabilty wicsashish61_scs
 

Viewers also liked (11)

10b rm
10b rm10b rm
10b rm
 
17 wics99 harkey
17 wics99 harkey17 wics99 harkey
17 wics99 harkey
 
16 greg hope_com_wics
16 greg hope_com_wics16 greg hope_com_wics
16 greg hope_com_wics
 
Project description2012
Project description2012Project description2012
Project description2012
 
Solution7.2012
Solution7.2012Solution7.2012
Solution7.2012
 
3 concurrency controlone_v3
3 concurrency controlone_v33 concurrency controlone_v3
3 concurrency controlone_v3
 
20 access paths
20 access paths20 access paths
20 access paths
 
08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick
 
2 shadowing
2 shadowing2 shadowing
2 shadowing
 
1 introduction
1 introduction1 introduction
1 introduction
 
14 scaleabilty wics
14 scaleabilty wics14 scaleabilty wics
14 scaleabilty wics
 

Similar to 9 queuing

5 application serversforproject
5 application serversforproject5 application serversforproject
5 application serversforprojectashish61_scs
 
8 application servers_v2
8 application servers_v28 application servers_v2
8 application servers_v2ashish61_scs
 
Multi-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocketMulti-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocketStéphane Maldini
 
A project on Clientserver SystemThis project is about a client
A project on Clientserver SystemThis project is about a clientA project on Clientserver SystemThis project is about a client
A project on Clientserver SystemThis project is about a clientlatashiadegale
 
A project on Clientserver SystemThis project is about a client.docx
A project on Clientserver SystemThis project is about a client.docxA project on Clientserver SystemThis project is about a client.docx
A project on Clientserver SystemThis project is about a client.docxmakdul
 
Remote invocation
Remote invocationRemote invocation
Remote invocationishapadhy
 
24. Advanced Transaction Processing in DBMS
24. Advanced Transaction Processing in DBMS24. Advanced Transaction Processing in DBMS
24. Advanced Transaction Processing in DBMSkoolkampus
 
3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-queryM Rezaur Rahman
 
Processing Semantically-Ordered Streams in Financial Services
Processing Semantically-Ordered Streams in Financial ServicesProcessing Semantically-Ordered Streams in Financial Services
Processing Semantically-Ordered Streams in Financial ServicesFlink Forward
 
1 messagepassing-121015032028-phpapp01
1 messagepassing-121015032028-phpapp011 messagepassing-121015032028-phpapp01
1 messagepassing-121015032028-phpapp01Zaigham Abbas
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure callSunita Sahu
 
Introduction to Business Process Analysis and Redesign
Introduction to Business Process Analysis and RedesignIntroduction to Business Process Analysis and Redesign
Introduction to Business Process Analysis and RedesignMarlon Dumas
 

Similar to 9 queuing (20)

5 application serversforproject
5 application serversforproject5 application serversforproject
5 application serversforproject
 
8 application servers_v2
8 application servers_v28 application servers_v2
8 application servers_v2
 
11 bpm
11 bpm11 bpm
11 bpm
 
Multi-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocketMulti-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocket
 
A project on Clientserver SystemThis project is about a client
A project on Clientserver SystemThis project is about a clientA project on Clientserver SystemThis project is about a client
A project on Clientserver SystemThis project is about a client
 
A project on Clientserver SystemThis project is about a client.docx
A project on Clientserver SystemThis project is about a client.docxA project on Clientserver SystemThis project is about a client.docx
A project on Clientserver SystemThis project is about a client.docx
 
Rpc
RpcRpc
Rpc
 
Remote Procedure Call
Remote Procedure CallRemote Procedure Call
Remote Procedure Call
 
basil.pptx
basil.pptxbasil.pptx
basil.pptx
 
Remote invocation
Remote invocationRemote invocation
Remote invocation
 
24. Advanced Transaction Processing in DBMS
24. Advanced Transaction Processing in DBMS24. Advanced Transaction Processing in DBMS
24. Advanced Transaction Processing in DBMS
 
3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query3 distributed transactions-cocurrency-query
3 distributed transactions-cocurrency-query
 
Processing Semantically-Ordered Streams in Financial Services
Processing Semantically-Ordered Streams in Financial ServicesProcessing Semantically-Ordered Streams in Financial Services
Processing Semantically-Ordered Streams in Financial Services
 
1 messagepassing-121015032028-phpapp01
1 messagepassing-121015032028-phpapp011 messagepassing-121015032028-phpapp01
1 messagepassing-121015032028-phpapp01
 
End User ServicesV1.0 training.ppt
End User ServicesV1.0 training.pptEnd User ServicesV1.0 training.ppt
End User ServicesV1.0 training.ppt
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 
Lecture9
Lecture9Lecture9
Lecture9
 
Introduction to Business Process Analysis and Redesign
Introduction to Business Process Analysis and RedesignIntroduction to Business Process Analysis and Redesign
Introduction to Business Process Analysis and Redesign
 
Transaction TCP
Transaction TCPTransaction TCP
Transaction TCP
 
Remote procedure call
Remote procedure callRemote procedure call
Remote procedure call
 

More from ashish61_scs

More from ashish61_scs (20)

7 concurrency controltwo
7 concurrency controltwo7 concurrency controltwo
7 concurrency controltwo
 
Transactions
TransactionsTransactions
Transactions
 
22 levine
22 levine22 levine
22 levine
 
21 domino mohan-1
21 domino mohan-121 domino mohan-1
21 domino mohan-1
 
19 structured files
19 structured files19 structured files
19 structured files
 
18 philbe replication stanford99
18 philbe replication stanford9918 philbe replication stanford99
18 philbe replication stanford99
 
15 bufferand records
15 bufferand records15 bufferand records
15 bufferand records
 
14 turing wics
14 turing wics14 turing wics
14 turing wics
 
13 tm adv
13 tm adv13 tm adv
13 tm adv
 
11 tm
11 tm11 tm
11 tm
 
10a log
10a log10a log
10a log
 
09 workflow
09 workflow09 workflow
09 workflow
 
06 07 lock
06 07 lock06 07 lock
06 07 lock
 
05 tp mon_orbs
05 tp mon_orbs05 tp mon_orbs
05 tp mon_orbs
 
04 transaction models
04 transaction models04 transaction models
04 transaction models
 
03 fault model
03 fault model03 fault model
03 fault model
 
02 fault tolerance
02 fault tolerance02 fault tolerance
02 fault tolerance
 
01 whirlwind tour
01 whirlwind tour01 whirlwind tour
01 whirlwind tour
 
Solution5.2012
Solution5.2012Solution5.2012
Solution5.2012
 
Solution6.2012
Solution6.2012Solution6.2012
Solution6.2012
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 

Recently uploaded (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 

9 queuing

  • 1. 2/21/2012 1 9. Queued Transaction Processing CSEP 545 Transaction Processing Philip A. Bernstein Copyright ©2012 Philip A. Bernstein
  • 2. 2/21/2012 2 Outline 1. Introduction 2. Transactional Semantics 3. Queue Manager 4. Message-Oriented Middleware Appendices A. Marshaling B. Microsoft Message Queue
  • 3. 2/21/2012 3 9.1 Introduction • Direct TP - a client sends a request to a server, waits (synchronously) for the server to run the transaction and possibly return a reply (e.g., RPC) • Problems with Direct TP – Server or client-server communications is down when the client wants to send the request – Client or client-server communications is down when the server wants to send the reply – If the server fails, how does the client find out what happened to its outstanding requests? – Load balancing across many servers – Priority-based scheduling of busy servers
  • 4. 2/21/2012 4 Persistent Queuing • Queuing - controlling work requests by moving them through persistent transactional queues • Benefits of queuing – Client can send a request to an unavailable server – Server can send a reply to an unavailable client – Since the queue is persistent, a client can (in principle) find out the state of a request – Can dequeue requests based on priority – Can have many servers feed off a single queue Client Server Enqueue Dequeue
  • 5. 2/21/2012 5 Other Benefits • Queue manager as a protocol gateway – Need to support multiple protocols in just one system environment – Can be a trusted client of other systems to bridge security barriers • Explicit traffic control, without message loss • Safe place to do message translation between application formats
  • 6. 2/21/2012 6 9.2 Transaction Semantics Server View • The queue is a transactional resource manager • Server dequeues request within a transaction • If the transaction aborts, the dequeue is undone, so the request is returned to the queue Start Dequeue(Req, Q1) process request Req Enqueue(Reply, Q2) Commit Client Server’s request queue Client’s reply queue Server ProgramQ1 Q2
  • 7. 2/21/2012 7 Transaction Semantics Server View (cont’d) • Server program is usually a workflow controller. • It functions as a dispatcher to – get a request, – call the appropriate transaction server, and – return the reply to the client. • Abort-count limit and error queue to deal with requests that repeatedly lead to an aborted transaction.
  • 8. 2/21/2012 8 • Client runs one transaction to enqueue a request and a second transaction to dequeue the reply Transaction Semantics - Client View Txn1: Start get input construct request Enqueue(Request, Q1) Commit Txn3: Start Dequeue(Reply, Q2) decode reply process output Commit Q1 Q2 Txn2: Start Dequeue(Req, Q1) process request Req Enqueue(Reply, Q2) Commit
  • 9. 2/21/2012 9 Transaction Semantics Client View (cont’d) • Client transactions are very light weight • Still, every request now requires 3 transactions, two on the client and one on the server – Moreover, if the queue manager is an independent resource manager (rather than being part of the database system), then Transaction 2 requires two phase commit • So queuing’s benefits come at a cost
  • 10. 2/21/2012 10 Client Recovery • If a client times out waiting for a reply, it can determine the state of the request from the queues – Request is in Q1, reply is in Q2, or request is executing • Assume each request has a globally unique ID • If client fails and then recovers, a request could be in one of 4 states: – A. Txn1 didn’t commit – no message in either queue. – B. Txn1 committed but server’s Txn2 did not – request is either in request queue or being processed – C. Txn2 committed but Txn3 did not – reply is in the reply queue – D. Txn3 committed – no message in either queue
  • 11. 2/21/2012 11 Client Recovery (2) • So, if the client knows the request id R, it can determine state C and maybe state B. • What if no queued message has the id R? Could be in state A, B, or D. • Can further clarify matters if the client has a local database that can run 2-phase commit with the queue manager. – Use the local database to store the state of the request.
  • 12. 2/21/2012 12 Transaction Semantics - Client View Txn1: Start R = LastRequest Enqueue(Request Q, R) LastEnqueuedID=R.ID Commit Txn3: Start R = Dequeue(Reply Q) decode reply & process output LastDequeuedID=R.ID Commit Q1 Q2 Txn2: Start Req=Dequeue(RequestQ) process request Req Enqueue(ReplyQ, reply) Commit Txn0: Start get input & construct request R LastRequest = R Commit
  • 13. 2/21/2012 13 Client Recovery (3) • If client fails and then recovers, a request R could be in one of 4 states: – A. Txn1 didn’t commit – Local DB says R is NotSubmitted. – B. Txn1 committed but server’s Txn2 did not – Local DB says R is Submitted and R is either in request queue or being processed – C. Txn2 committed but Txn3 did not – Local DB says R is Submitted and R’s reply is in the reply queue – D. Txn3 committed – Local DB says R is Done • To distinguish B and C, client first checks request queue (if desired) and then polls reply queue.
  • 14. 2/21/2012 14 Persistent Sessions • Suppose client doesn’t have a local database that runs 2PC with the queue manager. • The queue manager can help by persistently remembering each client’s last operation, which is returned when the client connects to a queue … amounts to a persistent session.
  • 15. 2/21/2012 15 Client Recovery with Persistent Sessions // Let R be id of client’s last request // Assume client ran Txn0 for R before Txn1 Client connects to request and reply queues; If (id of last request enqueued  R) { resubmit request } elseif (id of last reply message dequeued  R) { dequeue (and wait for) reply with id R } else // R was fully processed, nothing to recover • Now client can figure out • A – if last enqueued request is not R • D – if last dequeued reply is R • B – no evidence of R and not in states A, C, or D.
  • 16. 2/21/2012 16 Non-Undoable Operations • How to handle non-undoable non-idempotent operations in txn3 ? Txn3: Start Dequeue(Reply for R, Q2) decode reply & process output State(R) = “Done” Commit Crash! => R was processed. But Txn3 aborts. So R is back on Q2. • If the operation is undoable, then undo it. • If it’s idempotent, it’s safe to repeat it. • If it’s neither, it had better be testable.
  • 17. 2/21/2012 17 Testable Operations • Testable operations – After the operation runs, there is a test operation that the client can execute to tell whether the operation ran – Typically, the non-undoable operation returns a description of the state of the device (before-state) and then changes the state of the device – The test operation returns a description of the state of the device. – E.g., State description can be a unique ticket/check/form number under the print head
  • 18. 2/21/2012 18 Recovery Procedure for State C To process a reply 1. Start a transaction 2. Dequeue the reply 3. If there’s an earlier logged device state for this reply and it differs from the current device state, then ask the operator whether to abort this txn 4. Persistently log the current device state with the reply’s ID. This operation is permanent whether or not this transaction commits. 5. Perform the operation on the physical device 6. Commit Log
  • 19. 2/21/2012 19 Optimizations • In effect, the previous procedure makes the action “process output” idempotent. • If “process output” sent a message, it may not be testable, so make sure it’s idempotent! – If txn3 is sending a receipt, label it by the serial number of the request, so it can be sent twice • Log device state as part of Dequeue operation (saves an I/O). – i.e., run step 3 before step 2.
  • 20. 2/21/2012 20 9.3 Queue Manager • A queue supports most file-oriented operations – Create and destroy queue database – Create and destroy queue – Show and modify queue’s attributes (e.g. security) – Open-scan and get-next-element – Enqueue and Dequeue • Next element or element identified by index • Inside or outside a transaction – Read element
  • 21. 2/21/2012 21 Queue Manager (cont’d) • Also has some communication types of operations – Start and stop queue – Volatile queues (lost in a system failure) – Persistent sessions (explained earlier) • System management operations – Monitor load – Report on failures and recoveries
  • 22. 2/21/2012 22 Example of Enqueue Parameters (IBM Websphere MQ) • System-generated and application-assigned message Ids • Name of destination queue and reply queue (optional) • Flag indicating if message is persistent • Message type - datagram, request, reply, report • Message priority • Correlation id to link reply to request • Expiry time • Application-defined format type and code page (for I18N) • Report options - confirm on arrival (when enqueued)?, on delivery (when dequeued)?, on expiry?, on exception?
  • 23. 2/21/2012 23 Priority Ordering • Prioritize queue elements • Dequeue by priority • Abort makes strict priority-ordered dequeue too expensive – Could never have two elements of different priorities dequeued and uncommitted concurrently • But some systems require it for legal reasons – Stock trades must be processed in timestamp order
  • 24. 2/21/2012 24 Routing • Forwarding of messages between queues – Transactional, to avoid lost messages – Batch forwarding of messages, for better throughput – Can be implemented as an ordinary transaction server • Often, a lightweight client implementation supports a client queue, – Captures messages when client is disconnected, and – Forwards them when communication to queue server is re-established • Implies system mgmt requirement to display topology of forwarding links
  • 25. 2/21/2012 25 State of the Art • All app servers support some form of queuing • A new trend is to add queuing to the SQL DBMS – Oracle & SQL Server have it. – Avoids 2PC for Txn2, allows queries, …. • Queuing is hard to build well. – It’s a product or major sub-system, not just a feature. • Lots of queuing products with small market share. • Some major ones are – IBM’s MQSeries – Oracle Streams AQ – Oracle BEA MessageQ – Microsoft Message Queuing
  • 26. 9.4 Message-Oriented Middleware • Publish-Subscribe • Message Broker • Message Bus 2/21/2012 26
  • 27. Publish-Subscribe • Using queues, each message has one recipient • Some apps need to send to multiple recipients – E.g., notify changes of stock price, flight schedule • Publish-subscribe paradigm allows many recipients per message – Subscribers sign up for message types, by name (e.g. “Reuters”) or predicate (type=“Msft” and price > 33) • Similar to queues – Send and receiver are decoupled – Send or receive within a transaction – Subscribers can push (dispatch) or pull (dequeue)2/21/2012 27
  • 28. Publish-Subscribe (cont’d) • Hence, often supported by queue managers • E.g., Java Messaging Service (JMS) defines both peer-to-peer and pub-sub interfaces 2/21/2012 28
  • 29. Data Streams AKA Complex Event Processing • Treat a message stream like a table in a SQL database • A query retrieves messages within a time window – Distinguish message-time from event-time • An evolution of pub-sub and of SQL databases • Applications – sensors, financial markets, intelligence, gaming, telecom, mobile commerce, …. • Products are from startups & major vendors 2/21/2012 29 – Microsoft Stream Insight – IBM InfoSphere Streams – Oracle Complex Event Proc. – StreamBase
  • 30. Broker and Bus Middleware • Messaging technology is often used to integrate independent applications. – Broker-based: Enterprise Application Integration (EAI) – Bus-based: Enterprise Server Bus (ESB) • These functions are often combined with queuing and/or pub-sub. 2/21/2012 30
  • 31. Broker-Based 2/21/2012 31 Client Uniform Function Interface Protocol AdaptorParameter Translation Message Broker Protocol Adaptor       TP System TP Application TP System TP Application • The Broker bridges wire protocols, invocation mechanisms, and parameter formats
  • 32. Bus-Based 2/21/2012 32 Client TP System TP Application Protocol Adaptor    TP System TP Application Protocol Adaptor • All apps support the same protocol and invocation mechanism • Client or broker functions still needed for translating parameter formats
  • 33. Trends • There is much variety in message-oriented middleware • Probably this will continue, followed by some shakeout 2/21/2012 33
  • 34. 2/21/2012 34 Appendix A: Marshaling • Caller of Enqueue and Dequeue needs to marshal and unmarshal data into variables • Instead, use the automatic marshaling of RPC • Here’s how RPC works: App Proxy Runtime Runtime Stub App call P return to caller pack argu- ments unpack results send receive receive send unpack argu- ments pack results P work return wait Client’s System Server’s System Call packet Return packet
  • 35. 2/21/2012 35 Adapting RPC Marshaling for Queues App Proxy Runtime Runtime Stub App call P return to app pack argu- ments unpack results enqueue request dequeue reply dequeue request enqueue reply unpack argu- ments pack results P work return wait Client’s System Server’s Systemserver request queue client reply queue • In effect, use queuing as a transport for RPC • Example – Queued Component in MSMQ
  • 36. 2/21/2012 36 Appendix B : Microsoft Message Queuing (MSMQ) [from 2003] • Clients enqueue/dequeue to queue servers – API - Open/Close, Send/Receive – Each queue is named in the Active Directory – Additional functions: Create/Delete queue, Locate queue, Set/Get queue properties, Set/Get queue security • Send/Receive can be – Transactional on persistent queues (transparently gets transaction context), using DTC – Non-transactional on persistent/volatile queues • Independent client has a local persistent queue store. – Processes ops locally, asynchronously sends to a server – Dependent client issues RPC to a queue server (easier to administer, fewer resources required)
  • 37. 2/21/2012 37 MSMQ Servers Open Send Rec’v Close API Application 1 Application 2 Information Server Client Proxy Server Queue Manager ‘A’ ‘B’ ‘C’ Sys Sys Routing Server MSMQ Server • Stores messages • Dynamic min-cost routing • Volatile or persistent (txnal) store and forward • Support local / dependent clients and forwarding from servers / independent clients • Provides MSMQ Explorer – Topologies, routing, mgmt • Security via ACLs, journals, public key authentication
  • 38. 2/21/2012 38 MSMQ Interoperation • Exchange Connector - Send and receive messages and forms through Exchange Server and MSMQ • MAPI transport - Send and receive messages and forms through MAPI and MSMQ • Via Level 8 Systems, – Clients - MVS, AS/400, VMS, HP-Unix, Sun-Solaris, AIX, OS/2 clients – Interoperates with IBM MQSeries