DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. Recreating an HBase Table Without Violating Region Starting Keys

Recreating an HBase Table Without Violating Region Starting Keys

Adam Kawa user avatar by
Adam Kawa
·
Oct. 15, 12 · Interview
Like (0)
Save
Tweet
Share
5.90K Views

Join the DZone community and get the full member experience.

Join For Free

Recently, I was using completebulkload to load a large amount of data into HBase. To keep this process well-balanced over the entire cluster (and thus faster), I was loading data into a table with pre-created regions. Since my bulkloading process failed in the middle a couple of times (due to some misconfiguration), I needed to truncate the table over and over.

I have noticed that a command like

hbase(main):017:0> truncate 'table'

will disable, drop and recreate the table with the same name settings (number of column familiers, compression, ttl, blocksize etc), but it does not maintain the region boundaries. It means that if you have a table with some number of regions and then truncate it, the table will be recreated with a single one region e.g.

hbase(main):018:0> create 't1', 'f1', {SPLITS => ['10', '20', '30', '40']}
hbase(main):019:0> truncate 't1'
Truncating 't1' table (it may take a while):
 - Disabling table...
 - Dropping table...
 - Creating table...

If you look at http://${hbase-master}:60010/table.jsp?name=t1, you will find that truncating makes table t1 empty and reduces the number of regions to single one.

Actually, I needed a functionality to truncate a table, but not violate the region and their starting keys (since I have choosen them so carefully earlier to balance the load over all region servers). I've implemented simple script for this purpose:

include Java
 
import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.hbase.client.HBaseAdmin
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.HTableDescriptor
 
table_name = ARGV[0]
 
table = HTable.new(table_name)
region_start_keys = table.getStartKeys()
table.close()
 
admin = HBaseAdmin.new(Configuration.new())
table_descriptor = admin.getTableDescriptor(Bytes.toBytes(table_name))
admin.disableTable(table_name)
admin.deleteTable(table_name)
admin.createTable(table_descriptor, region_start_keys)

You may use it in the following day:

$ hbase org.jruby.Main region-keys.rb t1

The table should be successfully recreated with the same region boundaries, so that it will look the same as before, but it will be empty.

Database

Published at DZone with permission of Adam Kawa, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • AWS Cloud Migration: Best Practices and Pitfalls to Avoid
  • Stream Processing vs. Batch Processing: What to Know
  • A Real-Time Supply Chain Control Tower Powered by Kafka
  • Memory Debugging: A Deep Level of Insight

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: