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

    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 SplitMain {
    private static final Logger LOG = LoggerFactory.getLogger(SplitMain.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 numTotalSplit = 0;
        ClusterStatus clusterStatus = admin.getClusterStatus();
        for (ServerName sn : clusterStatus.getServers()) {
            int maxSplitByServer = 0;
            ServerLoad serverLoad = clusterStatus.getLoad(sn);
            Map<byte[], RegionLoad> regionsLoad = serverLoad.getRegionsLoad();
            for (Map.Entry<byte[], RegionLoad> rl : regionsLoad.entrySet()) {
                RegionLoad rlValue = rl.getValue();
                String regionName = Bytes.toStringBinary(rlValue.getName());
    
                int storefileSizeMB = rlValue.getStorefileSizeMB();
                if (storefileSizeMB > Constant.STOREFILES_SIZE_GB *1024) {
                    ++numTotalSplit;
                    ++maxSplitByServer;
                    LOG.info("HostName=" + sn.getHostname() + ",regionName=" + regionName + ", storefileSizeMB=" + storefileSizeMB + "MB");
                    admin.splitRegion(rlValue.getName());
    
                    if (maxSplitByServer == Constant.MAX_SPLIT_BY_SERVER) break;
                }
            }
        }
    
        LOG.info("splitCount=" + numTotalSplit);
    
    
        admin.close();
        connection.close();
    
    
        LOG.info("The job is ended, total cost time :" + (System.currentTimeMillis()-begin)/1000 + "s");
    }
    

    }

  • 相关阅读:
    python中的 if __name__ == "__main__": 语句的作用
    python的打包与解包
    python循环删除列表元素
    python字典键值对新增与修改的几种方法及差异总结
    python列表元素删除的几种方法以及差异总结
    python之redis(二)
    python之redis(一)
    python之mysql(四)
    python之mysql(三)
    python之mysql(二)
  • 原文地址:https://www.cnblogs.com/riordon/p/11844741.html
Copyright © 2011-2022 走看看