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.每次修改表或者列族时,是在下次才会写入存储文件中

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值