HBASE-11424 Avoid usage of CellUtil#getTagArray(Cell cell) within server. (Anoop)

This commit is contained in:
anoopsjohn 2014-06-27 22:35:08 +05:30
parent cac468f33f
commit 7c1135b3e3
5 changed files with 23 additions and 9 deletions

View File

@ -1108,7 +1108,8 @@ public final class ProtobufUtil {
kv.getValueArray(), kv.getValueOffset(), kv.getValueLength())); kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()));
valueBuilder.setTimestamp(kv.getTimestamp()); valueBuilder.setTimestamp(kv.getTimestamp());
if(cell.getTagsLength() > 0) { if(cell.getTagsLength() > 0) {
valueBuilder.setTags(ByteString.copyFrom(CellUtil.getTagArray(kv))); valueBuilder.setTags(HBaseZeroCopyByteString.wrap(kv.getTagsArray(), kv.getTagsOffset(),
kv.getTagsLength()));
} }
if (type == MutationType.DELETE) { if (type == MutationType.DELETE) {
KeyValue.Type keyValueType = KeyValue.Type.codeToType(kv.getType()); KeyValue.Type keyValueType = KeyValue.Type.codeToType(kv.getType());

View File

@ -83,6 +83,13 @@ public final class CellUtil {
return output; return output;
} }
/**
* Returns tag value in a new byte array. If server-side, use
* {@link Tag#getBuffer()} with appropriate {@link Tag#getTagOffset()} and
* {@link Tag#getTagLength()} instead to save on allocations.
* @param cell
* @return tag value in a new byte array.
*/
public static byte[] getTagArray(Cell cell){ public static byte[] getTagArray(Cell cell){
byte[] output = new byte[cell.getTagsLength()]; byte[] output = new byte[cell.getTagsLength()];
copyTagTo(cell, output, 0); copyTagTo(cell, output, 0);

View File

@ -130,6 +130,13 @@ public class Tag {
return this.offset + INFRASTRUCTURE_SIZE; return this.offset + INFRASTRUCTURE_SIZE;
} }
/**
* Returns tag value in a new byte array.
* Primarily for use client-side. If server-side, use
* {@link #getBuffer()} with appropriate {@link #getTagOffset()} and {@link #getTagLength()}
* instead to save on allocations.
* @return tag value in a new byte array.
*/
public byte[] getValue() { public byte[] getValue() {
int tagLength = getTagLength(); int tagLength = getTagLength();
byte[] tag = new byte[tagLength]; byte[] tag = new byte[tagLength];

View File

@ -685,8 +685,8 @@ public class AccessControlLists {
public static List<Permission> getCellPermissionsForUser(User user, Cell cell) public static List<Permission> getCellPermissionsForUser(User user, Cell cell)
throws IOException { throws IOException {
List<Permission> results = Lists.newArrayList(); List<Permission> results = Lists.newArrayList();
byte[] tags = CellUtil.getTagArray(cell); Iterator<Tag> tagsIterator = CellUtil.tagsIterator(cell.getTagsArray(), cell.getTagsOffset(),
Iterator<Tag> tagsIterator = CellUtil.tagsIterator(tags, 0, tags.length); cell.getTagsLength());
while (tagsIterator.hasNext()) { while (tagsIterator.hasNext()) {
Tag tag = tagsIterator.next(); Tag tag = tagsIterator.next();
if (tag.getType() == ACL_TAG_TYPE) { if (tag.getType() == ACL_TAG_TYPE) {

View File

@ -88,7 +88,6 @@ import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
import org.apache.hadoop.hbase.regionserver.RegionScanner; import org.apache.hadoop.hbase.regionserver.RegionScanner;
import org.apache.hadoop.hbase.regionserver.ScanType; import org.apache.hadoop.hbase.regionserver.ScanType;
import org.apache.hadoop.hbase.regionserver.Store; import org.apache.hadoop.hbase.regionserver.Store;
import org.apache.hadoop.hbase.regionserver.StoreFile;
import org.apache.hadoop.hbase.regionserver.wal.WALEdit; import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
import org.apache.hadoop.hbase.security.AccessDeniedException; import org.apache.hadoop.hbase.security.AccessDeniedException;
import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.security.User;
@ -753,8 +752,8 @@ public class AccessController extends BaseRegionObserver
List<Cell> newCells = Lists.newArrayList(); List<Cell> newCells = Lists.newArrayList();
for (Cell cell: e.getValue()) { for (Cell cell: e.getValue()) {
List<Tag> tags = Lists.newArrayList(new Tag(AccessControlLists.ACL_TAG_TYPE, perms)); List<Tag> tags = Lists.newArrayList(new Tag(AccessControlLists.ACL_TAG_TYPE, perms));
byte[] tagBytes = CellUtil.getTagArray(cell); Iterator<Tag> tagIterator = CellUtil.tagsIterator(cell.getTagsArray(),
Iterator<Tag> tagIterator = CellUtil.tagsIterator(tagBytes, 0, tagBytes.length); cell.getTagsOffset(), cell.getTagsLength());
while (tagIterator.hasNext()) { while (tagIterator.hasNext()) {
tags.add(tagIterator.next()); tags.add(tagIterator.next());
} }
@ -1808,14 +1807,14 @@ public class AccessController extends BaseRegionObserver
List<Tag> tags = Lists.newArrayList(); List<Tag> tags = Lists.newArrayList();
ListMultimap<String,Permission> perms = ArrayListMultimap.create(); ListMultimap<String,Permission> perms = ArrayListMultimap.create();
if (oldCell != null) { if (oldCell != null) {
byte[] tagBytes = CellUtil.getTagArray(oldCell); Iterator<Tag> tagIterator = CellUtil.tagsIterator(oldCell.getTagsArray(),
Iterator<Tag> tagIterator = CellUtil.tagsIterator(tagBytes, 0, tagBytes.length); oldCell.getTagsOffset(), oldCell.getTagsLength());
while (tagIterator.hasNext()) { while (tagIterator.hasNext()) {
Tag tag = tagIterator.next(); Tag tag = tagIterator.next();
if (tag.getType() != AccessControlLists.ACL_TAG_TYPE) { if (tag.getType() != AccessControlLists.ACL_TAG_TYPE) {
if (LOG.isTraceEnabled()) { if (LOG.isTraceEnabled()) {
LOG.trace("Carrying forward tag from " + oldCell + ": type " + tag.getType() + LOG.trace("Carrying forward tag from " + oldCell + ": type " + tag.getType() +
" length " + tag.getValue().length); " length " + tag.getTagLength());
} }
tags.add(tag); tags.add(tag);
} else { } else {