2016-06-21 7 views
2

각 매퍼의 HBase 테이블에 N 행을 일괄 적으로 삽입하려고합니다. 나는이 일을 두 가지 방법 중 currenly 알고 :MapReduce를 사용하여 HBase에 여러 행 삽입

  1. Put 개체의 목록을 작성하고 HTable 인스턴스의 put(List<Put> puts) 방법을 사용하고 또한 autoFlush 매개 변수를 사용하지 않도록해야합니다.
  2. TableOutputFormat 클래스를 사용하고 context.write(rowKey, put) 메서드를 사용하십시오.

어느 것이 더 낫습니까?

hTable.put(putsList) 메서드를 사용하여 테이블에 데이터를 직접 입력하기 때문에 첫 번째 방법에서는 context.write()이 필요하지 않습니다. 내 매퍼 클래스가 Class Mapper<KEYIN,VALUEIN,KEYOUT,VALUEOUT>까지 확장되어 있으므로 KEYOUTVALUEOUT에 어떤 클래스를 사용해야합니까?

두 번째 방법으로 context.write(rowKey, put) N 번 전화해야합니다. Put 작업 목록에 context.write()을 사용할 수있는 방법이 있습니까?

MapReduce를 사용하여 다른 방법이 있습니까?

미리 감사드립니다. 배치가 자연입니다

+0

로() BufferedMutator과 자연 왜라고? 매퍼 수를 어떻게 지정합니까? 코드를 제안하는 경우에도 매퍼 수는 1이됩니다. –

+0

setNumMapTasks 또는 conf.set ('mapred.map.tasks', 'numberofmappersyouwanttoset')을 사용하여 맵퍼의 수를 변경할 수 있지만 설정에 대한 제안은 있지만 맵퍼 인스턴스가 설정된다는 보장은 없습니다. 또한, inputsplits에 따라 다릅니다. –

+0

lookat http://stackoverflow.com/questions/37239944/is-it-possible-to-run-multiple-mappers-on-one-node 제 정교한 대답을 참조하십시오 .. 질문을 자유롭게하십시오. –

답변

1

내가 두 번째 옵션을 선호하는 맵리 듀스를위한 ... ( 풋의 목록이 필요) 귀하의 첫 번째 옵션) 깊은 통찰력을 내 두 번째 점을

(1)를 참조하십시오이 없습니다 List<Put> 일반적으로 독립 실행 형 Hbase Java 클라이언트에 사용됩니다. 내부적으로이 당신의 설정 중 하나에 아래와 같이 hbase.client.write.buffer에 의해 제어되는 말 2 메가 바이트 크기를 기본값이

<property> 
     <name>hbase.client.write.buffer</name> 
     <value>20971520</value> // around 2 mb i guess 
</property> 

을 XMLS. 일단 버퍼가 채워지면 실제로 모든 테이블을 플러시하여 테이블에 삽입합니다. , 두 번째 옵션에 대해서는 # 2

2)에 설명 된대로 TableOutputFormat 문서

org.apache.hadoop.hbase.mapreduce 
Class TableOutputFormat<KEY> 

java.lang.Object 
org.apache.hadoop.mapreduce.OutputFormat<KEY,Mutation> 
org.apache.hadoop.hbase.mapreduce.TableOutputFormat<KEY> 
All Implemented Interfaces: 
org.apache.hadoop.conf.Configurable 

@InterfaceAudience.Public 
@InterfaceStability.Stable 
public class TableOutputFormat<KEY> 
extends org.apache.hadoop.mapreduce.OutputFormat<KEY,Mutation> 
implements org.apache.hadoop.conf.Configurable 
Convert Map/Reduce output and write it to an HBase table. The KEY is ignored 

while the output value must be either a Put or a Delete instance을 보면 BufferedMutator와 같은 방법이다.

- code 통해 보는 다른 방법은 다음과 같다.

/** 
    * Writes a key/value pair into the table. 
    * 
    * @param key The key. 
    * @param value The value. 
    * @throws IOException When writing fails. 
    * @see RecordWriter#write(Object, Object) 
    */ 
    @Override 
    public void write(KEY key, Mutation value) 
    throws IOException { 
     if (!(value instanceof Put) && !(value instanceof Delete)) { 
     throw new IOException("Pass a Delete or a Put"); 
     } 
     mutator.mutate(value); 
    } 
    } 

결론 : context.write (rowkey, putlist) 그것은 API를 할 수 없습니다.

그러나, BufferedMutator (뮤 테이터로부터.위의 코드에서 돌연변이)

Map/reduce jobs benefit from batching, but have no natural flush point. {@code BufferedMutator} receives the puts from the M/R job and will batch puts based on some heuristic, such as the accumulated size of the puts, and submit batches of puts asynchronously so that the M/R logic can continue without interruption.

그래서 당신의 배치 여러 매퍼 왜 하나 매퍼는 상기