HBase(BigTable clone project) examples
- Posted at 2007/05/11 11:02
- Filed under project/lucene_hadoop
아직은 정식적으로 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를 사용하고 있는 것으로 모니터링 되었다.
Posted by 김형준
- Response
- No Trackback , 2 Comments
Trackback URL : http://www.jaso.co.kr/trackback/165
Comments List
-
음 기대되는군요
-
므흣~ 감사합니다.






