HBase 学习一: 客户端写缓冲区 autoFlush

时间:2025-03-02 08:47:54

 更多内容,请访问 

HBase的表操作,默认情况下客户端写缓冲区是关闭的,即() = true, 这种情况下,对表的单行操作会实时发送到服务端完成。

因此,对于海量数据插入,修改,RPC通信频繁,效率比较低。这种场景下,可以通过激活客户端缓冲区,批量提交操作请求,提高操作效率。

 

下面是一个简单的关于autoFlush的测试代码:

 

 

	public static void autoFlushTest(){
		HTable table;
		
		try {
			table = new HTable(conf, "test3");
			
			//默认是不激活,实时提交服务端处理请求.
			("=====auto flush:" + ());  
			
			if (())
				(false);    //激活缓冲区
			
			("=====auto flush2:" + ());
			
			
			Put put = new Put(("r1"));
			
			(("colf2"), ("q1"), ("v3"));
			(("colf2"), ("q2"), ("v4"));
			
			(put);
			
			// 当setAutoFlush=false时,只有当缓冲区满或调用()时
			// 或调用()时
			//客户端才会将table操作提交服务端执行。
			
			//();
			();
			
			("=====auto flush4:" + ());
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			();
		}
		
	}

缺点是如果程序崩溃,在缓冲区内的数据将会丢失,无法完成表操作。