Data Modeling and Databases Ch 14: Data Replication. Gustavo Alonso, Ce Zhang Systems Group Department of Computer Science ETH Zürich

Similar documents
Introduction to Database Replication

CSE 544 Principles of Database Management Systems. Alvin Cheung Fall 2015 Lecture 14 Distributed Transactions

Distributed Systems in practice HS 2007

10. Replication. CSEP 545 Transaction Processing Philip A. Bernstein Sameh Elnikety. Copyright 2012 Philip A. Bernstein

10. Replication. CSEP 545 Transaction Processing Philip A. Bernstein. Copyright 2003 Philip A. Bernstein. Outline

CMU SCS CMU SCS Who: What: When: Where: Why: CMU SCS

CSE 444: Database Internals. Lecture 25 Replication

Databases. Laboratorio de sistemas distribuidos. Universidad Politécnica de Madrid (UPM)

Administration Naive DBMS CMPT 454 Topics. John Edgar 2

Parallel DBs. April 25, 2017

Distributed KIDS Labs 1

Datenbanksysteme II: Implementation of Database Systems Synchronization of Concurrent Transactions

Database Architectures

Multi-User-Synchronization

Distributed Systems COMP 212. Revision 2 Othon Michail

Advanced Systems Lab (Intro and Administration) G. Alonso Systems Group

Everything You Need to Know About MySQL Group Replication

CS /15/16. Paul Krzyzanowski 1. Question 1. Distributed Systems 2016 Exam 2 Review. Question 3. Question 2. Question 5.

CS5412: TRANSACTIONS (I)

Distributed Systems. Characteristics of Distributed Systems. Lecture Notes 1 Basic Concepts. Operating Systems. Anand Tripathi

Distributed Systems. Characteristics of Distributed Systems. Characteristics of Distributed Systems. Goals in Distributed System Designs

Introduction to Distributed Data Systems

Chapter 11 - Data Replication Middleware

Integrity in Distributed Databases

Distributed Transaction Management

Synchronization. Chapter 5

Mobile and Heterogeneous databases Distributed Database System Transaction Management. A.R. Hurson Computer Science Missouri Science & Technology

Jargons, Concepts, Scope and Systems. Key Value Stores, Document Stores, Extensible Record Stores. Overview of different scalable relational systems

Mutual consistency, what for? Replication. Data replication, consistency models & protocols. Difficulties. Execution Model.

CSE 444: Database Internals. Section 9: 2-Phase Commit and Replication

Database Architectures

CockroachDB on DC/OS. Ben Darnell, CTO, Cockroach Labs

CS 347 Parallel and Distributed Data Processing

Large-Scale Key-Value Stores Eventual Consistency Marco Serafini

Replication in Distributed Systems

CompSci 516 Database Systems

Lock Tuning. Concurrency Control Goals. Trade-off between correctness and performance. Correctness goals. Performance goals.

Last time. Distributed systems Lecture 6: Elections, distributed transactions, and replication. DrRobert N. M. Watson

Building Consistent Transactions with Inconsistent Replication

Transaction Management & Concurrency Control. CS 377: Database Systems

Assignment 12: Commit Protocols and Replication Solution

Chapter 9: Concurrency Control

Control. CS432: Distributed Systems Spring 2017

On the Study of Different Approaches to Database Replication in the Cloud

Database Management Systems

Distributed Systems (5DV147)

Distributed systems. Lecture 6: distributed transactions, elections, consensus and replication. Malte Schwarzkopf

Datacenter replication solution with quasardb

Topics in Reliable Distributed Systems

CS 347 Parallel and Distributed Data Processing

Exercise 12: Commit Protocols and Replication

Database Replication: A Tutorial

Distributed Transaction Management. Distributed Database System

Consistency & Replication

10. Replication. Motivation

Atomicity. Bailu Ding. Oct 18, Bailu Ding Atomicity Oct 18, / 38

SCALABLE CONSISTENCY AND TRANSACTION MODELS

Consistency in Distributed Systems

Distributed Databases

Basic vs. Reliable Multicast

TAPIR. By Irene Zhang, Naveen Sharma, Adriana Szekeres, Arvind Krishnamurthy, and Dan Ports Presented by Todd Charlton

Transaction Processing Concurrency control

It also performs many parallelization operations like, data loading and query processing.

DISTRIBUTED DATABASES CS561-SPRING 2012 WPI, MOHAMED ELTABAKH

What are Transactions? Transaction Management: Introduction (Chap. 16) Major Example: the web app. Concurrent Execution. Web app in execution (CS636)

High Availability through Warm-Standby Support in Sybase Replication Server A Whitepaper from Sybase, Inc.

NoSQL systems: sharding, replication and consistency. Riccardo Torlone Università Roma Tre

Synchronization. Clock Synchronization

Transaction Management: Introduction (Chap. 16)

transaction - (another def) - the execution of a program that accesses or changes the contents of the database

L i (A) = transaction T i acquires lock for element A. U i (A) = transaction T i releases lock for element A

Chapter 20: Database System Architectures

Transaction Systems. Andrey Gubichev. October 21, Exercise Session 1

Replication and Consistency

CSC 261/461 Database Systems Lecture 21 and 22. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

Synchronization Part 2. REK s adaptation of Claypool s adaptation oftanenbaum s Distributed Systems Chapter 5 and Silberschatz Chapter 17

Database Replication Prototype

CSE 444: Database Internals. Lectures Transactions

CSE 530A ACID. Washington University Fall 2013

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

Last Class Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications

Module 8 Fault Tolerance CS655! 8-1!

Chapter 18: Parallel Databases

Transactions and ACID

TRANSACTION PROPERTIES

6.830 Lecture Recovery 10/30/2017

CISC 7610 Lecture 5 Distributed multimedia databases. Topics: Scaling up vs out Replication Partitioning CAP Theorem NoSQL NewSQL

Distributed Database Management System UNIT-2. Concurrency Control. Transaction ACID rules. MCA 325, Distributed DBMS And Object Oriented Databases

Fault Tolerance. Goals: transparent: mask (i.e., completely recover from) all failures, or predictable: exhibit a well defined failure behavior

Consensus and related problems

Distributed Databases

Distributed Databases Systems

CSE 444: Database Internals. Lectures 13 Transaction Schedules

Consistency and Scalability

CS Amazon Dynamo

Database Tuning and Physical Design: Execution of Transactions

CS October 2017

SQL, NoSQL, MongoDB. CSE-291 (Cloud Computing) Fall 2016 Gregory Kesden

CSE 344 MARCH 9 TH TRANSACTIONS

Transactions and Concurrency Control

Transcription:

Data Modeling and Databases Ch 14: Data Replication Gustavo Alonso, Ce Zhang Systems Group Department of Computer Science ETH Zürich

Database Replication What is database replication The advantages of database replication A taxonomy of replication strategies: Synchronous Asynchronous Update everywhere Primary copy Discussion on the various replication strategies. D-INFK, ETH Zurich, Data Modeling and Databases 2

Database Replication DB NETWORK DB Replication is a common strategy in data management: RAID technology (Redundant Array of Independent Disks), Mirror sites for web pages, Back up mechanisms (1-safe, 2-safe, hot/cold stand by) Here we will focus our attention on replicated databases but many of the ideas we will discuss apply to other environments as well. Why replication? PERFORMANCE: Location transparency is difficult to achieve in a distributed environment. Local accesses are fast, remote accesses are slow. If everything is local, then all accesses should be fast. FAULT TOLERANCE: Failure resilience is also difficult to achieve. If a site fails, the data it contains becomes unavailable. By keeping several copies of the data at different sites, single site failures should not affect the overall availability. APPLICATION TYPE: Databases have always tried to separate queries form updates to avoid interference. This leads to two different application types OLTP and OLAP, depending on whether they are update or read intensive. D-INFK, ETH Zurich, Data Modeling and Databases 3

Remote access to data? Zurich London New York Tokyo LOAD RESPONSE TIME CRITICAL D-INFK, ETH Zurich, Data Modeling and Databases 4

Replication Zurich London New York Tokyo LOAD RESPONSE TIME CRITICAL D-INFK, ETH Zurich, Data Modeling and Databases 5

How to replicate data? There are two basic parameters to select when designing a replication strategy: where and when. Depending on when the updates are propagated: Synchronous (eager) Asynchronous (lazy) Depending on where the updates can take place: Primary Copy (master) Update Everywhere (group) Sync master group Async D-INFK, ETH Zurich, Data Modeling and Databases 6

Synchronous Replication Synchronous replication propagates any changes to the data immediately to all existing copies. Moreover, the changes are propagated within the scope of the transaction making the changes. The ACID properties apply to all copy updates. Transaction updates commit Site 1 Site 2 Site 3 Site 4 D-INFK, ETH Zurich, Data Modeling and Databases 7

Synchronous Replication Zurich London New York Tokyo Price = $ 50 Price = $ 50 Price = $ 50 Price = $ 50 IS CONSISTENT AT ALL SITES D-INFK, ETH Zurich, Data Modeling and Databases 8

Synchronous Replication Zurich London New York Tokyo Price = $ 50 Price = $ 50 Price = $ 50 Price = $ 50 A SITE WANTS TO UPDATE THE PRICE... D-INFK, ETH Zurich, Data Modeling and Databases 9

Synchronous Replication Zurich London New York Tokyo Price = $ 50 Price = $ 50 Price = $ 50 Price = $ 50 IT FIRST CONSULTS WITH EVERYBODY ELSE... D-INFK, ETH Zurich, Data Modeling and Databases 10

Synchronous Replication Zurich London New York Tokyo Price = $ 50 Price = $ 50 Price = $ 50 Price = $ 50 AN AGREEMENT IS REACHED... D-INFK, ETH Zurich, Data Modeling and Databases 11

Synchronous Replication Zurich London New York Tokyo Price = $ 100 Price = $ 100 Price = $ 100 Price = $ 100 THE PRICE IS UPDATED AND PROCESSING CONTINUES. D-INFK, ETH Zurich, Data Modeling and Databases 12

Asynchronous Replication Asynchronous replication first executes the updating transaction on the local copy. Then the changes are propagated to all other copies. While the propagation takes place, the copies are inconsistent (they have different values). The time the copies are inconsistent is an adjustable parameter which is application dependent. Transaction updates commit Site 1 Site 2 Site 3 Site 4 D-INFK, ETH Zurich, Data Modeling and Databases 13

Asynchronous Replication Zurich London New York Tokyo Price = $ 50 Price = $ 50 Price = $ 50 Price = $ 50 IS CONSISTENT AT ALL SITES D-INFK, ETH Zurich, Data Modeling and Databases 14

Asynchronous Replication Zurich London New York Tokyo Price = $ 50 Price = $ 50 Price = $ 50 Price = $ 50 A SITE WANTS TO UPDATE THE PRICE... D-INFK, ETH Zurich, Data Modeling and Databases 15

Asynchronous Replication Zurich London New York Tokyo Price = $ 50 Price = $ 100 Price = $ 50 Price = $ 50 THEN IT UPDATES THE PRICE LOCALLY AND CONTINUES PROCESSING ( IS NOT CONSISTENT!)... D-INFK, ETH Zurich, Data Modeling and Databases 16

Asynchronous Replication Zurich London New York Tokyo Price = $ 100 Price = $ 100 Price = $ 100 Price = $ 50 THE UPDATE IS EVENTUALLY PROPAGATED TO ALL SITES (PUSH, PULL MODELS) D-INFK, ETH Zurich, Data Modeling and Databases 17

Update Everywhere With an update everywhere approach, changes can be initiated at any of the copies. That is, any of the sites which owns a copy can update the value of the data item Transaction updates commit Site 1 Site 2 Site 3 Site 4 Transaction updates commit Site 1 Site 2 Site 3 Site 4 D-INFK, ETH Zurich, Data Modeling and Databases 18

Update Everywhere Zurich London New York Tokyo Price = $ 50 Price = $ 50 Price = $ 50 Price = $ 50 ALL SITES ARE ALLOWED TO UPDATE THEIR COPY D-INFK, ETH Zurich, Data Modeling and Databases 19

Primary Copy With a primary copy approach, there is only one copy which can be updated (the master), all others (secondary copies) are updated reflecting the changes to the master. Site 1 Site 2 Site 3 Site 4 Site 1 Site 2 Site 3 Site 4 D-INFK, ETH Zurich, Data Modeling and Databases 20

Primary Copy Zurich London New York Tokyo Price = $ 50 Price = $ 50 Price = $ 50 Price = $ 50 ONLY ONE SITE IS ALLOWED TO DO UPDATES, THE OTHER ARE READ ONLY COPIES D-INFK, ETH Zurich, Data Modeling and Databases 21

Forms of replication Synchronous Advantages: No inconsistencies (identical copies) Reading the local copy yields the most up to date value Changes are atomic Disadvantages: A transaction has to update all sites (longer execution time, worse response time) Asynchronous Advantages: A transaction is always local (good response time) Disadvantages: Data inconsistencies A local read does not always return the most up to date value Changes to all copies are not guaranteed Replication is not transparent Update everywhere Advantages: Any site can run a transaction Load is evenly distributed Disadvantages: Copies need to be synchronized Primary Copy Advantages: No inter-site synchronization is necessary (it takes place at the primary copy) There is always one site which has all the updates Disadvantages: The load at the primary copy can be quite large Reading the local copy may not yield the most up to date value D-INFK, ETH Zurich, Data Modeling and Databases 22

Replication Strategies The previous ideas can be combined into 4 different replication strategies: Synchronous (eager) synchronous primary copy synchronous update everywhere Asynchronous (lazy) asynchronous primary copy asynchronous update everywhere Primary copy Update everywhere D-INFK, ETH Zurich, Data Modeling and Databases 23

Replication Strategies Advantages: Updates do not need to be coordinated No inconsistencies Disadvantages: Longest response time Only useful with few updates Local copies are can only be read Advantages: No inconsistencies Elegant (symmetrical solution) Disadvantages: Long response times Updates need to be coordinated Advantages: No coordination necessary Short response times Disadvantages: Local copies are not up to date Inconsistencies Advantages: No centralized coordination Shortest response times Disadvantages: Inconsistencies Updates can be lost (reconciliation) Primary copy Update everywhere D-INFK, ETH Zurich, Data Modeling and Databases 24

Replication (Ideal) Synchronous (eager) Globally correct Remote writes Globally correct Local writes Asynchronous (lazy) Inconsistent reads Inconsistent reads Reconciliation Primary copy Update everywhere D-INFK, ETH Zurich, Data Modeling and Databases 25

Replication (Practical) Synchronous (eager) Too Expensive (usefulness?) Too expensive (does not scale) Asynchronous (lazy) Feasible Feasible in some applications Primary copy Update everywhere D-INFK, ETH Zurich, Data Modeling and Databases 26

Summary - I Replication is used for performance and fault tolerant purposes. There are four possible strategies to implement replication solutions depending on whether it is synchronous or asynchronous, primary copy or update everywhere. Each strategy has advantages and disadvantages which are more or less obvious given the way they work. There seems to be a trade-off between correctness (data consistency) and performance (throughput and response time). The next step is to analyze these strategies in more detail to better understand how they work and where the problems lie. D-INFK, ETH Zurich, Data Modeling and Databases 27

Database Replication Strategies Database environments Managing replication Technical aspects and correctness/performance issues of each replication strategy: Synchronous - primary copy Synchronous - update everywhere Asynchronous - primary copy Asynchronous - update everywhere D-INFK, ETH Zurich, Data Modeling and Databases 28

Basic Database Notation A user interacts with the database by issuing read and write operations. These read and write operations are grouped into transactions with the following properties: Atomicity: either all of the transaction is executed or nothing at all. Consistency: the transaction produces consistent changes. Isolation: transactions do not interfere with each other. Durability: Once the transaction commits, its changes remain. Transaction User BoT r(x) r(y) r (z) w(x) w(y) EoT x y z Database D-INFK, ETH Zurich, Data Modeling and Databases 29

Isolation Isolation is guaranteed by a concurrency control protocol. In commercial databases, this is usually 2 Phase Locking (2PL): conflicting locks cannot coexist (writes conflict with reads and writes on the same item) Before accessing an item, the item must be locked. After releasing a lock, a transaction cannot obtain any more locks. Database User A Transaction BoT r(x) r(y) r (z) w(x) w(y) EoT Write-lock user A x z y Write-lock user A Read-lock user A D-INFK, ETH Zurich, Data Modeling and Databases 30

Atomicity A transaction must commit all its changes. When a transaction executes at various sites, it must execute an atomic commitment protocol, i.e., it must commit at all sites or at none of them. Commercial systems use 2 Phase Commit: A coordinator asks everybody whether they want to commit If everybody agrees, the coordinator sends a message indicating they can all commit Database A User Transaction BoT r(x) r(y) r (z) w(x) w(y) EoT x y z Database B Database C D-INFK, ETH Zurich, Data Modeling and Databases 31

Transaction Manager The transaction manager takes care of isolation and atomicity. It acquires locks on behalf of all transactions and tries to come up with a serializable execution, i.e., make it look like the transactions were executed one after the other. If the transactions follow 2 Phase Locking, serializability is guaranteed. Thus, the scheduler only needs to enforce 2PL behaviour. scheduler Transactions from different users Operations from the different transactions 2 Phase Locking is enforced Transactions are serialized D-INFK, ETH Zurich, Data Modeling and Databases 32

Managing Replication When the data is replicated, we still need to guarantee atomicity and isolation. Atomicity can be guaranteed by using 2 Phase Commit. This is the easy part. The problem is how to make sure the serialization orders are the same at all sites, i.e., make sure that all sites do the same things in the same order (otherwise the copies would be inconsistent). Scheduler A Scheduler B D-INFK, ETH Zurich, Data Modeling and Databases 33

Managing Replication To avoid this, replication protocols are used. A replication protocol specifies how the different sites must be coordinated in order to provide a concrete set of guarantees. The replication protocols depend on the replication strategy (synchronous, asynchronous, primary copy, update everywhere). Scheduler A Replication Protocol Scheduler B D-INFK, ETH Zurich, Data Modeling and Databases 34

Replication Strategies Now we can analyze the advantages and disadvantages of each strategy: Synchronous (eager) synchronous primary copy synchronous update everywhere Asynchronous (lazy) asynchronous primary copy asynchronous update everywhere Primary copy Update everywhere D-INFK, ETH Zurich, Data Modeling and Databases 35

Cost of Replication 60 50 40 30 20 Available CPU System with 50 nodes Assume a 50 node replicated system where a fraction s of the data is replicated and w represents the fraction of updates made (ws = replication factor) Overall computing power of the system: N 1 w s (N 1) 10 0 ws (replication factor) 0 0.1 0.3 0.5 0.7 0.9 1 No performance gain with large ws factor (many updates or many replicated data items) Reads must be local to get performance advantages. D-INFK, ETH Zurich, Data Modeling and Databases 36

Synchronous upd. everywhere Assume all sites contain the same data. READ ONE-WRITE ALL Each sites uses 2 Phase Locking. Read operations are performed locally. Write operations are performed at all sites (using a distributed locking protocol). This protocol guarantees that every site will behave as if there were only one database. The execution is serializable (correct) and all reads access the latest version. This simple protocol illustrates the main idea behind replication, but it needs to be extended in order to cope with realistic environments: Sites fail, which reduces the availability (if a site fails, no copy can be written). Sites eventually have to recover (a recently recovered site may not have the latest updates). D-INFK, ETH Zurich, Data Modeling and Databases 37

Dealing with Site Failures Assume, for the moment, that there are no communication failures. Instead of writing to all copies, we could WRITE ALL AVAILABLE COPIES READ = read any copy, if time-out, read another copy. WRITE = send Write(x) to all copies. If one site rejects the operation, then abort. Otherwise, all sites not responding are missing writes. VALIDATION = To commit a transaction Check that all sites in missing writes are still down. If not, then abort the transaction. Check that all sites that were available are still available. If some do not respond, then abort. D-INFK, ETH Zurich, Data Modeling and Databases 38

Dealing with Comm. Failures In practice, communications may fail leading to partitioned networks and inaccessible sites. The available copies algorithm assumes that when a site cannot be reached, it must have failed. To tolerate site and communication failures: QUORUM PROTOCOLS Quorums are sets of sites formed in such a way so as to be able to determine that it will have a non-empty intersection with other quorums: Simple majorities (site quorums). Weighted majorities (quorum consensus). Logical structures (tree,, matrix, projective planes quorums). D-INFK, ETH Zurich, Data Modeling and Databases 39

Quorum Protocols Desirable properties of quorums: Equal effort: all quorums should have about the same size. Equal responsibility: all sites participate on the same number of quorums. Dynamic reconfiguration: establishing a quorum should be dynamic to account for failures and configuration changes. Low communication overhead: minimize the number of messages exchanged. Graceful degradation: effort proportional to failures. D-INFK, ETH Zurich, Data Modeling and Databases 40

Weighted Quorums QUORUM CONSENSUS PROTOCOL Each copy has a weight assigned to it. The total weight of all copies is N. Let RT and WT be read and write thresholds, respectively, such that: 2 WT > N RT + WT > N A read quorum is a set of copies such that their total weight is greater or equal to RT. A write quorum is a set of copies such that their total weight is greater or equal to WT. D-INFK, ETH Zurich, Data Modeling and Databases 41

Weighted Quorums Each copy has a version number. READ = contact sites until a read quorum is formed. then read the copy with the highest version number. WRITE = contact sites until a write quorum is formed. Get the version number of the copy with the highest version number (k). Write to all sites in the quorum adding the new version number (k+1). Recovery is for free! but reading is no longer local and it is not possible to change the system dynamically (the copies must be known in advance). D-INFK, ETH Zurich, Data Modeling and Databases 42

Synchronous - Update Everywhere SITE A SITE B SITE C BOT R(x) W(x) Upd Lock Upd request ack...... change Lock Upd Each site uses 2PL Read operations are performed locally Write operations involve locking all copies of the data item (request a lock, obtain the lock, receive an acknowledgement) The transaction is committed using 2PC Main optimizations are based on the idea of quorums (but all we will say about this protocol also applies to quorums) D-INFK, ETH Zurich, Data Modeling and Databases 43

Response Time and Messages centralized database update T= T= replicated database update: 2N messages 2PC The way replication takes place (one operation at a time), increases the response time and, thereby, the conflict profile of the transaction. The message overhead is too high (even if broadcast facilities are available). D-INFK, ETH Zurich, Data Modeling and Databases 44

The Deadlock Problem A B C BOT R(x) D BOT Approximated deadlock rate: TPS Action_ Time Actions N 2 4 DB_ Size 2 5 3 W(x) Lock Lock W(x) if the database size remains constant, or 2 5 TPS Action_ TimeActions N 2 4DB_Size if the database size grows with the number of nodes. Optimistic approaches may result in too many aborts. D-INFK, ETH Zurich, Data Modeling and Databases 45

Synchronous - update everywhere Advantages: No inconsistencies Elegant (symmetrical solution) Disadvantages: Very high number of messages involved Transaction response time is very long The system will not scale because of deadlocks (as the number of nodes increases, the probability of getting into a deadlock gets too high) Data consistency is guaranteed. Performance may be seriously affected with this strategy. The system may also have scalability problems (deadlocks). High fault tolerance. D-INFK, ETH Zurich, Data Modeling and Databases 46

Synchronous - primary copy Advantages: Updates do not need to be coordinated No inconsistencies, no deadlocks. Disadvantages: Longest response time Only useful with few updates (primary copy is a bottleneck) Local copies are almost useless Not used in practice Similar problems to those of Sync - update everywhere. Including scalability problems (bottlenecks). Data consistency is guaranteed. Fault tolerant. D-INFK, ETH Zurich, Data Modeling and Databases 47

Async - primary copy protocol SITE A SITE B SITE C BOT W(x) EOT R(x) Upd Upd...... change Txn R(x) Upd Update transactions are executed at the primary copy site Read transactions are executed locally After the transaction is executed, the changes are propagated to all other sites Locally, the primary copy site uses 2 Phase Locking In this scenario, there is no atomic commitment problem (the other sites are not updated until later) D-INFK, ETH Zurich, Data Modeling and Databases 48

Asynchronous - primary copy Advantages: No coordination necessary Short response times (transaction is local) Disadvantages: Local copies are not up to date (a local read will not always include the updates made at the local copy) Inconsistencies (different sites have different values of the same data item) Performance is good (almost same as if no replication). Fault tolerance is limited. Data inconsistencies arise. D-INFK, ETH Zurich, Data Modeling and Databases 49

Async - update everywhere SITE A SITE B SITE C BOT W(x) EOT Upd BOT W(x) EOT Upd All transactions are executed locally After the transaction is executed, the changes are propagated to all other sites Locally, a site uses 2 Phase Locking In this scenario, there is no atomic commitment problem (the other sites are not updated until later) However, unlike with primary copy, updates need to be coordinated D-INFK, ETH Zurich, Data Modeling and Databases 50

Async / Update Everywhere DB 1 X=3 X=5 DB 2 Probability of needing reconciliation: TPS Action_ timeactions N 2DB_Size 2 3 3 DB 3 What does it mean to commit a transaction locally? There is no guarantee that a committed transaction will be valid (it may be eliminated if the other value wins). D-INFK, ETH Zurich, Data Modeling and Databases 51

Reconciliation Such problems can be solved using pre-arranged patterns: Latest update win (newer updates preferred over old ones) Site priority (preference to updates from headquarters) Largest value (the larger transaction is preferred) or using ad-hoc decision making procedures: identify the changes and try to combine them analyze the transactions and eliminate the nonimportant ones implement your own priority schemas D-INFK, ETH Zurich, Data Modeling and Databases 52

Asynchronous - update everywhere Advantages: No centralized coordination Shortest response times Disadvantages: Inconsistencies Updates can be lost (reconciliation) Performance is excellent (same as no replication). High fault tolerance. No data consistency. Reconciliation is a tough problem (to be solved almost manually). D-INFK, ETH Zurich, Data Modeling and Databases 53

Summary - II We have seen the different technical issues involved with each replication strategy Each replication strategy has well defined problems (deadlocks, reconciliation, message overhead, consistency) related to the way the replication protocols work The trade-off between correctness (data consistency) and performance (throughput and response time) is now clear The next step is to see how these ideas are implemented in practice D-INFK, ETH Zurich, Data Modeling and Databases 54

ALL THESE IDEAS IN PRACTICE D-INFK, ETH Zurich, Data Modeling and Databases 55

Key Value Stores Schema: Key + BLOG (or pointer to blog) Index on key (hashing) Deployment Horizontal partitioning Replication of partitions Replication strategy Quorums (simple majority) Asynchronous replication across all copies (eventual consistency) D-INFK, ETH Zurich, Data Modeling and Databases 56

KVS: the Good Very fast lookups (hashing) Easy to scale to many machines (simply add more copies/machines) Useful in many applications: Lookup user profiles Retrieve users web pages and info Scalable and easy to get going (no schema) D-INFK, ETH Zurich, Data Modeling and Databases 57

KVS: The Bad No easy support for queries beyond point queries Ranges, joins Queries on attributes (there are no attributes) Often, data is inconsistent Application dependent correctness D-INFK, ETH Zurich, Data Modeling and Databases 58

KVS: The Ugly Pushes complexity and responsibility to the application Price will be paid, the question is where Some operations are very costly to implement Range queries require to read all copies Joins out of the question Works well as cache or specialized system Not a replacement for a full blown database D-INFK, ETH Zurich, Data Modeling and Databases 59

Many variations Cloud computing has given raise to many variations on these theme Most serious system converging back towards a full blown transactional engine with a schema and SQL support Specialized systems in used as accelerators (memcached) or concrete application stages (profile look up) Nothing new under the sun (in computer science, we get to reinvent the wheel every ten years or so) D-INFK, ETH Zurich, Data Modeling and Databases 60

Common solution today BEFORE AFTER Pre-Ordering Mechanism Scheduler Scheduler Scheduler Scheduler 61