Ejemplo 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;
 }
Ejemplo n.º 2
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;
  }
  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");
  }