Database languages

Download Report

Transcript Database languages

Process Composition
Process Composition Hierarchies
 Control:
 Centralized
control: e.g., RPC/WSDL
 Mediated or orchestrated control: e.g., BPEL
 Fully distributed control: autonomous processes, e.g.,
WS-CDL (WSCI)
 Messaging:
 Shared variables: tight coupling, service internal
 Synchronous messaging: looser coupling; some
service-service interactions
 Asynchronous messaging: loose coupling; serviceservice interactions
 Synchronous and asynchronous both applicable to
BPEL:
 WSDL/SOAP, WSDL/JMS
Web Services: CSP/Pi-Calculus/Mealy
2
Communicating Sequential Processes

Mathematical framework for the description and
analysis of systems consisting of processes interacting
via exchange of messages

The evolution of processes is based on a sequence of
events or actions
 Visible actions S
Interaction with other processes, communication
 Invisible action t
Internal computation steps
Web Services: CSP/Pi-Calculus/Mealy
3
The CSP Language: Syntax
Termination: Stop
 Input: in ? x  P(x)
 Execute an input action on channel in, get message
x, then continue as P(x)
 Output: out ! x  P(x)
 Execute an output action on channel out, send
message x, then continue as P(x)
 Recursion: P(y1,…,yn) = Body(y1,…,yn)
 Process definition. P is a process name, y1,…,yn are
the parameters, Body(y1,…,yn) is a process
expression


Example: Copy = in ? x  out ! m  Copy
Web Services: CSP/Pi-Calculus/Mealy
4
CSP’s Syntax (Cont’ed)
External (aka guarded) choice: P | Q
 Execute a choice between P and Q. Do not choose a
process which cannot proceed
 Example: (a ? x  P(x)) | (b ? x  Q(x))
 Execute one and only one input action. If only one is
available then choose that one. If both are available
than choose arbitrarily. If none are available then
block. The unchoosen branch is discarded
 Internal choice: P + Q
 Execute an arbitrary choice between P and Q. It is
possible to choose a process which cannot proceed

Web Services: CSP/Pi-Calculus/Mealy
5
CSP’s Syntax (Cont’ed)
Parallel operator w/synchronization: P || Q
 P and Q proceed in parallel and are obliged to
synchronize on all the common actions
 Example: (c ? x  P(x)) || (c ! m  Q)
 Synchronization: the two processes can proceed only
if their actions correspond
 Handshaking: sending and receiving is simultaneous
(Buffered communication can anyway be modeled by
implementing a buffer process)
 Communication: m is transmitted to the first process,
which continues as P(m)

Web Services: CSP/Pi-Calculus/Mealy
6
Laws of CSP
 Equivalence
of expressions: useful in reasoning about
CSP processes
 Many laws concerning different aspects
 Examples:
 If Q does not involve e1:
(e1  P) || (e2  Q)
= e1  (P || (e2  Q))
 Synchronization:
(c ? b  P(b)) || (c ! a  Q)
= c ! a  (P(a) || Q)
Web Services: CSP/Pi-Calculus/Mealy
7
Example
= (in1 ?x  in2 ?y  out !(x+y)  ADD2)
 ADD2 = (in1 ?x  in2 ?y  out !(x+y)  ADD2) |
(in2 ?y  in1 ?x  out !(x+y)  ADD2)
 SQ = (out ?z  sqr !square(z)  SQ)
 ADDSQ = ADD2 || SQ = ?
= (in1 ?x  in2 ?y  out !(x+y)  ADD2) |
(in2 ?y  in1 ?x  out !(x+y)  ADD2)
|| (out ?z  sqr !square(z)  SQ)
= (in1 ?x  in2 ?y  out !(x+y)  ADD2)
|| (out ?z  sqr !square(z)  SQ)
| (in2 ?y  in1 ?x  out !(x+y)  ADD2)
|| (out ?z  sqr !square(z)  SQ)
 ADD2
Web Services: CSP/Pi-Calculus/Mealy
8
Example
 ADDSQ
(in1 ?x  in2 ?y  out !(x+y)  ADD2)
|| (out ?z  sqr !square(z)  SQ)
| (in2 ?y  in1 ?x  out !(x+y)  ADD2)
|| (out ?z  sqr !square(z)  SQ)
= in1 ?x  in2 ?y  (out !(x+y)  ADD2)
|| (out ?z  sqr !square(z)  SQ)
| in2 ?y  in1 ?x  (out !(x+y)  ADD2)
|| (out ?z  sqr !square(z)  SQ)
= in1?x in2?y out!(x+y) sqr!square(x+y) ADD2 || SQ
|…
= in1 ?x  in2 ?y out !(x+y) sqr !square(x+y)  ADDSQ
|…
=
Web Services: CSP/Pi-Calculus/Mealy
9
BPEL : CSP Semantics
 BPEL
interactions can be modeled in CSP
 Three main activities: invoke, receive, reply
<invoke partner=“...” portType=“...” operation=“...”
inputContainer= x outputContainer = y />
partner-port-in ! x  partner-port-out ? y  …
<receive partner=“...” portType=“...” operation=“...”
container=x [createInstance=“...”] />
my-port-in ? x  …
<reply partner=“...” portType=“...” operation=“...”
container =y />
… my-port-out ? y  …
Web Services: CSP/Pi-Calculus/Mealy
10
BPEL : CSP Semantics
 Synchronous
communication
 Advantages:
 Easier
to analyze
 Well studied
 Disadvantages:
 Not completely autonomous
Web Services: CSP/Pi-Calculus/Mealy
11
The p-Calculus
The p-calculus is a process algebra
 Constructs for concurrency
 Communication on channels
 channels are first-class
 channel names can be sent on channels
 access restrictions for channels
 In p-calculus everything is a process

Web Services: CSP/Pi-Calculus/Mealy
12
Communications in p-Calculus
Processes communicate on channels:
 c<M>
send message M on channel c
 c(x)
receives x on channel c
 Sequencing:
 c<M>.p sends message M on c, then does p
 c(x).p
receives x on c, then does p with x
 Concurrency:
 p|q
is the parallel composition of p and q
 Replication:
 !p
creates an infinite number of replicas of p

Web Services: CSP/Pi-Calculus/Mealy
13
Examples
For example we might define
Speaker = air<M>
Phone
= air(x).wire<x>
ATT
= wire(x).fiber<x>
System = Speaker | Phone | ATT
 Communication between processes is modeled by
reduction:
Speaker | Phone  wire<M>
wire<M> | ATT  fiber<M>
 Composing these reductions we get:
Speaker | Phone | ATT  fiber<M>

Web Services: CSP/Pi-Calculus/Mealy
14
Channel Visibility
Anybody can monitor an unrestricted channel:
 Consider that we define
WireTap = wire(x).wire<x>.NSA<x>
 Copies the messages from the wire to NSA
 Possible since the name “wire” is globally visible


Now
WireTap | wire<M> | ATT 
wire<M>.NSA<M> | ATT 
NSA<M> | fiber<M>
Web Services: CSP/Pi-Calculus/Mealy
15
Restriction
The restriction operator “(n c) p” makes a fresh channel
c within process p
 n is the Greek letter “nu”
 The name “c” is local (bound) in p
 Restricted channels cannot be monitored
wire (x) … | (n wire) (wire<M> | ATT) 
wire (x) … | fiber<M>

The scope of the name “wire” is restricted
 There is no conflict with the global “wire”

Web Services: CSP/Pi-Calculus/Mealy
16
Restriction and Scope

Restriction
 is a binding construct
 is lexically scoped
 allocates a new object (a channel)
(n c) p

is like “let c = new Channel() in p”
In particular, c can be sent outside its scope
 But only if “p” decides so
Web Services: CSP/Pi-Calculus/Mealy
17
First-Class Channels

A channel c can leave its scope of declaration
 via a message d<c> from within p

Allowing channels to be sent as messages means
communication topology is dynamic
 If channels are not sent as messages (or stored in
the heap) then the communication topology is static
 This differentiates p-calculus from CSP
Web Services: CSP/Pi-Calculus/Mealy
18
Example of First-Class Channels
Consider:
MobilePhone = air(x).cell<x>
ATT1
= wire<cell>
ATT2
= wire(y).y(x).fiber(x)
in
(n cell) (MobilePhone | ATT1) | ATT2

ATT1 is trying to pass cell out of the static scope of the
restriction n cell
Web Services: CSP/Pi-Calculus/Mealy
19
Scope Extrusion

A channel is a name
 First-class names must be usable even outside their
original scope

The p-calculus allows restrictions to move:
((n c) p) | q = (n c)(p | q)
if c not free in q

Renaming is needed in general:
((n c) p) | q = ((n d) [d/c] p) | q = (n d) ( [d/c] p | q )
where “d” is fresh (does not appear in p or q)
Web Services: CSP/Pi-Calculus/Mealy
20
Example, Continued
(n cell)( MobilePhone | ATT1) | ATT2
= (n cell)( MobilePhone | ATT1 | ATT2)
 (n cell)( MobilePhone | cell(x).fiber<x>)

Scope extrusion distinguishes the p-calculus from other
process calculi
Web Services: CSP/Pi-Calculus/Mealy
21
Syntax of the p-Calculus

There are many versions of the p-calculus
A basic version:
p, q ::=
nil
nil process (sometimes written 0)
x<y>.p
sending
x(y).p
receiving
p|q
parallel composition
!p
replication
(n x) p
restriction

Note that only variables can be channels and messages
Web Services: CSP/Pi-Calculus/Mealy
22
Choreography Definition Language (WS-CDL)
Global model
 Ensured conformance
 Description language
 Not executable
 Tools
 Generators for end points
 Advanced typing
 Status
 Moving for last call end of 2004

Web Services: CSP/Pi-Calculus/Mealy
23
Global Models
Web Services: CSP/Pi-Calculus/Mealy
24
WS-CDL Global Models

A sequential process
Client(open, close, request, reply) =
open.request1.reply1.request2.reply2.close.0
request
open
close
Web Services: CSP/Pi-Calculus/Mealy
Client
reply
25
WS-CDL Global Models

A repetitive process
Client (open, close, request, reply) =
open.request1.reply1.request2.reply2.close.Client(open,
close, request, reply)
request
open
close
Web Services: CSP/Pi-Calculus/Mealy
Client
reply
26
WS-CDL Global Models

A process with choices to make
IdleServer (o, req, rep, c) =
o.BusyServer(o, req, rep, close)
BusyServer(o, req, rep, c) =
req.rep.BusyServer(o, req, rep, c) +
c.IdleServer(o, req, rep, c)
request
open
IdleServer
close
Web Services: CSP/Pi-Calculus/Mealy
BusyServer
reply
27
WS-CDL Global Model

Communication, Concurrency and Replication
SYSTEM = (!Client | IdleServer)
When Clienti has
started an exchange
with IdleServer
 No other Clientj can
then communicate
with the server
 Until Clienti has finished
and the server is once
again IdleServer

Web Services: CSP/Pi-Calculus/Mealy
Clienti | IdleServer
Clienti | BusyServer
Clientj | IdleServer
Clientj | BusyServer
…..
28
WS-CDL and the p-Calculus
Operation
Meaning
Prefix
Notation
p.p
Action
a(y), a<y>
Communication
Summation
a(y).p + b(x).q
S pi.pi
Choice
Recursion
p={…..}.p
Repetition
Replication
!p
Repetition
Compositio
n
p|q
Concurrency
Restriction
(n x) p
Encapsulation
Web Services: CSP/Pi-Calculus/Mealy
Collapse send and receive
into an
interact on channels
Sequence
29
Composition: Formal Semantics
 WSDL
is fundamentally message based
 So is everything based on it
 Process algebra approach to formal semantics:
 BPEL : CSP
 WS-CDL : p-calculus
 Alternatives to process algebra:
 Automata theoretic
 PSL
Web Services: CSP/Pi-Calculus/Mealy
30
BPEL and Asynchronous Communication
Channels are assumed to be reliable
 Asynchronous, for example, the following channel:

store
order1
o1
warehouse1
send Order1
…
Queues are FIFO, unbounded length
send Order1
 Can simulate synchronous
receive Receipt1
and also bounded queues

…
Web Services: CSP/Pi-Calculus/Mealy
31
Messages
Messages are classified into classes
 Each class is associated with one channel

store

order1
warehouse1
Each message class may have additional attributes
which can carry the contents of messages
 For now, analysis involves no contents
 Results immediately apply to “finite domain”
contents
Web Services: CSP/Pi-Calculus/Mealy
32
Individual Web Services
input
messages
Do until halt
nondeterministic choice:
read an input;
send an output to some
other peer;
halt;
end choice
to other
e-services
message log
local store
Web Services: CSP/Pi-Calculus/Mealy
33
Individual Web Services
input
messages
Do until halt
nondeterministic choice:
read an input;
send an output to some
other peer;
halt;
end choice
to other
e-services
Again, ports and storages are ignored
 Internal logic of peers : finite state control

Web Services: CSP/Pi-Calculus/Mealy
34
Mealy Web Services

Mealy machines: Finite state machines with input
(incoming messages) & output (outgoing messages)
?o2
!r2
!b2
!b2
!r2
?p2
?p2
!r2
e
warehouse2
Web Services: CSP/Pi-Calculus/Mealy
35
Technical Definition
A Mealy web service is an FSA M = (T, s, F, Sin, Sout,  )
 T : a set of states
 s : the initial state
 F : a set of final states
 Sin : input message classes
 Sout : output message classes
  : transition relation that either
 consume an input, (s1, ?m, s2), or
 produce output, (s1, !m, s2), or
 make an empty (internal ) move, (s1, e, s2)
Web Services: CSP/Pi-Calculus/Mealy
36
Executing a Mealy Composition
?o2
!a
?k
!r2
!b2
?o1
!r2
!o1
…
!o2
!b2
?p2
…
?a
!k
?p2
!r2
…
e
…
store

w1
warehouse2
bank
Execution halts if
 All mealy peers are in final states
 All queues are empty
Web Services: CSP/Pi-Calculus/Mealy
37
Composite Web Service Execution
Investor
Stock Broker Firm
!register
?register
?accept
!ack
?reject
?report
!accept
!request
rep
acc
bil
!reject
?bill
!cancel
?bill
reg
ack
?ack
?cancel
!bill
!bill
!terminate
Research Dept.
?request
!report
req
ter
?terminate
Web Services: CSP/Pi-Calculus/Mealy
38
Web Service Composition: What Now?
store
authorize
ok
bank
warehouse1
 Execution:
 Is
there a deadlock?
 Always terminates in finite
steps?
…
Web Services: CSP/Pi-Calculus/Mealy
warehouse2
 Functionality:
 Is
it correct?
 Is there an unauthorized
payment?
…
39
Conversation Policies
A
conversation: a sequence of messages between two
parties
order
Store
Supplier
receipt
Start
AB: “Request bid”
Request
Pending
AB: “CounterBid=x”
BA: “Bid=x”
B’s Reply
Pending
A’s Reply
Pending
BA: “Bye”
BA: “CounterBid=x”
BA: “Accept”
Terminate/
Success
Web Services: CSP/Pi-Calculus/Mealy
AB: “Reject”
Terminate/
Failure
40
Multi-Party Conversations

Watcher: “records” the messages as they are sent
authorize
bill2
warehouse1
bank
payment2
ok
order1
receipt1
store
Watcher
a
k o1 o2 b1 p1 r1 r2 b2 p2
warehouse2
A conversation is a sequence of messages the watcher
sees in a successful run (or session)
 composition language: the set of all possible
conversations
 What properties do composition languages have?

Web Services: CSP/Pi-Calculus/Mealy
41
Warehouse Example
authorize
store
ok
bank
warehouse1
 The
warehouse2
composition language recognized
a k shuff ( ( o1(shuff ( r1, b1p1) )* , ( o2(shuff ( r2, b2p2) )* )
Web Services: CSP/Pi-Calculus/Mealy
42
Web Service Composition Schema

A composition schema is a triple (M, P, C ) where
 M : finite set of message classes
 P : finite set of peers (web services)
 C : finite set of peer to peer channels
authorize
store
warehouse1

ok
bank
warehouse2
Specifies the infrastructure of composition
Web Services: CSP/Pi-Calculus/Mealy
43
Global Configurations
Given n Mealy implementations
for composition schema (M, P, C)
 Global configuration: (Q1, t1, … , Qn, tn, w) where
 Qi : queue contents for peer i
 ti : state for peer i
 w : watcher contents

Web Services: CSP/Pi-Calculus/Mealy
44
Derivation
(Q1, t1, , Qn, tn, w)  (Q1, t1, , Qn, tn, w) if
pi takes an e move, or
 peer pi reads an input, or
 peer pi sends a message m to pj
 (ti, !m, ti)  i
 Qj = Qj m (m appended to pj’s queue)
 k  i, tk = tk
 k  j, Qk = Qk
 w = wm
(watcher records the message m)
 peer
Web Services: CSP/Pi-Calculus/Mealy
45
Conversations

A halting run:
 (e, s1, , e, sn, e) 
  (e, f1, , e, fn, w)
 Starting
from the initial configuration with empty
queues and
 Ending in final states with empty queues
 A word w is a conversation if
* (e, f1, , e, fn, w)
(e, s1, , e, sn, e) 
is a halting run

Composition language (CL) :
the set of all conversations
Web Services: CSP/Pi-Calculus/Mealy
46
Composition Languages Are Regular?
!a
?b
p1





a
?a
b
!b
p2
CL  a*b* = anbn
Composition languages are not always regular
Some may not even be context free
Causes: asynchronous communication & unbounded
queue
Bounded queues or synchronous: CL always regular
Web Services: CSP/Pi-Calculus/Mealy
47
Bounded Queues
 Synchronous
messaging case: composition language
can be recognized by the product machine
 If
queues are bounded, composition languages are also
regular
 Production machines can be constructed
Web Services: CSP/Pi-Calculus/Mealy
48
Conversations as Orchestration
p4
c
p1
a
d
e
b
p2
p3
“Programming” interactions
 Two questions:
 Given Mealy peers, what conversations can they
have?
 Given a conversation language, can we “implement”
it?

Web Services: CSP/Pi-Calculus/Mealy
49
Two Factors
p4
c
p1
a
d
e
b
p2
p3
Local views: Conversations with the same local views
are not distinguishable:
 abcde and acbde
 Queuing effect: a peer can postpone sending a message

Web Services: CSP/Pi-Calculus/Mealy
50
Local Views
Local view of a conversation for a peer: part of the
execution that is related to the peer
 Defined as projection: pp(w) for a conversation w
 Two conversations cannot be distinguished if they
have exactly the same set of local views

Web Services: CSP/Pi-Calculus/Mealy
51
Example
p1
a
p2
p3
b
c
p4
If abc is a part of a conversation, so are bac and bca
 pp (abc) = ppi (bac) = pp (bca) = a for i = 1, 2
i
i
 pp (abc) = pp (bac) = pp (bca) = bc for i = 3, 4
i
i
i

Web Services: CSP/Pi-Calculus/Mealy
52
Join

Given languages Li over Si, 1  i  n


i Li = w 1  i  n, π Si (w)  Li  (i Si )

*
Composition languages L are closed under
“projection-join”:
 peers π peer ( L)  L
Web Services: CSP/Pi-Calculus/Mealy
53
Local Prepone
 If
the global watcher sees:
… a b …
!b
p
!a
a peer
 What
happens inside p?
Web Services: CSP/Pi-Calculus/Mealy
54
Local Prepone
the global watcher:
… a b …
π p (w)
… a b …
!b
…
!a
local view at p
a peer p
pp(w) should also allow
Web Services: CSP/Pi-Calculus/Mealy
… b a …
55
A Synthesis Result

Given a regular language L, we can find a Mealy
composition such that its CL is the closure:
*
 peers LocalPrepo ne (π peer ( L))

Intuitively: given a regular L (e.g., ako1…), we can find
Mealy peers whose conversations are not arbitrary
 Opportunity for automatic composition

But some Mealy compositions do not relate to any
regular languages in this way
Web Services: CSP/Pi-Calculus/Mealy
56
The Converse (General Case)

There is an Mealy compositions whose CL is not
 peers LocalPrepo ne * (π peer ( L))
for every regular languages L
?b
!b
b
!a
p3
p1
a
Web Services: CSP/Pi-Calculus/Mealy
c
?a
!c
?c
p2
CL = { aibci | i 0 }
57
The Tree Case

When the schema graph is a tree, then the Mealy
composition has a composition language equal to
*
 peers LocalPrepo ne (π peer ( L))
for some regular languages L

Intuitively: the global behavior of bottom-up
composition is still predictable if the composition
infrastructure is a tree
 In particular, adding an mediator (hub-spoke) isn’t
a bad idea!
Web Services: CSP/Pi-Calculus/Mealy
58
Hub-and-spoke

For every star-shaped composition schema, and every
regular language L, we can construct an Mealy
composition whose CL = L

Good news for hub-and-spoke!
Web Services: CSP/Pi-Calculus/Mealy
59
Results of Mealy Web Services
1. CLs of some Mealy compositions are not regular,
some not context free
2. The “prepone” and “join” closure of every regular
language = CL of some composite Mealy web services
3. The converse of 2. is not true in general, true in special
cases
However: if bounded queue or synchronous:
CL of every Mealy composition is regular
 Design time decision! Need to be explicit in
specifications (BPEL4WS, BPLM, …)

Web Services: CSP/Pi-Calculus/Mealy
60
Communicating FSAs
 Two
communicating FSAs can simulate Turing machines
a0 a 1 aq …
p1
p2
b0 b 1 bq …
Web Services: CSP/Pi-Calculus/Mealy
61