<s>
In	O
transaction	B-General_Concept
processing	I-General_Concept
,	O
databases	O
,	O
and	O
computer	B-Architecture
networking	I-Architecture
,	O
the	O
two-phase	B-General_Concept
commit	I-General_Concept
protocol	I-General_Concept
(	O
2PC	B-General_Concept
)	O
is	O
a	O
type	O
of	O
atomic	B-Operating_System
commitment	I-Operating_System
protocol	I-Operating_System
(	O
ACP	O
)	O
.	O
</s>
<s>
It	O
is	O
a	O
distributed	B-Operating_System
algorithm	I-Operating_System
that	O
coordinates	O
all	O
the	O
processes	O
that	O
participate	O
in	O
a	O
distributed	B-General_Concept
atomic	I-General_Concept
transaction	I-General_Concept
on	O
whether	O
to	O
commit	B-Language
or	O
abort	O
(	O
roll	O
back	O
)	O
the	O
transaction	O
.	O
</s>
<s>
This	O
protocol	O
(	O
a	O
specialised	O
type	O
of	O
consensus	B-Operating_System
protocol	O
)	O
achieves	O
its	O
goal	O
even	O
in	O
many	O
cases	O
of	O
temporary	O
system	O
failure	O
(	O
involving	O
either	O
process	O
,	O
network	O
node	O
,	O
communication	O
,	O
etc	O
.	O
</s>
<s>
To	O
accommodate	O
recovery	O
from	O
failure	O
(	O
automatic	O
in	O
most	O
cases	O
)	O
the	O
protocol	O
's	O
participants	O
use	O
logging	B-Application
of	O
the	O
protocol	O
's	O
states	O
.	O
</s>
<s>
Many	O
protocol	O
variants	O
exist	O
that	O
primarily	O
differ	O
in	O
logging	B-Application
strategies	O
and	O
recovery	O
mechanisms	O
.	O
</s>
<s>
In	O
a	O
"	O
normal	O
execution	O
"	O
of	O
any	O
single	O
distributed	B-General_Concept
transaction	I-General_Concept
(	O
i.e.	O
,	O
when	O
no	O
failure	O
occurs	O
,	O
which	O
is	O
typically	O
the	O
most	O
frequent	O
situation	O
)	O
,	O
the	O
protocol	O
consists	O
of	O
two	O
phases	O
:	O
</s>
<s>
The	O
commit	B-Language
phase	O
,	O
in	O
which	O
,	O
based	O
on	O
voting	O
of	O
the	O
participants	O
,	O
the	O
coordinator	O
decides	O
whether	O
to	O
commit	B-Language
(	O
only	O
if	O
all	O
have	O
voted	O
"	O
Yes	O
"	O
)	O
or	O
abort	O
the	O
transaction	O
(	O
otherwise	O
)	O
,	O
and	O
notifies	O
the	O
result	O
to	O
all	O
the	O
participants	O
.	O
</s>
<s>
The	O
participants	O
then	O
follow	O
with	O
the	O
needed	O
actions	O
(	O
commit	B-Language
or	O
abort	O
)	O
with	O
their	O
local	O
transactional	O
resources	O
(	O
also	O
called	O
recoverable	O
resources	O
;	O
e.g.	O
,	O
database	O
data	O
)	O
and	O
their	O
respective	O
portions	O
in	O
the	O
transaction	O
's	O
other	O
output	O
(	O
if	O
applicable	O
)	O
.	O
</s>
<s>
The	O
two-phase	B-General_Concept
commit	I-General_Concept
(	O
2PC	B-General_Concept
)	O
protocol	O
should	O
not	O
be	O
confused	O
with	O
the	O
two-phase	B-Operating_System
locking	I-Operating_System
(	O
2PL	O
)	O
protocol	O
,	O
a	O
concurrency	B-Operating_System
control	I-Operating_System
protocol	O
.	O
</s>
<s>
The	O
protocol	O
assumes	O
that	O
there	O
is	O
stable	B-General_Concept
storage	I-General_Concept
at	O
each	O
node	O
with	O
a	O
write-ahead	B-Algorithm
log	I-Algorithm
,	O
that	O
no	O
node	O
crashes	O
forever	O
,	O
that	O
the	O
data	O
in	O
the	O
write-ahead	B-Algorithm
log	I-Algorithm
is	O
never	O
lost	O
or	O
corrupted	O
in	O
a	O
crash	O
,	O
and	O
that	O
any	O
two	O
nodes	O
can	O
communicate	O
with	O
each	O
other	O
.	O
</s>
<s>
The	O
coordinator	O
sends	O
a	O
query	O
to	O
commit	B-Language
message	O
to	O
all	O
participants	O
and	O
waits	O
until	O
it	O
has	O
received	O
a	O
reply	O
from	O
all	O
participants	O
.	O
</s>
<s>
The	O
participants	O
execute	O
the	O
transaction	O
up	O
to	O
the	O
point	O
where	O
they	O
will	O
be	O
asked	O
to	O
commit	B-Language
.	O
</s>
<s>
They	O
each	O
write	O
an	O
entry	O
to	O
their	O
undo	O
log	O
and	O
an	O
entry	O
to	O
their	O
redo	B-Application
log	I-Application
.	O
</s>
<s>
Each	O
participant	O
replies	O
with	O
an	O
agreement	O
message	O
(	O
participant	O
votes	O
Yes	O
to	O
commit	B-Language
)	O
,	O
if	O
the	O
participant	O
's	O
actions	O
succeeded	O
,	O
or	O
an	O
abort	O
message	O
(	O
participant	O
votes	O
No	O
to	O
commit	B-Language
)	O
,	O
if	O
the	O
participant	O
experiences	O
a	O
failure	O
that	O
will	O
make	O
it	O
impossible	O
to	O
commit	B-Language
.	O
</s>
<s>
If	O
the	O
coordinator	O
received	O
an	O
agreement	O
message	O
from	O
all	O
participants	O
during	O
the	O
commit-request	O
phase	O
:	O
</s>
<s>
The	O
coordinator	O
sends	O
a	O
commit	B-Language
message	O
to	O
all	O
the	O
participants	O
.	O
</s>
<s>
If	O
any	O
participant	O
votes	O
No	O
during	O
the	O
commit-request	O
phase	O
(	O
or	O
the	O
coordinator	O
's	O
timeout	O
expires	O
)	O
:	O
</s>
<s>
An	O
*	O
next	O
to	O
the	O
record	O
type	O
means	O
that	O
the	O
record	O
is	O
forced	O
to	O
stable	B-General_Concept
storage	I-General_Concept
.	O
</s>
<s>
The	O
greatest	O
disadvantage	O
of	O
the	O
two-phase	B-General_Concept
commit	I-General_Concept
protocol	I-General_Concept
is	O
that	O
it	O
is	O
a	O
blocking	O
protocol	O
.	O
</s>
<s>
If	O
the	O
coordinator	O
fails	O
permanently	O
,	O
some	O
participants	O
will	O
never	O
resolve	O
their	O
transactions	O
:	O
After	O
a	O
participant	O
has	O
sent	O
an	O
agreement	O
message	O
to	O
the	O
coordinator	O
,	O
it	O
will	O
block	O
until	O
a	O
commit	B-Language
or	O
rollback	O
is	O
received	O
.	O
</s>
<s>
In	O
many	O
cases	O
the	O
2PC	B-General_Concept
protocol	O
is	O
distributed	O
in	O
a	O
computer	B-Architecture
network	I-Architecture
.	O
</s>
<s>
It	O
is	O
easily	O
distributed	O
by	O
implementing	O
multiple	O
dedicated	O
2PC	B-General_Concept
components	O
similar	O
to	O
each	O
other	O
,	O
typically	O
named	O
Transaction	B-General_Concept
managers	I-General_Concept
(	O
TMs	O
;	O
also	O
referred	O
to	O
as	O
2PC	B-General_Concept
agents	O
or	O
Transaction	B-General_Concept
Processing	I-General_Concept
Monitors	I-General_Concept
)	O
,	O
that	O
carry	O
out	O
the	O
protocol	O
's	O
execution	O
for	O
each	O
transaction	O
(	O
e.g.	O
,	O
The	B-Application
Open	I-Application
Group	I-Application
's	O
X/Open	O
XA	O
)	O
.	O
</s>
<s>
The	O
databases	O
involved	O
with	O
a	O
distributed	B-General_Concept
transaction	I-General_Concept
,	O
the	O
participants	O
,	O
both	O
the	O
coordinator	O
and	O
participants	O
,	O
register	O
to	O
close	O
TMs	O
(	O
typically	O
residing	O
on	O
respective	O
same	O
network	O
nodes	O
as	O
the	O
participants	O
)	O
for	O
terminating	O
that	O
transaction	O
using	O
2PC	B-General_Concept
.	O
</s>
<s>
Each	O
distributed	B-General_Concept
transaction	I-General_Concept
has	O
an	O
ad	O
hoc	O
set	O
of	O
TMs	O
,	O
the	O
TMs	O
to	O
which	O
the	O
transaction	O
participants	O
register	O
.	O
</s>
<s>
A	O
leader	O
,	O
the	O
coordinator	O
TM	O
,	O
exists	O
for	O
each	O
transaction	O
to	O
coordinate	O
2PC	B-General_Concept
for	O
it	O
,	O
typically	O
the	O
TM	O
of	O
the	O
coordinator	O
database	O
.	O
</s>
<s>
Rather	O
than	O
exchanging	O
2PC	B-General_Concept
messages	O
among	O
themselves	O
,	O
the	O
participants	O
exchange	O
the	O
messages	O
with	O
their	O
respective	O
TMs	O
.	O
</s>
<s>
The	O
relevant	O
TMs	O
communicate	O
among	O
themselves	O
to	O
execute	O
the	O
2PC	B-General_Concept
protocol	O
schema	O
above	O
,	O
"	O
representing	O
"	O
the	O
respective	O
participants	O
,	O
for	O
terminating	O
that	O
transaction	O
.	O
</s>
<s>
This	O
common	O
architecture	O
is	O
also	O
effective	O
for	O
the	O
distribution	O
of	O
other	O
atomic	O
commitment	O
protocols	O
besides	O
2PC	B-General_Concept
,	O
since	O
all	O
such	O
protocols	O
use	O
the	O
same	O
voting	O
mechanism	O
and	O
outcome	O
propagation	O
to	O
protocol	O
participants	O
.	O
</s>
<s>
Database	O
research	O
has	O
been	O
done	O
on	O
ways	O
to	O
get	O
most	O
of	O
the	O
benefits	O
of	O
the	O
two-phase	B-General_Concept
commit	I-General_Concept
protocol	I-General_Concept
while	O
reducing	O
costs	O
by	O
protocol	O
optimizations	O
and	O
protocol	O
operations	O
saving	O
under	O
certain	O
system	O
's	O
behavior	O
assumptions	O
.	O
</s>
<s>
Presumed	O
abort	O
or	O
Presumed	O
commit	B-Language
are	O
common	O
such	O
optimizations	O
.	O
</s>
<s>
An	O
assumption	O
about	O
the	O
outcome	O
of	O
transactions	O
,	O
either	O
commit	B-Language
,	O
or	O
abort	O
,	O
can	O
save	O
both	O
messages	O
and	O
logging	B-Application
operations	O
by	O
the	O
participants	O
during	O
the	O
2PC	B-General_Concept
protocol	O
's	O
execution	O
.	O
</s>
<s>
For	O
example	O
,	O
when	O
presumed	O
abort	O
,	O
if	O
during	O
system	O
recovery	O
from	O
failure	O
no	O
logged	O
evidence	O
for	O
commit	B-Language
of	O
some	O
transaction	O
is	O
found	O
by	O
the	O
recovery	O
procedure	O
,	O
then	O
it	O
assumes	O
that	O
the	O
transaction	O
has	O
been	O
aborted	O
,	O
and	O
acts	O
accordingly	O
.	O
</s>
<s>
This	O
means	O
that	O
it	O
does	O
not	O
matter	O
if	O
aborts	O
are	O
logged	O
at	O
all	O
,	O
and	O
such	O
logging	B-Application
can	O
be	O
saved	O
under	O
this	O
assumption	O
.	O
</s>
<s>
The	O
Tree	B-Application
2PC	B-General_Concept
protocol	O
(	O
also	O
called	O
Nested	O
2PC	B-General_Concept
,	O
or	O
Recursive	O
2PC	B-General_Concept
)	O
is	O
a	O
common	O
variant	O
of	O
2PC	B-General_Concept
in	O
a	O
computer	B-Architecture
network	I-Architecture
,	O
which	O
better	O
utilizes	O
the	O
underlying	O
communication	O
infrastructure	O
.	O
</s>
<s>
The	O
participants	O
in	O
a	O
distributed	B-General_Concept
transaction	I-General_Concept
are	O
typically	O
invoked	O
in	O
an	O
order	O
which	O
defines	O
a	O
tree	B-Application
structure	O
,	O
the	O
invocation	O
tree	B-Application
,	O
where	O
the	O
participants	O
are	O
the	O
nodes	O
and	O
the	O
edges	O
are	O
the	O
invocations	O
(	O
communication	O
links	O
)	O
.	O
</s>
<s>
The	O
same	O
tree	B-Application
is	O
commonly	O
utilized	O
to	O
complete	O
the	O
transaction	O
by	O
a	O
2PC	B-General_Concept
protocol	O
,	O
but	O
also	O
another	O
communication	O
tree	B-Application
can	O
be	O
utilized	O
for	O
this	O
,	O
in	O
principle	O
.	O
</s>
<s>
In	O
a	O
tree	B-Application
2PC	B-General_Concept
the	O
coordinator	O
is	O
considered	O
the	O
root	O
(	O
"	O
top	O
"	O
)	O
of	O
a	O
communication	O
tree	B-Application
(	O
inverted	B-Application
tree	I-Application
)	O
,	O
while	O
the	O
participants	O
are	O
the	O
other	O
nodes	O
.	O
</s>
<s>
The	O
coordinator	O
can	O
be	O
the	O
node	O
that	O
originated	O
the	O
transaction	O
(	O
invoked	O
recursively	O
(	O
transitively	O
)	O
the	O
other	O
participants	O
)	O
,	O
but	O
also	O
another	O
node	O
in	O
the	O
same	O
tree	B-Application
can	O
take	O
the	O
coordinator	O
role	O
instead	O
.	O
</s>
<s>
2PC	B-General_Concept
messages	O
from	O
the	O
coordinator	O
are	O
propagated	O
"	O
down	O
"	O
the	O
tree	B-Application
,	O
while	O
messages	O
to	O
the	O
coordinator	O
are	O
"	O
collected	O
"	O
by	O
a	O
participant	O
from	O
all	O
the	O
participants	O
below	O
it	O
,	O
before	O
it	O
sends	O
the	O
appropriate	O
message	O
"	O
up	O
"	O
the	O
tree	B-Application
(	O
except	O
an	O
abort	O
message	O
,	O
which	O
is	O
propagated	O
"	O
up	O
"	O
immediately	O
upon	O
receiving	O
it	O
or	O
if	O
the	O
current	O
participant	O
initiates	O
the	O
abort	O
)	O
.	O
</s>
<s>
The	O
Dynamic	O
two-phase	B-General_Concept
commit	I-General_Concept
(	O
Dynamic	O
two-phase	O
commitment	O
,	O
D2PC	O
)	O
protocol	O
is	O
a	O
variant	O
of	O
Tree	B-Application
2PC	B-General_Concept
with	O
no	O
predetermined	O
coordinator	O
.	O
</s>
<s>
The	O
coordinator	O
is	O
determined	O
dynamically	O
by	O
racing	O
agreement	O
messages	O
over	O
the	O
transaction	O
tree	B-Application
,	O
at	O
the	O
place	O
where	O
they	O
collide	O
.	O
</s>
<s>
They	O
collide	O
either	O
at	O
a	O
transaction	O
tree	B-Application
node	O
,	O
to	O
be	O
the	O
coordinator	O
,	O
or	O
on	O
a	O
tree	B-Application
edge	O
.	O
</s>
<s>
D2PC	O
is	O
time	O
optimal	O
(	O
among	O
all	O
the	O
instances	O
of	O
a	O
specific	O
transaction	O
tree	B-Application
,	O
and	O
any	O
specific	O
Tree	B-Application
2PC	B-General_Concept
protocol	O
implementation	O
;	O
all	O
instances	O
have	O
the	O
same	O
tree	B-Application
;	O
each	O
instance	O
has	O
a	O
different	O
node	O
as	O
coordinator	O
)	O
:	O
By	O
choosing	O
an	O
optimal	O
coordinator	O
D2PC	O
commits	O
both	O
the	O
coordinator	O
and	O
each	O
participant	O
in	O
minimum	O
possible	O
time	O
,	O
allowing	O
the	O
earliest	O
possible	O
release	O
of	O
locked	O
resources	O
in	O
each	O
transaction	O
participant	O
(	O
tree	B-Application
node	O
)	O
.	O
</s>
