HBase:HBase and Schema Design

1.声明

当前内容主要用于本人学习和复习,当前内容主要为官方文档的HBase and Schema Design的翻译和理解

2.Schema Creation

HBase schemas can be created or updated using the The Apache HBase Shell or by using Admin in the Java API.
Tables must be disabled when making ColumnFamily modifications, for example:

HBase Schemas可以通过Apache HBase Shell或者使用Java API中的Admin.

修改列族的时候应该先禁用当前的表,例如:

public class SchemaCreationTest {
	private static String tableName = "myTest";

	@SuppressWarnings("deprecation")
	public static void main(String[] args) throws IOException {
		Configuration conf = HBaseConfiguration.create();
		conf.set("hbase.zookeeper.quorum", "192.168.1.107:2181");
		Connection conn = ConnectionFactory.createConnection(conf);
		Admin admin = conn.getAdmin();
		TableName table = TableName.valueOf("myTable");
		admin.disableTable(table);
		HColumnDescriptor cf1 = new HColumnDescriptor("cf1");
		admin.addColumn(table, cf1); // adding new ColumnFamily
		HColumnDescriptor cf2 = new HColumnDescriptor("cf2");
		admin.modifyColumn(table, cf2); // modifying existing ColumnFamily
		admin.enableTable(table);
		HTableDescriptor tableDescriptor = admin.getTableDescriptor(table);
		System.out.println(tableDescriptor.getColumnFamilyNames());
		admin.close();
		conn.close();
	}
}

当前的代码中myTest是一个已经存在的表并且具有字段cf2(这里的代码是修复后的代码)

3.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 store for more information on StoreFiles.

当我们修改这个表或者列族的时候(例如区域大小、块大小),这些改变将在下次压缩并重新写入存储文件时生效

也就是说:每次修改表和列族时(不写入存储文件),只有下次压缩才会写入存储文件中

4.总结

1.从上面的内容分析得到,修改表和列族的时候,首先应该禁用表,使用时启用表

=2.每次修改表或者列族时,是在下次才会写入存储文件中

以上纯属个人见解,如有问题请联本人!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章