standalone hbase(0.94)에서 table create하다가 hang 발생한 경우를 해결한 사례이다.


create 'xxxx', { NAME => 'c', BLOOMFILTER => 'ROWCOL', VERSIONS => '1', COMPRESSION => 'GZ', TTL => '-1', BLOCKCACHE => 'false'}

(hang)



/var/log/hbase에서 다음 로그가 남겨졌다.



ERROR org.apache.hadoop.hbase.master.handler.CreateTableHandler: Error trying to create the table nfeeds

java.io.IOException: Exception in renameDirForFileSystem

        at org.apache.hadoop.hbase.HBaseFileSystem.renameDirForFileSystem(HBaseFileSystem.java:161)

        at org.apache.hadoop.hbase.master.handler.CreateTableHandler.handleCreateTable(CreateTableHandler.java:184)

        at org.apache.hadoop.hbase.master.handler.CreateTableHandler.process(CreateTableHandler.java:127)

        at org.apache.hadoop.hbase.executor.EventHandler.run(EventHandler.java:175)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

        at java.lang.Thread.run(Thread.java:745)



원인은 hbase 디렉토리에 동일한 테이블의 이름을 가진 디렉토리가 있는데, 특정 이유(권한 또는 기타 등등) rename이 되지 않으면서 에러가 발생한다. 수동으로 작업한다.


cd /tmp/hbase-hbase/hbase

rm -rf xxxx/



다시 table 생성을 시도하지만 생성되지 않는다. zookeeper에 테이블 정보가 남아 있다. zk에서 해당 테이블을 삭제한다. 


[zk: 장비:2181(CONNECTED) 4] ls /hbase/table

[xxxx]

[zk: 장비:2181(CONNECTED) 4] delete /hbase/table/xxxx



다시 table 생성을 시도하지만 생성되지 않는다. hbase 내부 캐시가 있는 듯 하다. 재시작한 후, 테이블 생성을 할 수 있었다.


sudo service hbase-master restart 



Posted by '김용환'
,

[hbase] rowkey 검색하기

hbase 2016. 12. 15. 17:54


hbase 테이블에서 검색 필터를 사용해 특정 rowkey를  검색할 수 있다.



필터 타입은 아래 링크에 있다. 

https://www.cloudera.com/documentation/enterprise/latest/topics/admin_hbase_filtering.html 



예시는 다음과 같다. 

scan '.META.',{FILTER=>"PrefixFilter('feed')"}


scan 'xxxx', {COLUMNS => ['f'], FILTER => "SingleColumnValueFilter('abc','drug',=,'binary:avil')",STARTROW => "1000", ENDROW => "2000"}




만약 모든 rowkey를 얻으려면 다음 커맨드를 사용한다. 


count '.META.', { INTERVAL => 1 }

Posted by '김용환'
,



테스트용으로 사용하는 오래된 cloudera hbase 0.94와 apache phoenix 3.2를 연동하려 했지만, 실패한 내용을 적는다. 


추후 기회가 오면 최신 버전으로 다양하게 테스트를 잘 하는 것이 좋을 것 같다. ㅠㅠ



아래 링크를 참조했다. http://doc.mapr.com/display/MapR/Using+Apache+Phoenix+on+HBase



apache phoenix의 pheonix 3.2 라이브러리를 hbase에 라이브러리에 복사하고, hbase를 재시작했다. (모든 region 서버에 다 넣고 재시작해야 한다..)


$ sudo cp  phoenix-3.2.2/hadoop2/common/*.jar /usr/lib/hbase/lib/

$ ls -al /usr/lib/hbase/lib/

$ sudo service hbase-master restart



phoenix를 실행하려고 했더니. 에러가 난다. 


$ ./hadoop2/bin/sqlline.py  localhost:2181:/hbase

오류: 기본 클래스 sqlline.SqlLine을(를) 찾거나 로드할 수 없습니다.



아래처럼 대충 수정해놓고 실행했다.


$ mv ./hadoop2/phoenix-3.2.2-client-hadoop2.jar ./hadoop2/phoenix-3.2.2-client.jar

Connecting to jdbc:phoenix:localhost:2181:/hbase

.....


정상작동하는 것처럼 보이지만, shell 이 뜨지 않는다... 뜨헉!

하지만, hbase 로그 상으로는 특별한 것은 보이지 않다. 



hbase shell에 들어가 list 커맨드를 날리니. 아무 테이블도 보이지 않았다!


앱에서 다음과 같은 Exception을 발생시키고 있다!!




org.apache.hadoop.hbase.client.NoServerForRegionException: No server address listed in .META. for region xxxx,,1481780733642.719b5b9f72b8c7af2f338ef0b23d76c9. containing row

java.lang.RuntimeException: org.apache.hadoop.hbase.client.NoServerForRegionException: No server address listed in .META. for region xxxx,,1481780733642.719b5b9f72b8c7af2f338ef0b23d76c9. containing row

at org.apache.hadoop.hbase.client.HTableFactory.createHTableInterface(HTableFactory.java:38) 

at org.apache.hadoop.hbase.client.HTablePool.createHTable(HTablePool.java:265) 

at org.apache.hadoop.hbase.client.HTablePool.findOrCreateTable(HTablePool.java:195) 

at org.apache.hadoop.hbase.client.HTablePool.getTable(HTablePool.java:174) 




hbase를 재시작하다가 에러가 발생한다. 



ERROR org.apache.hadoop.hbase.regionserver.handler.OpenRegionHandler: Failed open of region=xxx,,1481780315502.2d152bb821024643f5959e9ea132246d., starting to roll back the global memstore size.

java.lang.IllegalStateException: Could not instantiate a region instance.

        at org.apache.hadoop.hbase.regionserver.HRegion.newHRegion(HRegion.java:4247)

        at org.apache.hadoop.hbase.regionserver.HRegion.openHRegion(HRegion.java:4427)

        at org.apache.hadoop.hbase.regionserver.handler.OpenRegionHandler.openRegion(OpenRegionHandler.java:335)

        at org.apache.hadoop.hbase.regionserver.handler.OpenRegionHandler.process(OpenRegionHandler.java:101)

        at org.apache.hadoop.hbase.executor.EventHandler.run(EventHandler.java:175)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

        at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.reflect.InvocationTargetException

        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

        at org.apache.hadoop.hbase.regionserver.HRegion.newHRegion(HRegion.java:4244)

        ... 7 more

Caused by: java.lang.NullPointerException

        at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.loadTableCoprocessors(RegionCoprocessorHost.java:163)

        at org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost.<init>(RegionCoprocessorHost.java:155)

        at org.apache.hadoop.hbase.regionserver.HRegion.<init>(HRegion.java:502)





.META. 테이블의 모든 rowkey를 하나씩 수동으로 deleteall로 날리고, 다시 테이블을 생성해서 문제를 해결했다. 


deleteall '.META.', 'xxxx,,1481780862570.b48ea78f2b093372649de89574bcb1a7.'


create 'xxxx', { NAME => 'c', BLOOMFILTER => 'ROWCOL', VERSIONS => '1', COMPRESSION => 'GZ', TTL => '-1', BLOCKCACHE => 'false'}




Posted by '김용환'
,


hbase를 mac local에 설치했다. 

http://knight76.tistory.com/entry/Hbase-mac-install-mac%EC%97%90-hbase-mac-%EC%84%A4%EC%B9%98


hbase api를 이용해서 위의 예제를 shell에서 진행하듯이 동작 여부를 확인했다. 



package com.google.sample.hbase;



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.client.HBaseAdmin;

import org.apache.hadoop.hbase.client.HTable;

import org.apache.hadoop.hbase.client.Put;

import org.apache.hadoop.hbase.client.Result;

import org.apache.hadoop.hbase.client.ResultScanner;

import org.apache.hadoop.hbase.client.Scan;

import org.apache.hadoop.hbase.util.Bytes;


public class HBaseTest2 {


public static void main(String[] args) {

Configuration config = HBaseConfiguration.create();

config.set("hbase.master", "127.0.0.1"); 

try {

HBaseAdmin hBaseAdmin = new HBaseAdmin(config);


if (hBaseAdmin.isTableAvailable("key1") == false) {

HTableDescriptor tableDs = new HTableDescriptor("key1");

tableDs.addFamily(new HColumnDescriptor("cf"));

hBaseAdmin.createTable(tableDs);

} else {

hBaseAdmin.disableTable("key1");

hBaseAdmin.deleteTable("key1");


HTableDescriptor tableDs = new HTableDescriptor("key1");

tableDs.addFamily(new HColumnDescriptor("cf"));

hBaseAdmin.createTable(tableDs);

}

HTable hTable = new HTable(config, "key1");

Put p = new Put(Bytes.toBytes("row1"));

p.add(Bytes.toBytes("cf"), Bytes.toBytes("a"), Bytes.toBytes("value1"));

hTable.put(p);

p = new Put(Bytes.toBytes("row2"));

p.add(Bytes.toBytes("cf"), Bytes.toBytes("b"), Bytes.toBytes("value2"));

hTable.put(p);

p = new Put(Bytes.toBytes("row3"));

p.add(Bytes.toBytes("cf"), Bytes.toBytes("c"), Bytes.toBytes("value3"));

hTable.put(p);

Scan s = new Scan();

ResultScanner scanner = hTable.getScanner(s);

try {

for (Result rowResult = scanner.next(); rowResult != null; rowResult = scanner.next()) {

System.out.println("row: " + rowResult);

}

} finally {

scanner.close();

}

hTable.close();

hBaseAdmin.close();

} catch (Exception e) {

e.printStackTrace();

}

}

}



결과 

row: keyvalues={row1/cf:a/1365065659856/Put/vlen=6/ts=0}

row: keyvalues={row2/cf:b/1365065659858/Put/vlen=6/ts=0}

row: keyvalues={row3/cf:c/1365065659859/Put/vlen=6/ts=0}



* 주의 사항

Spring data hadoop(Hbase) example 코드 (https://github.com/SpringSource/spring-hadoop-samples)를 참조해서 테스트를 진행했지만 쉽지 않다. 간단하게 설치한 만큼 spring data를 쓰기가 쉽지 않다. 

역시 hdfs를 기준으로 설치하고 테스트하는  것으로 가야할듯 싶다. 



Posted by '김용환'
,