zoukankan      html  css  js  c++  java
  • 代码片段2

    package com.glsx.main;

    import com.glsx.constants.Constant;
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.*;
    import org.apache.hadoop.hbase.client.Admin;
    import org.apache.hadoop.hbase.client.Connection;
    import org.apache.hadoop.hbase.client.ConnectionFactory;
    import org.apache.hadoop.hbase.util.Bytes;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;

    import java.io.IOException;
    import java.util.Map;

    public class CompactMain {
    private static final Logger LOG = LoggerFactory.getLogger(CompactMain.class);

    public static void main(String[] args) throws IOException {
        LOG.info("The job starting...");
        long begin = System.currentTimeMillis();
    
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", "hadoop-offline-60,hadoop-offline-61,hadoop-offline-62");
    
        Connection connection = ConnectionFactory.createConnection(conf);
        Admin admin = connection.getAdmin();
    
        int numTotalCompact = 0;
        ClusterStatus clusterStatus = admin.getClusterStatus();
        for (ServerName sn : clusterStatus.getServers()) {
            int maxCompactByServer = 0;
            ServerLoad serverLoad = clusterStatus.getLoad(sn);
            for (Map.Entry<byte[], RegionLoad> regionLoadEntry : serverLoad.getRegionsLoad().entrySet()) {
                RegionLoad rlValue = regionLoadEntry.getValue();
                String regionName = Bytes.toStringBinary(rlValue.getName());
                if (rlValue.getStorefiles() >= Constant.NUM_STOREFILES) {
                    ++numTotalCompact;
                    ++maxCompactByServer;
                    LOG.info("HostName=" + sn.getHostname() + ",regionName=" + regionName + ", storefilesCount=" + rlValue.getStorefiles());
    
                    admin.majorCompactRegion(rlValue.getName());
    
                    if (maxCompactByServer == Constant.MAX_COMPACT_BY_SERVER) break;
                }
            }
        }
    
        LOG.info("numTotalCompact=" + numTotalCompact);
    
        admin.close();
        connection.close();
    
        LOG.info("The job is ended, total cost time :" + (System.currentTimeMillis()-begin)/1000 + "s");
    }
    

    }

  • 相关阅读:
    idea spring boot启动项目上面有红色叉
    hibernate Criteria中多个or和and的用法 and ( or or)
    CAS Server 4.2.7(自定义密码验证) 部署
    Web应用系统集成CAS-rest指南
    用DBMS_REDEFINITION将普通表转换为分区表
    windows编译libevent时报告“缺少print_winsock_errors.obj”的解决
    Oracle表增删分区的脚本
    libcassandra开发示例
    关于MongoDB API的两个小经验
    C/C++开发Cassandra的一些经验
  • 原文地址:https://www.cnblogs.com/riordon/p/11844734.html
Copyright © 2011-2022 走看看