memstoreFlushSize是什么呢?
memstoreFlushSize为HRegion上设定的一个阈值,当MemStore的大小超过这个阈值时,将会发起flush请求。
它的计算首先是由Table决定的,即每个表可以设定自己的memstoreFlushSize,通过关键字MEMSTORE_FLUSHSIZE来设定,
如果表中未设定,则取参数hbase.hregion.memstore.flush.size,
如果参数再无配置的话,则默认为1024*1024*128L,即128M。
★HBase版本:1.3.1
源码内容:
void setHTableSpecificConf() {
if (this.htableDescriptor == null) return;
long flushSize = this.htableDescriptor.getMemStoreFlushSize(); if (flushSize <= 0) {
flushSize = conf.getLong(HConstants.HREGION_MEMSTORE_FLUSH_SIZE,
HTableDescriptor.DEFAULT_MEMSTORE_FLUSH_SIZE);
}
this.memstoreFlushSize = flushSize;
this.blockingMemStoreSize = this.memstoreFlushSize *
conf.getLong(HConstants.HREGION_MEMSTORE_BLOCK_MULTIPLIER,
HConstants.DEFAULT_HREGION_MEMSTORE_BLOCK_MULTIPLIER);
}
那么,如何设置table的memstoreFlushSize呢?这里选择了在通过java api创建表的时候进行设置。代码样例:
package api; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; public class create_table_sample1 {
public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "192.168.6.3,192.168.6.4,192.168.6.5");
Connection connection = ConnectionFactory.createConnection(conf);
Admin admin = connection.getAdmin(); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf("TEST1"));
desc.setMemStoreFlushSize(2097152L); //2M(默认128M) HColumnDescriptor family1 = new HColumnDescriptor(constants.COLUMN_FAMILY_DF.getBytes());
family1.setTimeToLive(2 * 60 * 60 * 24); //过期时间
family1.setMaxVersions(2); //版本数
desc.addFamily(family1);
HColumnDescriptor family2 = new HColumnDescriptor(constants.COLUMN_FAMILY_EX.getBytes());
family2.setTimeToLive(3 * 60 * 60 * 24); //过期时间
family2.setMaxVersions(3); //版本数
desc.addFamily(family2); try {
admin.createTable(desc);
} catch (Exception e) {
e.printStackTrace();
}
admin.close();
connection.close();
}
}
通过hbase shell也许也可以设置,不过没有试验过。
--END--