Exemple #1
0
    @Override
    protected void updateMeta(final byte[] oldRegion1, final byte[] oldRegion2, HRegion newRegion)
        throws IOException {
      byte[][] regionsToDelete = {oldRegion1, oldRegion2};
      for (int r = 0; r < regionsToDelete.length; r++) {
        Delete delete = new Delete(regionsToDelete[r]);
        delete.deleteColumns(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
        delete.deleteColumns(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
        delete.deleteColumns(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER);
        delete.deleteColumns(HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER);
        delete.deleteColumns(HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER);
        root.delete(delete, null, true);

        if (LOG.isDebugEnabled()) {
          LOG.debug("updated columns in row: " + Bytes.toStringBinary(regionsToDelete[r]));
        }
      }
      HRegionInfo newInfo = newRegion.getRegionInfo();
      newInfo.setOffline(true);
      Put put = new Put(newRegion.getRegionName());
      put.add(
          HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, Writables.getBytes(newInfo));
      root.put(put);
      if (LOG.isDebugEnabled()) {
        LOG.debug("updated columns in row: " + Bytes.toStringBinary(newRegion.getRegionName()));
      }
    }
Exemple #2
0
    @Override
    protected void updateMeta(final byte[] oldRegion1, final byte[] oldRegion2, HRegion newRegion)
        throws IOException {
      byte[][] regionsToDelete = {oldRegion1, oldRegion2};
      for (int r = 0; r < regionsToDelete.length; r++) {
        if (Bytes.equals(regionsToDelete[r], latestRegion.getRegionName())) {
          latestRegion = null;
        }
        Delete delete = new Delete(regionsToDelete[r]);
        table.delete(delete);
        if (LOG.isDebugEnabled()) {
          LOG.debug("updated columns in row: " + Bytes.toStringBinary(regionsToDelete[r]));
        }
      }
      newRegion.getRegionInfo().setOffline(true);

      Put put = new Put(newRegion.getRegionName());
      put.add(
          HConstants.CATALOG_FAMILY,
          HConstants.REGIONINFO_QUALIFIER,
          Writables.getBytes(newRegion.getRegionInfo()));
      table.put(put);

      if (LOG.isDebugEnabled()) {
        LOG.debug("updated columns in row: " + Bytes.toStringBinary(newRegion.getRegionName()));
      }
    }
Exemple #3
0
    protected boolean merge(final HRegionInfo[] info) throws IOException {
      if (info.length < 2) {
        LOG.info("only one region - nothing to merge");
        return false;
      }

      HRegion currentRegion = null;
      long currentSize = 0;
      HRegion nextRegion = null;
      long nextSize = 0;
      for (int i = 0; i < info.length - 1; i++) {
        if (currentRegion == null) {
          currentRegion = HRegion.newHRegion(tabledir, hlog, fs, conf, info[i], this.htd, null);
          currentRegion.initialize();
          currentSize = currentRegion.getLargestHStoreSize();
        }
        nextRegion = HRegion.newHRegion(tabledir, hlog, fs, conf, info[i + 1], this.htd, null);
        nextRegion.initialize();
        nextSize = nextRegion.getLargestHStoreSize();

        if ((currentSize + nextSize) <= (maxFilesize / 2)) {
          // We merge two adjacent regions if their total size is less than
          // one half of the desired maximum size
          LOG.info(
              "Merging regions "
                  + currentRegion.getRegionNameAsString()
                  + " and "
                  + nextRegion.getRegionNameAsString());
          HRegion mergedRegion = HRegion.mergeAdjacent(currentRegion, nextRegion);
          updateMeta(currentRegion.getRegionName(), nextRegion.getRegionName(), mergedRegion);
          break;
        }
        LOG.info(
            "not merging regions "
                + Bytes.toStringBinary(currentRegion.getRegionName())
                + " and "
                + Bytes.toStringBinary(nextRegion.getRegionName()));
        currentRegion.close();
        currentRegion = nextRegion;
        currentSize = nextSize;
      }
      if (currentRegion != null) {
        currentRegion.close();
      }
      return true;
    }
Exemple #4
0
 /**
  * A lower level API, return ID integer from raw value bytes. In case of not found
  *
  * <p>- if roundingFlag=0, throw IllegalArgumentException; <br>
  * - if roundingFlag<0, the closest smaller ID integer if exist; <br>
  * - if roundingFlag>0, the closest bigger ID integer if exist. <br>
  *
  * <p>Bypassing the cache layer, this could be significantly slower than getIdFromValue(T value).
  *
  * @throws IllegalArgumentException if value is not found in dictionary and rounding is off; or if
  *     rounding cannot find a smaller or bigger ID
  */
 public final int getIdFromValueBytes(byte[] value, int offset, int len, int roundingFlag)
     throws IllegalArgumentException {
   if (isNullByteForm(value, offset, len)) return nullId();
   else {
     int id = getIdFromValueBytesImpl(value, offset, len, roundingFlag);
     if (id == -1)
       throw new IllegalArgumentException(
           "Value '"
               + Bytes.toString(value, offset, len)
               + "' ("
               + Bytes.toStringBinary(value, offset, len)
               + ") not exists!");
     return id;
   }
 }
Exemple #5
0
 /*
  * Check current row has a HRegionInfo.  Skip to next row if HRI is empty.
  * @return A Map of the row content else null if we are off the end.
  * @throws IOException
  */
 private Result getMetaRow() throws IOException {
   Result currentRow = metaScanner.next();
   boolean foundResult = false;
   while (currentRow != null) {
     LOG.info("Row: <" + Bytes.toStringBinary(currentRow.getRow()) + ">");
     byte[] regionInfoValue =
         currentRow.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
     if (regionInfoValue == null || regionInfoValue.length == 0) {
       currentRow = metaScanner.next();
       continue;
     }
     foundResult = true;
     break;
   }
   return foundResult ? currentRow : null;
 }
Exemple #6
0
 private boolean splitFailsPrecondition(SplitAlgorithm algo, int numRegions) {
   try {
     byte[][] s = algo.split(numRegions);
     LOG.debug("split algo = " + algo);
     if (s != null) {
       StringBuilder sb = new StringBuilder();
       for (byte[] b : s) {
         sb.append(Bytes.toStringBinary(b) + "  ");
       }
       LOG.debug(sb.toString());
     }
     return false;
   } catch (IllegalArgumentException e) {
     return true;
   } catch (IllegalStateException e) {
     return true;
   } catch (IndexOutOfBoundsException e) {
     return true;
   }
 }