Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.HRegionLocation


      setupTable(table);
      assertEquals(ROWKEYS.length, countRows());

      // make sure data in regions, if in hlog only there is no data loss
      TEST_UTIL.getHBaseAdmin().flush(table);
      HRegionLocation location = tbl.getRegionLocation("B");

      meta = new HTable(conf, HTableDescriptor.META_TABLEDESC.getName());
      HRegionInfo hri = location.getRegionInfo();

      // do a regular split
      HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
      byte[] regionName = location.getRegionInfo().getRegionName();
      admin.split(location.getRegionInfo().getRegionName(), Bytes.toBytes("BM"));
      TestEndToEndSplitTransaction.blockUntilRegionSplit(
          TEST_UTIL.getConfiguration(), 60000, regionName, true);

      // TODO: fixHdfsHoles does not work against splits, since the parent dir lingers on
      // for some time until children references are deleted. HBCK erroneously sees this as
View Full Code Here


      setupTable(table);
      assertEquals(ROWKEYS.length, countRows());

      // make sure data in regions, if in hlog only there is no data loss
      TEST_UTIL.getHBaseAdmin().flush(table);
      HRegionLocation location = tbl.getRegionLocation("B");

      meta = new HTable(conf, HTableDescriptor.META_TABLEDESC.getName());
      HRegionInfo hri = location.getRegionInfo();

      // do a regular split
      HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
      byte[] regionName = location.getRegionInfo().getRegionName();
      admin.split(location.getRegionInfo().getRegionName(), Bytes.toBytes("BM"));
      TestEndToEndSplitTransaction.blockUntilRegionSplit(
          TEST_UTIL.getConfiguration(), 60000, regionName, true);

      PairOfSameType<HRegionInfo> daughters = MetaReader.getDaughterRegions(meta.get(new Get(regionName)));
View Full Code Here

          HServerAddress rootServer = hbaseMaster.getRootRegionLocation();
          if (rootServer != null) {
            // By setting the root region location, we bypass the wait imposed on
            // HTable for all regions being assigned.
            this.connection.setRootRegionLocation(
                new HRegionLocation(HRegionInfo.ROOT_REGIONINFO, rootServer));
            haveRootRegion.set(true);
          }
        }
        long now = System.currentTimeMillis();
        if (lastMsg != 0 && (now - lastMsg) >= serverLeaseTimeout) {
View Full Code Here

          // Store the Root Region location (in memory)
          HServerAddress rootServer = serverInfo.getServerAddress();
          if (master.regionManager.inSafeMode()) {
            master.connection.setRootRegionLocation(
                new HRegionLocation(region, rootServer));
          }
          master.regionManager.setRootRegionLocation(rootServer);
        } else {
          // Note that the table has been assigned and is waiting for the
          // meta table to be updated.
View Full Code Here

      * info that contains the table and row we're seeking.
      */
    private HRegionLocation locateRegionInMeta(final byte [] parentTable,
      final byte [] tableName, final byte [] row, boolean useCache)
    throws IOException{
      HRegionLocation location = null;
      // If supposed to be using the cache, then check it for a possible hit.
      // Otherwise, delete any existing cached location so it won't interfere.
      if (useCache) {
        location = getCachedLocation(tableName, row);
        if (location != null) {
          return location;
        }
      } else {
        deleteCachedLocation(tableName, row);
      }
     
      // build the key of the meta region we should be looking for.
      // the extra 9's on the end are necessary to allow "exact" matches
      // without knowing the precise region names.
      byte [] metaKey = HRegionInfo.createRegionName(tableName, row,
        HConstants.NINES);
      for (int tries = 0; true; tries++) {
        if (tries >= numRetries) {
          throw new NoServerForRegionException("Unable to find region for "
            + Bytes.toString(row) + " after " + numRetries + " tries.");
        }

        try {
          // locate the root region
          HRegionLocation metaLocation = locateRegion(parentTable, metaKey);
          HRegionInterface server =
            getHRegionConnection(metaLocation.getServerAddress());

          // Query the root region for the location of the meta region
          RowResult regionInfoRow = server.getClosestRowBefore(
            metaLocation.getRegionInfo().getRegionName(), metaKey,
            HConstants.COLUMN_FAMILY);
          if (regionInfoRow == null) {
            throw new TableNotFoundException(Bytes.toString(tableName));
          }

          Cell value = regionInfoRow.get(COL_REGIONINFO);
          if (value == null || value.getValue().length == 0) {
            throw new IOException("HRegionInfo was null or empty in " +
              Bytes.toString(parentTable));
          }
          // convert the row result into the HRegionLocation we need!
          HRegionInfo regionInfo = (HRegionInfo) Writables.getWritable(
              value.getValue(), new HRegionInfo());
          // possible we got a region of a different table...
          if (!Bytes.equals(regionInfo.getTableDesc().getName(), tableName)) {
            throw new TableNotFoundException(
              "Table '" + Bytes.toString(tableName) + "' was not found.");
          }
          if (regionInfo.isOffline()) {
            throw new RegionOfflineException("region offline: " +
              regionInfo.getRegionNameAsString());
          }
         
          String serverAddress =
            Writables.cellToString(regionInfoRow.get(COL_SERVER));
          if (serverAddress.equals("")) {
            throw new NoServerForRegionException("No server address listed " +
              "in " + Bytes.toString(parentTable) + " for region " +
              regionInfo.getRegionNameAsString());
          }
       
          // instantiate the location
          location = new HRegionLocation(regionInfo,
              new HServerAddress(serverAddress));
          cacheLocation(tableName, location);
          return location;
        } catch (TableNotFoundException e) {
          // if we got this error, probably means the table just plain doesn't
View Full Code Here

      // if there's something in the cache for this table.
      if (tableLocations.isEmpty()) {
        return null;
      }

      HRegionLocation rl = tableLocations.get(row);
      if (rl != null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Cache hit for row <" +
            Bytes.toString(row) +
            "> in tableName " + Bytes.toString(tableName) +
            ": location server " + rl.getServerAddress() +
            ", location region name " +
            rl.getRegionInfo().getRegionNameAsString());
        }
        return rl;
      }

      // Cut the cache so that we only get the part that could contain
      // regions that match our key
      SoftValueSortedMap<byte[], HRegionLocation> matchingRegions =
        tableLocations.headMap(row);

      // if that portion of the map is empty, then we're done. otherwise,
      // we need to examine the cached location to verify that it is
      // a match by end key as well.
      if (!matchingRegions.isEmpty()) {
        HRegionLocation possibleRegion =
          matchingRegions.get(matchingRegions.lastKey());

        // there is a possibility that the reference was garbage collected
        // in the instant since we checked isEmpty().
        if (possibleRegion != null) {
          byte[] endKey = possibleRegion.getRegionInfo().getEndKey();

          // make sure that the end key is greater than the row we're looking
          // for, otherwise the row actually belongs in the next region, not
          // this one. the exception case is when the endkey is EMPTY_START_ROW,
          // signifying that the region we're checking is actually the last
          // region in the table.
          if (HStoreKey.equalsTwoRowKeys(possibleRegion.getRegionInfo(),
              endKey, HConstants.EMPTY_END_ROW) ||
              HStoreKey.compareTwoRowKeys(possibleRegion.getRegionInfo(),
                  endKey, row) > 0) {
            return possibleRegion;
          }
        }
      }
View Full Code Here

        // if that portion of the map is empty, then we're done. otherwise,
        // we need to examine the cached location to verify that it is
        // a match by end key as well.
        if (!matchingRegions.isEmpty()) {
          HRegionLocation possibleRegion =
            matchingRegions.get(matchingRegions.lastKey());
          byte [] endKey = possibleRegion.getRegionInfo().getEndKey();

          // by nature of the map, we know that the start key has to be <
          // otherwise it wouldn't be in the headMap.
          if (HStoreKey.compareTwoRowKeys(possibleRegion.getRegionInfo(),
              endKey, row) <= 0) {
            // delete any matching entry
            HRegionLocation rl =
              tableLocations.remove(matchingRegions.lastKey());
            if (rl != null && LOG.isDebugEnabled()) {
              LOG.debug("Removed " + rl.getRegionInfo().getRegionNameAsString() +
                " for tableName=" + Bytes.toString(tableName) + " from cache " +
                "because of " + Bytes.toString(row));
            }
          }
        }
View Full Code Here

        throw new NoServerForRegionException(
          "unable to locate root region server");
      }
     
      // return the region location
      return new HRegionLocation(
        HRegionInfo.ROOT_REGIONINFO, rootRegionAddress);
    }
View Full Code Here

      boolean reload)
    throws IOException {
      boolean reloadFlag = reload;
      getMaster();
      List<Throwable> exceptions = new ArrayList<Throwable>();
      HRegionLocation location = null;
      int tries = 0;
      while (tries < numRetries) {
        try {
          location = getRegionLocation(tableName, rowKey, reloadFlag);
        } catch (Throwable t) {
View Full Code Here

      }
      boolean retryOnlyOne = false;
      int tries = 0;
      Collections.sort(list);
      List<BatchUpdate> tempUpdates = new ArrayList<BatchUpdate>();
      HRegionLocation location =
        getRegionLocationForRowWithRetries(tableName, list.get(0).getRow(),
            false);
      byte [] currentRegion = location.getRegionInfo().getRegionName();
      byte [] region = currentRegion;
      boolean isLastRow = false;
      for (int i = 0; i < list.size() && tries < numRetries; i++) {
        BatchUpdate batchUpdate = list.get(i);
        tempUpdates.add(batchUpdate);
        isLastRow = (i + 1) == list.size();
        if (!isLastRow) {
          location = getRegionLocationForRowWithRetries(tableName,
            list.get(i+1).getRow(), false);
          region = location.getRegionInfo().getRegionName();
        }
        if (!Bytes.equals(currentRegion, region) || isLastRow || retryOnlyOne) {
          final BatchUpdate[] updates = tempUpdates.toArray(new BatchUpdate[0]);
          int index = getRegionServerWithRetries(new ServerCallable<Integer>(
              this, tableName, batchUpdate.getRow()) {
            public Integer call() throws IOException {
              int i = server.batchUpdates(location.getRegionInfo()
                  .getRegionName(), updates);
              return i;
            }
          });
          if (index != -1) {
            if (tries == numRetries - 1) {
              throw new RetriesExhaustedException("Some server",
                  currentRegion, batchUpdate.getRow(),
                  tries, new ArrayList<Throwable>());
            }
            long sleepTime = getPauseTime(tries);
            if (LOG.isDebugEnabled()) {
              LOG.debug("Reloading region " + Bytes.toString(currentRegion) +
                " location because regionserver didn't accept updates; " +
                "tries=" + tries +
                " of max=" + this.numRetries + ", waiting=" + sleepTime + "ms");
            }
            try {
              Thread.sleep(sleepTime);
              tries++;
            } catch (InterruptedException e) {
              // continue
            }
            i = i - updates.length + index;
            retryOnlyOne = true;
            location = getRegionLocationForRowWithRetries(tableName,
              list.get(i + 1).getRow(), true);
            region = location.getRegionInfo().getRegionName();
          }
          else {
            retryOnlyOne = false;
          }
          currentRegion = region;
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.HRegionLocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.