Relaxed Transactions for HBaseFrancis Liu, Software Engineer
5/22/12
Mutable Data
Writes are effective immediately
Mutable Data
Writes are effective immediately
Mutable Data
Partial writes in the midst of failures
Mutable Data
Partial writes in the midst of failures
Revision Manager
Optimized for batch processing› Large number of writes (ie Data Ingestion, Batch
updates)
Cross row write transactions within a table Coprocessor Endpoint› Leverage HBase Security
Zookeeper for persistence› table revision information
Experimental feature in Hcatalog 0.4
Architecture
API
For reads› RevisionManager.createSnapshot(tableName)› SnapshotFilter.filter(result)
For writes› RevisionManager.beginWriteTransaction(table, families)› RevisionManager.commitWriteTransaction(transaction)› RevisionManager.abortWriteTransaction(transaction)
Concepts
Revision› Monotonically increasing number› All “Puts” of a job are written with the same revision number as the cell
version
TableSnapshot› Point-in-time consistent view of a table› Used for reading› Latest committed revision› List of aborted revisions› Upper bound on visible revision per CF
Transaction› Write transaction› Revision Number› List of column Families being written to
Relaxed Transaction Properties
Immutable Input Change After Commit Precedence Preservation
Immutable Input
Change After Commit
Revisions are only viewable after commit› A job cannot see it’s own writes
Aborted revisions are added to a table’s aborted list
Timed out revisions are aborted
Change After Commit
Precedence Preservation
Snapshot Isolation› Transaction is aborted when a write conflict is detected
Conflicts› Concurrent transactions to the same Column Family › Inefficient to abort
Resolved during read time• For every CF– find: min_rev = min(active_revision)– Only return closest revision to min_rev
• min_rev is what’s stored in a snapshot
Precedence Preservation
Snapshot Filter
Consumes TableSnapshot Read time filtering› Aborted revisions› Revisions written after snapshot was taken› Conflicting/Blocked revisions
Flow - Read
User/Client› RevisionManager.createSnapshot()
• TableSnapshot instance is serialized into JobConf
RecordReader› Using SnapshotFilter.filter(result)
Flow - Read
Flow - Write
User/Client› HBaseOutputFormat.checkOutputSpecs(FileSystem, JobConf)
• Write transaction is started by calling beginWriteTransaction(Transaction)
• Transaction instance is serialized into JobConf
RecordWriter› Puts make use of the revision number as the version
OutputCommitter› OutputCommitter.commitJob(JobContext)
• RevisionManager.commitWriteTransaction(Transaction)
› OutputCommitter.abortJob(JobContext)
• RevisionManager.abortWriteTransaction(Transaction)
Usage
Using HCatalog Revision Manager usage is done under the covers.
Work is being done to decouple HCatalog from HBaseInputFormat/HBaseOutputFormat
Other frameworks can make use of the RevisionManager API
Usage: HCatalog
Create Table
hcat –e “create table my_table(key string, gpa string) STORED BY 'org.apache.hcatalog.hbase.HBaseHCatStorageHandler' TBLPROPERTIES ('hbase.columns.mapping'=':key,info:gpa');”
Using Pig
A = LOAD ‘table1’ USING org.apache.hcatalog.pig.HCatLoader();
STORE A INTO ‘table1’ USING org.apache.hcatalog.pig.HCatStorer();
Using MapReduce
HCatInputFormat.setInput(job,…)
HCatOutputFormat.setOutput(job,…)
Future Work
Compaction of aborted transactions Server-side filtering using HBase Filters Compatibility with Hive
Further Info
[email protected] http://incubator.apache.org/hcatalog/ [email protected]
Questions?