Intro to Database Systems 15-445/15-645 Fall 2019 Andy Pavlo Computer Science Carnegie Mellon University
22 Introduction to Distributed Databases Intro to Database Systems - - PowerPoint PPT Presentation
22 Introduction to Distributed Databases Intro to Database Systems - - PowerPoint PPT Presentation
22 Introduction to Distributed Databases Intro to Database Systems Andy Pavlo AP AP 15-445/15-645 Computer Science Carnegie Mellon University Fall 2019 2 ADM IN ISTRIVIA Homework #5 : Monday Dec 3 rd @ 11:59pm Project #4 : Monday Dec 10
CMU 15-445/645 (Fall 2019)
ADM IN ISTRIVIA
Homework #5: Monday Dec 3rd @ 11:59pm Project #4: Monday Dec 10th @ 11:59pm Extra Credit: Wednesday Dec 10th @ 11:59pm Final Exam: Monday Dec 9th @ 5:30pm
2
CMU 15-445/645 (Fall 2019)
ADM IN ISTRIVIA
Monday Dec 2th – Oracle Lecture
→ Shasank Chavan (VP In-Memory Databases)
Wednesday Dec 4th – Potpourri + Review
→ Vote for what system you want me to talk about. → https://cmudb.io/f19-systems
Sunday Nov 24th – Extra Credit Check
→ Submit your extra credit assignment early to get feedback from me.
3
CMU 15-445/645 (Fall 2019)
UPCO M IN G DATABASE EVEN TS
Oracle Research Talk
→ Tuesday December 4th @ 12:00pm → CIC 4th Floor
4
CMU 15-445/645 (Fall 2019)
PARALLEL VS. DISTRIBUTED
Parallel DBMSs:
→ Nodes are physically close to each other. → Nodes connected with high-speed LAN. → Communication cost is assumed to be small.
Distributed DBMSs:
→ Nodes can be far from each other. → Nodes connected using public network. → Communication cost and problems cannot be ignored.
5
CMU 15-445/645 (Fall 2019)
DISTRIBUTED DBM Ss
Use the building blocks that we covered in single- node DBMSs to now support transaction processing and query execution in distributed environments.
→ Optimization & Planning → Concurrency Control → Logging & Recovery
6
CMU 15-445/645 (Fall 2019)
TO DAY'S AGEN DA
System Architectures Design Issues Partitioning Schemes Distributed Concurrency Control
7
CMU 15-445/645 (Fall 2019)
SYSTEM ARCH ITECTURE
A DBMS's system architecture specifies what shared resources are directly accessible to CPUs. This affects how CPUs coordinate with each other and where they retrieve/store objects in the database.
8
CMU 15-445/645 (Fall 2019)
SYSTEM ARCH ITECTURE
9
Shared Nothing
Network
Shared Memory
Network
Shared Disk
Network
Shared Everything
CMU 15-445/645 (Fall 2019)
SH ARED M EM O RY
CPUs have access to common memory address space via a fast interconnect.
→ Each processor has a global view of all the in-memory data structures. → Each DBMS instance on a processor has to "know" about the other instances.
10
Network
CMU 15-445/645 (Fall 2019)
SH ARED DISK
All CPUs can access a single logical disk directly via an interconnect, but each have their own private memories.
→ Can scale execution layer independently from the storage layer. → Must send messages between CPUs to learn about their current state.
11
Network
CMU 15-445/645 (Fall 2019)
Storage
SH ARED DISK EXAM PLE
12
Node
Application Server
Node Node
Update 101 Get Id=200 Get Id=101 Page ABC Page XYZ Get Id=101 Page ABC
CMU 15-445/645 (Fall 2019)
SH ARED N OTH IN G
Each DBMS instance has its own CPU, memory, and disk. Nodes only communicate with each
- ther via network.
→ Hard to increase capacity. → Hard to ensure consistency. → Better performance & efficiency.
13
Network
CMU 15-445/645 (Fall 2019)
SH ARED N OTH IN G EXAM PLE
14
Node
Application Server
Node
P1→ID:1-150 P2→ID:151-300
Node
P3→ID:101-200 P1→ID:1-100 P2→ID:201-300
Get Id=200 Get Id=10 Get Id=200 Get Id=200
CMU 15-445/645 (Fall 2019)
EARLY DISTRIBUTED DATABASE SYSTEM S
MUFFIN – UC Berkeley (1979) SDD-1 – CCA (1979) System R* – IBM Research (1984) Gamma – Univ. of Wisconsin (1986) NonStop SQL – Tandem (1987)
15 Bernstein Mohan DeWitt Gray Stonebraker
CMU 15-445/645 (Fall 2019)
DESIGN ISSUES
How does the application find data? How to execute queries on distributed data?
→ Push query to data. → Pull data to query.
How does the DBMS ensure correctness?
16
CMU 15-445/645 (Fall 2019)
H O M O GEN O US VS. H ETERO GEN O US
Approach #1: Homogenous Nodes
→ Every node in the cluster can perform the same set of tasks (albeit on potentially different partitions of data). → Makes provisioning and failover "easier".
Approach #2: Heterogenous Nodes
→ Nodes are assigned specific tasks. → Can allow a single physical node to host multiple "virtual" node types for dedicated tasks.
17
CMU 15-445/645 (Fall 2019)
M O N GO DB H ETERO GEN O US ARCH ITECTURE
18
Router (mongos)
Shards (mongod)
P3 P4 P1 P2
P1→ID:1-100 P2→ID:101-200 P3→ID:201-300 P4→ID:301-400
Config Server (mongod) Router (mongos)
⋮ ⋮
Application Server
Get Id=101
CMU 15-445/645 (Fall 2019)
DATA TRAN SPAREN CY
Users should not be required to know where data is physically located, how tables are partitioned
- r replicated.
A SQL query that works on a single-node DBMS should work the same on a distributed DBMS.
19
CMU 15-445/645 (Fall 2019)
DATABASE PARTITIO N IN G
Split database across multiple resources:
→ Disks, nodes, processors. → Sometimes called "sharding"
The DBMS executes query fragments on each partition and then combines the results to produce a single answer.
20
CMU 15-445/645 (Fall 2019)
N AÏVE TABLE PARTITIO N ING
Each node stores one and only table. Assumes that each node has enough storage space for a table.
21
CMU 15-445/645 (Fall 2019)
N AÏVE TABLE PARTITIO N ING
22
Table1
SELECT * FROM table
Ideal Query:
Table2 Partitions
Table1 Table2
CMU 15-445/645 (Fall 2019)
H O RIZO N TAL PARTITIO N IN G
Split a table's tuples into disjoint subsets.
→ Choose column(s) that divides the database equally in terms of size, load, or usage. → Hash Partitioning, Range Partitioning
The DBMS can partition a database physical (shared nothing) or logically (shared disk).
23
CMU 15-445/645 (Fall 2019)
H O RIZO N TAL PARTITIO N IN G
24
SELECT * FROM table WHERE partitionKey = ?
Ideal Query:
Partitions Table1
101 a XXX 2019-11-29 102 b XXY 2019-11-28 103 c XYZ 2019-11-29 104 d XYX 2019-11-27 105 e XYY 2019-11-29
P3 P4 P1 P2
hash(a)%4 = P2 hash(b)%4 = P4 hash(c)%4 = P3 hash(d)%4 = P2 hash(e)%4 = P1
Partitioning Key
CMU 15-445/645 (Fall 2019)
CO N SISTEN T H ASH IN G
25
1 1/2
Replication Factor = 3
hash(key2) hash(key1)
If hash(key)=D
E A C D B F
CMU 15-445/645 (Fall 2019)
Storage
LO GICAL PARTITIO N IN G
26
Node
Application Server
Node
Get Id=1 Get Id=3
Id=1 Id=2 Id=3 Id=4 Id=1 Id=2 Id=3 Id=4
CMU 15-445/645 (Fall 2019)
Node Node
PH YSICAL PARTITIO N IN G
27
Application Server
Get Id=1 Get Id=3
Id=1 Id=2 Id=3 Id=4
CMU 15-445/645 (Fall 2019)
SIN GLE- N O DE VS. DISTRIBUTED
A single-node txn only accesses data that is contained on one partition.
→ The DBMS does not need coordinate the behavior concurrent txns running on other nodes.
A distributed txn accesses data at one or more partitions.
→ Requires expensive coordination.
29
CMU 15-445/645 (Fall 2019)
TRAN SACTIO N CO O RDIN ATIO N
If our DBMS supports multi-operation and distributed txns, we need a way to coordinate their execution in the system. Two different approaches:
→ Centralized: Global "traffic cop". → Decentralized: Nodes organize themselves.
30
CMU 15-445/645 (Fall 2019)
TP M O N ITO RS
Example of a centralized coordinator. Originally developed in the 1970-80s to provide txns between terminals and mainframe databases.
→ Examples: ATMs, Airline Reservations.
Many DBMSs now support the same functionality internally.
31
CMU 15-445/645 (Fall 2019)
Coordinator
CEN TRALIZED CO O RDIN ATO R
32
Partitions
Lock Request Acknowledgement Commit Request Safe to commit?
Application Server
P3 P4 P1 P2
P1 P2 P3 P4
CMU 15-445/645 (Fall 2019)
CEN TRALIZED CO O RDIN ATO R
33
Middleware
Query Requests Safe to commit?
Application Server
P3 P4 P1 P2
P1→ID:1-100 P2→ID:101-200 P3→ID:201-300 P4→ID:301-400
Commit Request
Partitions
CMU 15-445/645 (Fall 2019)
P3 P4 P1 P2
DECEN TRALIZED CO O RDIN ATO R
34
Application Server
Safe to commit? Begin Request Query Request Commit Request
Partitions
CMU 15-445/645 (Fall 2019)
DISTRIBUTED CO N CURREN CY CO N TRO L
Need to allow multiple txns to execute simultaneously across multiple nodes.
→ Many of the same protocols from single-node DBMSs can be adapted.
This is harder because of:
→ Replication. → Network Communication Overhead. → Node Failures. → Clock Skew.
35
CMU 15-445/645 (Fall 2019)
DISTRIBUTED 2PL
36
Node 1 Node 2
NETWORK
Set A=2 A=1 A=2 Set B=7 B=8 B=7
Application Server Application Server
Set B=9 Set A=0
Waits-For Graph
T1 T2
CMU 15-445/645 (Fall 2019)
CO N CLUSIO N
I have barely scratched the surface on distributed database systems… It is hard to get right. More info (and humiliation):
→ Kyle Kingsbury's Jepsen Project
37
CMU 15-445/645 (Fall 2019)
N EXT CLASS
Distributed OLTP Systems Replication CAP Theorem Real-World Examples
38