Transactions in HBase
Andreas Neumann
ApacheCon Big Data May 2017 anew at apache.org @caskoid
Transactions in HBase Andreas Neumann anew at apache.org ApacheCon - - PowerPoint PPT Presentation
Transactions in HBase Andreas Neumann anew at apache.org ApacheCon Big Data May 2017 @caskoid Goals of this Talk - Why transactions? - Optimistic Concurrency Control - Three Apache projects: Omid, Tephra, Trafodion - How are they different?
ApacheCon Big Data May 2017 anew at apache.org @caskoid
2
History
Motivation:
3
4
HBase Table
...
Queue
... ...
Flowlet
... ...
HBase Table
...
Queue
... ...
Flowlet
... ...
5
6
HBase Table
...
Queue
... ...
Flowlet
From good old SQL:
7
8
Client Region Server
Region Region
Coprocessor
Region Server
Region Region
Coprocessor
9
Simplified:
How to implement full ACID?
10
11
12
time x=10 client1: start fail/rollback client2: start read x commit must see the
13
time incr x client1: start commit client2: start incr x commit x=10 rollback x=11 sees the old value of x=10
14
time tx:A tx:B tx:C (A fails) tx:D (A fails) tx:E (E fails) tx:F (F fails) tx:G
15
16
Apache Omid (incubating) (incubating) (incubating)
17
Daniel Gómez Ferro, Flavio Junqueira, Ivan Kelly, Benjamin Reed, Maysam Yabandeh: Omid: Lock-free transactional support for distributed data stores. ICDE 2014.
18
19
in progress
start new tx write to HBase
aborting
conflicts
invalid
failure roll back in HBase
time
detect conflicts
complete
make visible
when they do not overlap with in-flight tx
20
Tx Manager Client A
Region Server
x:10 37 write x=11 x:11 42
Region Server
write: y=17 y:17 42 in-flight: … start() id: 42, excludes = {…} ,42
21
Tx Manager
read x
Client B
x:10
Region Server
x:10 37 x:11 42
Region Server
y:17 42 in-flight: …,42 start() id: 48, excludes = {…,42} ,48
Region Server
Region Server
x:10 37 y:17 42
22
Tx Manager Client A
x:11 42 roll back commit() conflict x:10 37 in-flight: …,42 in-flight: … make visible
23
Region Server
x:10 37 x:11 42
Region Server
y:17 42 read x x:11
Tx Manager Client A
in-flight: …,42 commit() success in-flight: …
Client C
start() id: 52, excludes: {…} in-flight: …,52
24
Client Region Server
Region Region
Coprocessor
Region Server
Region Region
Coprocessor
Tx Manager
Tx id generation Tx lifecycle rollback Tx state lifecycle transitions data
25
txTable = new TransactionAwareHTable(table); txContext = new TransactionContext(txClient, txTable); txContext.start(); try { // perform Hbase operations in txTable txTable.put(…); ... } catch (Exception e) { // throws TransactionFailureException(e) txContext.abort(e); } // throws TransactionConflictException if so txContext.finish();
26
27
28
29
(incubating)
30
31
Tx Manager Client A
Region Server
x:10
Region Server
in-flight: … start() id:42 ,42 write: y=17 y:17 write x=11 x:11 region: … ,42
32
Tx Manager
read x
Client B
x:10 in-flight: …,42 start() id: 48 ,48
Region Server
x:10
Region Server
x:11 y:17
33
Tx Manager Client A
commit() in-flight: …,42 in-flight: …
Region Server
x:10
Region Server
x:11 y:17
34
Tx Manager Client A
commit() in-flight: …,42 in-flight: …
Region Server
x:10
Region Server
x:11 y:17
x:11 y:17
35
Client Region Server
Region Region
Coprocessor
Region Server
Region Region
Coprocessor
Tx Manager
Tx id generation conflicts Tx state Tx life cycle (commit) transitions region ids 2-phase commit data
Tx lifecycle In-flight data
Client 2 Tx 2 Manager
36
37
38
Daniel Peng, Frank Dabek: Large-scale Incremental Processing Using Distributed Transactions and Notifications, USENIX 2010.
39
40
41
Tx Manager Client A
start() id: 42
Region Server
x:10 37: commit.40 write x=11 x:11 42: in-flight
Region Server Commits
37: 40 write: y=17 y:17 42: in-flight
42
Tx Manager
start() id: 48 read x
Client B
x:10
Region Server
x:10 37: commit.40 x:11 42: in-flight
Region Server
y:17
Commits
37: 40 42: in-flight
Region Server
Region Server
x:10 37: commit.40 y:17 42: in-flight
43
Tx Manager Client A Commits
37: 40 x:11 42: in-flight roll back commit() conflict x:10 37: commit.40
44
Region Server Tx Manager Client A Client C
start() id: 52 x:10 37: commit.40 x:11 42: in-flight
Region Server
y:17
Commits
37: 40 42: in-flight mark as committed 42: commit.50 42: commit.50 read x x:11 commit() success:50 42: 50
45
Region Server
x:10 37: commit.40 x:11 42: in-flight
Region Server Commits
37: 40 y:17
46
Client Region Server
Region Region
Coprocessor
Region Server
Region Region
Coprocessor
Tx Manager
Tx id generation Conflict detection start commit data
+ shadow cells Tx state Tx lifecycle rollback commit commit table
47
48
49
Apache Tephra Apache Trafodion Apache Omid Tx State Tx Manager Distributed to region servers Tx Manager (changes) HBase (shadows/commits) Conflict detection Tx Manager Distributed to regions, 2- phase commit Tx Manager ID generation Tx Manager Distributed to multiple Tx Managers Tx Manager API HTable SQL Custom Multi-tenant Yes Yes No Strength Scans, Large Tx, API Scalable, full SQL Scale, throughput So so Scale, Throughput API not Hbase, Large Tx Scans, Producer/Consumer
Join the community:
50
Apache Omid (incubating) http://omid.apache.org/ (incubating) http://trafodion.apache.org/ (incubating) http://tephra.apache.org/
… for listening to my talk. Credits:
51