CSE 599c Hot Topics in Data Management Systems

Lecture 18: Replication and

Disconnected Operation

Magdalena Balazinska

Winter 2006

What We Have Seen So Far

Relational DBMSs, active databases

Stream processing, heterogeneous devices

Transactions, traditional distributed databases

Challenges in distributed data management

Autonomy, incentives, and heterogeneity

Fault-tolerance, and scalability

Today: replication

Next week: data heterogeneity

Reminder: write-up due by end of next week

Today's Paper

J. Gray, P. Helland, P. O'Neil, and D. Shasha. The Dangers of Replication and a Solution. ACM SIGMOD Record (25)2, 1996.

Outline

Goals of replication

Three types of replication

Eager replication

Lazy replication

Two-tier replication

Replication support in commercial databases

Goals of Replication

Goal 1: availability

Goal 2: performance

But, it's easy to build a replicated system that reduces performance and availability

Some

requests

Other

requests

Three replicas

Eager Replication

Also called synchronous replication

All updates are applied to all replicas (or to a majority) as part of a single transaction

Main goal: as if there was only one copy

Maintain consistency

Maintain one-copy serializability

I.e., execution of transactions has same effect as an execution on a non-replicated db

Transactions must aquire global locks

Eager Master

1 master for each object holds primary copy

To update an object, transaction must first aquire a lock at the master

Lock at the master is global lock

What happens when master/primary fails?

Blocking would hurt availability

Must chose a new primary: run election

Eager Group

With n copies

Exclusive lock on x copies is global exclusive lock

Shared lock on s copies is global shared lock

Must have: 2x > n and s + x > n

Majority locking

s = x = (n+1)/2

Read-locks-one, write-locks-all

s=1 and x = n, high read performance

Write All or Write Quorum

Both with master and with group

Either update all replicas (read-one write-all)

Or update only a quorum of replicas (voting)

Replicas in quorum must be up-to-date

Eager Replication Properties

Favors consistency over availability

Only majority partition can process requests

There appears to be a single copy of the db

High runtime overhead

Must lock and update at least majority of replicas

Two-phase commit

Runs at pace of slowest replica in quorum

So overall system is now slower

Higher deadlock rate (transactions take longer)

Lazy Replication

Also called asynchronous replication or optimistic replication

Main goal: availability and performance

Approach

One replica updated by original transaction

Updates propagate asynchronously to other replicas

Lazy Master

One master holds primary copy

Transactions update primary copy

Master asynchronously propagates updates to replicas, which process them in same order

Ensures single-copy serializability

Can lose most recent transactions when primary fails!

After electing a new primary, secondaries must agree who is most up-to-date

More About Lazy Master

Network failures can cause trouble...

Secondaries think that primary failed

Secondaries elect a new primary

But primary can still be running

Now have two primaries!

To avoid problem, only majority partition can continue processing at any time

So better performance than eager replication but not better availability

Lazy Group

Also called multi-master

Best scheme for availability

Cannot guarantee one-copy serializability!

R1

R2

Init: x=1

Update x=2

Init: x=1

Update x=3

Lazy Group

Also called multi-master

Best scheme for availability

Cannot guarantee one-copy serializability!

Instead guarantee convergence

Db state does not reflect any serial execution

But all replicas have the same state

Detect conflicts and reconcile replica states

Manual, most recent timestamp wins, site A wins over site B, user-defined rules, etc.

Detecting Conflicts Using Timestamps

R1

R2

x=2, Old: T0 New: T1

Init: x=1 at T0

Update at T1 : x=2

Init: x=1 at T0

x=2 at T1

x=2 at T1

Detecting Conflicts Using Timestamps

R1

R2

x=2, Old: T0 New: T1

Conflict!

Init: x=1 at T0

Update at T1 : x=2

Init: x=1 at T0

Update at T2: x=3

Conflict!

x=3, Old: T0 New: T2

Reconciliation rule

T2 > T1, so x=3

Reconciliation rule

T2 > T1, so x=3

Lazy Replication Properties

Favors availability over consistency

Can read and update any replica

High runtime performance

Weak consistency

Conflicts and reconciliation

Two-Tier Replication

Benefits of lazy master and lazy group

Each object has a master with primary copy

When disconnected from master

Secondary can only run tentative transactions

When reconnects to master

Master reprocesses all tentative transactions

Checks an acceptance criterion

If passes, we now have final commit order

Secondary undoes tentative and redoes committed

Replication in Commercial DBMSs

All major vendors provide replication

Oracle 9i, DB2, SQL Server

Eager master

Lazy master

Lazy group

Timestamps or before-values to detect conflicts

Pre-defined rules for state reconciliation

Support for user-defined reconciliation rules

Conclusion

Replication is a very important problem

Fault-tolerance (various forms of replication)

Caching (lazy master)

Warehousing (lazy master)

Mobility (two-tier techniques)

Replication is complex, but basic techniques and trade-offs are very well known

Eager or lazy replication

Master or no master

For eager replication: use quorum

2006-01-01T23:16:26