设为首页 加入收藏

TOP

HBase写入操作卡住长时间不返回的原因分析(一)
2015-07-24 11:10:42 来源: 作者: 【 】 浏览:1
Tags:HBase 写入 操作 卡住 时间 返回 原因分析

这些天研究HBase,写了一段Demo代码,具体如下:

?

@Test
public void doTest() throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
	Configuration config = HBaseConfiguration.create();
	config.set(zkSetKey, zkConn);
	HBaseAdmin hBaseAdmin = null;
	try{
		hBaseAdmin = new HBaseAdmin(config);
		ClusterStatus clusterStatus = hBaseAdmin.getClusterStatus();
		ServerName master = clusterStatus.getMaster();
		log.info("Master主机:{},端口号:{}", master.getHostname(), master.getPort());
		Collection servers = clusterStatus.getServers();
		for (ServerName serverName : servers) {
			log.info("Region主机{},端口号:{}", serverName.getHostname(), serverName.getPort());
		}
		HTableDescriptor targetTableDesc = null;
		try{
			targetTableDesc = hBaseAdmin.getTableDescriptor(TableName.valueOf(tableName));
			log.info("表已经存在,显示信息");
			log.info("属性:{}", targetTableDesc.toString());
		}catch(TableNotFoundException notFound){
			log.info("表不存在,创建");
			HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
			HColumnDescriptor hcd_info = new HColumnDescriptor("info");
			hcd_info.setMaxVersions(3);
			HColumnDescriptor hcd_data = new HColumnDescriptor("data");
			htd.addFamily(hcd_info);
			htd.addFamily(hcd_data);
			hBaseAdmin.createTable(htd);
			log.info("创建成功");
			targetTableDesc = hBaseAdmin.getTableDescriptor(TableName.valueOf(tableName));
			log.info("属性:{}", targetTableDesc.toString());
		}
		TableName[] listTableNames = hBaseAdmin.listTableNames();
		if (listTableNames == null){
			log.info("无表");
		}else{
			for (TableName tableName : listTableNames) {
				log.info("表名:{}", tableName.getNameAsString());
			}
		}
	}finally{
		IOUtils.closeQuietly(hBaseAdmin);
		log.info("结束");
	}
}
运行这段代码,程序会卡在第28行不动,也就是创建表操作,并且没有报出任何异常,其它的读取操作却很快(例如获取集群状态、列出所有表等操作)。于是本人陷入了深深地思考……

?

在CSDN找到了一种类似的情况:http://blog.csdn.net/lxpbs8851/article/details/8287471

主要是说HBase所依赖的HDFS进入了安全模式,需要手动退出该模式(运行命令:hdfs dfsadmin -safemode leave)。可是我查询当前的HDFS安全模式状态(hdfs dfsadmin -safemode get)时得到的信息是:Safe mode is OFF,也就是说根本没在安全模式下。

?

后来偶然地过了一段时间再去看日志发现如下信息:

?

#1, waiting for some tasks to finish. Expected max=0, tasksSent=9, tasksDone=8, currentTasksDone=8, retries=8 hasError=false, tableName=demo_table
#1, waiting for some tasks to finish. Expected max=0, tasksSent=10, tasksDone=9, currentTasksDone=9, retries=9 hasError=false, tableName=demo_table
#1, table=demo_table, attempt=10/35 failed 1 ops, last exception: java.net.UnknownHostException: unknown host: admin.demo.com on admin.demo.cn,5020,1426211698289, tracking started Fri Mar 13 11:41:19 CST 2015, retrying after 10037 ms, replay 1 ops.

?

最后一行的主机名:admin.demo.com和admin.demo.cn引起了我的注意。因为我的测试环境为3台实体服务器,配置如下:

?

IP地址 hosts文件配置的主机名 linux系统的hostname HBase角色 HDFS角色
192.168.1.21 hd-21 test-21 MasterServer NameNode、DataNode、ZooKeeper
192.168.1.22 hd-22 test-22 RegionServer NameNode、DataNode、ZooKeeper
192.168.1.23 hd-23 test-23 RegionServer DataNode、ZooKeeper
另外,因为是测试环境,在192.168.1.22这台机器上还添加了如下hosts信息:

?

?

192.168.1.22 admin.demo.com
192.168.1.22 admin.demo.cn
简单来说就是hosts文件中配置的主机名和真实主机名不一致,并且还加入了额外的hosts配置信息干扰到
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇文章标题多表查询:合并结果集,.. 下一篇DDL_LOCK_TIMEOUT的作用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·数据库:推荐几款 Re (2025-12-25 12:17:11)
·如何最简单、通俗地 (2025-12-25 12:17:09)
·什么是Redis?为什么 (2025-12-25 12:17:06)
·对于一个想入坑Linux (2025-12-25 11:49:07)
·Linux 怎么读? (2025-12-25 11:49:04)