Ejemplo n.º 1
0
      @Override
      public void run() {
        while (!isStopped()) {
          try {
            NavigableMap<HRegionInfo, ServerName> regions =
                MetaScanner.allTableRegions(connection, TABLENAME);

            LOG.info("-------");
            byte[] lastEndKey = HConstants.EMPTY_START_ROW;
            for (HRegionInfo hri : regions.navigableKeySet()) {
              long startKey = 0, endKey = Long.MAX_VALUE;
              if (!Bytes.equals(HConstants.EMPTY_START_ROW, hri.getStartKey())) {
                startKey = Bytes.toLong(hri.getStartKey());
              }
              if (!Bytes.equals(HConstants.EMPTY_END_ROW, hri.getEndKey())) {
                endKey = Bytes.toLong(hri.getEndKey());
              }
              LOG.info("start:" + startKey + " end:" + endKey + " hri:" + hri);
              Assert.assertTrue(
                  "lastEndKey="
                      + Bytes.toString(lastEndKey)
                      + ", startKey="
                      + Bytes.toString(hri.getStartKey()),
                  Bytes.equals(lastEndKey, hri.getStartKey()));
              lastEndKey = hri.getEndKey();
            }
            Assert.assertTrue(Bytes.equals(lastEndKey, HConstants.EMPTY_END_ROW));
            LOG.info("-------");
            Threads.sleep(10 + random.nextInt(50));
          } catch (Throwable e) {
            ex = e;
            Assert.fail(StringUtils.stringifyException(e));
          }
        }
      }
Ejemplo n.º 2
0
 @Override
 public byte[] createProtobufOutput() {
   Scanner.Builder builder = Scanner.newBuilder();
   if (!Bytes.equals(startRow, HConstants.EMPTY_START_ROW)) {
     builder.setStartRow(ByteString.copyFrom(startRow));
   }
   if (!Bytes.equals(endRow, HConstants.EMPTY_START_ROW)) {
     builder.setEndRow(ByteString.copyFrom(endRow));
   }
   for (byte[] column : columns) {
     builder.addColumns(ByteString.copyFrom(column));
   }
   builder.setBatch(batch);
   if (startTime != 0) {
     builder.setStartTime(startTime);
   }
   if (endTime != 0) {
     builder.setEndTime(endTime);
   }
   builder.setBatch(getBatch());
   builder.setMaxVersions(maxVersions);
   if (filter != null) {
     builder.setFilter(filter);
   }
   return builder.build().toByteArray();
 }
Ejemplo n.º 3
0
  /**
   * @param other
   * @return true if and only if the fields of the filter that are serialized are equal to the
   *     corresponding fields in other. Used for testing.
   */
  boolean areSerializedFieldsEqual(Filter o) {
    if (o == this) return true;
    if (!(o instanceof ColumnRangeFilter)) return false;

    ColumnRangeFilter other = (ColumnRangeFilter) o;
    return Bytes.equals(this.getMinColumn(), other.getMinColumn())
        && this.getMinColumnInclusive() == other.getMinColumnInclusive()
        && Bytes.equals(this.getMaxColumn(), other.getMaxColumn())
        && this.getMaxColumnInclusive() == other.getMaxColumnInclusive();
  }
Ejemplo n.º 4
0
 /**
  * @param name region name or encoded region name.
  * @param type
  * @return True if we are dealing with a hbase:meta region.
  */
 static boolean isMetaRegion(final byte[] name, final RegionSpecifierType type) {
   switch (type) {
     case REGION_NAME:
       return Bytes.equals(HRegionInfo.FIRST_META_REGIONINFO.getRegionName(), name);
     case ENCODED_REGION_NAME:
       return Bytes.equals(HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), name);
     default:
       throw new UnsupportedOperationException();
   }
 }
Ejemplo n.º 5
0
  @Test
  public void testWholesomeSplit() throws IOException {
    final int rowcount = TEST_UTIL.loadRegion(this.parent, CF, true);
    assertTrue(rowcount > 0);
    int parentRowCount = TEST_UTIL.countRows(this.parent);
    assertEquals(rowcount, parentRowCount);

    // Pretend region's blocks are not in the cache, used for
    // testWholesomeSplitWithHFileV1
    CacheConfig cacheConf = new CacheConfig(TEST_UTIL.getConfiguration());
    ((LruBlockCache) cacheConf.getBlockCache()).clearCache();

    // Start transaction.
    SplitTransactionImpl st = prepareGOOD_SPLIT_ROW();

    // Run the execute.  Look at what it returns.
    Server mockServer = Mockito.mock(Server.class);
    when(mockServer.getConfiguration()).thenReturn(TEST_UTIL.getConfiguration());
    PairOfSameType<Region> daughters = st.execute(mockServer, null);
    // Do some assertions about execution.
    assertTrue(this.fs.exists(this.parent.getRegionFileSystem().getSplitsDir()));
    // Assert the parent region is closed.
    assertTrue(this.parent.isClosed());

    // Assert splitdir is empty -- because its content will have been moved out
    // to be under the daughter region dirs.
    assertEquals(0, this.fs.listStatus(this.parent.getRegionFileSystem().getSplitsDir()).length);
    // Check daughters have correct key span.
    assertTrue(
        Bytes.equals(
            parent.getRegionInfo().getStartKey(),
            daughters.getFirst().getRegionInfo().getStartKey()));
    assertTrue(Bytes.equals(GOOD_SPLIT_ROW, daughters.getFirst().getRegionInfo().getEndKey()));
    assertTrue(Bytes.equals(daughters.getSecond().getRegionInfo().getStartKey(), GOOD_SPLIT_ROW));
    assertTrue(
        Bytes.equals(
            parent.getRegionInfo().getEndKey(), daughters.getSecond().getRegionInfo().getEndKey()));
    // Count rows. daughters are already open
    int daughtersRowCount = 0;
    for (Region openRegion : daughters) {
      try {
        int count = TEST_UTIL.countRows(openRegion);
        assertTrue(count > 0 && count != rowcount);
        daughtersRowCount += count;
      } finally {
        HBaseTestingUtility.closeRegionAndWAL(openRegion);
      }
    }
    assertEquals(rowcount, daughtersRowCount);
    // Assert the write lock is no longer held on parent
    assertTrue(!this.parent.lock.writeLock().isHeldByCurrentThread());
  }
Ejemplo n.º 6
0
 private void checkModel(CellSetModel model) {
   Iterator<RowModel> rows = model.getRows().iterator();
   RowModel row = rows.next();
   assertTrue(Bytes.equals(ROW1, row.getKey()));
   Iterator<CellModel> cells = row.getCells().iterator();
   CellModel cell = cells.next();
   assertTrue(Bytes.equals(COLUMN1, cell.getColumn()));
   assertTrue(Bytes.equals(VALUE1, cell.getValue()));
   assertTrue(cell.hasUserTimestamp());
   assertEquals(cell.getTimestamp(), TIMESTAMP1);
   assertFalse(cells.hasNext());
   row = rows.next();
   assertTrue(Bytes.equals(ROW2, row.getKey()));
   cells = row.getCells().iterator();
   cell = cells.next();
   assertTrue(Bytes.equals(COLUMN2, cell.getColumn()));
   assertTrue(Bytes.equals(VALUE2, cell.getValue()));
   assertTrue(cell.hasUserTimestamp());
   assertEquals(cell.getTimestamp(), TIMESTAMP2);
   cell = cells.next();
   assertTrue(Bytes.equals(COLUMN3, cell.getColumn()));
   assertTrue(Bytes.equals(VALUE3, cell.getValue()));
   assertTrue(cell.hasUserTimestamp());
   assertEquals(cell.getTimestamp(), TIMESTAMP3);
   assertFalse(cells.hasNext());
 }
  private static void verifyScanFull(Scan s, KeyValue[] kvs) throws Exception {
    ScannerModel model = ScannerModel.fromScan(s);
    model.setBatch(Integer.MAX_VALUE); // fetch it all at once
    StringWriter writer = new StringWriter();
    marshaller.marshal(model, writer);
    LOG.debug(writer.toString());
    byte[] body = Bytes.toBytes(writer.toString());
    Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
    assertEquals(response.getCode(), 201);
    String scannerURI = response.getLocation();
    assertNotNull(scannerURI);

    // get a cell set
    response = client.get(scannerURI, Constants.MIMETYPE_XML);
    assertEquals(response.getCode(), 200);
    CellSetModel cellSet =
        (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));

    // delete the scanner
    response = client.delete(scannerURI);
    assertEquals(response.getCode(), 200);

    int row = 0;
    int idx = 0;
    Iterator<RowModel> i = cellSet.getRows().iterator();
    for (boolean done = true; done; row++) {
      done = i.hasNext();
      if (!done) break;
      RowModel rowModel = i.next();
      List<CellModel> cells = rowModel.getCells();
      if (cells.isEmpty()) break;
      assertTrue(
          "Scanned too many keys! Only expected "
              + kvs.length
              + " total but already scanned "
              + (cells.size() + idx),
          kvs.length >= idx + cells.size());
      for (CellModel cell : cells) {
        assertTrue("Row mismatch", Bytes.equals(rowModel.getKey(), kvs[idx].getRow()));
        byte[][] split = KeyValue.parseColumn(cell.getColumn());
        assertTrue("Family mismatch", Bytes.equals(split[0], kvs[idx].getFamily()));
        assertTrue("Qualifier mismatch", Bytes.equals(split[1], kvs[idx].getQualifier()));
        assertTrue("Value mismatch", Bytes.equals(cell.getValue(), kvs[idx].getValue()));
        idx++;
      }
    }
    assertEquals("Expected " + kvs.length + " total keys but scanned " + idx, kvs.length, idx);
  }
Ejemplo n.º 8
0
  @Override
  public boolean prepare() throws IOException {
    if (!this.parent.isSplittable()) return false;
    // Split key can be null if this region is unsplittable; i.e. has refs.
    if (this.splitrow == null) return false;
    HRegionInfo hri = this.parent.getRegionInfo();
    parent.prepareToSplit();
    // Check splitrow.
    byte[] startKey = hri.getStartKey();
    byte[] endKey = hri.getEndKey();
    if (Bytes.equals(startKey, splitrow) || !this.parent.getRegionInfo().containsRow(splitrow)) {
      LOG.info(
          "Split row is not inside region key range or is equal to "
              + "startkey: "
              + Bytes.toStringBinary(this.splitrow));
      return false;
    }
    long rid = getDaughterRegionIdTimestamp(hri);
    this.hri_a = new HRegionInfo(hri.getTable(), startKey, this.splitrow, false, rid);
    this.hri_b = new HRegionInfo(hri.getTable(), this.splitrow, endKey, false, rid);

    transition(SplitTransactionPhase.PREPARED);

    return true;
  }
Ejemplo n.º 9
0
  private WALEntry createEntry(byte[] table, int row, KeyValue.Type type, List<Cell> cells) {
    byte[] fam = Bytes.equals(table, TABLE_NAME1) ? FAM_NAME1 : FAM_NAME2;
    byte[] rowBytes = Bytes.toBytes(row);
    // Just make sure we don't get the same ts for two consecutive rows with
    // same key
    try {
      Thread.sleep(1);
    } catch (InterruptedException e) {
      LOG.info("Was interrupted while sleep, meh", e);
    }
    final long now = System.currentTimeMillis();
    KeyValue kv = null;
    if (type.getCode() == KeyValue.Type.Put.getCode()) {
      kv = new KeyValue(rowBytes, fam, fam, now, KeyValue.Type.Put, Bytes.toBytes(row));
    } else if (type.getCode() == KeyValue.Type.DeleteColumn.getCode()) {
      kv = new KeyValue(rowBytes, fam, fam, now, KeyValue.Type.DeleteColumn);
    } else if (type.getCode() == KeyValue.Type.DeleteFamily.getCode()) {
      kv = new KeyValue(rowBytes, fam, null, now, KeyValue.Type.DeleteFamily);
    }
    WALEntry.Builder builder = WALEntry.newBuilder();
    builder.setAssociatedCellCount(1);
    WALKey.Builder keyBuilder = WALKey.newBuilder();
    UUID.Builder uuidBuilder = UUID.newBuilder();
    uuidBuilder.setLeastSigBits(HConstants.DEFAULT_CLUSTER_ID.getLeastSignificantBits());
    uuidBuilder.setMostSigBits(HConstants.DEFAULT_CLUSTER_ID.getMostSignificantBits());
    keyBuilder.setClusterId(uuidBuilder.build());
    keyBuilder.setTableName(HBaseZeroCopyByteString.wrap(table));
    keyBuilder.setWriteTime(now);
    keyBuilder.setEncodedRegionName(HBaseZeroCopyByteString.wrap(HConstants.EMPTY_BYTE_ARRAY));
    keyBuilder.setLogSequenceNumber(-1);
    builder.setKey(keyBuilder.build());
    cells.add(kv);

    return builder.build();
  }
Ejemplo n.º 10
0
  /**
   * Checks that a given table operation is authorized by this permission instance.
   *
   * @param table the table where the operation is being performed
   * @param family the column family to which the operation is restricted, if <code>null</code>
   *     implies "all"
   * @param qualifier the column qualifier to which the action is restricted, if <code>null</code>
   *     implies "all"
   * @param action the action being requested
   * @return <code>true</code> if the action within the given scope is allowed by this permission,
   *     <code>false</code>
   */
  public boolean implies(TableName table, byte[] family, byte[] qualifier, Action action) {
    if (!this.table.equals(table)) {
      return false;
    }

    if (this.family != null && (family == null || !Bytes.equals(this.family, family))) {
      return false;
    }

    if (this.qualifier != null && (qualifier == null || !Bytes.equals(this.qualifier, qualifier))) {
      return false;
    }

    // check actions
    return super.implies(action);
  }
Ejemplo n.º 11
0
      @Override
      public void run() {
        while (!isStopped()) {
          try {
            List<HRegionInfo> regions =
                MetaScanner.listAllRegions(TEST_UTIL.getConfiguration(), connection, false);

            // select a random region
            HRegionInfo parent = regions.get(random.nextInt(regions.size()));
            if (parent == null || !TABLENAME.equals(parent.getTable())) {
              continue;
            }

            long startKey = 0, endKey = Long.MAX_VALUE;
            byte[] start = parent.getStartKey();
            byte[] end = parent.getEndKey();
            if (!Bytes.equals(HConstants.EMPTY_START_ROW, parent.getStartKey())) {
              startKey = Bytes.toLong(parent.getStartKey());
            }
            if (!Bytes.equals(HConstants.EMPTY_END_ROW, parent.getEndKey())) {
              endKey = Bytes.toLong(parent.getEndKey());
            }
            if (startKey == endKey) {
              continue;
            }

            long midKey =
                BigDecimal.valueOf(startKey)
                    .add(BigDecimal.valueOf(endKey))
                    .divideToIntegralValue(BigDecimal.valueOf(2))
                    .longValue();

            HRegionInfo splita = new HRegionInfo(TABLENAME, start, Bytes.toBytes(midKey));
            HRegionInfo splitb = new HRegionInfo(TABLENAME, Bytes.toBytes(midKey), end);

            MetaTableAccessor.splitRegion(
                connection, parent, splita, splitb, ServerName.valueOf("fooserver", 1, 0));

            Threads.sleep(random.nextInt(200));
          } catch (Throwable e) {
            ex = e;
            Assert.fail(StringUtils.stringifyException(e));
          }
        }
      }
Ejemplo n.º 12
0
  /**
   * @param catalogTracker
   * @param tableName
   * @return Return list of regioninfos and server addresses.
   * @throws IOException
   * @throws InterruptedException
   */
  public static List<Pair<HRegionInfo, ServerName>> getTableRegionsAndLocations(
      final CatalogTracker catalogTracker,
      final byte[] tableName,
      final boolean excludeOfflinedSplitParents)
      throws IOException, InterruptedException {
    if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {
      // If root, do a bit of special handling.
      ServerName serverName = catalogTracker.getRootLocation();
      List<Pair<HRegionInfo, ServerName>> list = new ArrayList<Pair<HRegionInfo, ServerName>>();
      list.add(new Pair<HRegionInfo, ServerName>(HRegionInfo.ROOT_REGIONINFO, serverName));
      return list;
    }
    // Make a version of CollectingVisitor that collects HRegionInfo and ServerAddress
    CollectingVisitor<Pair<HRegionInfo, ServerName>> visitor =
        new CollectingVisitor<Pair<HRegionInfo, ServerName>>() {
          private Pair<HRegionInfo, ServerName> current = null;

          @Override
          public boolean visit(Result r) throws IOException {
            HRegionInfo hri = parseHRegionInfoFromCatalogResult(r, HConstants.REGIONINFO_QUALIFIER);
            if (hri == null) {
              LOG.warn("No serialized HRegionInfo in " + r);
              return true;
            }
            if (!isInsideTable(hri, tableName)) return false;
            if (excludeOfflinedSplitParents && hri.isSplitParent()) return true;
            ServerName sn = getServerNameFromCatalogResult(r);
            // Populate this.current so available when we call #add
            this.current = new Pair<HRegionInfo, ServerName>(hri, sn);
            // Else call super and add this Result to the collection.
            return super.visit(r);
          }

          @Override
          void add(Result r) {
            this.results.add(this.current);
          }
        };
    fullScan(
        catalogTracker,
        visitor,
        getTableStartRowForMeta(tableName),
        Bytes.equals(tableName, HConstants.META_TABLE_NAME));
    return visitor.getResults();
  }
Ejemplo n.º 13
0
 /**
  * @param left
  * @param right
  * @return True if the rows in <code>left</code> and <code>right</code> Cells match
  */
 public static boolean matchingRow(final Cell left, final Cell right) {
   return Bytes.equals(
       left.getRowArray(),
       left.getRowOffset(),
       left.getRowLength(),
       right.getRowArray(),
       right.getRowOffset(),
       right.getRowLength());
 }
Ejemplo n.º 14
0
 public static boolean matchingValue(final Cell left, final Cell right) {
   return Bytes.equals(
       left.getValueArray(),
       left.getValueOffset(),
       left.getValueLength(),
       right.getValueArray(),
       right.getValueOffset(),
       right.getValueLength());
 }
    public boolean equals(Object arg0) {

      if (arg0 instanceof WorkSet) {
        WorkSet arg = (WorkSet) arg0;
        if (this.indexSpec.equals(arg.indexSpec) && Bytes.equals(this.row, arg.row)) return true;
        else return false;
      }
      return false;
    }
Ejemplo n.º 16
0
 public static boolean matchingFamily(final Cell left, final Cell right) {
   return Bytes.equals(
       left.getFamilyArray(),
       left.getFamilyOffset(),
       left.getFamilyLength(),
       right.getFamilyArray(),
       right.getFamilyOffset(),
       right.getFamilyLength());
 }
Ejemplo n.º 17
0
 public static boolean matchingQualifier(final Cell left, final Cell right) {
   return Bytes.equals(
       left.getQualifierArray(),
       left.getQualifierOffset(),
       left.getQualifierLength(),
       right.getQualifierArray(),
       right.getQualifierOffset(),
       right.getQualifierLength());
 }
Ejemplo n.º 18
0
 /**
  * Enable in memory caching for .META.
  */
 public static void setInfoFamilyCachingForMeta(final boolean b) {
   for (HColumnDescriptor hcd:
       HTableDescriptor.META_TABLEDESC.getColumnFamilies()) {
     if (Bytes.equals(hcd.getName(), HConstants.CATALOG_FAMILY)) {
       hcd.setBlockCacheEnabled(b);
       hcd.setInMemory(b);
     }
   }
 }
Ejemplo n.º 19
0
 /**
  * @param row
  * @return True if <code>row</code> is row of <code>-ROOT-</code> table.
  */
 private static boolean isRootTableRow(final byte[] row) {
   if (row.length < META_REGION_PREFIX.length + 2 /* ',', + '1' */) {
     // Can't be meta table region.
     return false;
   }
   // Compare the prefix of row.  If it matches META_REGION_PREFIX prefix,
   // then this is row from -ROOT_ table.
   return Bytes.equals(
       row, 0, META_REGION_PREFIX.length, META_REGION_PREFIX, 0, META_REGION_PREFIX.length);
 }
Ejemplo n.º 20
0
  @Override
  public Result next() throws IOException {
    // If the scanner is closed and there's nothing left in the cache, next is a
    // no-op.
    if (cache.size() == 0 && this.closed) {
      return null;
    }
    if (cache.size() == 0) {
      Result[] values = null;
      long remainingResultSize = maxScannerResultSize;
      int countdown = this.caching;
      boolean currentRegionDone = false;
      // Values == null means server-side filter has determined we must STOP
      while (remainingResultSize > 0
          && countdown > 0
          && nextScanner(countdown, values == null, currentRegionDone)) {
        // Server returns a null values if scanning is to stop. Else,
        // returns an empty array if scanning is to go on and we've just
        // exhausted current region.
        values = this.caller.callWithRetries(smallScanCallable, scannerTimeout);
        this.currentRegion = smallScanCallable.getHRegionInfo();
        long currentTime = System.currentTimeMillis();
        if (this.scanMetrics != null) {
          this.scanMetrics.sumOfMillisSecBetweenNexts.addAndGet(currentTime - lastNext);
        }
        lastNext = currentTime;
        if (values != null && values.length > 0) {
          for (int i = 0; i < values.length; i++) {
            Result rs = values[i];
            if (i == 0
                && this.skipRowOfFirstResult != null
                && Bytes.equals(skipRowOfFirstResult, rs.getRow())) {
              // Skip the first result
              continue;
            }
            cache.add(rs);
            for (Cell kv : rs.rawCells()) {
              remainingResultSize -= KeyValueUtil.ensureKeyValue(kv).heapSize();
            }
            countdown--;
            this.lastResult = rs;
          }
        }
        currentRegionDone = countdown > 0;
      }
    }

    if (cache.size() > 0) {
      return cache.poll();
    }
    // if we exhausted this scanner before calling close, write out the scan
    // metrics
    writeScanMetrics();
    return null;
  }
Ejemplo n.º 21
0
  /*
   * Gets a scanner for the next region.  If this.currentRegion != null, then
   * we will move to the endrow of this.currentRegion.  Else we will get
   * scanner at the scan.getStartRow().  We will go no further, just tidy
   * up outstanding scanners, if <code>currentRegion != null</code> and
   * <code>done</code> is true.
   * @param nbRows
   * @param done Server-side says we're done scanning.
   */
  protected boolean nextScanner(int nbRows, final boolean done) throws IOException {
    // Close the previous scanner if it's open
    if (this.callable != null) {
      this.callable.setClose();
      call(scan, callable, caller, scannerTimeout);
      this.callable = null;
    }

    // Where to start the next scanner
    byte[] localStartKey;

    // if we're at end of table, close and return false to stop iterating
    if (this.currentRegion != null) {
      byte[] endKey = this.currentRegion.getEndKey();
      if (endKey == null
          || Bytes.equals(endKey, HConstants.EMPTY_BYTE_ARRAY)
          || checkScanStopRow(endKey)
          || done) {
        close();
        if (LOG.isTraceEnabled()) {
          LOG.trace("Finished " + this.currentRegion);
        }
        return false;
      }
      localStartKey = endKey;
      if (LOG.isTraceEnabled()) {
        LOG.trace("Finished " + this.currentRegion);
      }
    } else {
      localStartKey = this.scan.getStartRow();
    }

    if (LOG.isDebugEnabled() && this.currentRegion != null) {
      // Only worth logging if NOT first region in scan.
      LOG.debug(
          "Advancing internal scanner to startKey at '"
              + Bytes.toStringBinary(localStartKey)
              + "'");
    }
    try {
      callable = getScannerCallable(localStartKey, nbRows);
      // Open a scanner on the region server starting at the
      // beginning of the region
      call(scan, callable, caller, scannerTimeout);
      this.currentRegion = callable.getHRegionInfo();
      if (this.scanMetrics != null) {
        this.scanMetrics.countOfRegions.incrementAndGet();
      }
    } catch (IOException e) {
      close();
      throw e;
    }
    return true;
  }
Ejemplo n.º 22
0
  public void testWideScanBatching() throws IOException {
    final int batch = 256;
    try {
      this.r = createNewHRegion(TESTTABLEDESC, null, null);
      int inserted = addWideContent(this.r);
      List<Cell> results = new ArrayList<Cell>();
      Scan scan = new Scan();
      scan.addFamily(A);
      scan.addFamily(B);
      scan.addFamily(C);
      scan.setMaxVersions(100);
      scan.setBatch(batch);
      InternalScanner s = r.getScanner(scan);
      int total = 0;
      int i = 0;
      boolean more;
      do {
        more = s.next(results);
        i++;
        LOG.info("iteration #" + i + ", results.size=" + results.size());

        // assert that the result set is no larger
        assertTrue(results.size() <= batch);

        total += results.size();

        if (results.size() > 0) {
          // assert that all results are from the same row
          byte[] row = CellUtil.cloneRow(results.get(0));
          for (Cell kv : results) {
            assertTrue(Bytes.equals(row, CellUtil.cloneRow(kv)));
          }
        }

        results.clear();

        // trigger ChangedReadersObservers
        Iterator<KeyValueScanner> scanners =
            ((HRegion.RegionScannerImpl) s).storeHeap.getHeap().iterator();
        while (scanners.hasNext()) {
          StoreScanner ss = (StoreScanner) scanners.next();
          ss.updateReaders();
        }
      } while (more);

      // assert that the scanner returned all values
      LOG.info("inserted " + inserted + ", scanned " + total);
      assertEquals(total, inserted);

      s.close();
    } finally {
      HRegion.closeHRegion(this.r);
    }
  }
Ejemplo n.º 23
0
 /**
  * Returns if the given permission matches the given qualifier.
  *
  * @param table the table name to match
  * @param family the column family to match
  * @param qualifier the qualifier name to match
  * @param action the action requested
  * @return <code>true</code> if the table, family and qualifier match, otherwise <code>false
  *     </code>
  */
 public boolean matchesFamilyQualifier(
     TableName table, byte[] family, byte[] qualifier, Action action) {
   if (!matchesFamily(table, family, action)) {
     return false;
   } else {
     if (this.qualifier != null
         && (qualifier == null || !Bytes.equals(this.qualifier, qualifier))) {
       return false;
     }
   }
   return super.implies(action);
 }
Ejemplo n.º 24
0
 public static boolean matchingQualifier(final Cell left, final byte[] buf) {
   if (buf == null) {
     return left.getQualifierLength() == 0;
   }
   return Bytes.equals(
       left.getQualifierArray(),
       left.getQualifierOffset(),
       left.getQualifierLength(),
       buf,
       0,
       buf.length);
 }
Ejemplo n.º 25
0
    public void doAnAction() throws Exception {
      Scan s = new Scan();
      for (byte[] family : targetFamilies) {
        s.addFamily(family);
      }
      ResultScanner scanner = table.getScanner(s);

      for (Result res : scanner) {
        byte[] lastRow = null, lastFam = null, lastQual = null;
        byte[] gotValue = null;
        for (byte[] family : targetFamilies) {
          byte qualifier[] = QUAL;
          byte thisValue[] = res.getValue(family, qualifier);
          if (gotValue != null && thisValue != null && !Bytes.equals(gotValue, thisValue)) {

            StringBuilder msg = new StringBuilder();
            msg.append("Failed on scan ")
                .append(numScans)
                .append(" after scanning ")
                .append(numRowsScanned)
                .append(" rows!\n");
            msg.append(
                "Current  was "
                    + Bytes.toString(res.getRow())
                    + "/"
                    + Bytes.toString(family)
                    + ":"
                    + Bytes.toString(qualifier)
                    + " = "
                    + Bytes.toString(thisValue)
                    + "\n");
            msg.append(
                "Previous  was "
                    + Bytes.toString(lastRow)
                    + "/"
                    + Bytes.toString(lastFam)
                    + ":"
                    + Bytes.toString(lastQual)
                    + " = "
                    + Bytes.toString(gotValue));
            throw new RuntimeException(msg.toString());
          }

          lastFam = family;
          lastQual = qualifier;
          lastRow = res.getRow();
          gotValue = thisValue;
        }
        numRowsScanned.getAndIncrement();
      }
      numScans.getAndIncrement();
    }
Ejemplo n.º 26
0
  /**
   * Returns <code>true</code> if this permission matches the given column family at least. This
   * only indicates a partial match against the table and column family, however, and does not
   * guarantee that implies() for the column same family would return <code>true</code>. In the case
   * of a column-qualifier specific permission, for example, implies() would still return false.
   */
  public boolean matchesFamily(TableName table, byte[] family, Action action) {
    if (!this.table.equals(table)) {
      return false;
    }

    if (this.family != null && (family == null || !Bytes.equals(this.family, family))) {
      return false;
    }

    // ignore qualifier
    // check actions
    return super.implies(action);
  }
 @Override
 public boolean equals(Object obj) {
   if (obj == null || !(obj instanceof AuthenticationKey)) {
     return false;
   }
   AuthenticationKey other = (AuthenticationKey) obj;
   return id == other.getKeyId()
       && expirationDate == other.getExpiration()
       && (secret == null
           ? other.getKey() == null
           : other.getKey() != null
               && Bytes.equals(secret.getEncoded(), other.getKey().getEncoded()));
 }
Ejemplo n.º 28
0
  public static void main(String[] args) {
    HItemData hi = null;
    try {
      byte b0 = ByteArray.b0;

      // for unit test
      int shopID = 48;
      int itemID = 51;
      byte[] rowkey = encodeRowkey(shopID, itemID);

      byte[] expected =
          new byte[] {
            b0,
            b0,
            b0,
            ByteArray.b1,
            ByteArray.bg,
            b0,
            b0,
            b0,
            b0,
            b0,
            b0,
            ByteArray.b1,
            ByteArray.bj
          };
      assert (Bytes.equals(rowkey, expected));

      String decoded = decodeRowkey(rowkey);
      assert ("48-51".equals(decoded));

      hi = new HItemData();
      ItemData id = new ItemData();
      id.shopID = 235063;
      Map<String, HCompareOp> ops = new HashMap<String, HCompareOp>();
      ops.put("shop_id", HCompareOp.EQUAL);
      HScanner<ItemData> scanner = hi.scan(id, ops);
      assert (scanner.hasNext());
      if (scanner.hasNext()) {
        System.out.println(scanner.next());
      }

      System.out.println("unit test passed");
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (hi != null) {
        hi.close();
      }
    }
  }
Ejemplo n.º 29
0
  /**
   * Test that {@link HFileOutputFormat2} RecordWriter amends timestamps if passed a keyvalue whose
   * timestamp is {@link HConstants#LATEST_TIMESTAMP}.
   *
   * @see <a href="https://issues.apache.org/jira/browse/HBASE-2615">HBASE-2615</a>
   */
  @Ignore("Goes zombie too frequently; needs work. See HBASE-14563")
  @Test
  public void test_LATEST_TIMESTAMP_isReplaced() throws Exception {
    Configuration conf = new Configuration(this.util.getConfiguration());
    RecordWriter<ImmutableBytesWritable, Cell> writer = null;
    TaskAttemptContext context = null;
    Path dir = util.getDataTestDir("test_LATEST_TIMESTAMP_isReplaced");
    try {
      Job job = new Job(conf);
      FileOutputFormat.setOutputPath(job, dir);
      context = createTestTaskAttemptContext(job);
      HFileOutputFormat2 hof = new HFileOutputFormat2();
      writer = hof.getRecordWriter(context);
      final byte[] b = Bytes.toBytes("b");

      // Test 1.  Pass a KV that has a ts of LATEST_TIMESTAMP.  It should be
      // changed by call to write.  Check all in kv is same but ts.
      KeyValue kv = new KeyValue(b, b, b);
      KeyValue original = kv.clone();
      writer.write(new ImmutableBytesWritable(), kv);
      assertFalse(original.equals(kv));
      assertTrue(Bytes.equals(CellUtil.cloneRow(original), CellUtil.cloneRow(kv)));
      assertTrue(Bytes.equals(CellUtil.cloneFamily(original), CellUtil.cloneFamily(kv)));
      assertTrue(Bytes.equals(CellUtil.cloneQualifier(original), CellUtil.cloneQualifier(kv)));
      assertNotSame(original.getTimestamp(), kv.getTimestamp());
      assertNotSame(HConstants.LATEST_TIMESTAMP, kv.getTimestamp());

      // Test 2. Now test passing a kv that has explicit ts.  It should not be
      // changed by call to record write.
      kv = new KeyValue(b, b, b, kv.getTimestamp() - 1, b);
      original = kv.clone();
      writer.write(new ImmutableBytesWritable(), kv);
      assertTrue(original.equals(kv));
    } finally {
      if (writer != null && context != null) writer.close(context);
      dir.getFileSystem(conf).delete(dir, true);
    }
  }
Ejemplo n.º 30
0
  @Override
  @edu.umd.cs.findbugs.annotations.SuppressWarnings(
      value = "NP_NULL_ON_SOME_PATH",
      justification = "Passed on construction except on constructor not to be used")
  public boolean equals(Object obj) {
    if (!(obj instanceof TablePermission)) {
      return false;
    }
    TablePermission other = (TablePermission) obj;

    if (!(table.equals(other.getTableName())
        && ((family == null && other.getFamily() == null)
            || Bytes.equals(family, other.getFamily()))
        && ((qualifier == null && other.getQualifier() == null)
            || Bytes.equals(qualifier, other.getQualifier()))
        && ((namespace == null && other.getNamespace() == null)
            || (namespace != null && namespace.equals(other.getNamespace()))))) {
      return false;
    }

    // check actions
    return super.equals(other);
  }