org.apache.hadoop.hbase.Tag Java Examples

The following examples show how to use org.apache.hadoop.hbase.Tag. 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: TestDataBlockEncoders.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Test data block encoding of empty KeyValue.
 *
 * @throws IOException
 *           On test failure.
 */
@Test
public void testEmptyKeyValues() throws IOException {
  List<KeyValue> kvList = new ArrayList<>();
  byte[] row = new byte[0];
  byte[] family = new byte[0];
  byte[] qualifier = new byte[0];
  byte[] value = new byte[0];
  if (!includesTags) {
    kvList.add(new KeyValue(row, family, qualifier, 0L, value));
    kvList.add(new KeyValue(row, family, qualifier, 0L, value));
  } else {
    byte[] metaValue1 = Bytes.toBytes("metaValue1");
    byte[] metaValue2 = Bytes.toBytes("metaValue2");
    kvList.add(new KeyValue(row, family, qualifier, 0L, value,
        new Tag[] { new ArrayBackedTag((byte) 1, metaValue1) }));
    kvList.add(new KeyValue(row, family, qualifier, 0L, value,
        new Tag[] { new ArrayBackedTag((byte) 1, metaValue2) }));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
 
Example #2
Source File: HFileTestUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * This verifies that each cell has a tag that is equal to its rowkey name.  For this to work
 * the hbase instance must have HConstants.RPC_CODEC_CONF_KEY set to
 * KeyValueCodecWithTags.class.getCanonicalName());
 * @param table table containing tagged cells
 * @throws IOException if problems reading table
 */
public static void verifyTags(Table table) throws IOException {
  ResultScanner s = table.getScanner(new Scan());
  for (Result r : s) {
    for (Cell c : r.listCells()) {
      Optional<Tag> tag = PrivateCellUtil.getTag(c, TagType.MOB_TABLE_NAME_TAG_TYPE);
      if (!tag.isPresent()) {
        fail(c.toString() + " has null tag");
        continue;
      }
      Tag t = tag.get();
      byte[] tval = Tag.cloneValue(t);
      assertArrayEquals(c.toString() + " has tag" + Bytes.toString(tval),
          r.getRow(), tval);
    }
  }
}
 
Example #3
Source File: DefaultVisibilityLabelServiceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @param putVisTags Visibility tags in Put Mutation
 * @param deleteVisTags Visibility tags in Delete Mutation
 * @return true when all the visibility tags in Put matches with visibility tags in Delete.
 * This is used when both the set of tags are sorted based on the label ordinal.
 */
private static boolean matchOrdinalSortedVisibilityTags(List<Tag> putVisTags,
    List<Tag> deleteVisTags) {
  boolean matchFound = false;
  // If the size does not match. Definitely we are not comparing the equal tags.
  if ((deleteVisTags.size()) == putVisTags.size()) {
    for (Tag tag : deleteVisTags) {
      matchFound = false;
      for (Tag givenTag : putVisTags) {
        if (Tag.matchingValue(tag, givenTag)) {
          matchFound = true;
          break;
        }
      }
      if (!matchFound) break;
    }
  }
  return matchFound;
}
 
Example #4
Source File: TestVisibilityLabelsReplication.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> e, Put m, WALEdit edit,
    Durability durability) throws IOException {
  byte[] attribute = m.getAttribute(NON_VISIBILITY);
  byte[] cf = null;
  List<Cell> updatedCells = new ArrayList<>();
  if (attribute != null) {
    for (List<? extends Cell> edits : m.getFamilyCellMap().values()) {
      for (Cell cell : edits) {
        KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
        if (cf == null) {
          cf = CellUtil.cloneFamily(kv);
        }
        Tag tag = new ArrayBackedTag((byte) NON_VIS_TAG_TYPE, attribute);
        List<Tag> tagList = new ArrayList<>(PrivateCellUtil.getTags(cell).size() + 1);
        tagList.add(tag);
        tagList.addAll(PrivateCellUtil.getTags(cell));
        Cell newcell = PrivateCellUtil.createCell(kv, tagList);
        ((List<Cell>) updatedCells).add(newcell);
      }
    }
    m.getFamilyCellMap().remove(cf);
    // Update the family map
    m.getFamilyCellMap().put(cf, updatedCells);
  }
}
 
Example #5
Source File: DefaultVisibilityLabelServiceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matchVisibility(List<Tag> putVisTags, Byte putTagsFormat, List<Tag> deleteVisTags,
    Byte deleteTagsFormat) throws IOException {
  // Early out if there are no tags in both of cell and delete
  if (putVisTags.isEmpty() && deleteVisTags.isEmpty()) {
    return true;
  }
  // Early out if one of the tags is empty
  if (putVisTags.isEmpty() ^ deleteVisTags.isEmpty()) {
    return false;
  }
  if ((deleteTagsFormat != null && deleteTagsFormat == SORTED_ORDINAL_SERIALIZATION_FORMAT)
      && (putTagsFormat == null || putTagsFormat == SORTED_ORDINAL_SERIALIZATION_FORMAT)) {
    if (putTagsFormat == null) {
      return matchUnSortedVisibilityTags(putVisTags, deleteVisTags);
    } else {
      return matchOrdinalSortedVisibilityTags(putVisTags, deleteVisTags);
    }
  }
  throw new IOException("Unexpected tag format passed for comparison, deleteTagsFormat : "
      + deleteTagsFormat + ", putTagsFormat : " + putTagsFormat);
}
 
Example #6
Source File: TestStoreFileScannerWithTagCompression.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void writeStoreFile(final StoreFileWriter writer) throws IOException {
  byte[] fam = Bytes.toBytes("f");
  byte[] qualifier = Bytes.toBytes("q");
  long now = System.currentTimeMillis();
  byte[] b = Bytes.toBytes("k1");
  Tag t1 = new ArrayBackedTag((byte) 1, "tag1");
  Tag t2 = new ArrayBackedTag((byte) 2, "tag2");
  Tag t3 = new ArrayBackedTag((byte) 3, "tag3");
  try {
    writer.append(new KeyValue(b, fam, qualifier, now, b, new Tag[] { t1 }));
    b = Bytes.toBytes("k3");
    writer.append(new KeyValue(b, fam, qualifier, now, b, new Tag[] { t2, t1 }));
    b = Bytes.toBytes("k4");
    writer.append(new KeyValue(b, fam, qualifier, now, b, new Tag[] { t3 }));
    b = Bytes.toBytes("k5");
    writer.append(new KeyValue(b, fam, qualifier, now, b, new Tag[] { t3 }));
  } finally {
    writer.close();
  }
}
 
Example #7
Source File: TestVisibilityLabelsReplication.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected static void doAssert(byte[] row, String visTag) throws Exception {
  if (VisibilityReplicationEndPointForTest.lastEntries == null) {
    return; // first call
  }
  Assert.assertEquals(1, VisibilityReplicationEndPointForTest.lastEntries.size());
  List<Cell> cells = VisibilityReplicationEndPointForTest.lastEntries.get(0).getEdit().getCells();
  Assert.assertEquals(4, cells.size());
  boolean tagFound = false;
  for (Cell cell : cells) {
    if ((Bytes.equals(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(), row, 0,
        row.length))) {
      List<Tag> tags = PrivateCellUtil.getTags(cell);
      for (Tag tag : tags) {
        if (tag.getType() == TagType.STRING_VIS_TAG_TYPE) {
          assertEquals(visTag, Tag.getValueAsString(tag));
          tagFound = true;
          break;
        }
      }
    }
  }
  assertTrue(tagFound);
}
 
Example #8
Source File: AccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void checkForReservedTagPresence(User user, Mutation m) throws IOException {
  // No need to check if we're not going to throw
  if (!authorizationEnabled) {
    m.setAttribute(TAG_CHECK_PASSED, TRUE);
    return;
  }
  // Superusers are allowed to store cells unconditionally.
  if (Superusers.isSuperUser(user)) {
    m.setAttribute(TAG_CHECK_PASSED, TRUE);
    return;
  }
  // We already checked (prePut vs preBatchMutation)
  if (m.getAttribute(TAG_CHECK_PASSED) != null) {
    return;
  }
  for (CellScanner cellScanner = m.cellScanner(); cellScanner.advance();) {
    Iterator<Tag> tagsItr = PrivateCellUtil.tagsIterator(cellScanner.current());
    while (tagsItr.hasNext()) {
      if (tagsItr.next().getType() == PermissionStorage.ACL_TAG_TYPE) {
        throw new AccessDeniedException("Mutation contains cell with reserved type tag");
      }
    }
  }
  m.setAttribute(TAG_CHECK_PASSED, TRUE);
}
 
Example #9
Source File: AccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
private static void addCellPermissions(final byte[] perms, Map<byte[], List<Cell>> familyMap) {
  // Iterate over the entries in the familyMap, replacing the cells therein
  // with new cells including the ACL data
  for (Map.Entry<byte[], List<Cell>> e: familyMap.entrySet()) {
    List<Cell> newCells = Lists.newArrayList();
    for (Cell cell: e.getValue()) {
      // Prepend the supplied perms in a new ACL tag to an update list of tags for the cell
      List<Tag> tags = new ArrayList<>();
      tags.add(new ArrayBackedTag(PermissionStorage.ACL_TAG_TYPE, perms));
      Iterator<Tag> tagIterator = PrivateCellUtil.tagsIterator(cell);
      while (tagIterator.hasNext()) {
        tags.add(tagIterator.next());
      }
      newCells.add(PrivateCellUtil.createCell(cell, tags));
    }
    // This is supposed to be safe, won't CME
    e.setValue(newCells);
  }
}
 
Example #10
Source File: MobUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Get the table name from when this cell was written into a mob hfile as a TableName.
 * @param cell to extract tag from
 * @return name of table as a TableName. empty if the tag is not found.
 */
public static Optional<TableName> getTableName(Cell cell) {
  Optional<Tag> maybe = getTableNameTag(cell);
  Optional<TableName> name = Optional.empty();
  if (maybe.isPresent()) {
    final Tag tag = maybe.get();
    if (tag.hasArray()) {
      name = Optional.of(TableName.valueOf(tag.getValueArray(), tag.getValueOffset(),
          tag.getValueLength()));
    } else {
      // TODO ByteBuffer handling in tags looks busted. revisit.
      ByteBuffer buffer = tag.getValueByteBuffer().duplicate();
      buffer.mark();
      buffer.position(tag.getValueOffset());
      buffer.limit(tag.getValueOffset() + tag.getValueLength());
      name = Optional.of(TableName.valueOf(buffer));
    }
  }
  return name;
}
 
Example #11
Source File: ExpAsStringVisibilityLabelServiceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
private static boolean checkForMatchingVisibilityTagsWithSortedOrder(List<Tag> putVisTags,
    List<Tag> deleteVisTags) {
  // Early out if there are no tags in both of cell and delete
  if (putVisTags.isEmpty() && deleteVisTags.isEmpty()) {
    return true;
  }
  boolean matchFound = false;
  // If the size does not match. Definitely we are not comparing the equal
  // tags.
  if ((deleteVisTags.size()) == putVisTags.size()) {
    for (Tag tag : deleteVisTags) {
      matchFound = false;
      for (Tag givenTag : putVisTags) {
        if (Tag.matchingValue(tag, givenTag)) {
          matchFound = true;
          break;
        }
      }
      if (!matchFound)
        break;
    }
  }
  return matchFound;
}
 
Example #12
Source File: TestDataBlockEncoders.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Test KeyValues with negative timestamp.
 *
 * @throws IOException
 *           On test failure.
 */
@Test
public void testNegativeTimestamps() throws IOException {
  List<KeyValue> kvList = new ArrayList<>();
  byte[] row = new byte[0];
  byte[] family = new byte[0];
  byte[] qualifier = new byte[0];
  byte[] value = new byte[0];
  if (includesTags) {
    byte[] metaValue1 = Bytes.toBytes("metaValue1");
    byte[] metaValue2 = Bytes.toBytes("metaValue2");
    kvList.add(new KeyValue(row, family, qualifier, 0L, value,
        new Tag[] { new ArrayBackedTag((byte) 1, metaValue1) }));
    kvList.add(new KeyValue(row, family, qualifier, 0L, value,
        new Tag[] { new ArrayBackedTag((byte) 1, metaValue2) }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier, -1L, Type.Put, value));
    kvList.add(new KeyValue(row, family, qualifier, -2L, Type.Put, value));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
 
Example #13
Source File: TestDataBlockEncoders.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testZeroByte() throws IOException {
  List<KeyValue> kvList = new ArrayList<>();
  byte[] row = Bytes.toBytes("abcd");
  byte[] family = new byte[] { 'f' };
  byte[] qualifier0 = new byte[] { 'b' };
  byte[] qualifier1 = new byte[] { 'c' };
  byte[] value0 = new byte[] { 'd' };
  byte[] value1 = new byte[] { 0x00 };
  if (includesTags) {
    kvList.add(new KeyValue(row, family, qualifier0, 0, value0,
        new Tag[] { new ArrayBackedTag((byte) 1, "value1") }));
    kvList.add(new KeyValue(row, family, qualifier1, 0, value1,
        new Tag[] { new ArrayBackedTag((byte) 1, "value1") }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier0, 0, Type.Put, value0));
    kvList.add(new KeyValue(row, family, qualifier1, 0, Type.Put, value1));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
 
Example #14
Source File: ExpAsStringVisibilityLabelServiceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public List<Tag> createVisibilityExpTags(String visExpression, boolean withSerializationFormat,
    boolean checkAuths) throws IOException {
  ExpressionNode node = null;
  try {
    node = this.expressionParser.parse(visExpression);
  } catch (ParseException e) {
    throw new IOException(e);
  }
  node = this.expressionExpander.expand(node);
  List<Tag> tags = new ArrayList<>();
  if (withSerializationFormat) {
    tags.add(STRING_SERIALIZATION_FORMAT_TAG);
  }
  if (node instanceof NonLeafExpressionNode
      && ((NonLeafExpressionNode) node).getOperator() == Operator.OR) {
    for (ExpressionNode child : ((NonLeafExpressionNode) node).getChildExps()) {
      tags.add(createTag(child));
    }
  } else {
    tags.add(createTag(node));
  }
  return tags;
}
 
Example #15
Source File: Mutation.java    From hbase with Apache License 2.0 6 votes vote down vote up
private static Map<String, Object> cellToStringMap(Cell c) {
  Map<String, Object> stringMap = new HashMap<>();
  stringMap.put("qualifier", Bytes.toStringBinary(c.getQualifierArray(), c.getQualifierOffset(),
              c.getQualifierLength()));
  stringMap.put("timestamp", c.getTimestamp());
  stringMap.put("vlen", c.getValueLength());
  List<Tag> tags = PrivateCellUtil.getTags(c);
  if (tags != null) {
    List<String> tagsString = new ArrayList<>(tags.size());
    for (Tag t : tags) {
      tagsString
          .add((t.getType()) + ":" + Bytes.toStringBinary(Tag.cloneValue(t)));
    }
    stringMap.put("tag", tagsString);
  }
  return stringMap;
}
 
Example #16
Source File: VisibilityController.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether cell contains any tag with type as VISIBILITY_TAG_TYPE. This
 * tag type is reserved and should not be explicitly set by user. There are
 * two versions of this method one that accepts pair and other without pair.
 * In case of preAppend and preIncrement the additional operations are not
 * needed like checking for STRING_VIS_TAG_TYPE and hence the API without pair
 * could be used.
 *
 * @param cell
 * @throws IOException
 */
private boolean checkForReservedVisibilityTagPresence(Cell cell) throws IOException {
  // Bypass this check when the operation is done by a system/super user.
  // This is done because, while Replication, the Cells coming to the peer
  // cluster with reserved
  // typed tags and this is fine and should get added to the peer cluster
  // table
  if (isSystemOrSuperUser()) {
    return true;
  }
  Iterator<Tag> tagsItr = PrivateCellUtil.tagsIterator(cell);
  while (tagsItr.hasNext()) {
    if (RESERVED_VIS_TAG_TYPES.contains(tagsItr.next().getType())) {
      return false;
    }
  }
  return true;
}
 
Example #17
Source File: WALPrettyPrinter.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static Map<String, Object> toStringMap(Cell cell) {
  Map<String, Object> stringMap = new HashMap<>();
  stringMap.put("row",
      Bytes.toStringBinary(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
  stringMap.put("type", cell.getType());
  stringMap.put("family", Bytes.toStringBinary(cell.getFamilyArray(), cell.getFamilyOffset(),
              cell.getFamilyLength()));
  stringMap.put("qualifier",
      Bytes.toStringBinary(cell.getQualifierArray(), cell.getQualifierOffset(),
          cell.getQualifierLength()));
  stringMap.put("timestamp", cell.getTimestamp());
  stringMap.put("vlen", cell.getValueLength());
  if (cell.getTagsLength() > 0) {
    List<String> tagsString = new ArrayList<>();
    Iterator<Tag> tagsIterator = PrivateCellUtil.tagsIterator(cell);
    while (tagsIterator.hasNext()) {
      Tag tag = tagsIterator.next();
      tagsString
          .add((tag.getType()) + ":" + Bytes.toStringBinary(Tag.cloneValue(tag)));
    }
    stringMap.put("tag", tagsString);
  }
  return stringMap;
}
 
Example #18
Source File: HMobStore.java    From hbase with Apache License 2.0 6 votes vote down vote up
public HMobStore(final HRegion region, final ColumnFamilyDescriptor family,
    final Configuration confParam, boolean warmup) throws IOException {
  super(region, family, confParam, warmup);
  this.family = family;
  this.mobFileCache = region.getMobFileCache();
  this.homePath = MobUtils.getMobHome(conf);
  this.mobFamilyPath = MobUtils.getMobFamilyPath(conf, this.getTableName(),
      family.getNameAsString());
  List<Path> locations = new ArrayList<>(2);
  locations.add(mobFamilyPath);
  TableName tn = region.getTableDescriptor().getTableName();
  locations.add(HFileArchiveUtil.getStoreArchivePath(conf, tn, MobUtils.getMobRegionInfo(tn)
      .getEncodedName(), family.getNameAsString()));
  map.put(tn, locations);
  List<Tag> tags = new ArrayList<>(2);
  tags.add(MobConstants.MOB_REF_TAG);
  Tag tableNameTag = new ArrayBackedTag(TagType.MOB_TABLE_NAME_TAG_TYPE,
      getTableName().getName());
  tags.add(tableNameTag);
  this.refCellTags = TagUtil.fromList(tags);
}
 
Example #19
Source File: PerformanceEvaluation.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
void testRow(final int i) throws IOException {
  byte[] row = getRandomRow(this.rand, this.totalRows);
  Put put = new Put(row);
  byte[] value = generateData(this.rand, ROW_LENGTH);
  if (useTags) {
    byte[] tag = generateData(this.rand, TAG_LENGTH);
    Tag[] tags = new Tag[noOfTags];
    for (int n = 0; n < noOfTags; n++) {
      Tag t = new ArrayBackedTag((byte) n, tag);
      tags[n] = t;
    }
    KeyValue kv = new KeyValue(row, FAMILY_NAME, QUALIFIER_NAME, HConstants.LATEST_TIMESTAMP,
        value, tags);
    put.add(kv);
  } else {
    put.addColumn(FAMILY_NAME, QUALIFIER_NAME, value);
  }
  put.setDurability(writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
  mutator.mutate(put);
}
 
Example #20
Source File: PerformanceEvaluation.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
void testRow(final int i) throws IOException {
  byte[] row = format(i);
  Put put = new Put(row);
  byte[] value = generateData(this.rand, ROW_LENGTH);
  if (useTags) {
    byte[] tag = generateData(this.rand, TAG_LENGTH);
    Tag[] tags = new Tag[noOfTags];
    for (int n = 0; n < noOfTags; n++) {
      Tag t = new ArrayBackedTag((byte) n, tag);
      tags[n] = t;
    }
    KeyValue kv = new KeyValue(row, FAMILY_NAME, QUALIFIER_NAME, HConstants.LATEST_TIMESTAMP,
        value, tags);
    put.add(kv);
  } else {
    put.addColumn(FAMILY_NAME, QUALIFIER_NAME, value);
  }
  put.setDurability(writeToWAL ? Durability.SYNC_WAL : Durability.SKIP_WAL);
  mutator.mutate(put);
}
 
Example #21
Source File: TestEncodedSeekers.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void doPuts(HRegion region) throws IOException{
  LoadTestKVGenerator dataGenerator = new LoadTestKVGenerator(MIN_VALUE_SIZE, MAX_VALUE_SIZE);
   for (int i = 0; i < NUM_ROWS; ++i) {
    byte[] key = Bytes.toBytes(LoadTestKVGenerator.md5PrefixedKey(i));
    for (int j = 0; j < NUM_COLS_PER_ROW; ++j) {
      Put put = new Put(key);
      put.setDurability(Durability.ASYNC_WAL);
      byte[] col = Bytes.toBytes(String.valueOf(j));
      byte[] value = dataGenerator.generateRandomSizeValue(key, col);
      if (includeTags) {
        Tag[] tag = new Tag[1];
        tag[0] = new ArrayBackedTag((byte) 1, "Visibility");
        KeyValue kv = new KeyValue(key, CF_BYTES, col, HConstants.LATEST_TIMESTAMP, value, tag);
        put.add(kv);
      } else {
        put.addColumn(CF_BYTES, col, value);
      }
      if(VERBOSE){
        KeyValue kvPut = new KeyValue(key, CF_BYTES, col, value);
        System.err.println(Strings.padFront(i+"", ' ', 4)+" "+kvPut);
      }
      region.put(put);
    }
    if (i % NUM_ROWS_PER_FLUSH == 0) {
      region.flush(true);
    }
  }
}
 
Example #22
Source File: ExpAsStringVisibilityLabelServiceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static String getTagValuePartAsString(Tag t, int offset, int length) {
  if (t.hasArray()) {
    return Bytes.toString(t.getValueArray(), offset, length);
  }
  byte[] b = new byte[length];
  ByteBufferUtils.copyFromBufferToArray(b, t.getValueByteBuffer(), offset, 0, length);
  return Bytes.toString(b);
}
 
Example #23
Source File: TestTagCompressionContext.java    From hbase with Apache License 2.0 5 votes vote down vote up
private Cell createOffheapKVWithTags(int noOfTags) {
  List<Tag> tags = new ArrayList<>();
  for (int i = 0; i < noOfTags; i++) {
    tags.add(new ArrayBackedTag((byte) i, "tagValue" + i));
  }
  KeyValue kv = new KeyValue(ROW, CF, Q, 1234L, V, tags);
  ByteBuffer dbb = ByteBuffer.allocateDirect(kv.getBuffer().length);
  ByteBufferUtils.copyFromArrayToBuffer(dbb, kv.getBuffer(), 0, kv.getBuffer().length);
  ByteBufferKeyValue offheapKV = new ByteBufferKeyValue(dbb, 0, kv.getBuffer().length, 0);
  return offheapKV;
}
 
Example #24
Source File: TestWALCellCodecWithCompression.java    From hbase with Apache License 2.0 5 votes vote down vote up
private KeyValue createKV(int noOfTags) {
  byte[] row = Bytes.toBytes("myRow");
  byte[] cf = Bytes.toBytes("myCF");
  byte[] q = Bytes.toBytes("myQualifier");
  byte[] value = Bytes.toBytes("myValue");
  List<Tag> tags = new ArrayList<>(noOfTags);
  for (int i = 1; i <= noOfTags; i++) {
    tags.add(new ArrayBackedTag((byte) i, Bytes.toBytes("tagValue" + i)));
  }
  return new KeyValue(row, cf, q, HConstants.LATEST_TIMESTAMP, value, tags);
}
 
Example #25
Source File: Mutation.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Tag> getTags() {
  if (cell instanceof RawCell) {
    return ((RawCell) cell).getTags();
  }
  return PrivateCellUtil.tagsIterator(cell);
}
 
Example #26
Source File: TestWALCellCodecWithCompression.java    From hbase with Apache License 2.0 5 votes vote down vote up
private ByteBufferKeyValue createOffheapKV(int noOfTags) {
  byte[] row = Bytes.toBytes("myRow");
  byte[] cf = Bytes.toBytes("myCF");
  byte[] q = Bytes.toBytes("myQualifier");
  byte[] value = Bytes.toBytes("myValue");
  List<Tag> tags = new ArrayList<>(noOfTags);
  for (int i = 1; i <= noOfTags; i++) {
    tags.add(new ArrayBackedTag((byte) i, Bytes.toBytes("tagValue" + i)));
  }
  KeyValue kv = new KeyValue(row, cf, q, HConstants.LATEST_TIMESTAMP, value, tags);
  ByteBuffer dbb = ByteBuffer.allocateDirect(kv.getBuffer().length);
  dbb.put(kv.getBuffer());
  return new ByteBufferKeyValue(dbb, 0, kv.getBuffer().length);
}
 
Example #27
Source File: Mutation.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<Tag> getTag(byte type) {
  if (cell instanceof RawCell) {
    return ((RawCell) cell).getTag(type);
  }
  return PrivateCellUtil.getTag(cell, type);
}
 
Example #28
Source File: TestReplicationWithTags.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e, final Put put,
    final WALEdit edit, final Durability durability) throws IOException {
  byte[] attribute = put.getAttribute("visibility");
  byte[] cf = null;
  List<Cell> updatedCells = new ArrayList<>();
  if (attribute != null) {
    for (List<? extends Cell> edits : put.getFamilyCellMap().values()) {
      for (Cell cell : edits) {
        KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
        if (cf == null) {
          cf = CellUtil.cloneFamily(kv);
        }
        Tag tag = new ArrayBackedTag(TAG_TYPE, attribute);
        List<Tag> tagList = new ArrayList<>(1);
        tagList.add(tag);

        KeyValue newKV = new KeyValue(CellUtil.cloneRow(kv), 0, kv.getRowLength(),
            CellUtil.cloneFamily(kv), 0, kv.getFamilyLength(), CellUtil.cloneQualifier(kv), 0,
            kv.getQualifierLength(), kv.getTimestamp(),
            KeyValue.Type.codeToType(kv.getTypeByte()), CellUtil.cloneValue(kv), 0,
            kv.getValueLength(), tagList);
        ((List<Cell>) updatedCells).add(newKV);
      }
    }
    put.getFamilyCellMap().remove(cf);
    // Update the family map
    put.getFamilyCellMap().put(cf, updatedCells);
  }
}
 
Example #29
Source File: ExpAsStringVisibilityLabelServiceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] encodeVisibilityForReplication(final List<Tag> tags, final Byte serializationFormat)
    throws IOException {
  if (tags.size() > 0 && (serializationFormat == null
      || serializationFormat == STRING_SERIALIZATION_FORMAT)) {
    return createModifiedVisExpression(tags);
  }
  return null;
}
 
Example #30
Source File: ExpAsStringVisibilityLabelServiceImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public boolean matchVisibility(List<Tag> putTags, Byte putTagsFormat, List<Tag> deleteTags,
    Byte deleteTagsFormat) throws IOException {
  assert putTagsFormat == STRING_SERIALIZATION_FORMAT;
  assert deleteTagsFormat == STRING_SERIALIZATION_FORMAT;
  return checkForMatchingVisibilityTagsWithSortedOrder(putTags, deleteTags);
}