ramkrish86 commented on a change in pull request #2582:
URL: https://github.com/apache/hbase/pull/2582#discussion_r529255627



##########
File path: 
hbase-common/src/main/java/org/apache/hadoop/hbase/SizeCachedByteBufferKeyValue.java
##########
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import java.nio.ByteBuffer;
+
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * This Cell is an implementation of {@link ByteBufferExtendedCell} where the 
data resides in
+ * off heap/ on heap ByteBuffer
+ */
+@InterfaceAudience.Private
+public class SizeCachedByteBufferKeyValue extends ByteBufferKeyValue {
+
+  public static final int FIXED_OVERHEAD = Bytes.SIZEOF_SHORT + 
Bytes.SIZEOF_INT;
+  private short rowLen;
+  private int keyLen;
+
+  public SizeCachedByteBufferKeyValue(ByteBuffer buf, int offset, int length, 
long seqId,
+      int keyLen) {
+    super(buf, offset, length);
+    // We will read all these cached values at least once. Initialize now 
itself so that we can
+    // avoid uninitialized checks with every time call
+    this.rowLen = super.getRowLength();
+    this.keyLen = keyLen;
+    setSequenceId(seqId);
+  }
+
+  public SizeCachedByteBufferKeyValue(ByteBuffer buf, int offset, int length, 
long seqId,
+      int keyLen, short rowLen) {
+    super(buf, offset, length);
+    // We will read all these cached values at least once. Initialize now 
itself so that we can
+    // avoid uninitialized checks with every time call
+    this.rowLen = rowLen;
+    this.keyLen = keyLen;
+    setSequenceId(seqId);
+  }
+
+  @Override
+  public short getRowLength() {
+    return rowLen;
+  }
+
+  @Override
+  public int getKeyLength() {
+    return this.keyLen;
+  }
+
+  @Override
+  public long heapSize() {
+    return super.heapSize() + FIXED_OVERHEAD;
+  }
+
+  /**
+   * Override by just returning the length for saving cost of method 
dispatching. If not, it will
+   * call {@link ExtendedCell#getSerializedSize()} firstly, then forward to
+   * {@link SizeCachedKeyValue#getSerializedSize(boolean)}. (See HBASE-21657)
+   */
+  @Override
+  public int getSerializedSize() {
+    return this.length;
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    return super.equals(other);

Review comment:
       Actually not needed it is basically for the spot bugs report we had to 
add that. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to