Docsity

Database Replication and Failure Handling, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
Request Propagation
•Or propagate requests (e.g. txn-bracketed stored proc calls)
•Must ensure requests run in the same order at primary and
replica (same requirement as updates or procedure calls).
–As for updates, can propagate requests asynchronously, or …
–can run requests synchronously at all replicas, but commit even if
one replica fails (need a recovery procedure for failed replicas).
–If supported, it’s often an app server (not DB) feature.
• An alternative to propagating updates is to propagate
procedure calls (e.g., a DB stored procedure call).
SP1: Write(x)
Write(y)
x, y
DB-A w[x]
w[y] SP1: Write(x)
Write(y) x, y
DB-B
w[x]
w[y]
Replicate
Call(SP1)
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Database Replication and Failure Handling and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

Request Propagation

Or propagate requests (e.g. txn-bracketed stored proc calls)

Must ensure requests run in the same order at primary andreplica (same requirement as updates or procedure calls).

As for updates, can propagate requests asynchronously, or …

can run requests synchronously at all replicas, but commit even if one replica fails (need a recovery procedure for failed replicas).

If supported, it’s often an app server (not DB) feature.

An alternative to propagating updates is to propagateprocedure calls (e.g., a DB stored procedure call).

SP1: Write(x)

Write(y)

DB-Ax, y

w[x]w[y]

SP1: Write(x)

Write(y)

x, y

DB-B

w[x]w[y]

ReplicateCall(SP1)

Failure & Recovery Handling

Secondary failure - nothing to do till it recovers

At recovery, apply the updates it missed while down

Needs to determine which updates it missed,just like non-replicated log-based recovery

If down for too long, it may be faster to get a whole copy

Primary failure

Normally, secondaries just wait till the primary recovers

Can get higher availability by electing a new primary

A secondary that detects primary’s failure announces a newelection by broadcasting its unique replica identifier

Other secondaries reply with their replica identifier

The largest replica identifier wins

Communications Failures

Secondaries can’t distinguish a primary failure from acommunication failure that partitions the network.

If the secondaries elect a new primary and the oldprimary is still running, there will be a reconciliationproblem when they’re reunited. This is multi-master.

To avoid this, one partition must know it’s the only onethat can operate, and can’t communicate with otherpartitions to figure this out.

Could make a static decision.E.g., the partition that has the primary wins.

Dynamic solutions are based on Majority Consensus

Majority Consensus

Whenever a set of communicating replicas detects areplica failure or recovery, they test if they have amajority (more than half) of the replicas.

If so, they can elect a primary

Only one set of replicas can have a majority.

Doesn’t work with an even number of copies.

Useless with 2 copies

Quorum consensus

Give a weight to each replica

The replica set that has a majority of the weight wins

E.g. 2 replicas, one has weight 1, the other weight 2

Example of Conflicting Updates

A Classic Race Condition

Replica 1

Initially x=

T

1

: X=

Primary

Initially x= Send (X=1)

Replica 2

Initially x=

T

2

: X=

Send (X=1)

X=

X=

X=

Send (X=2)

X=

Send (X=2)

  • Replicas end up in different states