繁体   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