问题1
在网上找到的一些API有些是已经过期的,虽然可以用,但弃用了还是有原因的。比如HTableDescriptor
?对于已经弃用的类或方法,点new后面的构造器 进去看源码,可以看到注释说明该方法有bug,并附上链接,可以自己选择要不要看一下哈。
/**
* Construct a table descriptor specifying a TableName object
* @param name Table name.
* @see <a href="https://issues.apache.org/jira/browse/HBASE-174">HADOOP-1581 HBASE: (HBASE-174) Un-openable tablename bug</a>
*/
public HTableDescriptor(final TableName name) {
this(new ModifyableTableDescriptor(name));
}
弃用了肯定有更好的替代方案,发现这里并没有说明该用什么,点击类查看源码,可以看到弃用的时间和代替方案
/**
* HTableDescriptor contains the details about an HBase table such as the descriptors of
* all the column families, is the table a catalog table, <code> hbase:meta </code>,
* if the table is read only, the maximum size of the memstore,
* when the region split should occur, coprocessors associated with it etc...
* @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0.
* Use {@link TableDescriptorBuilder} to build {@link HTableDescriptor}.
*/
@Deprecated
@InterfaceAudience.Public
public class HTableDescriptor implements TableDescriptor, Comparable<HTableDescriptor> {}
替换使用就好了,这里的tableName根据入参提示可以知道可以这样获得
TableName.valueOf(myTableName);
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName);
问题2
代码整完启动测试,发现有一个DEBUG信息,参考微博https://blog.csdn.net/houyefeng/article/details/41455385解决了该问题
11:43:26.194 [main] DEBUG org.apache.hadoop.util.Shell - Failed to detect a valid hadoop home directory
java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset.
at org.apache.hadoop.util.Shell.checkHadoopHomeInner(Shell.java:468)
at org.apache.hadoop.util.Shell.checkHadoopHome(Shell.java:439)
at org.apache.hadoop.util.Shell.<clinit>(Shell.java:516)
at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:79)
at org.apache.hadoop.conf.Configuration.getBoolean(Configuration.java:1691)
at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:70)
at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:84)
at org.apache.hadoop.hbase.HBaseConfiguration.create(HBaseConfiguration.java:98)
at com.sprucetec.crm.sales.business.manager.hbase.HbaseHandleManager.init(HbaseHandleManager.java:41)
at com.sprucetec.crm.sales.business.manager.hbase.HbaseHandleManager.main(HbaseHandleManager.java:139)
?问题3
Exception in thread "main" org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException: org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException: Column family table does not exist in region hbase:meta,,1.1588230740 in table 'hbase:meta', {TABLE_ATTRIBUTES => {IS_META => 'true', coprocessor$1 => '|org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint|536870911|'}, {NAME => 'info', BLOOMFILTER => 'NONE', VERSIONS => '3', IN_MEMORY => 'true', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', CACHE_DATA_IN_L1 => 'true', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '8192', REPLICATION_SCOPE => '0'}
at org.apache.hadoop.hbase.regionserver.HRegion.checkFamily(HRegion.java:8298)
at org.apache.hadoop.hbase.regionserver.HRegion.get(HRegion.java:7306)
at org.apache.hadoop.hbase.regionserver.RSRpcServices.get(RSRpcServices.java:2259)
at org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$2.callBlockingMethod(ClientProtos.java:36609)
at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:2354)
at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:124)
at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:297)
at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:277)
百度说是客户端使用的hbase_client版本高于服务器上使用的版本,从2.4.3改为1.4.13后,问题解决。
问题4
14:53:51.138 [hconnection-0x2ea6137-shared--pool3-t1] INFO org.apache.hadoop.hbase.client.AsyncProcess - #2, table=student, attempt=10/35 failed=1ops, last exception: org.apache.hadoop.hbase.NotServingRegionException: org.apache.hadoop.hbase.NotServingRegionException: Region student,,1587529378578.372b6f111e379a856f5caf9b7b39bf85. is not online on dev03,16020,1629084516977
at org.apache.hadoop.hbase.regionserver.HRegionServer.getRegionByEncodedName(HRegionServer.java:3081)
at org.apache.hadoop.hbase.regionserver.RSRpcServices.getRegion(RSRpcServices.java:1271)
at org.apache.hadoop.hbase.regionserver.RSRpcServices.multi(RSRpcServices.java:2365)
at org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$2.callBlockingMethod(ClientProtos.java:36621)
at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:2354)
at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:124)
at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:297)
at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:277)
这个没解决,自己好了,没在遇见了,遇见再说
Hbase Client常用的一些命令
登录服务器
登录 输入密码
进入到hbase安装目录,进入bin目录(find / -name hbase 这样可以找到的安装目录)
cd /data/hbase_src/hbase-1.4.6/bin
进入Hbase Client
hbase shell
然后可以正常操作了,下面是常用命令
list 查看所有表
create 'student','score' 创建列族为score的student1表
put 'student','zhangsan','score:Java','99' 插入一条记录到表student,表名、rowkey、列族、列限定符、时间戳(时间戳这里忽略,可以详细了解,还有点东西)确定一行数据
count 'student' 查看表中有多少条数据
get 'student','zhangsan' 获取数据,可以只根据表名和rowkey进行查询,也可以更详细
disable 'student' 禁用表,删除(drop)表的充分条件
drop 'student' 删除表
时间关系就先不贴代码了,有时间在补
|