Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9D09D200D0B for ; Mon, 28 Aug 2017 17:10:40 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9B86A164DA8; Mon, 28 Aug 2017 15:10:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 490D6164D95 for ; Mon, 28 Aug 2017 17:10:38 +0200 (CEST) Received: (qmail 20488 invoked by uid 500); 28 Aug 2017 15:10:37 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 20090 invoked by uid 99); 28 Aug 2017 15:10:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Aug 2017 15:10:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9F8ECF5F4F; Mon, 28 Aug 2017 15:10:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Mon, 28 Aug 2017 15:10:44 -0000 Message-Id: <9dcb670560264fe59c0117e81492ca29@git.apache.org> In-Reply-To: <275119e7f59d4d5ba72aedbd564a8a23@git.apache.org> References: <275119e7f59d4d5ba72aedbd564a8a23@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [10/51] [partial] hbase-site git commit: Published site at . archived-at: Mon, 28 Aug 2017 15:10:40 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/f751513b/devapidocs/src-html/org/apache/hadoop/hbase/CellUtil.ValueAndTagRewriteByteBufferCell.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/CellUtil.ValueAndTagRewriteByteBufferCell.html b/devapidocs/src-html/org/apache/hadoop/hbase/CellUtil.ValueAndTagRewriteByteBufferCell.html index 3e734a6..6b0729b 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/CellUtil.ValueAndTagRewriteByteBufferCell.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/CellUtil.ValueAndTagRewriteByteBufferCell.html @@ -324,2879 +324,2916 @@ 316 return buffer; 317 } 318 -319 public static Cell createCell(final byte [] row, final byte [] family, final byte [] qualifier, -320 final long timestamp, final byte type, final byte [] value) { -321 // I need a Cell Factory here. Using KeyValue for now. TODO. -322 // TODO: Make a new Cell implementation that just carries these -323 // byte arrays. -324 // TODO: Call factory to create Cell -325 return new KeyValue(row, family, qualifier, timestamp, KeyValue.Type.codeToType(type), value); -326 } -327 -328 public static Cell createCell(final byte [] rowArray, final int rowOffset, final int rowLength, -329 final byte [] familyArray, final int familyOffset, final int familyLength, -330 final byte [] qualifierArray, final int qualifierOffset, final int qualifierLength) { -331 // See createCell(final byte [] row, final byte [] value) for why we default Maximum type. -332 return new KeyValue(rowArray, rowOffset, rowLength, -333 familyArray, familyOffset, familyLength, -334 qualifierArray, qualifierOffset, qualifierLength, -335 HConstants.LATEST_TIMESTAMP, -336 KeyValue.Type.Maximum, -337 HConstants.EMPTY_BYTE_ARRAY, 0, HConstants.EMPTY_BYTE_ARRAY.length); -338 } -339 -340 /** -341 * Marked as audience Private as of 1.2.0. -342 * Creating a Cell with a memstoreTS/mvcc is an internal implementation detail not for -343 * public use. -344 */ -345 @InterfaceAudience.Private -346 public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, -347 final long timestamp, final byte type, final byte[] value, final long memstoreTS) { -348 KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp, -349 KeyValue.Type.codeToType(type), value); -350 keyValue.setSequenceId(memstoreTS); -351 return keyValue; -352 } -353 -354 /** -355 * Marked as audience Private as of 1.2.0. -356 * Creating a Cell with tags and a memstoreTS/mvcc is an internal implementation detail not for -357 * public use. -358 */ -359 @InterfaceAudience.Private -360 public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, -361 final long timestamp, final byte type, final byte[] value, byte[] tags, -362 final long memstoreTS) { -363 KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp, -364 KeyValue.Type.codeToType(type), value, tags); -365 keyValue.setSequenceId(memstoreTS); -366 return keyValue; -367 } -368 -369 /** -370 * Marked as audience Private as of 1.2.0. -371 * Creating a Cell with tags is an internal implementation detail not for -372 * public use. -373 */ -374 @InterfaceAudience.Private -375 public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, -376 final long timestamp, Type type, final byte[] value, byte[] tags) { -377 KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp, type, value, tags); -378 return keyValue; -379 } -380 -381 /** -382 * Create a Cell with specific row. Other fields defaulted. -383 * @param row -384 * @return Cell with passed row but all other fields are arbitrary -385 */ -386 public static Cell createCell(final byte [] row) { -387 return createCell(row, HConstants.EMPTY_BYTE_ARRAY); -388 } -389 -390 /** -391 * Create a Cell with specific row and value. Other fields are defaulted. -392 * @param row -393 * @param value -394 * @return Cell with passed row and value but all other fields are arbitrary -395 */ -396 public static Cell createCell(final byte [] row, final byte [] value) { -397 // An empty family + empty qualifier + Type.Minimum is used as flag to indicate last on row. -398 // See the CellComparator and KeyValue comparator. Search for compareWithoutRow. -399 // Lets not make a last-on-row key as default but at same time, if you are making a key -400 // without specifying type, etc., flag it as weird by setting type to be Maximum. -401 return createCell(row, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, -402 HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum.getCode(), value); -403 } -404 -405 /** -406 * Create a Cell with specific row. Other fields defaulted. -407 * @param row -408 * @param family -409 * @param qualifier -410 * @return Cell with passed row but all other fields are arbitrary -411 */ -412 public static Cell createCell(final byte [] row, final byte [] family, final byte [] qualifier) { -413 // See above in createCell(final byte [] row, final byte [] value) why we set type to Maximum. -414 return createCell(row, family, qualifier, -415 HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum.getCode(), HConstants.EMPTY_BYTE_ARRAY); -416 } -417 -418 /** -419 * @return A new cell which is having the extra tags also added to it. -420 */ -421 public static Cell createCell(Cell cell, List<Tag> tags) { -422 return createCell(cell, TagUtil.fromList(tags)); -423 } -424 -425 /** -426 * @return A new cell which is having the extra tags also added to it. -427 */ -428 public static Cell createCell(Cell cell, byte[] tags) { -429 if (cell instanceof ByteBufferCell) { -430 return new TagRewriteByteBufferCell((ByteBufferCell) cell, tags); -431 } -432 return new TagRewriteCell(cell, tags); -433 } -434 -435 public static Cell createCell(Cell cell, byte[] value, byte[] tags) { -436 if (cell instanceof ByteBufferCell) { -437 return new ValueAndTagRewriteByteBufferCell((ByteBufferCell) cell, value, tags); -438 } -439 return new ValueAndTagRewriteCell(cell, value, tags); -440 } -441 -442 /** -443 * This can be used when a Cell has to change with addition/removal of one or more tags. This is an -444 * efficient way to do so in which only the tags bytes part need to recreated and copied. All other -445 * parts, refer to the original Cell. -446 */ -447 @InterfaceAudience.Private -448 private static class TagRewriteCell implements ExtendedCell { -449 protected Cell cell; -450 protected byte[] tags; -451 private static final long HEAP_SIZE_OVERHEAD = ClassSize.OBJECT + 2 * ClassSize.REFERENCE; -452 -453 /** -454 * @param cell The original Cell which it rewrites -455 * @param tags the tags bytes. The array suppose to contain the tags bytes alone. -456 */ -457 public TagRewriteCell(Cell cell, byte[] tags) { -458 assert cell instanceof ExtendedCell; -459 assert tags != null; -460 this.cell = cell; -461 this.tags = tags; -462 // tag offset will be treated as 0 and length this.tags.length -463 if (this.cell instanceof TagRewriteCell) { -464 // Cleaning the ref so that the byte[] can be GCed -465 ((TagRewriteCell) this.cell).tags = null; -466 } -467 } -468 -469 @Override -470 public byte[] getRowArray() { -471 return cell.getRowArray(); -472 } -473 -474 @Override -475 public int getRowOffset() { -476 return cell.getRowOffset(); -477 } +319 /** +320 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. +321 * Use {@link CellBuilder} instead +322 */ +323 @Deprecated +324 public static Cell createCell(final byte [] row, final byte [] family, final byte [] qualifier, +325 final long timestamp, final byte type, final byte [] value) { +326 return CellBuilderFactory.create(CellBuilderType.DEEP_COPY) +327 .setRow(row) +328 .setFamily(family) +329 .setQualifier(qualifier) +330 .setTimestamp(timestamp) +331 .setType(type) +332 .setValue(value) +333 .build(); +334 } +335 +336 /** +337 * Creates a cell with deep copy of all passed bytes. +338 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. +339 * Use {@link CellBuilder} instead +340 */ +341 @Deprecated +342 public static Cell createCell(final byte [] rowArray, final int rowOffset, final int rowLength, +343 final byte [] familyArray, final int familyOffset, final int familyLength, +344 final byte [] qualifierArray, final int qualifierOffset, final int qualifierLength) { +345 // See createCell(final byte [] row, final byte [] value) for why we default Maximum type. +346 return CellBuilderFactory.create(CellBuilderType.DEEP_COPY) +347 .setRow(rowArray, rowOffset, rowLength) +348 .setFamily(familyArray, familyOffset, familyLength) +349 .setQualifier(qualifierArray, qualifierOffset, qualifierLength) +350 .setTimestamp(HConstants.LATEST_TIMESTAMP) +351 .setType(KeyValue.Type.Maximum.getCode()) +352 .setValue(HConstants.EMPTY_BYTE_ARRAY, 0, HConstants.EMPTY_BYTE_ARRAY.length) +353 .build(); +354 } +355 +356 /** +357 * Marked as audience Private as of 1.2.0. +358 * Creating a Cell with a memstoreTS/mvcc is an internal implementation detail not for +359 * public use. +360 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. +361 * Use {@link ExtendedCellBuilder} instead +362 */ +363 @InterfaceAudience.Private +364 @Deprecated +365 public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, +366 final long timestamp, final byte type, final byte[] value, final long memstoreTS) { +367 return createCell(row, family, qualifier, timestamp, type, value, null, memstoreTS); +368 } +369 +370 /** +371 * Marked as audience Private as of 1.2.0. +372 * Creating a Cell with tags and a memstoreTS/mvcc is an internal implementation detail not for +373 * public use. +374 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. +375 * Use {@link ExtendedCellBuilder} instead +376 */ +377 @InterfaceAudience.Private +378 @Deprecated +379 public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, +380 final long timestamp, final byte type, final byte[] value, byte[] tags, +381 final long memstoreTS) { +382 return ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY) +383 .setRow(row) +384 .setFamily(family) +385 .setQualifier(qualifier) +386 .setTimestamp(timestamp) +387 .setType(type) +388 .setValue(value) +389 .setTags(tags) +390 .setSequenceId(memstoreTS) +391 .build(); +392 } +393 +394 /** +395 * Marked as audience Private as of 1.2.0. +396 * Creating a Cell with tags is an internal implementation detail not for +397 * public use. +398 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. +399 * Use {@link ExtendedCellBuilder} instead +400 */ +401 @InterfaceAudience.Private +402 @Deprecated +403 public static Cell createCell(final byte[] row, final byte[] family, final byte[] qualifier, +404 final long timestamp, Type type, final byte[] value, byte[] tags) { +405 return createCell(row, family, qualifier, timestamp, type.getCode(), value, +406 tags, 0); +407 } +408 +409 /** +410 * Create a Cell with specific row. Other fields defaulted. +411 * @param row +412 * @return Cell with passed row but all other fields are arbitrary +413 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. +414 * Use {@link CellBuilder} instead +415 */ +416 @Deprecated +417 public static Cell createCell(final byte [] row) { +418 return createCell(row, HConstants.EMPTY_BYTE_ARRAY); +419 } +420 +421 /** +422 * Create a Cell with specific row and value. Other fields are defaulted. +423 * @param row +424 * @param value +425 * @return Cell with passed row and value but all other fields are arbitrary +426 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. +427 * Use {@link CellBuilder} instead +428 */ +429 @Deprecated +430 public static Cell createCell(final byte [] row, final byte [] value) { +431 // An empty family + empty qualifier + Type.Minimum is used as flag to indicate last on row. +432 // See the CellComparator and KeyValue comparator. Search for compareWithoutRow. +433 // Lets not make a last-on-row key as default but at same time, if you are making a key +434 // without specifying type, etc., flag it as weird by setting type to be Maximum. +435 return createCell(row, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, +436 HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum.getCode(), value); +437 } +438 +439 /** +440 * Create a Cell with specific row. Other fields defaulted. +441 * @param row +442 * @param family +443 * @param qualifier +444 * @return Cell with passed row but all other fields are arbitrary +445 * @deprecated As of release 2.0.0, this will be removed in HBase 3.0.0. +446 * Use {@link CellBuilder} instead +447 */ +448 @Deprecated +449 public static Cell createCell(final byte [] row, final byte [] family, final byte [] qualifier) { +450 // See above in createCell(final byte [] row, final byte [] value) why we set type to Maximum. +451 return createCell(row, family, qualifier, +452 HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum.getCode(), HConstants.EMPTY_BYTE_ARRAY); +453 } +454 +455 /** +456 * @return A new cell which is having the extra tags also added to it. +457 */ +458 public static Cell createCell(Cell cell, List<Tag> tags) { +459 return createCell(cell, TagUtil.fromList(tags)); +460 } +461 +462 /** +463 * @return A new cell which is having the extra tags also added to it. +464 */ +465 public static Cell createCell(Cell cell, byte[] tags) { +466 if (cell instanceof ByteBufferCell) { +467 return new TagRewriteByteBufferCell((ByteBufferCell) cell, tags); +468 } +469 return new TagRewriteCell(cell, tags); +470 } +471 +472 public static Cell createCell(Cell cell, byte[] value, byte[] tags) { +473 if (cell instanceof ByteBufferCell) { +474 return new ValueAndTagRewriteByteBufferCell((ByteBufferCell) cell, value, tags); +475 } +476 return new ValueAndTagRewriteCell(cell, value, tags); +477 } 478 -479 @Override -480 public short getRowLength() { -481 return cell.getRowLength(); -482 } -483 -484 @Override -485 public byte[] getFamilyArray() { -486 return cell.getFamilyArray(); -487 } -488 -489 @Override -490 public int getFamilyOffset() { -491 return cell.getFamilyOffset(); -492 } -493 -494 @Override -495 public byte getFamilyLength() { -496 return cell.getFamilyLength(); -497 } -498 -499 @Override -500 public byte[] getQualifierArray() { -501 return cell.getQualifierArray(); -502 } -503 -504 @Override -505 public int getQualifierOffset() { -506 return cell.getQualifierOffset(); -507 } -508 -509 @Override -510 public int getQualifierLength() { -511 return cell.getQualifierLength(); -512 } -513 -514 @Override -515 public long getTimestamp() { -516 return cell.getTimestamp(); -517 } -518 -519 @Override -520 public byte getTypeByte() { -521 return cell.getTypeByte(); -522 } -523 -524 @Override -525 public long getSequenceId() { -526 return cell.getSequenceId(); -527 } -528 -529 @Override -530 public byte[] getValueArray() { -531 return cell.getValueArray(); -532 } -533 -534 @Override -535 public int getValueOffset() { -536 return cell.getValueOffset(); -537 } -538 -539 @Override -540 public int getValueLength() { -541 return cell.getValueLength(); -542 } -543 -544 @Override -545 public byte[] getTagsArray() { -546 return this.tags; -547 } -548 -549 @Override -550 public int getTagsOffset() { -551 return 0; -552 } -553 -554 @Override -555 public int getTagsLength() { -556 if (null == this.tags) { -557 // Nulled out tags array optimization in constructor -558 return 0; -559 } -560 return this.tags.length; -561 } -562 -563 @Override -564 public long heapSize() { -565 long sum = HEAP_SIZE_OVERHEAD + CellUtil.estimatedHeapSizeOf(cell); -566 if (this.tags != null) { -567 sum += ClassSize.sizeOf(this.tags); -568 } -569 return sum; -570 } -571 -572 @Override -573 public void setTimestamp(long ts) throws IOException { -574 // The incoming cell is supposed to be SettableTimestamp type. -575 CellUtil.setTimestamp(cell, ts); -576 } -577 -578 @Override -579 public void setTimestamp(byte[] ts, int tsOffset) throws IOException { -580 // The incoming cell is supposed to be SettableTimestamp type. -581 CellUtil.setTimestamp(cell, ts, tsOffset); -582 } -583 -584 @Override -585 public void setSequenceId(long seqId) throws IOException { -586 // The incoming cell is supposed to be SettableSequenceId type. -587 CellUtil.setSequenceId(cell, seqId); -588 } -589 -590 @Override -591 public int write(OutputStream out, boolean withTags) throws IOException { -592 int len = ((ExtendedCell) this.cell).write(out, false); -593 if (withTags && this.tags != null) { -594 // Write the tagsLength 2 bytes -595 out.write((byte) (0xff & (this.tags.length >> 8))); -596 out.write((byte) (0xff & this.tags.length)); -597 out.write(this.tags); -598 len += KeyValue.TAGS_LENGTH_SIZE + this.tags.length; -599 } -600 return len; -601 } -602 -603 @Override -604 public int getSerializedSize(boolean withTags) { -605 int len = ((ExtendedCell) this.cell).getSerializedSize(false); -606 if (withTags && this.tags != null) { -607 len += KeyValue.TAGS_LENGTH_SIZE + this.tags.length; -608 } -609 return len; -610 } -611 -612 @Override -613 public void write(ByteBuffer buf, int offset) { -614 offset = KeyValueUtil.appendTo(this.cell, buf, offset, false); -615 int tagsLen = this.tags == null ? 0 : this.tags.length; -616 if (tagsLen > 0) { -617 offset = ByteBufferUtils.putAsShort(buf, offset, tagsLen); -618 ByteBufferUtils.copyFromArrayToBuffer(buf, offset, this.tags, 0, tagsLen); -619 } -620 } -621 -622 @Override -623 public Cell deepClone() { -624 Cell clonedBaseCell = ((ExtendedCell) this.cell).deepClone(); -625 return new TagRewriteCell(clonedBaseCell, this.tags); -626 } -627 } -628 -629 @InterfaceAudience.Private -630 private static class TagRewriteByteBufferCell extends ByteBufferCell implements ExtendedCell { -631 -632 protected ByteBufferCell cell; -633 protected byte[] tags; -634 private static final long HEAP_SIZE_OVERHEAD = ClassSize.OBJECT + 2 * ClassSize.REFERENCE; -635 -636 /** -637 * @param cell The original ByteBufferCell which it rewrites -638 * @param tags the tags bytes. The array suppose to contain the tags bytes alone. -639 */ -640 public TagRewriteByteBufferCell(ByteBufferCell cell, byte[] tags) { -641 assert cell instanceof ExtendedCell; -642 assert tags != null; -643 this.cell = cell; -644 this.tags = tags; -645 // tag offset will be treated as 0 and length this.tags.length -646 if (this.cell instanceof TagRewriteByteBufferCell) { -647 // Cleaning the ref so that the byte[] can be GCed -648 ((TagRewriteByteBufferCell) this.cell).tags = null; -649 } -650 } -651 -652 @Override -653 public byte[] getRowArray() { -654 return this.cell.getRowArray(); -655 } -656 -657 @Override -658 public int getRowOffset() { -659 return this.cell.getRowOffset(); -660 } -661 -662 @Override -663 public short getRowLength() { -664 return this.cell.getRowLength(); -665 } -666 -667 @Override -668 public byte[] getFamilyArray() { -669 return this.cell.getFamilyArray(); -670 } -671 -672 @Override -673 public int getFamilyOffset() { -674 return this.cell.getFamilyOffset(); -675 } -676 -677 @Override -678 public byte getFamilyLength() { -679 return this.cell.getFamilyLength(); -680 } -681 -682 @Override -683 public byte[] getQualifierArray() { -684 return this.cell.getQualifierArray(); -685 } -686 -687 @Override -688 public int getQualifierOffset() { -689 return this.cell.getQualifierOffset(); -690 } -691 -692 @Override -693 public int getQualifierLength() { -694 return this.cell.getQualifierLength(); -695 } -696 -697 @Override -698 public long getTimestamp() { -699 return this.cell.getTimestamp(); -700 } -701 -702 @Override -703 public byte getTypeByte() { -704 return this.cell.getTypeByte(); -705 } -706 -707 @Override -708 public long getSequenceId() { -709 return this.cell.getSequenceId(); -710 } -711 -712 @Override -713 public byte[] getValueArray() { -714 return this.cell.getValueArray(); -715 } -716 -717 @Override -718 public int getValueOffset() { -719 return this.cell.getValueOffset(); -720 } -721 -722 @Override -723 public int getValueLength() { -724 return this.cell.getValueLength(); -725 } -726 -727 @Override -728 public byte[] getTagsArray() { -729 return this.tags; -730 } -731 -732 @Override -733 public int getTagsOffset() { -734 return 0; -735 } -736 -737 @Override -738 public int getTagsLength() { -739 if (null == this.tags) { -740 // Nulled out tags array optimization in constructor -741 return 0; -742 } -743 return this.tags.length; -744 } -745 -746 @Override -747 public void setSequenceId(long seqId) throws IOException { -748 CellUtil.setSequenceId(this.cell, seqId); -749 } -750 -751 @Override -752 public void setTimestamp(long ts) throws IOException { -753 CellUtil.setTimestamp(this.cell, ts); -754 } -755 -756 @Override -757 public void setTimestamp(byte[] ts, int tsOffset) throws IOException { -758 CellUtil.setTimestamp(this.cell, ts, tsOffset); -759 } -760 -761 @Override -762 public long heapSize() { -763 long sum = HEAP_SIZE_OVERHEAD + CellUtil.estimatedHeapSizeOf(cell); -764 // this.tags is on heap byte[] -765 if (this.tags != null) { -766 sum += ClassSize.sizeOf(this.tags); -767 } -768 return sum; -769 } -770 -771 @Override -772 public int write(OutputStream out, boolean withTags) throws IOException { -773 int len = ((ExtendedCell) this.cell).write(out, false); -774 if (withTags && this.tags != null) { -775 // Write the tagsLength 2 bytes -776 out.write((byte) (0xff & (this.tags.length >> 8))); -777 out.write((byte) (0xff & this.tags.length)); -778 out.write(this.tags); -779 len += KeyValue.TAGS_LENGTH_SIZE + this.tags.length; -780 } -781 return len; -782 } -783 -784 @Override -785 public int getSerializedSize(boolean withTags) { -786 int len = ((ExtendedCell) this.cell).getSerializedSize(false); -787 if (withTags && this.tags != null) { -788 len += KeyValue.TAGS_LENGTH_SIZE + this.tags.length; -789 } -790 return len; +479 /** +480 * This can be used when a Cell has to change with addition/removal of one or more tags. This is an +481 * efficient way to do so in which only the tags bytes part need to recreated and copied. All other +482 * parts, refer to the original Cell. +483 */ +484 @InterfaceAudience.Private +485 private static class TagRewriteCell implements ExtendedCell { +486 protected Cell cell; +487 protected byte[] tags; +488 private static final long HEAP_SIZE_OVERHEAD = ClassSize.OBJECT + 2 * ClassSize.REFERENCE; +489 +490 /** +491 * @param cell The original Cell which it rewrites +492 * @param tags the tags bytes. The array suppose to contain the tags bytes alone. +493 */ +494 public TagRewriteCell(Cell cell, byte[] tags) { +495 assert cell instanceof ExtendedCell; +496 assert tags != null; +497 this.cell = cell; +498 this.tags = tags; +499 // tag offset will be treated as 0 and length this.tags.length +500 if (this.cell instanceof TagRewriteCell) { +501 // Cleaning the ref so that the byte[] can be GCed +502 ((TagRewriteCell) this.cell).tags = null; +503 } +504 } +505 +506 @Override +507 public byte[] getRowArray() { +508 return cell.getRowArray(); +509 } +510 +511 @Override +512 public int getRowOffset() { +513 return cell.getRowOffset(); +514 } +515 +516 @Override +517 public short getRowLength() { +518 return cell.getRowLength(); +519 } +520 +521 @Override +522 public byte[] getFamilyArray() { +523 return cell.getFamilyArray(); +524 } +525 +526 @Override +527 public int getFamilyOffset() { +528 return cell.getFamilyOffset(); +529 } +530 +531 @Override +532 public byte getFamilyLength() { +533 return cell.getFamilyLength(); +534 } +535 +536 @Override +537 public byte[] getQualifierArray() { +538 return cell.getQualifierArray(); +539 } +540 +541 @Override +542 public int getQualifierOffset() { +543 return cell.getQualifierOffset(); +544 } +545 +546 @Override +547 public int getQualifierLength() { +548 return cell.getQualifierLength(); +549 } +550 +551 @Override +552 public long getTimestamp() { +553 return cell.getTimestamp(); +554 } +555 +556 @Override +557 public byte getTypeByte() { +558 return cell.getTypeByte(); +559 } +560 +561 @Override +562 public long getSequenceId() { +563 return cell.getSequenceId(); +564 } +565 +566 @Override +567 public byte[] getValueArray() { +568 return cell.getValueArray(); +569 } +570 +571 @Override +572 public int getValueOffset() { +573 return cell.getValueOffset(); +574 } +575 +576 @Override +577 public int getValueLength() { +578 return cell.getValueLength(); +579 } +580 +581 @Override +582 public byte[] getTagsArray() { +583 return this.tags; +584 } +585 +586 @Override +587 public int getTagsOffset() { +588 return 0; +589 } +590 +591 @Override +592 public int getTagsLength() { +593 if (null == this.tags) { +594 // Nulled out tags array optimization in constructor +595 return 0; +596 } +597 return this.tags.length; +598 } +599 +600 @Override +601 public long heapSize() { +602 long sum = HEAP_SIZE_OVERHEAD + CellUtil.estimatedHeapSizeOf(cell); +603 if (this.tags != null) { +604 sum += ClassSize.sizeOf(this.tags); +605 } +606 return sum; +607 } +608 +609 @Override +610 public void setTimestamp(long ts) throws IOException { +611 // The incoming cell is supposed to be SettableTimestamp type. +612 CellUtil.setTimestamp(cell, ts); +613 } +614 +615 @Override +616 public void setTimestamp(byte[] ts, int tsOffset) throws IOException { +617 // The incoming cell is supposed to be SettableTimestamp type. +618 CellUtil.setTimestamp(cell, ts, tsOffset); +619 } +620 +621 @Override +622 public void setSequenceId(long seqId) throws IOException { +623 // The incoming cell is supposed to be SettableSequenceId type. +624 CellUtil.setSequenceId(cell, seqId); +625 } +626 +627 @Override +628 public int write(OutputStream out, boolean withTags) throws IOException { +629 int len = ((ExtendedCell) this.cell).write(out, false); +630 if (withTags && this.tags != null) { +631 // Write the tagsLength 2 bytes +632 out.write((byte) (0xff & (this.tags.length >> 8))); +633 out.write((byte) (0xff & this.tags.length)); +634 out.write(this.tags); +635 len += KeyValue.TAGS_LENGTH_SIZE + this.tags.length; +636 } +637 return len; +638 } +639 +640 @Override +641 public int getSerializedSize(boolean withTags) { +642 int len = ((ExtendedCell) this.cell).getSerializedSize(false); +643 if (withTags && this.tags != null) { +644 len += KeyValue.TAGS_LENGTH_SIZE + this.tags.length; +645 } +646 return len; +647 } +648 +649 @Override +650 public void write(ByteBuffer buf, int offset) { +651 offset = KeyValueUtil.appendTo(this.cell, buf, offset, false); +652 int tagsLen = this.tags == null ? 0 : this.tags.length; +653 if (tagsLen > 0) { +654 offset = ByteBufferUtils.putAsShort(buf, offset, tagsLen); +655 ByteBufferUtils.copyFromArrayToBuffer(buf, offset, this.tags, 0, tagsLen); +656 } +657 } +658 +659 @Override +660 public Cell deepClone() { +661 Cell clonedBaseCell = ((ExtendedCell) this.cell).deepClone(); +662 return new TagRewriteCell(clonedBaseCell, this.tags); +663 } +664 } +665 +666 @InterfaceAudience.Private +667 private static class TagRewriteByteBufferCell extends ByteBufferCell implements ExtendedCell { +668 +669 protected ByteBufferCell cell; +670 protected byte[] tags; +671 private static final long HEAP_SIZE_OVERHEAD = ClassSize.OBJECT + 2 * ClassSize.REFERENCE; +672 +673 /** +674 * @param cell The original ByteBufferCell which it rewrites +675 * @param tags the tags bytes. The array suppose to contain the tags bytes alone. +676 */ +677 public TagRewriteByteBufferCell(ByteBufferCell cell, byte[] tags) { +678 assert cell instanceof ExtendedCell; +679 assert tags != null; +680 this.cell = cell; +681 this.tags = tags; +682 // tag offset will be treated as 0 and length this.tags.length +683 if (this.cell instanceof TagRewriteByteBufferCell) { +684 // Cleaning the ref so that the byte[] can be GCed +685 ((TagRewriteByteBufferCell) this.cell).tags = null; +686 } +687 } +688 +689 @Override +690 public byte[] getRowArray() { +691 return this.cell.getRowArray(); +692 } +693 +694 @Override +695 public int getRowOffset() { +696 return this.cell.getRowOffset(); +697 } +698 +699 @Override +700 public short getRowLength() { +701 return this.cell.getRowLength(); +702 } +703 +704 @Override +705 public byte[] getFamilyArray() { +706 return this.cell.getFamilyArray(); +707 } +708 +709 @Override +710 public int getFamilyOffset() { +711 return this.cell.getFamilyOffset(); +712 } +713 +714 @Override +715 public byte getFamilyLength() { +716 return this.cell.getFamilyLength(); +717 } +718 +719 @Override +720 public byte[] getQualifierArray() { +721 return this.cell.getQualifierArray(); +722 } +723 +724 @Override +725 public int getQualifierOffset() { +726 return this.cell.getQualifierOffset(); +727 } +728 +729 @Override +730 public int getQualifierLength() { +731 return this.cell.getQualifierLength(); +732 } +733 +734 @Override +735 public long getTimestamp() { +736 return this.cell.getTimestamp(); +737 } +738 +739 @Override +740 public byte getTypeByte() { +741 return this.cell.getTypeByte(); +742 } +743 +744 @Override +745 public long getSequenceId() { +746 return this.cell.getSequenceId(); +747 } +748 +749 @Override +750 public byte[] getValueArray() { +751 return this.cell.getValueArray(); +752 } +753 +754 @Override +755 public int getValueOffset() { +756 return this.cell.getValueOffset(); +757 } +758 +759 @Override +760 public int getValueLength() { +761 return this.cell.getValueLength(); +762 } +763 +764 @Override +765 public byte[] getTagsArray() { +766 return this.tags; +767 } +768 +769 @Override +770 public int getTagsOffset() { +771 return 0; +772 } +773 +774 @Override +775 public int getTagsLength() { +776 if (null == this.tags) { +777 // Nulled out tags array optimization in constructor +778 return 0; +779 } +780 return this.tags.length; +781 } +782 +783 @Override +784 public void setSequenceId(long seqId) throws IOException { +785 CellUtil.setSequenceId(this.cell, seqId); +786 } +787 +788 @Override +789 public void setTimestamp(long ts) throws IOException { +790 CellUtil.setTimestamp(this.cell, ts); 791 } 792 793 @Override -794 public void write(ByteBuffer buf, int offset) { -795 offset = KeyValueUtil.appendTo(this.cell, buf, offset, false); -796 int tagsLen = this.tags == null ? 0 : this.tags.length; -797 if (tagsLen > 0) { -798 offset = ByteBufferUtils.putAsShort(buf, offset, tagsLen); -799 ByteBufferUtils.copyFromArrayToBuffer(buf, offset, this.tags, 0, tagsLen); -800 } -801 } -802 -803 @Override -804 public Cell deepClone() { -805 Cell clonedBaseCell = ((ExtendedCell) this.cell).deepClone(); -806 if (clonedBaseCell instanceof ByteBufferCell) { -807 return new TagRewriteByteBufferCell((ByteBufferCell) clonedBaseCell, this.tags); -808 } -809 return new TagRewriteCell(clonedBaseCell, this.tags); -810 } -811 -812 @Override -813 public ByteBuffer getRowByteBuffer() { -814 ret