簡體   English   中英

如何從一個HBase實例讀取但如何寫入另一個實例?

[英]How can I read from one HBase instance but write to another?

目前,我有兩個Hbase表(讓它們稱為tableAtableB )。 使用單階段MapReduce作業,對tableA的數據進行讀取處理並將其保存到tableB 當前,兩個表都位於同一HBase群集上。 但是,我需要將tableB重定位到其在群集上。

是否可以在Hadoop中配置單階段映射減少作業以從單獨的HBase實例讀取和寫入?

可能的是,HBase的CopyTable MapReduce作業可以通過使用TableMapReduceUtil.initTableReducerJob()此操作,該功能允許您設置備用quorumAddress,以防需要寫入遠程集群:

public static void initTableReducerJob(String table, Class<? extends TableReducer> reducer, org.apache.hadoop.mapreduce.Job job, Class partitioner, String quorumAddress, String serverClass, String serverImpl)

quorumAddress-要寫入的遠程群集; 對於輸出到hbase-site.xml中指定的集群的默認值為null。 當您要讓reduce編寫非默認集群時,將此字符串設置為備用遠程集群的zookeeper集合。 例如,在群集之間復制表,則源將由hbase-site.xml指定,並且該參數將具有遠程群集的集合地址。 要傳遞的格式特別。 傳遞::,例如server,server2,server3:2181:/ hbase。


另一個選擇是實現您自己的自定義化簡器以寫入遠程表,而不是寫入上下文。 類似於以下內容:

public static class MyReducer extends Reducer<Text, Result, Text, Text> {

    protected Table remoteTable; 
    protected Connection connection;

    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        super.setup(context);
        // Clone configuration and provide a new quorum address for the remote cluster
        Configuration config = HBaseConfiguration.create(context.getConfiguration());
        config.set("hbase.zookeeper.quorum","quorum1,quorum2,quorum3");
        connection = ConnectionFactory.createConnection(config); // HBase 0.99+
        //connection = HConnectionManager.createConnection(config); // HBase <0.99
        remoteTable = connection.getTable("myTable".getBytes());
        remoteTable.setAutoFlush(false);
        remoteTable.setWriteBufferSize(1024L*1024L*10L); // 10MB buffer
    }

    public void reduce(Text boardKey, Iterable<Result> results, Context context) throws IOException, InterruptedException {
        /* Write puts to remoteTable */
    }

    @Override
    protected void cleanup(Context context) throws IOException, InterruptedException {
        super.cleanup(context);
        if (remoteTable!=null) {
            remoteTable.flushCommits();
            remoteTable.close();
        }
        if(connection!=null) {
            connection.close();
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM