Пример #1
0
 protected static List<HRegionInfo> getRegionInfoList(ServerName serverName, String tableName)
     throws IOException {
   List<HRegionInfo> onlineRegions = new ArrayList<>();
   for (HRegionInfo onlineRegion : CommandAdapter.getOnlineRegions(null, admin, serverName)) {
     if (onlineRegion.getTableNameAsString().equals(tableName)) {
       onlineRegions.add(onlineRegion);
     }
   }
   return onlineRegions;
 }
  public void deleteFamilyFromFS(HRegionInfo region, byte[] familyName)
      throws IOException {
    // archive family store files
    Path tableDir = new Path(rootdir, region.getTableNameAsString());
    HFileArchiver.archiveFamily(fs, conf, region, tableDir, familyName);

    // delete the family folder
    Path familyDir = new Path(tableDir,
      new Path(region.getEncodedName(), Bytes.toString(familyName)));
    if (fs.delete(familyDir, true) == false) {
      throw new IOException("Could not delete family "
          + Bytes.toString(familyName) + " from FileSystem for region "
          + region.getRegionNameAsString() + "(" + region.getEncodedName()
          + ")");
    }
  }
Пример #3
0
  public static Map<String, HRegionContent> getRegionMap(HTable table, HBaseAdmin admin)
      throws Exception {
    // TODO Auto-generated method stub
    Map<String, HRegionContent> regionMap = new HashMap<String, HRegionContent>();

    try {
      Map<HRegionInfo, ServerName> regionsInfo = table.getRegionLocations();
      for (HRegionInfo ri : regionsInfo.keySet()) {
        HRegionContent regionContent = new HRegionContent();
        regionContent.tableName = ri.getTableNameAsString();
        regionContent.encodedName = ri.getEncodedName();
        regionContent.regionName = ri.getRegionNameAsString();
        regionContent.regionNameBytes = ri.getRegionName();
        regionContent.regionId = ri.getRegionId();
        regionContent.startKey = ri.getStartKey();
        regionContent.endKey = ri.getEndKey();

        regionMap.put(regionContent.encodedName, regionContent);
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    ClusterStatus status = admin.getClusterStatus();
    /*      System.out.println("Cluster Status:\n--------------");
    System.out.println("HBase Version: " + status.getHBaseVersion());
    System.out.println("Version: " + status.getVersion());
    System.out.println("No. Live Servers: " + status.getServersSize());
    System.out.println("Cluster ID: " + status.getClusterId());
    System.out.println("Servers: " + status.getServers());
    System.out.println("No. Dead Servers: " + status.getDeadServers());
    System.out.println("Dead Servers: " + status.getDeadServerNames());

    System.out.println("No. Regions: " + status.getRegionsCount());
    System.out.println("Regions in Transition: " + status.getRegionsInTransition());
    System.out.println("No. Requests: " + status.getRequestsCount());
    System.out.println("Avg Load: " + status.getAverageLoad());
    System.out.println("\nServer Info:\n--------------");*/
    for (ServerName server : status.getServers()) {
      /*System.out.println("Hostname: " + server.getHostname());
      System.out.println("Host and Port: " + server.getHostAndPort());
      System.out.println("Server Name: " + server.getServerName());
      System.out.println("RPC Port: " + server.getPort());
      System.out.println("Start Code: " + server.getStartcode());*/
      HServerLoad load = status.getLoad(server);
      /*System.out.println("\nServer Load:\n--------------");
      System.out.println("Load: " + load.getLoad());
      System.out.println("Max Heap (MB): " + load.getMaxHeapMB());
      System.out.println("Memstore Size (MB): " + load.getMemStoreSizeInMB());
      System.out.println("No. Regions: " + load.getNumberOfRegions());
      System.out.println("No. Requests: " + load.getNumberOfRequests());
      System.out.println("Storefile Index Size (MB): " +
      load.getStorefileIndexSizeInMB());
      System.out.println("No. Storefiles: " + load.getStorefiles());
      System.out.println("Storefile Size (MB): " + load.getStorefileSizeInMB());
      System.out.println("Used Heap (MB): " + load.getUsedHeapMB());
      System.out.println("\nRegion Load:\n--------------");*/
      for (Map.Entry<byte[], HServerLoad.RegionLoad> entry : load.getRegionsLoad().entrySet()) {

        HServerLoad.RegionLoad regionLoad = entry.getValue();
        String regionLoadName = regionLoad.getNameAsString();
        String[] tmpStrings = regionLoadName.split("\\.");
        String encodeName = tmpStrings[tmpStrings.length - 1];

        if (!regionMap.containsKey(encodeName)) {
          continue;
        }

        HRegionContent regionContent = regionMap.get(encodeName);
        regionContent.stores = regionLoad.getStores();
        regionContent.storeFiles = regionLoad.getStorefiles();
        regionContent.storefileSizeMB = regionLoad.getStorefileSizeMB();
        regionContent.storefileIndexSizeMB = regionLoad.getStorefileIndexSizeMB();
        regionContent.memStoreSizeMB = regionLoad.getMemStoreSizeMB();
        regionContent.requestsCount = regionLoad.getRequestsCount();
        regionContent.readRequestCount = regionLoad.getReadRequestsCount();
        regionContent.writeRequestCount = regionLoad.getWriteRequestsCount();
      }
    }

    int count = 0;
    for (HRegionContent regionContent : regionMap.values()) {

      /*System.out.println("table name : " + regionContent.tableName);
      System.out.println("encoded name : " + regionContent.encodedName);
      System.out.println("region name : " + regionContent.regionName);
      System.out.println("regionId : " + regionContent.regionId);
      System.out.println("startKey : " + regionContent.startKey.toString());
      System.out.println("endKey : " + regionContent.endKey.toString());

      System.out.println("No. Stores: " + regionContent.stores);
      System.out.println("No. Storefiles: " + regionContent.storeFiles);
      System.out.println("Storefile Size (MB): " + regionContent.storefileSizeMB);
      System.out.println("Storefile Index Size (MB): " + regionContent.storefileIndexSizeMB);
      System.out.println("Memstore Size (MB): " + regionContent.memStoreSizeMB);
      System.out.println("No. Requests: " + regionContent.requestsCount);
      System.out.println("No. Read Requests: " +
      		regionContent.readRequestCount);
      System.out.println("No. Write Requests: " +
      		regionContent.writeRequestCount);
      System.out.println();*/
      count++;
    }

    /*LOG.info("region sum num: " + regionMap.size());
    LOG.info("not null region num:" + count);
    LOG.info("file size :" + fileSize);*/

    return regionMap;
  }