Docsity

Replication in Databases: Challenges and Solutions, Slides of Transaction Processing for E Commerce

Partial preview of the text

Download Replication in Databases: Challenges and Solutions and more Slides Transaction Processing for E Commerce in PDF only on Docsity!

Outline

1. Introduction

2. Primary-Copy Replication

3. Multi-Master Replication

4. Other Approaches

5. Products

docsity.com

1. Introduction

  • Replication - using multiple copies of a server or

resource for better availability and performance.

  • Replica and Copy are synonyms
  • If you’re not careful, replication can lead to
  • worse performance - updates must be applied to all replicas and synchronized
  • worse availability - some algorithms require multiple replicas to be operational for any of them to be used

docsity.com

Update-only Database

Database Server

Database Server 1

Database Server 2

Database Server 3

  • T 1 = { w[x=1] }
  • T 2 = { w[x=2] }

docsity.com

Update-only Database

Database Server

Database Server 1

Database Server 2

Database Server 3

  • T 1 = { w[x=1] }
  • T 2 = { w[y=1] }

docsity.com

Replicated Server

  • Can replicate servers on a common resource
    • Data sharing - DB servers communicate with shared disk

Resource

Server Replica 1 Server Replica 2

Client

  • Helps availability for process (not resource) failure
  • Requires a replica cache coherence mechanism, so

this helps performance only if

  • little conflict between transactions at different servers or
  • loose coherence guarantees (e.g. read committed) docsity.com

Replicated Resource

  • To get more improvement in availability,

replicate the resources (too)

  • Also increases potential throughput
  • This is what’s usually meant by replication
  • It’s the scenario we’ll focus on

Resource replica

Server Replica 1 Server Replica 2

Client Client

Resource replica docsity.com

Synchronous Replication - Issues

r 1 [xA]

r 2 [yD] w 2 [xB]

yD fails w 1 [yC]

xA fails

Not equivalent to a one-copy execution, even if xA and yD never recover!

  • DBMS products support it only in special situations
  • If you just use transactions, availability suffers.
  • For high-availability, the algorithms are complex and expensive, because they require heavy-duty synchronization of failures.
  • … of failures? How do you synchronize failures?
  • Assume replicas xA, xB of x and yC, yD of y

docsity.com

Atomicity & Isolation Goal

  • One-copy serializability (abbr. 1SR )
    • An execution of transactions on the replicated database has the same effect as a serial execution on a one-copy database.
  • Readset (resp. writeset ) - the set of data items (not copies) that a transaction reads (resp. writes).
  • 1SR Intuition: the execution is SR and in an equivalent serial execution, for each txn T and each data item x in readset(T), T reads from the most recent txn that wrote into any copy of x.
  • To check for 1SR, first check for SR (using SG), then see if there’s equivalent serial history with the above property docsity.com

Asynchronous Replication

  • Asynchronous replication
    • Each transaction updates one replica.
    • Updates are propagated later to other replicas.
  • Primary copy: Each data item has a primary copy
    • All transactions update the primary copy
    • Other copies are for queries and failure handling
  • Multi-master: Transactions update different copies
    • Useful for disconnected operation, partitioned network
  • Both approaches ensure that
    • Updates propagate to all replicas
    • If new updates stop, replicas converge to the same state
  • Primary copy ensures serializability, and often 1SR
    • Multi-master does not. docsity.com

2. Primary-Copy Replication

  • Designate one replica as the primary copy (publisher)
  • Transactions may update only the primary copy
  • Updates to the primary are sent later to secondary replicas (subscribers) in the order they were applied to the primary

T1: Start … Write(x1) ... Commit

T2^ x

Tn

... Primary

Copy

x

xm

Secondaries docsity.com

Update Processing 1/

  • At the replica, for each tx T in the propagation stream, execute a refresh tx that applies T’s updates to replica.
  • Process the stream serially
    • Otherwise, conflicting transactions may run in a different order at the replica than at the primary.
    • Suppose log contains w 1 [x] c 1 w 2 [x] c 2. Obviously, T 1 must run before T 2 at the replica.
    • So the execution of update transactions is serial.
  • Optimizations
    • Batching: {w(x)} {w(y)} -> {w(x), w(y)}
    • “Concurrent” execution docsity.com

Update Processing 2/

  • To get a 1SR execution at the replica
    • Refresh transactions and read-only queries use an atomic and isolated mechanism (e.g., 2PL)
  • Why this works
    • The execution is serializable
    • Each state in the serial execution is one that occurred at the primary copy
    • Each query reads one of those states
  • Client view
    • Session consistency docsity.com

Failure & Recovery Handling 1/

  • 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, may be faster to get a whole copy
  • Primary failure
    • Normally, secondaries wait till the primary recovers
    • Can get higher availability by electing a new primary
    • A secondary that detects primary’s failure starts a new election by broadcasting its unique replica identifier
    • Other secondaries reply with their replica identifier
    • The largest replica identifier wins docsity.com

Failure & Recovery Handling 2/

  • Primary failure (cont’d)
    • All replicas must now check that they have the same updates from the failed primary
    • During the election, each replica reports the id of the last log record it received from the primary
    • The most up-to-date replica sends its latest updates to (at least) the new primary.

docsity.com