Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lecture 9
Notes from:
Web Services & Contemporary SOA Ch 6, Erl
XML Transactions for Web Services, Faheem Khan
Distributed Systems Text, Tanenbaum
Microsoft Article at
http://msdn2.microsoft.com/en-gb/library/ms996526.aspx
2
WS-Coordination
An OASIS standard
Developed by IBM, Microsoft & BEA
Implemented in WebSpehere V6
Part of MS Vista and the Windows
Communication Foundation (Indigo
project)
Apache Foundation Kandula Project
3
Coordination
Every activity introduces a level of
context into an application runtime
environment.
Context Information must be managed,
preserved and/or updated and
distributed to activity participants.
WS-Coordination establishes such a
framework.
4
From IBM
5
From Apaches Kandula Project
6
activation
registration
Service
service
coordinator
Potential participants
7
CreateCoordinationContext
activation
Service
registration
service
participant
participant
coordinator
Potential participants
8
activation
registration
Service
register
service
participant
participant
Potential
coordinator
participants
participant
9
activation
registration
Service
service
10
activation
registration
Service
service
Each coordinator
has a type: currently
either
WS-AtomicTransaction
participant
participant
or WS-BusinessActivity
This participant
wants to engage
coordinator
others in an atomic
participant
transaction.
11
Call createCoordinationContext
activation
registration
Service
service
1
2
coordinator
participant
participant
activation
registration
Service
service
3
4
coordinator
participant
participant
coordinator
participant
participant
participant
coordinator
participant
participant
participant
18
1. Sending a CreateCoordinationContext message to the Activation
service creates an activity. The optional CurrentContext parameter is absent, so a
new activity is created and the returned CoordinationContext has a new activity
identifier and Registration service A.
2. The CoordinationContext is propagated from application services A to B as a
SOAP header in an application message. This acts as an invitation to application
service B to participate in the activity using one of the coordination protocols for
that coordination type. The service that receives this invitation can either register
to participate or not.
3. Service B registers using the Registration service A from the propagated context.
4. The coordination protocol instance can then begin between the participants. This
Coordination protocol enables coordination. For example, this may be either the WS-
AtomicTransaction 2PC or WS-BusinessActivity protocol.
19
WS-Coordination
The participant application has gained possession of
an instance of the coordination context.
The participant application then propagates the
coordination context instance to other applications
that it would like to take part in the same activity.
Those applications also register themselves with the
coordinator for the same activity.
The different participating applications may use the
same coordinator or they may want to use their own
trusted coordinators. In case different participating
applications use their respective coordinators, the
coordinators will talk to each other in order to provide
coordination services.
20
From Microsoft article
21
In the above, after the import of the activity or the interposition of the trusted
coordinator service B, Application B can deal with its own coordination services,
which in turn deals with A's coordination services.
1. Create the activity and receive a CoordinationContext.
2. Propagate A's CoordinationContext to B in an application message.
3. B has a choice of whether to deal directly with A's coordination services, as
in our first example, or use another set of coordination services as its
representative. It decides to import the activity to B's coordination services by
sending its Activation service the CreateCoordinationContext message with the
context from A as the optional CurrentContext parameter. The returned
CoordinationContext has the same activity identifier, but has B's Registration
service.
4. Register B with its own Registration service obtained from its
CoordinationContext identifier.
5. B's coordination services delegate the registration to A's Registration service,
which it obtained from the CurrentContext parameter during import.
This creates a new coordination protocol instance between A and B.
6. The coordination protocol instance can then begin between the participants A and B.
22
WS-Coordination
But what is the coordinated activity (the
actual sequence of operations) that will
take place?
WS-Coordination says nothing about
the actual activity. It leaves it up to the
participating applications to decide what
they want to do with the coordination
context.
23
activation
registration
Service
service
coordinator
participant
participant
participant
activation
registration
Service
service
coordinator
Book Trip
WS
Book
Car WS
Book
Book
Plane WS
Hotel WS
BookHotel Participant
Recoverable objects needed
openTrans Unique Transaction ID to book a hotel.
TID
BookRentalCar Participant
Recoverable objects needed
BookTrip Client to rent a car.
TID = openTransaction()
28
Client Calls Methods
Different servers
Any server
BookPlane Participant
BookTrip Recoverable objects needed
Coordinator to book a plane
BookHotel Participant
Recoverable objects needed
to book a hotel.
Call + TID
BookRentalCar Participant
Recoverable objects needed
BookTrip Client to rent a car.
plane.bookFlight(111,Seat32A,TID)
29
The participant only
calls join if it has not
already done so.
Plane Joins the Transaction
Different servers
BookPlane Participant
Recoverable objects needed
Coordinator to book a plane
join(TID,ref to participant)
BookHotel Participant
Recoverable objects needed
to book a hotel.
BookRentalCar Participant
BookTrip Client
The participant knows where the
coordinator is because that
information can be included in
the TID (eg. an IP address.)
The coordinator now has a pointer to the
participant. 30
Suppose All Goes Well (1)
Different servers
BookPlane Participant
Recoverable objects needed
Coordinator to book a plane
BookHotel Participant
Recoverable objects needed
to book a hotel.
BookRentalCar Participant
BookTrip Client
Recoverable objects needed
to rent a car.
OK returned
OK returned
OK returned 31
Suppose All Goes Well (2)
Different servers
BookPlane Participant
Recoverable objects needed
Coordinator to book a plane
BookPlane Participant
Recoverable objects needed
Coordinator to book a plane
BookHotel Participant
Recoverable objects needed
to book a hotel.
BookRentalCar Participant
Recoverable objects needed
BookTrip Client to rent a car.
OK returned
OK returned
NO CARS AVAIL 33
abortTransaction(TID) called
This Time No Cars Available (2)
Different servers
BookPlane Participant
Recoverable objects needed
Coordinator to book a plane
BookHotel Participant
Coordinator sends a Recoverable objects needed
GLOBAL_ABORT to all to book a hotel.
particpants
BookRentalCar Participant
Recoverable objects needed
BookTrip Client to rent a car.
OK returned
OK returned
NO CARS AVAIL 34
abortTransaction(TID) called
This Time No Cars Available (3)
Different servers
BookPlane Participant
ROLLBACK CHANGES
Coordinator
abortTransaction BookHotel Participant
ROLLBACK CHANGES
Each participant
Gets a GLOBAL_ABORT
BookRentalCar Participant
ROLLBACK CHANGES
BookTrip Client
OK returned
OK returned
NO CARS AVAIL 35
abortTransaction(TID)
BookPlane Server Crashes After
Returning OK (1)
Different servers
BookPlane Participant
Recoverable objects needed
Coordinator to book a plane
BookHotel Participant
Recoverable objects needed
to book a hotel.
BookRentalCar Participant
BookTrip Client
Recoverable objects needed
to rent a car.
OK returned
OK returned
OK returned 36
BookPlane Server Crashes
After Returning OK (2)
Different servers
BookPlane Participant
Recoverable objects needed
Coordinator to book a plane
BookPlane Participant
Recoverable objects needed
Coordinator to book a plane
BookRentalCar Participant
ROLLBACK
BookTrip Client
OK returned
OK returned
ROLLBACK
OK returned
38
CloseTransaction(TID) Called
Two-Phase Commit Protocol -
Phase 1
BookPlane
Vote_Request
Vote_Commit
Coordinator
Vote Request
BookHotel
Vote Commit
Vote Request
Phase 1 Coordinator BookRentalCar
sends a Vote_Request to each Vote Commit
process. Each process returns
a Vote_Commit or Vote_Abort.
39
Two-Phase Commit Protocol -
Phase 2
BookPlane
Global Commit
ACK
Coordinator BookHotel
Global Commit
ACK
Global Commit
Init
Init
Vote-request Vote-request
Commit
----------------- -----------------
----------
Vote-abort Vote-commit
Vote-request
Ready
wait
Vote-abort Vote-commit Global-commit
-------------- ---------------- -------------------
Global-abort Global-commit ACK
Global-abort
----------------
Abort Commit
ACK
Commit
Abort
42
2PC Blocks in Three Places
Init
Init
Vote-request
Commit If waiting too long
-----------------
---------- After Vote-request
Vote-commit
Vote-request Send a Global-Abort
Vote-request Ready
wait -----------------
Vote-abort Vote-commit Vote-abort Global-commit
-------------- ---------------- -------------------
Global-abort Global-commit ACK
Global-abort
----------------
Abort Commit
ACK
Commit
Abort
43
2PC Blocks inweThree
If waiting too long Places
cant simply abort! We must wait
until the coordinator recovers. We might also make queries
on other participants.
Init
Init
Vote-request
Commit Vote-request -----------------
---------- ----------------- Vote-commit
Vote-request Vote-abort
Ready
wait
Vote-abort Vote-commit Global-commit
-------------- ---------------- -------------------
Global-abort Global-commit ACK
Global-abort
----------------
Abort Commit
ACK
Commit
Abort
44
2PC Blocks in Three
If this process learns that another hasPlaces
committed then this
process is free to commit. The coordinator must have sent out
a Global-commit that did not get to this process.
Init
Init
Vote-request
Commit Vote-request -----------------
---------- ----------------- Vote-commit
Vote-request Vote-abort
Ready
wait
Vote-abort Vote-commit Global-commit
-------------- ---------------- -------------------
Global-abort Global-commit ACK
Global-abort
----------------
Abort Commit
ACK
Commit
Abort
45
2PC Blocks in Three
If this process learns that another hasPlaces
aborted then it too
is free to abort.
Init
Init
Vote-request
Commit Vote-request -----------------
---------- ----------------- Vote-commit
Vote-request Vote-abort
Ready
wait
Vote-abort Vote-commit Global-commit
-------------- ---------------- -------------------
Global-abort Global-commit ACK
Global-abort
----------------
Abort Commit
ACK
Commit
Abort
46
2PC Blocks in Three
Suppose this process Places
learns that another
process is still in its init state. The coordinator must have
crashed while multicasting the Vote-request. Its safe for
this process (and the queried process) to abort.
Init
Init
Vote-request
Commit Vote-request -----------------
---------- ----------------- Vote-commit
Vote-request Vote-abort
Ready
wait
Vote-abort Vote-commit Global-commit
-------------- ---------------- -------------------
Global-abort Global-commit ACK
Global-abort
----------------
Abort Commit
ACK
Commit
Abort
47
2PC Blocks inqueried
Tricky case: If the Three processes Places
are all still in their ready
state what do we know? We have to block and wait until the
Coordinator recovers.
Init
Init
Vote-request
Commit Vote-request -----------------
---------- ----------------- Vote-commit
Vote-request Vote-abort
Ready
wait
Vote-abort Vote-commit Global-commit
-------------- ---------------- -------------------
Global-abort Global-commit ACK
Global-abort
----------------
Abort Commit
ACK
Commit
Abort
48
Strong Division of Function
With atomic transactions there is a
strong division of function between the
business activity and coordination of the
transaction.
The applications decides who to involve
in the transaction and whether to
commit or abort.
After this, coordination takes over and
decides the outcome.
49
Mutual Trust Is Required
Any system can abort the entire
transaction. Systems must be trusted to
have cooperative intentions.
Systems must trust each other to be
responsive.
50
Business Activity Differs from
Atomic Transactions
Has a longer duration (minutes,
days,weeks)
Locks are released between steps.
Changes become visible.
Application logic is involved in
coordination.
51