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.每次修改表或者列族時,是在下次纔會寫入存儲文件中

以上純屬個人見解,如有問題請聯本人!

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