blob: 0c0015746c2aa51dd86f5107161ee9d8a5b4ccfc [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (17) -->
<title>Source code</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="source: package: org.apache.hadoop.hbase, class: ByteBufferExtendedCell">
<meta name="generator" content="javadoc/SourceToHTMLConverter">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
</head>
<body class="source-page">
<main role="main">
<div class="source-container">
<pre><span class="source-line-no">001</span><span id="line-1">/*</span>
<span class="source-line-no">002</span><span id="line-2"> * Licensed to the Apache Software Foundation (ASF) under one</span>
<span class="source-line-no">003</span><span id="line-3"> * or more contributor license agreements. See the NOTICE file</span>
<span class="source-line-no">004</span><span id="line-4"> * distributed with this work for additional information</span>
<span class="source-line-no">005</span><span id="line-5"> * regarding copyright ownership. The ASF licenses this file</span>
<span class="source-line-no">006</span><span id="line-6"> * to you under the Apache License, Version 2.0 (the</span>
<span class="source-line-no">007</span><span id="line-7"> * "License"); you may not use this file except in compliance</span>
<span class="source-line-no">008</span><span id="line-8"> * with the License. You may obtain a copy of the License at</span>
<span class="source-line-no">009</span><span id="line-9"> *</span>
<span class="source-line-no">010</span><span id="line-10"> * http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="source-line-no">011</span><span id="line-11"> *</span>
<span class="source-line-no">012</span><span id="line-12"> * Unless required by applicable law or agreed to in writing, software</span>
<span class="source-line-no">013</span><span id="line-13"> * distributed under the License is distributed on an "AS IS" BASIS,</span>
<span class="source-line-no">014</span><span id="line-14"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="source-line-no">015</span><span id="line-15"> * See the License for the specific language governing permissions and</span>
<span class="source-line-no">016</span><span id="line-16"> * limitations under the License.</span>
<span class="source-line-no">017</span><span id="line-17"> */</span>
<span class="source-line-no">018</span><span id="line-18">package org.apache.hadoop.hbase;</span>
<span class="source-line-no">019</span><span id="line-19"></span>
<span class="source-line-no">020</span><span id="line-20">import java.nio.ByteBuffer;</span>
<span class="source-line-no">021</span><span id="line-21">import org.apache.yetus.audience.InterfaceAudience;</span>
<span class="source-line-no">022</span><span id="line-22"></span>
<span class="source-line-no">023</span><span id="line-23">/**</span>
<span class="source-line-no">024</span><span id="line-24"> * This class is a server side extension to the {@link Cell} interface. It is used when the Cell is</span>
<span class="source-line-no">025</span><span id="line-25"> * backed by a {@link ByteBuffer}: i.e. &lt;code&gt;cell instanceof ByteBufferedCell&lt;/code&gt;.</span>
<span class="source-line-no">026</span><span id="line-26"> * &lt;p&gt;</span>
<span class="source-line-no">027</span><span id="line-27"> * This class has getters for the row, column family, column qualifier, value and tags hosting</span>
<span class="source-line-no">028</span><span id="line-28"> * ByteBuffers. It also has getters of the *position* within a ByteBuffer where these field bytes</span>
<span class="source-line-no">029</span><span id="line-29"> * begin. These are needed because a single ByteBuffer may back one or many Cell instances -- it</span>
<span class="source-line-no">030</span><span id="line-30"> * depends on the implementation -- so the ByteBuffer position as returned by</span>
<span class="source-line-no">031</span><span id="line-31"> * {@link ByteBuffer#arrayOffset()} cannot be relied upon. Also, do not confuse these position</span>
<span class="source-line-no">032</span><span id="line-32"> * methods with the getXXXOffset methods from the super Interface, {@link Cell}; dependent up on</span>
<span class="source-line-no">033</span><span id="line-33"> * implementation, the Cell getXXXOffset methods can return the same value as a call to its</span>
<span class="source-line-no">034</span><span id="line-34"> * equivalent position method from below BUT they can also stray; if a ByteBufferedCell, use the</span>
<span class="source-line-no">035</span><span id="line-35"> * below position methods to find where a field begins.</span>
<span class="source-line-no">036</span><span id="line-36"> * &lt;p&gt;</span>
<span class="source-line-no">037</span><span id="line-37"> * Use the getXXXLength methods from Cell to find a fields length.</span>
<span class="source-line-no">038</span><span id="line-38"> * &lt;p&gt;</span>
<span class="source-line-no">039</span><span id="line-39"> * A Cell object can be of this type only on the server side.</span>
<span class="source-line-no">040</span><span id="line-40"> * &lt;p&gt;</span>
<span class="source-line-no">041</span><span id="line-41"> * WARNING: If a Cell is backed by an offheap ByteBuffer, any call to getXXXArray() will result in a</span>
<span class="source-line-no">042</span><span id="line-42"> * temporary byte array creation and a bytes copy. Avoid these allocations by using the appropriate</span>
<span class="source-line-no">043</span><span id="line-43"> * Cell access server-side: i.e. ByteBufferedCell when backed by a ByteBuffer and Cell when it is</span>
<span class="source-line-no">044</span><span id="line-44"> * not.</span>
<span class="source-line-no">045</span><span id="line-45"> */</span>
<span class="source-line-no">046</span><span id="line-46">/*</span>
<span class="source-line-no">047</span><span id="line-47"> * Even though all the methods are abstract, ByteBufferExtendedCell is not made to be an interface</span>
<span class="source-line-no">048</span><span id="line-48"> * with intent. In CellComparator compare method, we have instance of check to decide whether to use</span>
<span class="source-line-no">049</span><span id="line-49"> * getXXXArray() or getXXXByteBuffer(). This is a very hot method in read and write paths. if (left</span>
<span class="source-line-no">050</span><span id="line-50"> * instanceof ByteBufferExtendedCell &amp;&amp; right instanceof ByteBufferExtendedCell) { .... } if (left</span>
<span class="source-line-no">051</span><span id="line-51"> * instanceof ByteBufferExtendedCell) { .... } if (right instanceof ByteBufferExtendedCell) { .... }</span>
<span class="source-line-no">052</span><span id="line-52"> * return Bytes.compareTo(left.getRowArray(), left.getRowOffset(), left.getRowLength(),</span>
<span class="source-line-no">053</span><span id="line-53"> * right.getRowArray(), right.getRowOffset(), right.getRowLength()); We did JMH micro benchmark</span>
<span class="source-line-no">054</span><span id="line-54"> * tests with both left and right cells as ByteBufferExtendedCell, one only ByteBufferExtendedCell</span>
<span class="source-line-no">055</span><span id="line-55"> * and both as Cells. This is compared against JMH results on compare logic with out any instance of</span>
<span class="source-line-no">056</span><span id="line-56"> * checks. We noticed that if ByteBufferExtendedCell is an interface, the benchmark result seems to</span>
<span class="source-line-no">057</span><span id="line-57"> * be very bad for case of both right and left are Cell only (Not ByteBufferExtendedCell). When</span>
<span class="source-line-no">058</span><span id="line-58"> * ByteBufferExtendedCell is an abstract class all 4 possible cases giving almost similar</span>
<span class="source-line-no">059</span><span id="line-59"> * performance number compared with compare logic with no instance of checks.</span>
<span class="source-line-no">060</span><span id="line-60"> */</span>
<span class="source-line-no">061</span><span id="line-61">@InterfaceAudience.Private</span>
<span class="source-line-no">062</span><span id="line-62">public abstract class ByteBufferExtendedCell implements ExtendedCell {</span>
<span class="source-line-no">063</span><span id="line-63"> /** Returns The {@link ByteBuffer} containing the row bytes. */</span>
<span class="source-line-no">064</span><span id="line-64"> public abstract ByteBuffer getRowByteBuffer();</span>
<span class="source-line-no">065</span><span id="line-65"></span>
<span class="source-line-no">066</span><span id="line-66"> /** Returns Position in the {@link ByteBuffer} where row bytes start */</span>
<span class="source-line-no">067</span><span id="line-67"> public abstract int getRowPosition();</span>
<span class="source-line-no">068</span><span id="line-68"></span>
<span class="source-line-no">069</span><span id="line-69"> /** Returns The {@link ByteBuffer} containing the column family bytes. */</span>
<span class="source-line-no">070</span><span id="line-70"> public abstract ByteBuffer getFamilyByteBuffer();</span>
<span class="source-line-no">071</span><span id="line-71"></span>
<span class="source-line-no">072</span><span id="line-72"> /** Returns Position in the {@link ByteBuffer} where column family bytes start */</span>
<span class="source-line-no">073</span><span id="line-73"> public abstract int getFamilyPosition();</span>
<span class="source-line-no">074</span><span id="line-74"></span>
<span class="source-line-no">075</span><span id="line-75"> /** Returns The {@link ByteBuffer} containing the column qualifier bytes. */</span>
<span class="source-line-no">076</span><span id="line-76"> public abstract ByteBuffer getQualifierByteBuffer();</span>
<span class="source-line-no">077</span><span id="line-77"></span>
<span class="source-line-no">078</span><span id="line-78"> /** Returns Position in the {@link ByteBuffer} where column qualifier bytes start */</span>
<span class="source-line-no">079</span><span id="line-79"> public abstract int getQualifierPosition();</span>
<span class="source-line-no">080</span><span id="line-80"></span>
<span class="source-line-no">081</span><span id="line-81"> /** Returns The {@link ByteBuffer} containing the value bytes. */</span>
<span class="source-line-no">082</span><span id="line-82"> public abstract ByteBuffer getValueByteBuffer();</span>
<span class="source-line-no">083</span><span id="line-83"></span>
<span class="source-line-no">084</span><span id="line-84"> /** Returns Position in the {@link ByteBuffer} where value bytes start */</span>
<span class="source-line-no">085</span><span id="line-85"> public abstract int getValuePosition();</span>
<span class="source-line-no">086</span><span id="line-86"></span>
<span class="source-line-no">087</span><span id="line-87"> /** Returns The {@link ByteBuffer} containing the tag bytes. */</span>
<span class="source-line-no">088</span><span id="line-88"> public abstract ByteBuffer getTagsByteBuffer();</span>
<span class="source-line-no">089</span><span id="line-89"></span>
<span class="source-line-no">090</span><span id="line-90"> /** Returns Position in the {@link ByteBuffer} where tag bytes start */</span>
<span class="source-line-no">091</span><span id="line-91"> public abstract int getTagsPosition();</span>
<span class="source-line-no">092</span><span id="line-92">}</span>
</pre>
</div>
</main>
</body>
</html>