Chapter 6. HBase and Schema Design

Table of Contents

6.1. Schema Creation
6.1.1. Schema Updates
6.2. On the number of column families
6.2.1. Cardinality of ColumnFamilies
6.3. Rowkey Design
6.3.1. Hotspotting
6.3.2. Monotonically Increasing Row Keys/Timeseries Data
6.3.3. Try to minimize row and column sizes
6.3.4. Reverse Timestamps
6.3.5. Rowkeys and ColumnFamilies
6.3.6. Immutability of Rowkeys
6.3.7. Relationship Between RowKeys and Region Splits
6.4. Number of Versions
6.4.1. Maximum Number of Versions
6.4.2. Minimum Number of Versions
6.5. Supported Datatypes
6.5.1. Counters
6.6. Joins
6.7. Time To Live (TTL)
6.8. Keeping Deleted Cells
6.9. Secondary Indexes and Alternate Query Paths
6.9.1. Filter Query
6.9.2. Periodic-Update Secondary Index
6.9.3. Dual-Write Secondary Index
6.9.4. Summary Tables
6.9.5. Coprocessor Secondary Index
6.10. Constraints
6.11. Schema Design Case Studies
6.11.1. Case Study - Log Data and Timeseries Data
6.11.2. Case Study - Log Data and Timeseries Data on Steroids
6.11.3. Case Study - Customer/Order
6.11.4. Case Study - "Tall/Wide/Middle" Schema Design Smackdown
6.11.5. Case Study - List Data
6.12. Operational and Performance Configuration Options

A good general introduction on the strength and weaknesses modelling on the various non-rdbms datastores is Ian Varley's Master thesis, No Relation: The Mixed Blessings of Non-Relational Databases. Recommended. Also, read Section 9.7.7.6, “KeyValue” for how HBase stores data internally, and the section on Section 6.11, “Schema Design Case Studies”.

6.1.  Schema Creation

HBase schemas can be created or updated with Chapter 4, The Apache HBase Shell or by using HBaseAdmin in the Java API.

Tables must be disabled when making ColumnFamily modifications, for example:

Configuration config = HBaseConfiguration.create();
HBaseAdmin admin = new HBaseAdmin(conf);
String table = "myTable";

admin.disableTable(table);

HColumnDescriptor cf1 = ...;
admin.addColumn(table, cf1);      // adding new ColumnFamily
HColumnDescriptor cf2 = ...;
admin.modifyColumn(table, cf2);    // modifying existing ColumnFamily

admin.enableTable(table);
    

See Section 2.4.4, “Client configuration and dependencies connecting to an HBase cluster” for more information about configuring client connections.

Note: online schema changes are supported in the 0.92.x codebase, but the 0.90.x codebase requires the table to be disabled.

6.1.1. Schema Updates

When changes are made to either Tables or ColumnFamilies (e.g., region size, block size), these changes take effect the next time there is a major compaction and the StoreFiles get re-written.

See Section 9.7.7, “Store” for more information on StoreFiles.

comments powered by Disqus