MapReduce服务 MRS-如何配置HBase双读功能:将主备集群相关配置设置到HBaseMultiClusterConnection中

时间:2025-02-12 15:00:33

将主备集群相关配置设置到HBaseMultiClusterConnection中

该操作仅适用于 MRS 3.3.0及之后版本。

  1. 创建双读Configuration,取消“com.huawei.bigdata.hbase.examples”包的“TestMain”类main方法中的testHBaseDualReadSample注释,确保“com.huawei.bigdata.hbase.examples”包的“HBaseDualReadSample”类中的“IS_CREATE_CONNECTION_BY_XML”值为“false”。
  2. 在“HBaseDualReadSample”类的addHbaseDualXmlParam方法中添加相关配置,相关配置项可参考HBase双读操作相关配置项说明

    private void addHbaseDualXmlParam(Configuration conf) {    // We need to set the optional parameters contained in hbase-dual.xml to conf    // when we use configuration transfer solution    conf.set(CONNECTION_IMPL_KEY, DUAL_READ_CONNECTION);    // conf.set("", "");}

  3. 在“HBaseDualReadSample”类的initActiveConf方法中添加主集群客户端相关配置:

    private void initActiveConf() {    // The hbase-dual.xml configuration scheme is used to generate the client configuration of the active cluster.    // In actual application development, you need to generate the client configuration of the active cluster.    String activeDir = HBaseDualReadSample.class.getClassLoader().getResource(Utils.CONF_DIRECTORY).getPath()        + File.separator + ACTIVE_DIRECTORY + File.separator;    Configuration activeConf = Utils.createConfByUserDir(activeDir);    HBaseMultiClusterConnection.setActiveConf(activeConf);}

  4. 在“HBaseDualReadSample”类initStandbyConf方法中添加备集群客户端相关配置:

    private void initStandbyConf() {    // The hbase-dual.xml configuration scheme is used to generate the client configuration of the standby cluster.    // In actual application development, you need to generate the client configuration of the standby cluster.    String standbyDir = HBaseDualReadSample.class.getClassLoader().getResource(Utils.CONF_DIRECTORY).getPath()        + File.separator + STANDBY_DIRECTORY + File.separator;    Configuration standbyConf = Utils.createConfByUserDir(standbyDir);    HBaseMultiClusterConnection.setStandbyConf(standbyConf);}

  5. 确定数据来源的集群。

    • GET请求,以下代码片段在“com.huawei.bigdata.hbase.examples”包的“HBaseSample”类的testGet方法中添加。
      Result result = table.get(get); if (result instanceof DualResult) {      LOG .info(((DualResult)result).getClusterId()); }
    • Scan请求,以下代码片段在“com.huawei.bigdata.hbase.examples”包的“HBaseSample”类的testScanData方法中添加。
      ResultScanner rScanner = table.getScanner(scan);  if (rScanner instanceof HBaseMultiScanner) {     LOG.info(((HBaseMultiScanner)rScanner).getClusterId()); }

  6. 客户端支持打印metric信息。

    “log4j.properties”文件中增加如下内容,客户端将metric信息输出到指定文件。指标项信息可参考打印metric信息说明

    log4j.logger.DUAL=debug,DUAL log4j.appender.DUAL=org.apache.log4j.RollingFileAppender log4j.appender.DUAL.File=/var/log/dual.log //客户端本地双读日志路径,根据实际路径修改,但目录要有写入权限log4j.additivity.DUAL=false log4j.appender.DUAL.MaxFileSize=${hbase.log.maxfilesize} log4j.appender.DUAL.MaxBackupIndex=${hbase.log.maxbackupindex} log4j.appender.DUAL.layout=org.apache.log4j.PatternLayout log4j.appender.DUAL.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c{2}: %m%n

support.huaweicloud.com/devg-lts-mrs/mrs_07_290067.html