Java 类org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor 实例源码

项目:LCIndex-HBase-0.94.16    文件:HConnectionManager.java   
public boolean isTableAvailable(final byte[] tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      byte[] value = row.getValue(HConstants.CATALOG_FAMILY,
          HConstants.REGIONINFO_QUALIFIER);
      HRegionInfo info = Writables.getHRegionInfoOrNull(value);
      if (info != null && !info.isSplitParent()) {
        if (Bytes.equals(tableName, info.getTableName())) {
          value = row.getValue(HConstants.CATALOG_FAMILY,
              HConstants.SERVER_QUALIFIER);
          if (value == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, this, visitor, null);
  return available.get() && (regionCount.get() > 0);
}
项目:IRIndex    文件:HConnectionManager.java   
public boolean isTableAvailable(final byte[] tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      byte[] value = row.getValue(HConstants.CATALOG_FAMILY,
          HConstants.REGIONINFO_QUALIFIER);
      HRegionInfo info = Writables.getHRegionInfoOrNull(value);
      if (info != null && !info.isSplitParent()) {
        if (Bytes.equals(tableName, info.getTableName())) {
          value = row.getValue(HConstants.CATALOG_FAMILY,
              HConstants.SERVER_QUALIFIER);
          if (value == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, this, visitor, null);
  return available.get() && (regionCount.get() > 0);
}
项目:RStore    文件:HConnectionManager.java   
public boolean isTableAvailable(final byte[] tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitor() {
    @Override
    public boolean processRow(Result row) throws IOException {
      byte[] value = row.getValue(HConstants.CATALOG_FAMILY,
          HConstants.REGIONINFO_QUALIFIER);
      HRegionInfo info = Writables.getHRegionInfoOrNull(value);
      if (info != null) {
        if (Bytes.equals(tableName, info.getTableName())) {
          value = row.getValue(HConstants.CATALOG_FAMILY,
              HConstants.SERVER_QUALIFIER);
          if (value == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, visitor);
  return available.get() && (regionCount.get() > 0);
}
项目:HBase-Research    文件:HConnectionManager.java   
public boolean isTableAvailable(final byte[] tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      byte[] value = row.getValue(HConstants.CATALOG_FAMILY,
          HConstants.REGIONINFO_QUALIFIER);
      HRegionInfo info = Writables.getHRegionInfoOrNull(value);
      if (info != null) {
        if (Bytes.equals(tableName, info.getTableName())) {
          value = row.getValue(HConstants.CATALOG_FAMILY,
              HConstants.SERVER_QUALIFIER);
          if (value == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, visitor);
  return available.get() && (regionCount.get() > 0);
}
项目:hbase-0.94.8-qod    文件:HConnectionManager.java   
public boolean isTableAvailable(final byte[] tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      byte[] value = row.getValue(HConstants.CATALOG_FAMILY,
          HConstants.REGIONINFO_QUALIFIER);
      HRegionInfo info = Writables.getHRegionInfoOrNull(value);
      if (info != null) {
        if (Bytes.equals(tableName, info.getTableName())) {
          value = row.getValue(HConstants.CATALOG_FAMILY,
              HConstants.SERVER_QUALIFIER);
          if (value == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, visitor);
  return available.get() && (regionCount.get() > 0);
}
项目:hbase-0.94.8-qod    文件:HConnectionManager.java   
public boolean isTableAvailable(final byte[] tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      byte[] value = row.getValue(HConstants.CATALOG_FAMILY,
          HConstants.REGIONINFO_QUALIFIER);
      HRegionInfo info = Writables.getHRegionInfoOrNull(value);
      if (info != null) {
        if (Bytes.equals(tableName, info.getTableName())) {
          value = row.getValue(HConstants.CATALOG_FAMILY,
              HConstants.SERVER_QUALIFIER);
          if (value == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, visitor);
  return available.get() && (regionCount.get() > 0);
}
项目:DominoHBase    文件:HConnectionManager.java   
@Override
public boolean isTableAvailable(final byte[] tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      HRegionInfo info = MetaScanner.getHRegionInfo(row);
      if (info != null) {
        if (Bytes.equals(tableName, info.getTableName())) {
          ServerName server = HRegionInfo.getServerName(row);
          if (server == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, visitor);
  return available.get() && (regionCount.get() > 0);
}
项目:hindex    文件:HConnectionManager.java   
public boolean isTableAvailable(final byte[] tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      byte[] value = row.getValue(HConstants.CATALOG_FAMILY,
          HConstants.REGIONINFO_QUALIFIER);
      HRegionInfo info = Writables.getHRegionInfoOrNull(value);
      if (info != null) {
        if (Bytes.equals(tableName, info.getTableName())) {
          value = row.getValue(HConstants.CATALOG_FAMILY,
              HConstants.SERVER_QUALIFIER);
          if (value == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, visitor);
  return available.get() && (regionCount.get() > 0);
}
项目:ditb    文件:HMaster.java   
/**
 * Return the region and current deployment for the region containing
 * the given row. If the region cannot be found, returns null. If it
 * is found, but not currently deployed, the second element of the pair
 * may be null.
 */
@VisibleForTesting // Used by TestMaster.
Pair<HRegionInfo, ServerName> getTableRegionForRow(
    final TableName tableName, final byte [] rowKey)
throws IOException {
  final AtomicReference<Pair<HRegionInfo, ServerName>> result =
    new AtomicReference<Pair<HRegionInfo, ServerName>>(null);

  MetaScannerVisitor visitor =
    new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        Pair<HRegionInfo, ServerName> pair = HRegionInfo.getHRegionInfoAndServerName(data);
        if (pair == null) {
          return false;
        }
        if (!pair.getFirst().getTable().equals(tableName)) {
          return false;
        }
        result.set(pair);
        return true;
      }
  };

  MetaScanner.metaScan(clusterConnection, visitor, tableName, rowKey, 1);
  return result.get();
}
项目:ditb    文件:MasterProcedureTestingUtility.java   
private static int countMetaRegions(final HMaster master, final TableName tableName)
    throws IOException {
  final AtomicInteger actualRegCount = new AtomicInteger(0);
  final MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result rowResult) throws IOException {
      RegionLocations list = MetaTableAccessor.getRegionLocations(rowResult);
      if (list == null) {
        LOG.warn("No serialized HRegionInfo in " + rowResult);
        return true;
      }
      HRegionLocation l = list.getRegionLocation();
      if (l == null) {
        return true;
      }
      if (!l.getRegionInfo().getTable().equals(tableName)) {
        return false;
      }
      if (l.getRegionInfo().isOffline() || l.getRegionInfo().isSplit()) return true;
      HRegionLocation[] locations = list.getRegionLocations();
      for (HRegionLocation location : locations) {
        if (location == null) continue;
        ServerName serverName = location.getServerName();
        // Make sure that regions are assigned to server
        if (serverName != null && serverName.getHostAndPort() != null) {
          actualRegCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(master.getConnection(), visitor, tableName);
  return actualRegCount.get();
}
项目:ditb    文件:HBaseAdmin.java   
/**
 * @param regionName Name of a region.
 * @return a pair of HRegionInfo and ServerName if <code>regionName</code> is
 *  a verified region name (we call {@link
 *  MetaTableAccessor#getRegion(HConnection, byte[])}
 *  else null.
 * Throw IllegalArgumentException if <code>regionName</code> is null.
 * @throws IOException
 */
Pair<HRegionInfo, ServerName> getRegion(final byte[] regionName) throws IOException {
  if (regionName == null) {
    throw new IllegalArgumentException("Pass a table name or region name");
  }
  Pair<HRegionInfo, ServerName> pair =
    MetaTableAccessor.getRegion(connection, regionName);
  if (pair == null) {
    final AtomicReference<Pair<HRegionInfo, ServerName>> result =
      new AtomicReference<Pair<HRegionInfo, ServerName>>(null);
    final String encodedName = Bytes.toString(regionName);
    MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        HRegionInfo info = HRegionInfo.getHRegionInfo(data);
        if (info == null) {
          LOG.warn("No serialized HRegionInfo in " + data);
          return true;
        }
        RegionLocations rl = MetaTableAccessor.getRegionLocations(data);
        boolean matched = false;
        ServerName sn = null;
        for (HRegionLocation h : rl.getRegionLocations()) {
          if (h != null && encodedName.equals(h.getRegionInfo().getEncodedName())) {
            sn = h.getServerName();
            info = h.getRegionInfo();
            matched = true;
          }
        }
        if (!matched) return true;
        result.set(new Pair<HRegionInfo, ServerName>(info, sn));
        return false; // found the region, stop
      }
    };

    MetaScanner.metaScan(connection, visitor, null);
    pair = result.get();
  }
  return pair;
}
项目:ditb    文件:ConnectionManager.java   
@Override
public boolean isTableAvailable(final TableName tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      HRegionInfo info = MetaScanner.getHRegionInfo(row);
      if (info != null && !info.isSplitParent()) {
        if (tableName.equals(info.getTable())) {
          ServerName server = HRegionInfo.getServerName(row);
          if (server == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        } else if (tableName.compareTo(info.getTable()) < 0) {
          // Return if we are done with the current table
          return false;
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(this, visitor, tableName);
  return available.get() && (regionCount.get() > 0);
}
项目:ditb    文件:ConnectionManager.java   
@Override
public boolean isTableAvailable(final TableName tableName, final byte[][] splitKeys)
    throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      HRegionInfo info = MetaScanner.getHRegionInfo(row);
      if (info != null && !info.isSplitParent()) {
        if (tableName.equals(info.getTable())) {
          ServerName server = HRegionInfo.getServerName(row);
          if (server == null) {
            available.set(false);
            return false;
          }
          if (!Bytes.equals(info.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) {
            for (byte[] splitKey : splitKeys) {
              // Just check if the splitkey is available
              if (Bytes.equals(info.getStartKey(), splitKey)) {
                regionCount.incrementAndGet();
                break;
              }
            }
          } else {
            // Always empty start row should be counted
            regionCount.incrementAndGet();
          }
        } else if (tableName.compareTo(info.getTable()) < 0) {
          // Return if we are done with the current table
          return false;
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(this, visitor, tableName);
  // +1 needs to be added so that the empty start row is also taken into account
  return available.get() && (regionCount.get() == splitKeys.length + 1);
}
项目:LCIndex-HBase-0.94.16    文件:HBaseAdmin.java   
/**
 * @param tableNameOrRegionName Name of a table or name of a region.
 * @param ct A {@link CatalogTracker} instance (caller of this method usually has one).
 * @return a pair of HRegionInfo and ServerName if <code>tableNameOrRegionName</code> is a
 *         verified region name (we call {@link MetaReader#getRegion(CatalogTracker, byte[])} else
 *         null. Throw an exception if <code>tableNameOrRegionName</code> is null.
 * @throws IOException
 */
Pair<HRegionInfo, ServerName> getRegion(final byte[] tableNameOrRegionName,
    final CatalogTracker ct) throws IOException {
  if (tableNameOrRegionName == null) {
    throw new IllegalArgumentException("Pass a table name or region name");
  }
  Pair<HRegionInfo, ServerName> pair = MetaReader.getRegion(ct, tableNameOrRegionName);
  if (pair == null) {
    final AtomicReference<Pair<HRegionInfo, ServerName>> result = new AtomicReference<Pair<HRegionInfo, ServerName>>(
        null);
    final String encodedName = Bytes.toString(tableNameOrRegionName);
    MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        HRegionInfo info = MetaReader.parseHRegionInfoFromCatalogResult(data,
          HConstants.REGIONINFO_QUALIFIER);
        if (info == null) {
          LOG.warn("No serialized HRegionInfo in " + data);
          return true;
        }
        if (!encodedName.equals(info.getEncodedName())) return true;
        ServerName sn = MetaReader.getServerNameFromCatalogResult(data);
        result.set(new Pair<HRegionInfo, ServerName>(info, sn));
        return false; // found the region, stop
      }
    };

    MetaScanner.metaScan(conf, connection, visitor, null);
    pair = result.get();
  }
  return pair;
}
项目:LCIndex-HBase-0.94.16    文件:CatalogJanitor.java   
/**
 * Scans META and returns a number of scanned rows, and
 * an ordered map of split parents.
 */
Pair<Integer, Map<HRegionInfo, Result>> getSplitParents() throws IOException {
  // TODO: Only works with single .META. region currently.  Fix.
  final AtomicInteger count = new AtomicInteger(0);
  // Keep Map of found split parents.  There are candidates for cleanup.
  // Use a comparator that has split parents come before its daughters.
  final Map<HRegionInfo, Result> splitParents =
    new TreeMap<HRegionInfo, Result>(new SplitParentFirstComparator());
  // This visitor collects split parents and counts rows in the .META. table

  MetaScannerVisitor visitor = new MetaScanner.BlockingMetaScannerVisitor(server.getConfiguration()) {
    @Override
    public boolean processRowInternal(Result r) throws IOException {
      if (r == null || r.isEmpty()) return true;
      count.incrementAndGet();
      HRegionInfo info = getHRegionInfo(r);
      if (info == null) return true; // Keep scanning
      if (info.isSplitParent()) splitParents.put(info, r);
      // Returning true means "keep scanning"
      return true;
    }
  };

  // Run full scan of .META. catalog table passing in our custom visitor
  MetaScanner.metaScan(server.getConfiguration(), visitor);

  return new Pair<Integer, Map<HRegionInfo, Result>>(count.get(), splitParents);
}
项目:LCIndex-HBase-0.94.16    文件:HMaster.java   
/**
 * Return the region and current deployment for the region containing
 * the given row. If the region cannot be found, returns null. If it
 * is found, but not currently deployed, the second element of the pair
 * may be null.
 */
Pair<HRegionInfo, ServerName> getTableRegionForRow(
    final byte [] tableName, final byte [] rowKey)
throws IOException {
  final AtomicReference<Pair<HRegionInfo, ServerName>> result =
    new AtomicReference<Pair<HRegionInfo, ServerName>>(null);

  MetaScannerVisitor visitor =
    new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        Pair<HRegionInfo, ServerName> pair = MetaReader.parseCatalogResult(data);
        if (pair == null) {
          return false;
        }
        if (!Bytes.equals(pair.getFirst().getTableName(), tableName)) {
          return false;
        }
        result.set(pair);
        return true;
      }
  };

  MetaScanner.metaScan(conf, visitor, tableName, rowKey, 1);
  return result.get();
}
项目:pbase    文件:HMaster.java   
/**
 * Return the region and current deployment for the region containing
 * the given row. If the region cannot be found, returns null. If it
 * is found, but not currently deployed, the second element of the pair
 * may be null.
 */
@VisibleForTesting
// Used by TestMaster.
Pair<HRegionInfo, ServerName> getTableRegionForRow(
        final TableName tableName, final byte[] rowKey)
        throws IOException {
    final AtomicReference<Pair<HRegionInfo, ServerName>> result =
            new AtomicReference<Pair<HRegionInfo, ServerName>>(null);

    MetaScannerVisitor visitor =
            new MetaScannerVisitorBase() {
                @Override
                public boolean processRow(Result data) throws IOException {
                    if (data == null || data.size() <= 0) {
                        return true;
                    }
                    Pair<HRegionInfo, ServerName> pair = HRegionInfo.getHRegionInfoAndServerName(data);
                    if (pair == null) {
                        return false;
                    }
                    if (!pair.getFirst().getTable().equals(tableName)) {
                        return false;
                    }
                    result.set(pair);
                    return true;
                }
            };

    MetaScanner.metaScan(clusterConnection, visitor, tableName, rowKey, 1);
    return result.get();
}
项目:pbase    文件:HBaseAdmin.java   
/**
 * @param regionName Name of a region.
 * @return a pair of HRegionInfo and ServerName if <code>regionName</code> is
 *  a verified region name (we call {@link
 *  MetaTableAccessor#getRegion(HConnection, byte[])}
 *  else null.
 * Throw IllegalArgumentException if <code>regionName</code> is null.
 * @throws IOException
 */
Pair<HRegionInfo, ServerName> getRegion(final byte[] regionName) throws IOException {
  if (regionName == null) {
    throw new IllegalArgumentException("Pass a table name or region name");
  }
  Pair<HRegionInfo, ServerName> pair =
    MetaTableAccessor.getRegion(connection, regionName);
  if (pair == null) {
    final AtomicReference<Pair<HRegionInfo, ServerName>> result =
      new AtomicReference<Pair<HRegionInfo, ServerName>>(null);
    final String encodedName = Bytes.toString(regionName);
    MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        HRegionInfo info = HRegionInfo.getHRegionInfo(data);
        if (info == null) {
          LOG.warn("No serialized HRegionInfo in " + data);
          return true;
        }
        if (!encodedName.equals(info.getEncodedName())) return true;
        ServerName sn = HRegionInfo.getServerName(data);
        result.set(new Pair<HRegionInfo, ServerName>(info, sn));
        return false; // found the region, stop
      }
    };

    MetaScanner.metaScan(connection, visitor, null);
    pair = result.get();
  }
  return pair;
}
项目:pbase    文件:ConnectionManager.java   
@Override
public boolean isTableAvailable(final TableName tableName) throws IOException {
    final AtomicBoolean available = new AtomicBoolean(true);
    final AtomicInteger regionCount = new AtomicInteger(0);
    MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
        @Override
        public boolean processRow(Result row) throws IOException {
            HRegionInfo info = MetaScanner.getHRegionInfo(row);
            if (info != null && !info.isSplitParent()) {
                if (tableName.equals(info.getTable())) {
                    ServerName server = HRegionInfo.getServerName(row);
                    if (server == null) {
                        available.set(false);
                        return false;
                    }
                    regionCount.incrementAndGet();
                } else if (tableName.compareTo(info.getTable()) < 0) {
                    // Return if we are done with the current table
                    return false;
                }
            }
            return true;
        }
    };
    MetaScanner.metaScan(this, visitor, tableName);
    return available.get() && (regionCount.get() > 0);
}
项目:pbase    文件:ConnectionManager.java   
@Override
public boolean isTableAvailable(final TableName tableName, final byte[][] splitKeys)
        throws IOException {
    final AtomicBoolean available = new AtomicBoolean(true);
    final AtomicInteger regionCount = new AtomicInteger(0);
    MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
        @Override
        public boolean processRow(Result row) throws IOException {
            HRegionInfo info = MetaScanner.getHRegionInfo(row);
            if (info != null && !info.isSplitParent()) {
                if (tableName.equals(info.getTable())) {
                    ServerName server = HRegionInfo.getServerName(row);
                    if (server == null) {
                        available.set(false);
                        return false;
                    }
                    if (!Bytes.equals(info.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) {
                        for (byte[] splitKey : splitKeys) {
                            // Just check if the splitkey is available
                            if (Bytes.equals(info.getStartKey(), splitKey)) {
                                regionCount.incrementAndGet();
                                break;
                            }
                        }
                    } else {
                        // Always empty start row should be counted
                        regionCount.incrementAndGet();
                    }
                } else if (tableName.compareTo(info.getTable()) < 0) {
                    // Return if we are done with the current table
                    return false;
                }
            }
            return true;
        }
    };
    MetaScanner.metaScan(this, visitor, tableName);
    // +1 needs to be added so that the empty start row is also taken into account
    return available.get() && (regionCount.get() == splitKeys.length + 1);
}
项目:HIndex    文件:HMaster.java   
/**
 * Return the region and current deployment for the region containing
 * the given row. If the region cannot be found, returns null. If it
 * is found, but not currently deployed, the second element of the pair
 * may be null.
 */
Pair<HRegionInfo, ServerName> getTableRegionForRow(
    final TableName tableName, final byte [] rowKey)
throws IOException {
  final AtomicReference<Pair<HRegionInfo, ServerName>> result =
    new AtomicReference<Pair<HRegionInfo, ServerName>>(null);

  MetaScannerVisitor visitor =
    new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        Pair<HRegionInfo, ServerName> pair = HRegionInfo.getHRegionInfoAndServerName(data);
        if (pair == null) {
          return false;
        }
        if (!pair.getFirst().getTable().equals(tableName)) {
          return false;
        }
        result.set(pair);
        return true;
      }
  };

  MetaScanner.metaScan(conf, visitor, tableName, rowKey, 1);
  return result.get();
}
项目:HIndex    文件:HBaseAdmin.java   
/**
 * @param tableNameOrRegionName Name of a table or name of a region.
 * @param ct A {@link CatalogTracker} instance (caller of this method usually has one).
 * @return a pair of HRegionInfo and ServerName if <code>tableNameOrRegionName</code> is
 *  a verified region name (we call {@link  MetaReader#getRegion( CatalogTracker, byte[])}
 *  else null.
 * Throw an exception if <code>tableNameOrRegionName</code> is null.
 * @throws IOException
 */
Pair<HRegionInfo, ServerName> getRegion(final byte[] tableNameOrRegionName,
    final CatalogTracker ct) throws IOException {
  if (tableNameOrRegionName == null) {
    throw new IllegalArgumentException("Pass a table name or region name");
  }
  Pair<HRegionInfo, ServerName> pair = MetaReader.getRegion(ct, tableNameOrRegionName);
  if (pair == null) {
    final AtomicReference<Pair<HRegionInfo, ServerName>> result =
      new AtomicReference<Pair<HRegionInfo, ServerName>>(null);
    final String encodedName = Bytes.toString(tableNameOrRegionName);
    MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        HRegionInfo info = HRegionInfo.getHRegionInfo(data);
        if (info == null) {
          LOG.warn("No serialized HRegionInfo in " + data);
          return true;
        }
        if (!encodedName.equals(info.getEncodedName())) return true;
        ServerName sn = HRegionInfo.getServerName(data);
        result.set(new Pair<HRegionInfo, ServerName>(info, sn));
        return false; // found the region, stop
      }
    };

    MetaScanner.metaScan(conf, connection, visitor, null);
    pair = result.get();
  }
  return pair;
}
项目:HIndex    文件:HConnectionManager.java   
@Override
public boolean isTableAvailable(final TableName tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      HRegionInfo info = MetaScanner.getHRegionInfo(row);
      if (info != null && !info.isSplitParent()) {
        if (tableName.equals(info.getTable())) {
          ServerName server = HRegionInfo.getServerName(row);
          if (server == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        } else if (tableName.compareTo(info.getTable()) < 0) {
          // Return if we are done with the current table
          return false;
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, this, visitor, tableName);
  return available.get() && (regionCount.get() > 0);
}
项目:HIndex    文件:HConnectionManager.java   
@Override
public boolean isTableAvailable(final TableName tableName, final byte[][] splitKeys)
    throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      HRegionInfo info = MetaScanner.getHRegionInfo(row);
      if (info != null && !info.isSplitParent()) {
        if (tableName.equals(info.getTable())) {
          ServerName server = HRegionInfo.getServerName(row);
          if (server == null) {
            available.set(false);
            return false;
          }
          if (!Bytes.equals(info.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) {
            for (byte[] splitKey : splitKeys) {
              // Just check if the splitkey is available
              if (Bytes.equals(info.getStartKey(), splitKey)) {
                regionCount.incrementAndGet();
                break;
              }
            }
          } else {
            // Always empty start row should be counted
            regionCount.incrementAndGet();
          }
        } else if (tableName.compareTo(info.getTable()) < 0) {
          // Return if we are done with the current table
          return false;
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, this, visitor, tableName);
  // +1 needs to be added so that the empty start row is also taken into account
  return available.get() && (regionCount.get() == splitKeys.length + 1);
}
项目:IRIndex    文件:HBaseAdmin.java   
/**
 * @param tableNameOrRegionName Name of a table or name of a region.
 * @param ct A {@link CatalogTracker} instance (caller of this method usually has one).
 * @return a pair of HRegionInfo and ServerName if <code>tableNameOrRegionName</code> is
 *  a verified region name (we call {@link  MetaReader#getRegion( CatalogTracker, byte[])}
 *  else null.
 * Throw an exception if <code>tableNameOrRegionName</code> is null.
 * @throws IOException
 */
Pair<HRegionInfo, ServerName> getRegion(final byte[] tableNameOrRegionName,
    final CatalogTracker ct) throws IOException {
  if (tableNameOrRegionName == null) {
    throw new IllegalArgumentException("Pass a table name or region name");
  }
  Pair<HRegionInfo, ServerName> pair = MetaReader.getRegion(ct, tableNameOrRegionName);
  if (pair == null) {
    final AtomicReference<Pair<HRegionInfo, ServerName>> result =
      new AtomicReference<Pair<HRegionInfo, ServerName>>(null);
    final String encodedName = Bytes.toString(tableNameOrRegionName);
    MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        HRegionInfo info = MetaReader.parseHRegionInfoFromCatalogResult(
          data, HConstants.REGIONINFO_QUALIFIER);
        if (info == null) {
          LOG.warn("No serialized HRegionInfo in " + data);
          return true;
        }
        if (!encodedName.equals(info.getEncodedName())) return true;
        ServerName sn = MetaReader.getServerNameFromCatalogResult(data);
        result.set(new Pair<HRegionInfo, ServerName>(info, sn));
        return false; // found the region, stop
      }
    };

    MetaScanner.metaScan(conf, connection, visitor, null);
    pair = result.get();
  }
  return pair;
}
项目:IRIndex    文件:CatalogJanitor.java   
/**
 * Scans META and returns a number of scanned rows, and
 * an ordered map of split parents.
 */
Pair<Integer, Map<HRegionInfo, Result>> getSplitParents() throws IOException {
  // TODO: Only works with single .META. region currently.  Fix.
  final AtomicInteger count = new AtomicInteger(0);
  // Keep Map of found split parents.  There are candidates for cleanup.
  // Use a comparator that has split parents come before its daughters.
  final Map<HRegionInfo, Result> splitParents =
    new TreeMap<HRegionInfo, Result>(new SplitParentFirstComparator());
  // This visitor collects split parents and counts rows in the .META. table

  MetaScannerVisitor visitor = new MetaScanner.BlockingMetaScannerVisitor(server.getConfiguration()) {
    @Override
    public boolean processRowInternal(Result r) throws IOException {
      if (r == null || r.isEmpty()) return true;
      count.incrementAndGet();
      HRegionInfo info = getHRegionInfo(r);
      if (info == null) return true; // Keep scanning
      if (info.isSplitParent()) splitParents.put(info, r);
      // Returning true means "keep scanning"
      return true;
    }
  };

  // Run full scan of .META. catalog table passing in our custom visitor
  MetaScanner.metaScan(server.getConfiguration(), visitor);

  return new Pair<Integer, Map<HRegionInfo, Result>>(count.get(), splitParents);
}
项目:IRIndex    文件:HMaster.java   
/**
 * Return the region and current deployment for the region containing
 * the given row. If the region cannot be found, returns null. If it
 * is found, but not currently deployed, the second element of the pair
 * may be null.
 */
Pair<HRegionInfo, ServerName> getTableRegionForRow(
    final byte [] tableName, final byte [] rowKey)
throws IOException {
  final AtomicReference<Pair<HRegionInfo, ServerName>> result =
    new AtomicReference<Pair<HRegionInfo, ServerName>>(null);

  MetaScannerVisitor visitor =
    new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        Pair<HRegionInfo, ServerName> pair = MetaReader.parseCatalogResult(data);
        if (pair == null) {
          return false;
        }
        if (!Bytes.equals(pair.getFirst().getTableName(), tableName)) {
          return false;
        }
        result.set(pair);
        return true;
      }
  };

  MetaScanner.metaScan(conf, visitor, tableName, rowKey, 1);
  return result.get();
}
项目:RStore    文件:HTable.java   
/**
 * Gets the starting and ending row keys for every region in the currently
 * open table.
 * <p>
 * This is mainly useful for the MapReduce integration.
 * @return Pair of arrays of region starting and ending row keys
 * @throws IOException if a remote or network exception occurs
 */
@SuppressWarnings("unchecked")
public Pair<byte[][],byte[][]> getStartEndKeys() throws IOException {
  final List<byte[]> startKeyList = new ArrayList<byte[]>();
  final List<byte[]> endKeyList = new ArrayList<byte[]>();
  MetaScannerVisitor visitor = new MetaScannerVisitor() {
    public boolean processRow(Result rowResult) throws IOException {
      byte [] bytes = rowResult.getValue(HConstants.CATALOG_FAMILY,
        HConstants.REGIONINFO_QUALIFIER);
      if (bytes == null) {
        LOG.warn("Null " + HConstants.REGIONINFO_QUALIFIER + " cell in " +
          rowResult);
        return true;
      }
      HRegionInfo info = Writables.getHRegionInfo(bytes);
      if (Bytes.equals(info.getTableName(), getTableName())) {
        if (!(info.isOffline() || info.isSplit())) {
          startKeyList.add(info.getStartKey());
          endKeyList.add(info.getEndKey());
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(configuration, visitor, this.tableName);
  return new Pair<byte [][], byte [][]>(
    startKeyList.toArray(new byte[startKeyList.size()][]),
    endKeyList.toArray(new byte[endKeyList.size()][]));
}
项目:RStore    文件:HMaster.java   
/**
 * Return the region and current deployment for the region containing
 * the given row. If the region cannot be found, returns null. If it
 * is found, but not currently deployed, the second element of the pair
 * may be null.
 */
Pair<HRegionInfo, ServerName> getTableRegionForRow(
    final byte [] tableName, final byte [] rowKey)
throws IOException {
  final AtomicReference<Pair<HRegionInfo, ServerName>> result =
    new AtomicReference<Pair<HRegionInfo, ServerName>>(null);

  MetaScannerVisitor visitor =
    new MetaScannerVisitor() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        Pair<HRegionInfo, ServerName> pair = MetaReader.parseCatalogResult(data);
        if (pair == null) {
          return false;
        }
        if (!Bytes.equals(pair.getFirst().getTableName(), tableName)) {
          return false;
        }
        result.set(pair);
        return true;
      }
  };

  MetaScanner.metaScan(conf, visitor, tableName, rowKey, 1);
  return result.get();
}
项目:PyroDB    文件:HMaster.java   
/**
 * Return the region and current deployment for the region containing
 * the given row. If the region cannot be found, returns null. If it
 * is found, but not currently deployed, the second element of the pair
 * may be null.
 */
Pair<HRegionInfo, ServerName> getTableRegionForRow(
    final TableName tableName, final byte [] rowKey)
throws IOException {
  final AtomicReference<Pair<HRegionInfo, ServerName>> result =
    new AtomicReference<Pair<HRegionInfo, ServerName>>(null);

  MetaScannerVisitor visitor =
    new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        Pair<HRegionInfo, ServerName> pair = HRegionInfo.getHRegionInfoAndServerName(data);
        if (pair == null) {
          return false;
        }
        if (!pair.getFirst().getTable().equals(tableName)) {
          return false;
        }
        result.set(pair);
        return true;
      }
  };

  MetaScanner.metaScan(conf, visitor, tableName, rowKey, 1);
  return result.get();
}
项目:PyroDB    文件:HBaseAdmin.java   
/**
 * @param tableNameOrRegionName Name of a table or name of a region.
 * @param ct A {@link CatalogTracker} instance (caller of this method usually has one).
 * @return a pair of HRegionInfo and ServerName if <code>tableNameOrRegionName</code> is
 *  a verified region name (we call {@link  MetaReader#getRegion( CatalogTracker, byte[])}
 *  else null.
 * Throw an exception if <code>tableNameOrRegionName</code> is null.
 * @throws IOException
 */
Pair<HRegionInfo, ServerName> getRegion(final byte[] tableNameOrRegionName,
    final CatalogTracker ct) throws IOException {
  if (tableNameOrRegionName == null) {
    throw new IllegalArgumentException("Pass a table name or region name");
  }
  Pair<HRegionInfo, ServerName> pair = MetaReader.getRegion(ct, tableNameOrRegionName);
  if (pair == null) {
    final AtomicReference<Pair<HRegionInfo, ServerName>> result =
      new AtomicReference<Pair<HRegionInfo, ServerName>>(null);
    final String encodedName = Bytes.toString(tableNameOrRegionName);
    MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        HRegionInfo info = HRegionInfo.getHRegionInfo(data);
        if (info == null) {
          LOG.warn("No serialized HRegionInfo in " + data);
          return true;
        }
        if (!encodedName.equals(info.getEncodedName())) return true;
        ServerName sn = HRegionInfo.getServerName(data);
        result.set(new Pair<HRegionInfo, ServerName>(info, sn));
        return false; // found the region, stop
      }
    };

    MetaScanner.metaScan(conf, connection, visitor, null);
    pair = result.get();
  }
  return pair;
}
项目:PyroDB    文件:ConnectionManager.java   
@Override
public boolean isTableAvailable(final TableName tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      HRegionInfo info = MetaScanner.getHRegionInfo(row);
      if (info != null && !info.isSplitParent()) {
        if (tableName.equals(info.getTable())) {
          ServerName server = HRegionInfo.getServerName(row);
          if (server == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        } else if (tableName.compareTo(info.getTable()) < 0) {
          // Return if we are done with the current table
          return false;
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, this, visitor, tableName);
  return available.get() && (regionCount.get() > 0);
}
项目:PyroDB    文件:ConnectionManager.java   
@Override
public boolean isTableAvailable(final TableName tableName, final byte[][] splitKeys)
    throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      HRegionInfo info = MetaScanner.getHRegionInfo(row);
      if (info != null && !info.isSplitParent()) {
        if (tableName.equals(info.getTable())) {
          ServerName server = HRegionInfo.getServerName(row);
          if (server == null) {
            available.set(false);
            return false;
          }
          if (!Bytes.equals(info.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) {
            for (byte[] splitKey : splitKeys) {
              // Just check if the splitkey is available
              if (Bytes.equals(info.getStartKey(), splitKey)) {
                regionCount.incrementAndGet();
                break;
              }
            }
          } else {
            // Always empty start row should be counted
            regionCount.incrementAndGet();
          }
        } else if (tableName.compareTo(info.getTable()) < 0) {
          // Return if we are done with the current table
          return false;
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, this, visitor, tableName);
  // +1 needs to be added so that the empty start row is also taken into account
  return available.get() && (regionCount.get() == splitKeys.length + 1);
}
项目:c5    文件:HMaster.java   
/**
 * Return the region and current deployment for the region containing
 * the given row. If the region cannot be found, returns null. If it
 * is found, but not currently deployed, the second element of the pair
 * may be null.
 */
Pair<HRegionInfo, ServerName> getTableRegionForRow(
    final TableName tableName, final byte [] rowKey)
throws IOException {
  final AtomicReference<Pair<HRegionInfo, ServerName>> result =
    new AtomicReference<Pair<HRegionInfo, ServerName>>(null);

  MetaScannerVisitor visitor =
    new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        Pair<HRegionInfo, ServerName> pair = HRegionInfo.getHRegionInfoAndServerName(data);
        if (pair == null) {
          return false;
        }
        if (!pair.getFirst().getTable().equals(tableName)) {
          return false;
        }
        result.set(pair);
        return true;
      }
  };

  MetaScanner.metaScan(conf, visitor, tableName, rowKey, 1);
  return result.get();
}
项目:c5    文件:HBaseAdmin.java   
/**
 * @param tableNameOrRegionName Name of a table or name of a region.
 * @param ct A {@link CatalogTracker} instance (caller of this method usually has one).
 * @return a pair of HRegionInfo and ServerName if <code>tableNameOrRegionName</code> is
 *  a verified region name (we call {@link  MetaReader#getRegion( CatalogTracker, byte[])}
 *  else null.
 * Throw an exception if <code>tableNameOrRegionName</code> is null.
 * @throws IOException
 */
Pair<HRegionInfo, ServerName> getRegion(final byte[] tableNameOrRegionName,
    final CatalogTracker ct) throws IOException {
  if (tableNameOrRegionName == null) {
    throw new IllegalArgumentException("Pass a table name or region name");
  }
  Pair<HRegionInfo, ServerName> pair = MetaReader.getRegion(ct, tableNameOrRegionName);
  if (pair == null) {
    final AtomicReference<Pair<HRegionInfo, ServerName>> result =
      new AtomicReference<Pair<HRegionInfo, ServerName>>(null);
    final String encodedName = Bytes.toString(tableNameOrRegionName);
    MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        HRegionInfo info = HRegionInfo.getHRegionInfo(data);
        if (info == null) {
          LOG.warn("No serialized HRegionInfo in " + data);
          return true;
        }
        if (!encodedName.equals(info.getEncodedName())) return true;
        ServerName sn = HRegionInfo.getServerName(data);
        result.set(new Pair<HRegionInfo, ServerName>(info, sn));
        return false; // found the region, stop
      }
    };

    MetaScanner.metaScan(conf, connection, visitor, null);
    pair = result.get();
  }
  return pair;
}
项目:c5    文件:HConnectionManager.java   
@Override
public boolean isTableAvailable(final TableName tableName) throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      HRegionInfo info = MetaScanner.getHRegionInfo(row);
      if (info != null && !info.isSplitParent()) {
        if (tableName.equals(info.getTable())) {
          ServerName server = HRegionInfo.getServerName(row);
          if (server == null) {
            available.set(false);
            return false;
          }
          regionCount.incrementAndGet();
        } else if (tableName.compareTo(info.getTable()) < 0) {
          // Return if we are done with the current table
          return false;
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, this, visitor, tableName);
  return available.get() && (regionCount.get() > 0);
}
项目:c5    文件:HConnectionManager.java   
@Override
public boolean isTableAvailable(final TableName tableName, final byte[][] splitKeys)
    throws IOException {
  final AtomicBoolean available = new AtomicBoolean(true);
  final AtomicInteger regionCount = new AtomicInteger(0);
  MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result row) throws IOException {
      HRegionInfo info = MetaScanner.getHRegionInfo(row);
      if (info != null && !info.isSplitParent()) {
        if (tableName.equals(info.getTable())) {
          ServerName server = HRegionInfo.getServerName(row);
          if (server == null) {
            available.set(false);
            return false;
          }
          if (!Bytes.equals(info.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) {
            for (byte[] splitKey : splitKeys) {
              // Just check if the splitkey is available
              if (Bytes.equals(info.getStartKey(), splitKey)) {
                regionCount.incrementAndGet();
                break;
              }
            }
          } else {
            // Always empty start row should be counted
            regionCount.incrementAndGet();
          }
        } else if (tableName.compareTo(info.getTable()) < 0) {
          // Return if we are done with the current table
          return false;
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(conf, this, visitor, tableName);
  // +1 needs to be added so that the empty start row is also taken into account
  return available.get() && (regionCount.get() == splitKeys.length + 1);
}
项目:HBase-Research    文件:HBaseAdmin.java   
/**
 * @param tableNameOrRegionName Name of a table or name of a region.
 * @param ct A {@link CatalogTracker} instance (caller of this method usually has one).
 * @return a pair of HRegionInfo and ServerName if <code>tableNameOrRegionName</code> is
 *  a verified region name (we call {@link  MetaReader#getRegion( CatalogTracker, byte[])}
 *  else null.
 * Throw an exception if <code>tableNameOrRegionName</code> is null.
 * @throws IOException
 */
Pair<HRegionInfo, ServerName> getRegion(final byte[] tableNameOrRegionName,
    final CatalogTracker ct) throws IOException {
  if (tableNameOrRegionName == null) {
    throw new IllegalArgumentException("Pass a table name or region name");
  }
  Pair<HRegionInfo, ServerName> pair = MetaReader.getRegion(ct, tableNameOrRegionName);
  if (pair == null) {
    final AtomicReference<Pair<HRegionInfo, ServerName>> result =
      new AtomicReference<Pair<HRegionInfo, ServerName>>(null);
    final String encodedName = Bytes.toString(tableNameOrRegionName);
    MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        HRegionInfo info = MetaReader.parseHRegionInfoFromCatalogResult(
          data, HConstants.REGIONINFO_QUALIFIER);
        if (info == null) {
          LOG.warn("No serialized HRegionInfo in " + data);
          return true;
        }
        if (!encodedName.equals(info.getEncodedName())) return true;
        ServerName sn = MetaReader.getServerNameFromCatalogResult(data);
        result.set(new Pair<HRegionInfo, ServerName>(info, sn));
        return false; // found the region, stop
      }
    };

    MetaScanner.metaScan(conf, visitor);
    pair = result.get();
  }
  return pair;
}
项目:HBase-Research    文件:CatalogJanitor.java   
/**
 * Scans META and returns a number of scanned rows, and
 * an ordered map of split parents.
 */
Pair<Integer, Map<HRegionInfo, Result>> getSplitParents() throws IOException {
  // TODO: Only works with single .META. region currently.  Fix.
  final AtomicInteger count = new AtomicInteger(0);
  // Keep Map of found split parents.  There are candidates for cleanup.
  // Use a comparator that has split parents come before its daughters.
  final Map<HRegionInfo, Result> splitParents =
    new TreeMap<HRegionInfo, Result>(new SplitParentFirstComparator());
  // This visitor collects split parents and counts rows in the .META. table

  MetaScannerVisitor visitor = new MetaScanner.BlockingMetaScannerVisitor(server.getConfiguration()) {
    @Override
    public boolean processRowInternal(Result r) throws IOException {
      if (r == null || r.isEmpty()) return true;
      count.incrementAndGet();
      HRegionInfo info = getHRegionInfo(r);
      if (info == null) return true; // Keep scanning
      if (info.isSplitParent()) splitParents.put(info, r);
      // Returning true means "keep scanning"
      return true;
    }
  };

  // Run full scan of .META. catalog table passing in our custom visitor
  MetaScanner.metaScan(server.getConfiguration(), visitor);

  return new Pair<Integer, Map<HRegionInfo, Result>>(count.get(), splitParents);
}
项目:HBase-Research    文件:HMaster.java   
/**
 * Return the region and current deployment for the region containing
 * the given row. If the region cannot be found, returns null. If it
 * is found, but not currently deployed, the second element of the pair
 * may be null.
 */
Pair<HRegionInfo, ServerName> getTableRegionForRow(
    final byte [] tableName, final byte [] rowKey)
throws IOException {
  final AtomicReference<Pair<HRegionInfo, ServerName>> result =
    new AtomicReference<Pair<HRegionInfo, ServerName>>(null);

  MetaScannerVisitor visitor =
    new MetaScannerVisitorBase() {
      @Override
      public boolean processRow(Result data) throws IOException {
        if (data == null || data.size() <= 0) {
          return true;
        }
        Pair<HRegionInfo, ServerName> pair = MetaReader.parseCatalogResult(data);
        if (pair == null) {
          return false;
        }
        if (!Bytes.equals(pair.getFirst().getTableName(), tableName)) {
          return false;
        }
        result.set(pair);
        return true;
      }
  };

  MetaScanner.metaScan(conf, visitor, tableName, rowKey, 1);
  return result.get();
}