21 Distributed
21 Distributed
21 Introduction to
Distributed Databases
FALL Andy
2022 Pavlo
2
ADMINISTRIVIA
PA R A L L E L V S . D I S T R I B U T E D
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.
DISTRIBUTED DBMSs
TO DAY ' S AG E N DA
System Architectures
Design Issues
Partitioning Schemes
Distributed Concurrency Control
S Y S T E M A RC H I T E C T U R E
S Y S T E M A RC H I T E C T U R E
Network
Network
Network
SHARED MEMORY
SHARED DISK
Application
Server Node
Get Id=102
Page XYZ
Application
Server Node
Application
Server Node
Node
Application
Server Node
S H A R E D N OT H I N G
S H A R E D N OT H I N G E X A M P L E
Node
P1→ID:1-150
Get Id=200
Application
Server Node
P2→ID:151-300
S H A R E D N OT H I N G E X A M P L E
Get Id=100 Node
Get Id=200 P1→ID:1-150
Application
Server Node
P2→ID:151-300
S H A R E D N OT H I N G E X A M P L E
Node
P1→ID:1-100
Node
P3→ID:101-200
Application
Server Node
P2→ID:201-300
E A R LY D I S T R I B U T E D DATA B A S E S Y S T E M S
Gray
15-445/645 (Fall 2022)
19
DESIGN ISSUES
H O M O G E N O U S V S . H E T E RO G E N O U S
M O N G O D B H E T E RO G E N O U S A RC H I T E C T U R E
Shards (mongod)
Router
(mongos) P1 P2
Get Id=101
Router
(mongos)
⋮
P3 P4
Application
Server
Config Server P1→ID:1-100
(mongod) P2→ID:101-200
P3→ID:201-300
⋮ P4→ID:301-400
15-445/645 (Fall 2022)
22
DATA T R A N S PA R E N C Y
DATA B A S E PA RT I T I O N I N G
N A Ï V E TA B L E PA RT I T I O N I N G
N A Ï V E TA B L E PA RT I T I O N I N G
Table1
V E RT I C A L PA RT I T I O N I N G
CREATE TABLE foo (
Split a table's attributes into separate attr1 INT,
partitions. attr2 INT,
attr3 INT,
Must store tuple information to attr4 TEXT
reconstruct the original record. );
V E RT I C A L PA RT I T I O N I N G
CREATE TABLE foo (
Split a table's attributes into separate attr1 INT,
partitions. attr2 INT,
attr3 INT,
Must store tuple information to attr4 TEXT
reconstruct the original record. );
Partition #1 Partition #2
Tuple#1 attr1 attr2 attr3 Tuple#1 attr4
Tuple#2 attr1 attr2 attr3 Tuple#2 attr4
Tuple#3 attr1 attr2 attr3 Tuple#3 attr4
Tuple#4 attr1 attr2 attr3 Tuple#4 attr4
H O R I ZO N TA L PA RT I T I O N I N G
Partitioning Schemes:
→ Hashing
→ Ranges
→ Predicates
H O R I ZO N TA L PA RT I T I O N I N G
Partitioning Key
Table1 Partitions
101 a XXX 2022-11-29 hash(a)%4 = P2
102 b XXY 2022-11-28 hash(b)%4 = P4 P1 P2
103 c XYZ 2022-11-29 hash(c)%4 = P3
104 d XYX 2022-11-27 hash(d)%4 = P2
105 e XYY 2022-11-29 hash(e)%4 = P1
Ideal Query: P3 P4
SELECT * FROM table
WHERE partitionKey = ?
LO G I C A L PA RT I T I O N I N G
Node Id=1
Id=2 Storage
Get Id=1
Id=1
Id=2
Id=3
Application Id=4
Server Node
Id=3
Id=4
LO G I C A L PA RT I T I O N I N G
Node Id=1
Id=2 Storage
Id=1
Id=2
Get Id=3 Id=3
Application Id=4
Server Node
Id=3
Id=4
LO G I C A L PA RT I T I O N I N G
Node Id=1
Id=2 Storage
Id=1
Get Id=3 Id=2
Get Id=2
Id=3
Application Id=4
Server Node
Id=3
Id=4
P H Y S I C A L PA RT I T I O N I N G
Node
Id=1
Get Id=1 Id=2
Get Id=3
Application
Server Node
Id=3
Id=4
H O R I ZO N TA L PA RT I T I O N I N G
Partitioning Key
Table1 Partitions
101 a XXX 2022-11-29 hash(a)%4 = P2
102 b XXY 2022-11-28 hash(b)%4 = P4 P1 P2
103 c XYZ 2022-11-29 hash(c)%4 = P3
104 d XYX 2022-11-27 hash(d)%4 = P2
105 e XYY 2022-11-29 hash(e)%4 = P1
Ideal Query: P3 P4
SELECT * FROM table
WHERE partitionKey = ?
H O R I ZO N TA L PA RT I T I O N I N G
Partitioning Key
Table1 Partitions
101 a XXX 2022-11-29 hash(a)%5 = P4
102 b XXY 2022-11-28 hash(b)%5 = P3 P1 P2
103 c XYZ 2022-11-29 hash(c)%5 = P5
104 d XYX 2022-11-27 hash(d)%5 = P1
105 e XYY 2022-11-29 hash(e)%5 = P3
Ideal Query: P3 P4
SELECT * FROM table
WHERE partitionKey = ?
CONSISTENT HASHING
10 hash(key1)
P1
P3
P2
CONSISTENT HASHING
10 hash(key1)
P1
P3
hash(key2)
P2
CONSISTENT HASHING
10 hash(key1)
P1
P3
hash(key2)
P2
CONSISTENT HASHING
10
P1
P3 If hash(key)=P4
P2
P4
CONSISTENT HASHING
10
P5
P1
P3
P6
P2
P4
CONSISTENT HASHING
10
P5 Replication Factor = 3
P1
P3
P6
P2
P4
CONSISTENT HASHING
10 hash(key1)
P5 Replication Factor = 3
P1
P3
P6
P2
P4
CONSISTENT HASHING
10 hash(key1)
P5 Replication Factor = 3
P1
P3
P6
P2
P4
T R A N S AC T I O N C O O R D I N AT I O N
T P M O N I TO R S
C E N T R A L I Z E D C O O R D I N ATO R
Coordinator
Lock Request Partitions
P1 P2
Application
Server P3 P4
C E N T R A L I Z E D C O O R D I N ATO R
P1
Coordinator P2
Lock Request P3 Partitions
P4
P1 P2
Application
Server P3 P4
C E N T R A L I Z E D C O O R D I N ATO R
P1
Coordinator P2
Lock Request P3 Partitions
P4
Acknowledgement P1 P2
Application
Server P3 P4
C E N T R A L I Z E D C O O R D I N ATO R
P1
Coordinator P2
Commit Request P3 Partitions
P4
P1 P2
C E N T R A L I Z E D C O O R D I N ATO R
P1
Coordinator P2
Commit Request P3 Partitions
P4
Acknowledgement P1 P2
C E N T R A L I Z E D C O O R D I N ATO R
P1
Coordinator P2
Commit Request P3 Partitions
P4
Acknowledgement P1 P2
C E N T R A L I Z E D C O O R D I N ATO R
Partitions
Middleware
Commit
Query Requests
Request Safe to commit?
P1 P2
Application P1→ID:1-100
Server P2→ID:101-200 P3 P4
P3→ID:201-300
P4→ID:301-400
D E C E N T R A L I Z E D C O O R D I N ATO R
Application
Server P3 P4
D E C E N T R A L I Z E D C O O R D I N ATO R
P1 P2
Query Request
Application
Server P3 P4
D E C E N T R A L I Z E D C O O R D I N ATO R
Safe to commit?
Application
Server P3 P4
D I S T R I B U T E D C O N C U R R E N C Y C O N T RO L
DISTRIBUTED 2PL
A=1 B=8
NETWORK
Node 1 Node 2
15-445/645 (Fall 2022)
59
DISTRIBUTED 2PL
A=2
A=1 B=7
B=8
NETWORK
Node 1 Node 2
15-445/645 (Fall 2022)
59
DISTRIBUTED 2PL
A=2
A=1 B=7
B=8
NETWORK
Node 1 Node 2
15-445/645 (Fall 2022)
59
DISTRIBUTED 2PL
Waits-For Graph
A=2
A=1 B=7
B=8
NETWORK
Node 1 Node 2
15-445/645 (Fall 2022)
63
CONCLUSION
P RO J E C T # 4 – C O N C U R R E N C Y C O N T RO L
P RO J E C T # 3 – TA S K S
Lock Manager
→ Maintain internal lock table and queues.
→ Track the growing/shrinking phases of txns.
→ Notify waiting txns when their locks are available.
Deadlock Detector:
→ Build the waits-for graph and deterministically identify
what txn to kill off to break deadlocks
Execution Engine
→ Modify Project #3 executors to support txn requests.
15-445/645 (Fall 2022)
66
P RO J E C T # 3 - L E A D E R B OA R D
Tasks:
→ UpdateExecutor
→ Predicate Pushdown
T H I N G S TO N OT E
P L AG I A R I S M WA R N I N G
NEXT CLASS