HBase(BigTable clone project) examples

HBase는 hadoop 기반의 BigTable clone 프로젝트이다.
아직은 정식적으로 hadoop의 소스 코드내에 등록되어 있지 않지만 0.13에서는 distribution 형태로 등록될 예정이다.
간단한 사용 방법을 보면 다음과 같다.
간단하게 기능 정도만 확인해볼 목적이었기 때문에 1대의 PC에서 돌렸으며 운영체제는 Windows이다.

1. hadoop start

2. hbase start
   (두 종류의 서버로 구성, HMaster, HRegionServer)
   org.apache.hadoop.hbase.HMaster start
   org.apache.hadoop.hbase.HRegionServer start

3. Table create
    java org.apache.hadoop.hbase.HClient createTable webtable contents: anchors: 10
   (contents, anchors의 column family로 구성된 webtable 생성)
  
4. run Test program

public class HBaseTest {

       public static void main(String[] args) throws Exception {

             if(args.length < 1) {

                    System.out.println("Usage: java org.apache.hadoop.hbase.Test [insert|select] [tableName] [row-key] [col-key] [val] [col-key] [val] ...");

                    return;

             }

             if("insert".equals(args[0])) {

                    insert(args);

             } else if("select".equals(args[0])) {

                    select(args);

             } else {

                    System.out.println("Usage: java org.apache.hadoop.hbase.Test [insert|select] [row-key] [col-key] [val] [col-key] [val] ...");

             }

       }

       public static void insert(String[] args) throws Exception {

             Configuration conf = new Configuration();

             HClient client = new HClient(conf);

             client.openTable(new Text(args[1]));

             long lockId = client.startUpdate(new Text(args[2]));

            

             Map<String, String> columns = getColumns(args);

             Iterator it = columns.keySet().iterator();

             while(it.hasNext()) {

                    String key = (String)it.next();

                    String value = columns.get(key);

                    client.put(lockId, new Text(key), value.getBytes());

             }

             client.commit(lockId);

       }

 

       public static void select(String[] args) throws Exception {

             Configuration conf = new Configuration();

             HClient client = new HClient(conf);

             client.openTable(new Text(args[1]));

             byte[] result = client.get(new Text(args[2]), new Text(args[3]));

             System.out.println("Result:" + new String(result));

       }

      

       private static Map<String, String> getColumns(String[] args) {

             Map<String, String> columns = new HashMap<String, String>();

             for(int i = 3; i < args.length;) {

                    columns.put(args[i++], args[i++]);

             }

            

             return columns;

       }

}

다음과 같이 실행
* java org.apache.hadoop.hbase.Test insert webtable row_12 anchors:www.naver.com NAVER
* java org.apache.hadoop.hbase.Test select webtable row_12 anchors:www.naver.com
  Result:NAVER

5. HBase shutdown
  java org.apache.hadoop.hbase.HClient shutdown

일단 기능적인 부분에서는 어느 정도 실행이 되는 것 같은데 성능 부분에 대해서는 테스트가 더 필요할 것 같다.
HMaster, HRegionServer 각각 아무런 동작으로 하지 않고 있는 상태에서도 CPU를 사용하고 있는 것으로 모니터링 되었다.
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by 김형준


Trackback URL : http://www.jaso.co.kr/trackback/165

Comments List

  1. typos 2007/05/11 11:34 # M/D Reply Permalink

    음 기대되는군요

  2. udanax 2007/05/11 15:02 # M/D Reply Permalink

    므흣~ 감사합니다.

Leave a comment
« Previous : 1 : ... 256 : 257 : 258 : 259 : 260 : 261 : 262 : 263 : 264 : ... 388 : Next »