(Limited) crossrowtransactionsinHBase

Source: Internet
Author: User
Forbidden. thisachievedbyco-locatingallcellswiththesamerow-key (seeintroduction-to-hbase) inthesameregion. Thekeyobservationisthatallthatisrequiredfor

Atomic operations in HBase are currently limited to single row operations. this is achieved by co-locating all cells with the same row-key (see introduction-to-hbase) in the same region. the key observation is that all that is required

Atomic operations in HBase are currently limited to single row operations. This is achieved by co-locating all cells with the same row-key (see introduction-to-hbase) in the same region.

The key observation is that all that is required for atomic operations are co-located cells.

HBASE-5304 allows defining more flexible RegionSplitPolicies (note Javadoc is not yet updated, so this link leads to nowhere right now ).
HBASE-5368 provides an example (KeyPrefixRegionSplitPolicies) that co-locates cells with the same row-key- PrefixIn the same region.
By choosing the prefix smartly, useful ranges of rows can be co-located together. Obviously one needs to be careful, as regions cannot grow without bounds.

HBASE-5229 finally allows cross row atomic operations over multiple rows as long as they are co-located in the same region.
This is a developer-only feature and only accessible through coprocessor endpoints. However, HBASE-5229 also includes an endpoint that can be used directly.

An example can be setup as follows:
1. add this to hbase-site.xml:

Hbase. coprocessor. user. region. classes
Org. apache. hadoop. hbase. coprocessor. MultiRowMutationEndpoint


This loads the necessary coprocessor endpoint into all regions of all user tables.

2. Create a table that uses KeyPrefixRegionSplitPolicy:
HTableDescriptor myHtd = new HTableDescriptor ("myTable"); myHtd. setValue (HTableDescriptor. SPLIT_POLICY,
KeyPrefixRegionSplitPolicy. class. getName ());
// Set the prefix to 3 in this example
MyHtd. setValue (KeyPrefixRegionSplitPolicy. PREFIX_LENGTH_KEY,
String. valueOf (3 ));

HColumnDescriptor hcd = new HColumnDescriptor (...);
MyHtd. addFamily (hcd );

HBaseAdmin admin = ...;

Admin. createTable (myHtd );

Regions of "myTable" are now split according to KeyPrefixRegionSplitPolicy with a prefix of 3.


3. Execute an atomic multirow transaction:

List MS = new ArrayList ();
Put p = new Put (Bytes. toBytes ("xxxabc "));

...
Ms. add (p );
Put p1 = new Put (Bytes. toBytes ("xxx123 "));

...

Ms. add (p1 );
Delete d = new Delete (Bytes. toBytes ("xxxzzz "));

...

Ms. add (d );
// Get a proxy for MultiRowMutationEndpoint
// Note that the passed row is used to locate
// Region. Any of the other row keys cocould have
// Been used as well, as long as they identify
// The same region.
MultiRowMutationProtocol mr = t. coprocessorProxy (
MultiRowMutationProtocol. class,
Bytes. toBytes ("xxxabc "));
// Perform the atomic operation
Mr. mutateRows (MS );

Update, Saturday, February 18,201 2:
In fact using just "xxx" in the call to get the coprocessorProxy wocould be correct as well, since it identifies he same region. "xxx" cocould be considered"Partition"Key.

That's it... The two puts and the delete are executed atomically, even though these are different rows.
KeyPrefixRegionSplitPolicy ensures that the three rows are co-located, because they share the same 3-byte prefix.
If any of the involved row-keys is located in a different region, the operation will fail, the client will not try again.
Again, care must be taken to pick a useful prefix length for co-location here, or regions will grow out of bounds, or at least be very skewed in size.

This feature is useful in certain multi-tenant setups, or for time-based data sets (for example the split boundaries cocould be set to whole hours, or days ).

Original article address: (limited) cross row transactions in HBase. Thank you for sharing it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.