Esempio n. 1
0
 public Map<String, Long> getRegionSizes(String tableName) {
   Map<String, Long> regions = new HashMap<>();
   try {
     final Table table = connection.getTable(TableName.valueOf(tableName));
     RegionLocator regionLocator = connection.getRegionLocator(table.getName());
     List<HRegionLocation> tableRegionInfos = regionLocator.getAllRegionLocations();
     Set<byte[]> tableRegions = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
     for (HRegionLocation regionInfo : tableRegionInfos) {
       tableRegions.add(regionInfo.getRegionInfo().getRegionName());
     }
     ClusterStatus clusterStatus = connection.getAdmin().getClusterStatus();
     Collection<ServerName> servers = clusterStatus.getServers();
     final long megaByte = 1024L * 1024L;
     for (ServerName serverName : servers) {
       ServerLoad serverLoad = clusterStatus.getLoad(serverName);
       for (RegionLoad regionLoad : serverLoad.getRegionsLoad().values()) {
         byte[] regionId = regionLoad.getName();
         if (tableRegions.contains(regionId)) {
           long regionSizeBytes = regionLoad.getStorefileSizeMB() * megaByte;
           regions.put(regionLoad.getNameAsString(), regionSizeBytes);
         }
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return regions;
 }
Esempio n. 2
0
 protected HServerLoad.RegionLoad getRegionLoad(HRegionInfo regionInfo, ServerName serverName)
     throws IOException {
   HServerLoad serverLoad = admin.getClusterStatus().getLoad(serverName);
   Map<byte[], HServerLoad.RegionLoad> regionsLoad = serverLoad.getRegionsLoad();
   for (Map.Entry<byte[], HServerLoad.RegionLoad> entry : regionsLoad.entrySet()) {
     if (Arrays.equals(entry.getKey(), regionInfo.getRegionName())) {
       return entry.getValue();
     }
   }
   return null;
 }
Esempio n. 3
0
  private Long getWriteRequestMetric(String tableName, ServerName serverName) {
    Map<String, Long> serverMap = tableServerWriteRequestMap.get(tableName);
    if (serverMap == null) {
      serverMap = new HashMap<>();
      tableServerWriteRequestMap.put(tableName, serverMap);
    }

    Long writeRequest = serverMap.get(serverName.getServerName());
    if (writeRequest == null) {
      writeRequest = 0L;
      serverMap.put(serverName.getServerName(), writeRequest);
    }
    return writeRequest;
  }
Esempio n. 4
0
  protected void waitForMoving(HRegionInfo hRegionInfo, ServerName serverName) throws Exception {
    Map<byte[], HServerLoad.RegionLoad> regionsLoad = null;
    for (int i = 0; i < MAX_WAIT_ITERATION; i++) {
      HServerLoad load = admin.getClusterStatus().getLoad(serverName);
      regionsLoad = load.getRegionsLoad();
      for (byte[] regionName : regionsLoad.keySet()) {
        if (Arrays.equals(regionName, hRegionInfo.getRegionName())) return;
      }
      admin.move(hRegionInfo.getEncodedNameAsBytes(), serverName.getServerName().getBytes());
      Thread.sleep(WAIT_INTERVAL);
    }

    System.out.println("hRegionInfo = " + Bytes.toString(hRegionInfo.getRegionName()));
    for (Map.Entry<byte[], HServerLoad.RegionLoad> entry : regionsLoad.entrySet()) {
      System.out.println(
          "regionsLoad = " + Bytes.toString(entry.getKey()) + " - " + entry.getValue());
    }

    Assert.fail(Util.getMethodName() + " failed");
  }
  public static void main(String[] args) {
    List<String> cFs = new ArrayList<String>();

    cFs.add("cf1");
    cFs.add("cf2");

    List<String> zks = new ArrayList<String>();
    zks.add("127.0.0.1");

    Map<String, Map<String, Object>> record = new HashMap<String, Map<String, Object>>();

    Map<String, Object> cf1 = new HashMap<String, Object>();
    cf1.put("aa", "1");

    Map<String, Object> cf2 = new HashMap<String, Object>();
    cf2.put("bb", "1");

    record.put("cf1", cf1);
    record.put("cf2", cf2);

    HBaseOperations operations = new HBaseOperations("skyfree_big_table", cFs, zks, 2181);
    operations.insert(record, UUID.randomUUID().toString());
    System.out.println("done");
  }