コード例 #1
0
ファイル: SplitTransactionImpl.java プロジェクト: enis/hbase
 /**
  * Calculate daughter regionid to use.
  *
  * @param hri Parent {@link HRegionInfo}
  * @return Daughter region id (timestamp) to use.
  */
 private static long getDaughterRegionIdTimestamp(final HRegionInfo hri) {
   long rid = EnvironmentEdgeManager.currentTime();
   // Regionid is timestamp.  Can't be less than that of parent else will insert
   // at wrong location in hbase:meta (See HBASE-710).
   if (rid < hri.getRegionId()) {
     LOG.warn(
         "Clock skew; parent regions id is "
             + hri.getRegionId()
             + " but current time here is "
             + rid);
     rid = hri.getRegionId() + 1;
   }
   return rid;
 }
コード例 #2
0
 /**
  * Create a new {@link HRegionInfo} from the snapshot region info. Keep the same startKey, endKey,
  * regionId and split information but change the table name.
  *
  * @param snapshotRegionInfo Info for region to clone.
  * @return the new HRegion instance
  */
 public HRegionInfo cloneRegionInfo(final HRegionInfo snapshotRegionInfo) {
   return new HRegionInfo(
       tableDesc.getName(),
       snapshotRegionInfo.getStartKey(),
       snapshotRegionInfo.getEndKey(),
       snapshotRegionInfo.isSplit(),
       snapshotRegionInfo.getRegionId());
 }
コード例 #3
0
ファイル: HRegionInfo.java プロジェクト: dobromyslov/hbase
 /**
  * Costruct a copy of another HRegionInfo
  *
  * @param other
  */
 public HRegionInfo(HRegionInfo other) {
   super();
   this.endKey = other.getEndKey();
   this.offLine = other.isOffline();
   this.regionId = other.getRegionId();
   this.regionName = other.getRegionName();
   this.split = other.isSplit();
   this.startKey = other.getStartKey();
   this.hashCode = other.hashCode();
   this.encodedName = other.getEncodedName();
   this.tableName = other.tableName;
   this.replicaId = other.replicaId;
 }
コード例 #4
0
ファイル: HRegionInfo.java プロジェクト: dobromyslov/hbase
 /**
  * Convert a HRegionInfo to a RegionInfo
  *
  * @param info the HRegionInfo to convert
  * @return the converted RegionInfo
  */
 public static RegionInfo convert(final HRegionInfo info) {
   if (info == null) return null;
   RegionInfo.Builder builder = RegionInfo.newBuilder();
   builder.setTableName(ProtobufUtil.toProtoTableName(info.getTable()));
   builder.setRegionId(info.getRegionId());
   if (info.getStartKey() != null) {
     builder.setStartKey(ByteStringer.wrap(info.getStartKey()));
   }
   if (info.getEndKey() != null) {
     builder.setEndKey(ByteStringer.wrap(info.getEndKey()));
   }
   builder.setOffline(info.isOffline());
   builder.setSplit(info.isSplit());
   builder.setReplicaId(info.getReplicaId());
   return builder.build();
 }
コード例 #5
0
  /**
   * Get merged region info through the specified two regions
   *
   * @param a merging region A
   * @param b merging region B
   * @return the merged region info
   */
  public static HRegionInfo getMergedRegionInfo(final HRegionInfo a, final HRegionInfo b) {
    long rid = EnvironmentEdgeManager.currentTime();
    // Regionid is timestamp. Merged region's id can't be less than that of
    // merging regions else will insert at wrong location in hbase:meta
    if (rid < a.getRegionId() || rid < b.getRegionId()) {
      LOG.warn(
          "Clock skew; merging regions id are "
              + a.getRegionId()
              + " and "
              + b.getRegionId()
              + ", but current time here is "
              + rid);
      rid = Math.max(a.getRegionId(), b.getRegionId()) + 1;
    }

    byte[] startKey = null;
    byte[] endKey = null;
    // Choose the smaller as start key
    if (a.compareTo(b) <= 0) {
      startKey = a.getStartKey();
    } else {
      startKey = b.getStartKey();
    }
    // Choose the bigger as end key
    if (Bytes.equals(a.getEndKey(), HConstants.EMPTY_BYTE_ARRAY)
        || (!Bytes.equals(b.getEndKey(), HConstants.EMPTY_BYTE_ARRAY)
            && Bytes.compareTo(a.getEndKey(), b.getEndKey()) > 0)) {
      endKey = a.getEndKey();
    } else {
      endKey = b.getEndKey();
    }

    // Merged region is sorted between two merging regions in META
    HRegionInfo mergedRegionInfo = new HRegionInfo(a.getTable(), startKey, endKey, false, rid);
    return mergedRegionInfo;
  }
コード例 #6
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;
  }