Java Code Examples for org.apache.hadoop.hbase.CellUtil#matchingFamily()

The following examples show how to use org.apache.hadoop.hbase.CellUtil#matchingFamily() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * @param next
 * @return
 */
public boolean matchesPoint(KeyValue next) {
  // point deletes only apply to the exact KV that they reference, so we only need to ensure
  // that the timestamp matches exactly. Because we sort by timestamp first, either the next
  // keyvalue has the exact timestamp or is an older (smaller) timestamp, and we can allow that
  // one.
  if (pointDelete != null && CellUtil.matchingFamily(pointDelete, next)
      && CellUtil.matchingQualifier(pointDelete, next)) {
    if (pointDelete.getTimestamp() == next.getTimestamp()) {
      return true;
    }
    // clear the point delete since the TS must not be matching
    pointDelete = null;
  }
  return false;
}
 
Example 2
Source File: TablePermission.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if this permission grants access to perform the given action on
 * the given table and key value.
 * @param table the table on which the operation is being performed
 * @param kv the KeyValue on which the operation is being requested
 * @param action the action requested
 * @return <code>true</code> if the action is allowed over the given scope
 *   by this permission, otherwise <code>false</code>
 */
public boolean implies(TableName table, KeyValue kv, Action action) {
  if (failCheckTable(table)) {
    return false;
  }

  if (family != null && !(CellUtil.matchingFamily(kv, family))) {
    return false;
  }

  if (qualifier != null && !(CellUtil.matchingQualifier(kv, qualifier))) {
    return false;
  }

  // check actions
  return super.implies(action);
}
 
Example 3
Source File: ApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * @param next
 * @return
 */
public boolean matchesPoint(KeyValue next) {
  // point deletes only apply to the exact KV that they reference, so we only need to ensure
  // that the timestamp matches exactly. Because we sort by timestamp first, either the next
  // keyvalue has the exact timestamp or is an older (smaller) timestamp, and we can allow that
  // one.
  if (pointDelete != null && CellUtil.matchingFamily(pointDelete, next)
      && CellUtil.matchingQualifier(pointDelete, next)) {
    if (pointDelete.getTimestamp() == next.getTimestamp()) {
      return true;
    }
    // clear the point delete since the TS must not be matching
    coveringDelete.pointDelete = null;
  }
  return false;
}
 
Example 4
Source File: ResponseTimeMapper.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public ResponseTime mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return null;
    }

    final byte[] rowKey = getOriginalKey(result.getRow());

    ResponseTime responseTime = createResponseTime(rowKey);
    for (Cell cell : result.rawCells()) {
        if (CellUtil.matchingFamily(cell, HbaseColumnFamily.MAP_STATISTICS_SELF_VER2_COUNTER.getName())) {
            recordColumn(responseTime, cell);
        }

        if (logger.isDebugEnabled()) {
            String columnFamily = Bytes.toString(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
            logger.debug("unknown column family:{}", columnFamily);
        }
    }
    return responseTime;
}
 
Example 5
Source File: SimpleRegionObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void postGetOp(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get,
    final List<Cell> results) {
  RegionCoprocessorEnvironment e = c.getEnvironment();
  assertNotNull(e);
  assertNotNull(e.getRegion());
  assertNotNull(get);
  assertNotNull(results);
  if (e.getRegion().getTableDescriptor().getTableName().equals(
      TestRegionObserverInterface.TEST_TABLE)) {
    boolean foundA = false;
    boolean foundB = false;
    boolean foundC = false;
    for (Cell kv: results) {
      if (CellUtil.matchingFamily(kv, TestRegionObserverInterface.A)) {
        foundA = true;
      }
      if (CellUtil.matchingFamily(kv, TestRegionObserverInterface.B)) {
        foundB = true;
      }
      if (CellUtil.matchingFamily(kv, TestRegionObserverInterface.C)) {
        foundC = true;
      }
    }
    assertTrue(foundA);
    assertTrue(foundB);
    assertTrue(foundC);
  }
  ctPostGet.incrementAndGet();
}
 
Example 6
Source File: FilterListWithOR.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * For MUST_PASS_ONE, we cannot make sure that when filter-A in filter list return NEXT_COL then
 * the next cell passing to filterList will be the first cell in next column, because if filter-B
 * in filter list return SKIP, then the filter list will return SKIP. In this case, we should pass
 * the cell following the previous cell, and it's possible that the next cell has the same column
 * as the previous cell even if filter-A has NEXT_COL returned for the previous cell. So we should
 * save the previous cell and the return code list when checking previous cell for every filter in
 * filter list, and verify if currentCell fit the previous return code, if fit then pass the
 * currentCell to the corresponding filter. (HBASE-17678) <br>
 * Note that: In StoreScanner level, NEXT_ROW will skip to the next row in current family, and in
 * RegionScanner level, NEXT_ROW will skip to the next row in current family and switch to the
 * next family for RegionScanner, INCLUDE_AND_NEXT_ROW is the same. so we should pass current cell
 * to the filter, if row mismatch or row match but column family mismatch. (HBASE-18368)
 * @see org.apache.hadoop.hbase.filter.Filter.ReturnCode
 * @param subFilter which sub-filter to calculate the return code by using previous cell and
 *          previous return code.
 * @param prevCell the previous cell passed to given sub-filter.
 * @param currentCell the current cell which will pass to given sub-filter.
 * @param prevCode the previous return code for given sub-filter.
 * @return return code calculated by using previous cell and previous return code. null means can
 *         not decide which return code should return, so we will pass the currentCell to
 *         subFilter for getting currentCell's return code, and it won't impact the sub-filter's
 *         internal states.
 */
private ReturnCode calculateReturnCodeByPrevCellAndRC(Filter subFilter, Cell currentCell,
    Cell prevCell, ReturnCode prevCode) throws IOException {
  if (prevCell == null || prevCode == null) {
    return null;
  }
  switch (prevCode) {
  case INCLUDE:
  case SKIP:
      return null;
  case SEEK_NEXT_USING_HINT:
      Cell nextHintCell = subFilter.getNextCellHint(prevCell);
      return nextHintCell != null && compareCell(currentCell, nextHintCell) < 0
        ? ReturnCode.SEEK_NEXT_USING_HINT : null;
  case NEXT_COL:
  case INCLUDE_AND_NEXT_COL:
      // Once row changed, reset() will clear prevCells, so we need not to compare their rows
      // because rows are the same here.
      return CellUtil.matchingColumn(prevCell, currentCell) ? ReturnCode.NEXT_COL : null;
  case NEXT_ROW:
  case INCLUDE_AND_SEEK_NEXT_ROW:
      // As described above, rows are definitely the same, so we only compare the family.
      return CellUtil.matchingFamily(prevCell, currentCell) ? ReturnCode.NEXT_ROW : null;
  default:
      throw new IllegalStateException("Received code is not valid.");
  }
}
 
Example 7
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the current cell should be skipped. The cell will be skipped
 * if the previous keyvalue had the same key as the current cell. This means filter already responded
 * for the previous keyvalue with ReturnCode.NEXT_COL or ReturnCode.INCLUDE_AND_NEXT_COL.
 * @param cell the {@link Cell} to be tested for skipping
 * @return true is current cell should be skipped, false otherwise
 */
private boolean skipCellVersion(Cell cell) {
  return skipColumn != null
    && CellUtil.matchingRow(cell, skipColumn.getRowArray(), skipColumn.getRowOffset(),
                            skipColumn.getRowLength())
    && CellUtil.matchingFamily(cell, skipColumn.getFamilyArray(), skipColumn.getFamilyOffset(),
                               skipColumn.getFamilyLength())
    && CellUtil.matchingQualifier(cell, skipColumn.getQualifierArray(), skipColumn.getQualifierOffset(),
                                  skipColumn.getQualifierLength());
}
 
Example 8
Source File: ApplicationStatMapper.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public List<JoinStatBo> mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return Collections.emptyList();
    }
    final byte[] distributedRowKey = result.getRow();
    final String applicationId = this.hbaseOperationFactory.getApplicationId(distributedRowKey);
    final long baseTimestamp = this.hbaseOperationFactory.getBaseTimestamp(distributedRowKey);

    List<JoinStatBo> dataPoints = new ArrayList<>();

    for (Cell cell : result.rawCells()) {
        if (CellUtil.matchingFamily(cell, HbaseColumnFamily.APPLICATION_STAT_STATISTICS.getName())) {
            Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
            Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());

            long timestampDelta = this.decoder.decodeQualifier(qualifierBuffer);

            ApplicationStatDecodingContext decodingContext = new ApplicationStatDecodingContext();
            decodingContext.setApplicationId(applicationId);
            decodingContext.setBaseTimestamp(baseTimestamp);
            decodingContext.setTimestampDelta(timestampDelta);
            List<JoinStatBo> candidates = this.decoder.decodeValue(valueBuffer, decodingContext);
            for (JoinStatBo candidate : candidates) {
                long timestamp = candidate.getTimestamp();
                if (this.filter.filter(timestamp)) {
                    continue;
                }
                dataPoints.add(candidate);
            }
        }
    }
    // Reverse sort as timestamp is stored in a reversed order.
    dataPoints.sort(REVERSE_TIMESTAMP_COMPARATOR);
    return dataPoints;
}
 
Example 9
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the current cell should be skipped. The cell will be skipped
 * if the previous keyvalue had the same key as the current cell. This means filter already responded
 * for the previous keyvalue with ReturnCode.NEXT_COL or ReturnCode.INCLUDE_AND_NEXT_COL.
 * @param cell the {@link Cell} to be tested for skipping
 * @return true is current cell should be skipped, false otherwise
 */
private boolean skipCellVersion(Cell cell) {
  return skipColumn != null
    && CellUtil.matchingRow(cell, skipColumn.getRowArray(), skipColumn.getRowOffset(),
                            skipColumn.getRowLength())
    && CellUtil.matchingFamily(cell, skipColumn.getFamilyArray(), skipColumn.getFamilyOffset(),
                               skipColumn.getFamilyLength())
    && CellUtil.matchingQualifier(cell, skipColumn.getQualifierArray(), skipColumn.getQualifierOffset(),
                                  skipColumn.getQualifierLength());
}
 
Example 10
Source File: AgentStatMapperV2.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public List<T> mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return Collections.emptyList();
    }
    final byte[] distributedRowKey = result.getRow();
    final String agentId = this.hbaseOperationFactory.getAgentId(distributedRowKey);
    final long baseTimestamp = this.hbaseOperationFactory.getBaseTimestamp(distributedRowKey);

    List<T> dataPoints = new ArrayList<>();

    for (Cell cell : result.rawCells()) {
        if (CellUtil.matchingFamily(cell, HbaseColumnFamily.AGENT_STAT_STATISTICS.getName())) {
            Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
            Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());

            long timestampDelta = this.decoder.decodeQualifier(qualifierBuffer);

            AgentStatDecodingContext decodingContext = new AgentStatDecodingContext();
            decodingContext.setAgentId(agentId);
            decodingContext.setBaseTimestamp(baseTimestamp);
            decodingContext.setTimestampDelta(timestampDelta);
            List<T> candidates = this.decoder.decodeValue(valueBuffer, decodingContext);
            for (T candidate : candidates) {
                if (filter(candidate)) {
                    continue;
                }
                dataPoints.add(candidate);
            }
        }
    }
    // Reverse sort as timestamp is stored in a reversed order.
    dataPoints.sort(REVERSE_TIMESTAMP_COMPARATOR);
    return dataPoints;
}
 
Example 11
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the current cell should be skipped. The cell will be skipped
 * if the previous keyvalue had the same key as the current cell. This means filter already responded
 * for the previous keyvalue with ReturnCode.NEXT_COL or ReturnCode.INCLUDE_AND_NEXT_COL.
 * @param cell the {@link Cell} to be tested for skipping
 * @return true is current cell should be skipped, false otherwise
 */
private boolean skipCellVersion(Cell cell) {
  return skipColumn != null
    && CellUtil.matchingRow(cell, skipColumn.getRowArray(), skipColumn.getRowOffset(),
                            skipColumn.getRowLength())
    && CellUtil.matchingFamily(cell, skipColumn.getFamilyArray(), skipColumn.getFamilyOffset(),
                               skipColumn.getFamilyLength())
    && CellUtil.matchingQualifier(cell, skipColumn.getQualifierArray(), skipColumn.getQualifierOffset(),
                                  skipColumn.getQualifierLength());
}
 
Example 12
Source File: TestScanner.java    From hbase with Apache License 2.0 5 votes vote down vote up
private Cell getColumn(final List<Cell> kvs, final byte [] family,
    final byte [] qualifier) {
  for (Cell kv: kvs) {
    if (CellUtil.matchingFamily(kv, family) && CellUtil.matchingQualifier(kv, qualifier)) {
      return kv;
    }
  }
  return null;
}
 
Example 13
Source File: CellUtils.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean matchingColumn(Cell kv, byte[] family, byte[] qualifier) {
        return CellUtil.matchingFamily(kv, family) && CellUtil.matchingQualifier(kv,qualifier);
}
 
Example 14
Source File: HBCKMetaTableAccessor.java    From hbase-operator-tools with Apache License 2.0 4 votes vote down vote up
private static boolean isMergeQualifierPrefix(Cell cell) {
  // Check to see if has family and that qualifier starts with the MERGE_QUALIFIER_PREFIX
  return CellUtil.matchingFamily(cell, HConstants.CATALOG_FAMILY) && qualifierStartsWith(cell,
      MERGE_QUALIFIER_PREFIX);
}
 
Example 15
Source File: TestSyncTable.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void assertTargetDoDeletesFalse(int expectedRows, TableName sourceTableName,
    TableName targetTableName) throws Exception {
  Table sourceTable = TEST_UTIL.getConnection().getTable(sourceTableName);
  Table targetTable = TEST_UTIL.getConnection().getTable(targetTableName);

  ResultScanner sourceScanner = sourceTable.getScanner(new Scan());
  ResultScanner targetScanner = targetTable.getScanner(new Scan());
  Result targetRow = targetScanner.next();
  Result sourceRow = sourceScanner.next();
  int rowsCount = 0;
  while (targetRow != null) {
    rowsCount++;
    //only compares values for existing rows, skipping rows existing on
    //target only that were not deleted given --doDeletes=false
    if (Bytes.toInt(sourceRow.getRow()) != Bytes.toInt(targetRow.getRow())) {
      targetRow = targetScanner.next();
      continue;
    }

    LOG.debug("SOURCE row: " + (sourceRow == null ? "null"
        : Bytes.toInt(sourceRow.getRow()))
        + " cells:" + sourceRow);
    LOG.debug("TARGET row: " + (targetRow == null ? "null"
        : Bytes.toInt(targetRow.getRow()))
        + " cells:" + targetRow);

    Cell[] sourceCells = sourceRow.rawCells();
    Cell[] targetCells = targetRow.rawCells();
    int targetRowKey = Bytes.toInt(targetRow.getRow());
    if (targetRowKey >= 70 && targetRowKey < 80) {
      if (sourceCells.length == targetCells.length) {
        LOG.debug("Source cells: " + Arrays.toString(sourceCells));
        LOG.debug("Target cells: " + Arrays.toString(targetCells));
        Assert.fail("Row " + targetRowKey + " should have more cells in "
            + "target than in source");
      }

    } else {
      if (sourceCells.length != targetCells.length) {
        LOG.debug("Source cells: " + Arrays.toString(sourceCells));
        LOG.debug("Target cells: " + Arrays.toString(targetCells));
        Assert.fail("Row " + Bytes.toInt(sourceRow.getRow())
            + " has " + sourceCells.length
            + " cells in source table but " + targetCells.length
            + " cells in target table");
      }
    }
    for (int j = 0; j < sourceCells.length; j++) {
      Cell sourceCell = sourceCells[j];
      Cell targetCell = targetCells[j];
      try {
        if (!CellUtil.matchingRows(sourceCell, targetCell)) {
          Assert.fail("Rows don't match");
        }
        if (!CellUtil.matchingFamily(sourceCell, targetCell)) {
          Assert.fail("Families don't match");
        }
        if (!CellUtil.matchingQualifier(sourceCell, targetCell)) {
          Assert.fail("Qualifiers don't match");
        }
        if (targetRowKey < 80 && targetRowKey >= 90){
          if (!CellUtil.matchingTimestamp(sourceCell, targetCell)) {
            Assert.fail("Timestamps don't match");
          }
        }
        if (!CellUtil.matchingValue(sourceCell, targetCell)) {
          Assert.fail("Values don't match");
        }
      } catch (Throwable t) {
        LOG.debug("Source cell: " + sourceCell + " target cell: "
            + targetCell);
        Throwables.propagate(t);
      }
    }
    targetRow = targetScanner.next();
    sourceRow = sourceScanner.next();
  }
  assertEquals("Target expected rows does not match.",expectedRows,
      rowsCount);
  sourceScanner.close();
  targetScanner.close();
  sourceTable.close();
  targetTable.close();
}
 
Example 16
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
  if (!CellUtil.matchingFamily(cell, currentFamily)) {
    // column family changed
    currentFamily = CellUtil.cloneFamily(cell);
    Long familyOldestTs = oldestTsByFamily.get(currentFamily);
    currentOldestTs = familyOldestTs != null ? familyOldestTs : 0;
    deleteTracker.reset();
  }
  // need to apply TTL for the column family here
  long kvTimestamp = cell.getTimestamp();
  if (TxUtils.getTimestampForTTL(kvTimestamp) < currentOldestTs) {
    // passed TTL for this column, seek to next
    return ReturnCode.NEXT_COL;
  } else if (tx.isVisible(kvTimestamp)) {
    // Return all writes done by current transaction (including deletes) for VisibilityLevel.SNAPSHOT_ALL
    if (tx.getVisibilityLevel() == Transaction.VisibilityLevel.SNAPSHOT_ALL && tx.isCurrentWrite(kvTimestamp)) {
      // cell is visible
      // visibility SNAPSHOT_ALL needs all matches
      return runSubFilter(ReturnCode.INCLUDE, cell);
    }
    if (DeleteTracker.isFamilyDelete(cell)) {
      deleteTracker.addFamilyDelete(cell);
      if (clearDeletes) {
        return ReturnCode.NEXT_COL;
      } else {
        // cell is visible
        // as soon as we find a KV to include we can move to the next column
        return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
      }
    }
    // check if masked by family delete
    if (deleteTracker.isDeleted(cell)) {
      return ReturnCode.NEXT_COL;
    }
    // check for column delete
    if (isColumnDelete(cell)) {
      if (clearDeletes) {
        // skip "deleted" cell
        return ReturnCode.NEXT_COL;
      } else {
        // keep the marker but skip any remaining versions
        return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
      }
    }
    // cell is visible
    // as soon as we find a KV to include we can move to the next column
    return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
  } else {
    return ReturnCode.SKIP;
  }
}
 
Example 17
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
  if (!CellUtil.matchingFamily(cell, currentFamily.get(), currentFamily.getOffset(), currentFamily.getLength())) {
    // column family changed
    currentFamily.set(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
    Long familyOldestTs = oldestTsByFamily.get(currentFamily);
    currentOldestTs = familyOldestTs != null ? familyOldestTs : 0;
    deleteTracker.reset();
  }
  // need to apply TTL for the column family here
  long kvTimestamp = cell.getTimestamp();
  if (TxUtils.getTimestampForTTL(kvTimestamp) < currentOldestTs) {
    // passed TTL for this column, seek to next
    return ReturnCode.NEXT_COL;
  } else if (tx.isVisible(kvTimestamp)) {
    // Return all writes done by current transaction (including deletes) for VisibilityLevel.SNAPSHOT_ALL
    if (tx.getVisibilityLevel() == Transaction.VisibilityLevel.SNAPSHOT_ALL && tx.isCurrentWrite(kvTimestamp)) {
      // cell is visible
      // visibility SNAPSHOT_ALL needs all matches
      return runSubFilter(ReturnCode.INCLUDE, cell);
    }
    if (DeleteTracker.isFamilyDelete(cell)) {
      deleteTracker.addFamilyDelete(cell);
      if (clearDeletes) {
        return ReturnCode.NEXT_COL;
      } else {
        // cell is visible
        // as soon as we find a KV to include we can move to the next column
        return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
      }
    }
    // check if masked by family delete
    if (deleteTracker.isDeleted(cell)) {
      return ReturnCode.NEXT_COL;
    }
    // check for column delete
    if (isColumnDelete(cell)) {
      if (clearDeletes) {
        // skip "deleted" cell
        return ReturnCode.NEXT_COL;
      } else {
        // keep the marker but skip any remaining versions
        return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
      }
    }
    // cell is visible
    // as soon as we find a KV to include we can move to the next column
    
    return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
  } else {
    return ReturnCode.SKIP;
  }
}
 
Example 18
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
  if (!CellUtil.matchingFamily(cell, currentFamily.get(), currentFamily.getOffset(), currentFamily.getLength())) {
    // column family changed
    currentFamily.set(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
    Long familyOldestTs = oldestTsByFamily.get(currentFamily);
    currentOldestTs = familyOldestTs != null ? familyOldestTs : 0;
    deleteTracker.reset();
  }
  // need to apply TTL for the column family here
  long kvTimestamp = cell.getTimestamp();
  if (TxUtils.getTimestampForTTL(kvTimestamp) < currentOldestTs) {
    // passed TTL for this column, seek to next
    return ReturnCode.NEXT_COL;
  } else if (tx.isVisible(kvTimestamp)) {
    // Return all writes done by current transaction (including deletes) for VisibilityLevel.SNAPSHOT_ALL
    if (tx.getVisibilityLevel() == Transaction.VisibilityLevel.SNAPSHOT_ALL && tx.isCurrentWrite(kvTimestamp)) {
      // cell is visible
      // visibility SNAPSHOT_ALL needs all matches
      return runSubFilter(ReturnCode.INCLUDE, cell);
    }
    if (DeleteTracker.isFamilyDelete(cell)) {
      deleteTracker.addFamilyDelete(cell);
      if (clearDeletes) {
        return ReturnCode.NEXT_COL;
      } else {
        // cell is visible
        // as soon as we find a KV to include we can move to the next column
        return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
      }
    }
    // check if masked by family delete
    if (deleteTracker.isDeleted(cell)) {
      return ReturnCode.NEXT_COL;
    }
    // check for column delete
    if (isColumnDelete(cell)) {
      if (clearDeletes) {
        // skip "deleted" cell
        return ReturnCode.NEXT_COL;
      } else {
        // keep the marker but skip any remaining versions
        return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
      }
    }
    // cell is visible
    // as soon as we find a KV to include we can move to the next column
    return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
  } else {
    return ReturnCode.SKIP;
  }
}
 
Example 19
Source File: AbstractPrefixMatchingExtractor.java    From hbase-indexer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isApplicable(KeyValue keyValue) {
    return CellUtil.matchingFamily(keyValue, columnFamily) && Bytes.startsWith(CellUtil.cloneQualifier(keyValue), prefix);
}
 
Example 20
Source File: TransactionVisibilityFilter.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
  if (!CellUtil.matchingFamily(cell, currentFamily.get(), currentFamily.getOffset(), currentFamily.getLength())) {
    // column family changed
    currentFamily.set(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
    Long familyOldestTs = oldestTsByFamily.get(currentFamily);
    currentOldestTs = familyOldestTs != null ? familyOldestTs : 0;
    deleteTracker.reset();
  }
  // need to apply TTL for the column family here
  long kvTimestamp = cell.getTimestamp();
  if (TxUtils.getTimestampForTTL(kvTimestamp) < currentOldestTs) {
    // passed TTL for this column, seek to next
    return ReturnCode.NEXT_COL;
  } else if (tx.isVisible(kvTimestamp)) {
    // Return all writes done by current transaction (including deletes) for VisibilityLevel.SNAPSHOT_ALL
    if (tx.getVisibilityLevel() == Transaction.VisibilityLevel.SNAPSHOT_ALL && tx.isCurrentWrite(kvTimestamp)) {
      // cell is visible
      // visibility SNAPSHOT_ALL needs all matches
      return runSubFilter(ReturnCode.INCLUDE, cell);
    }
    if (DeleteTracker.isFamilyDelete(cell)) {
      deleteTracker.addFamilyDelete(cell);
      if (clearDeletes) {
        return ReturnCode.NEXT_COL;
      } else {
        // cell is visible
        // as soon as we find a KV to include we can move to the next column
        return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
      }
    }
    // check if masked by family delete
    if (deleteTracker.isDeleted(cell)) {
      return ReturnCode.NEXT_COL;
    }
    // check for column delete
    if (isColumnDelete(cell)) {
      if (clearDeletes) {
        // skip "deleted" cell
        return ReturnCode.NEXT_COL;
      } else {
        // keep the marker but skip any remaining versions
        return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
      }
    }
    // cell is visible
    // as soon as we find a KV to include we can move to the next column
    return runSubFilter(ReturnCode.INCLUDE_AND_NEXT_COL, cell);
  } else {
    return ReturnCode.SKIP;
  }
}