HBASE-24163 MOB compactor implementations should use format specifiers when calling...
[hbase.git] / hbase-common / src / main / java / org / apache / hadoop / hbase / util / RowColBloomHashKey.java
blob17a26acf3f607fb2b675b141305de51f9399078f
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.util;
20 import org.apache.hadoop.hbase.Cell;
21 import org.apache.hadoop.hbase.KeyValue;
22 import org.apache.hadoop.hbase.PrivateCellUtil;
23 import org.apache.yetus.audience.InterfaceAudience;
25 /**
26 * An hash key for ROWCOL bloom. This assumes the cells to be serialized in the Keyvalue
27 * serialization format with Empty column family. Note that the byte representing the family length
28 * is considered to be 0
30 @InterfaceAudience.Private
31 public class RowColBloomHashKey extends CellHashKey {
33 private final int rowLength;
34 private final int qualLength;
36 public RowColBloomHashKey(Cell cell) {
37 super(cell);
38 rowLength = cell.getRowLength();
39 // We don't consider the family length for ROWCOL bloom. So subtract the famLen from the
40 // length calculation. Timestamp and type are of no relevance here
41 qualLength = cell.getQualifierLength();
44 @Override
45 public byte get(int offset) {
46 // For ROW_COL blooms we use bytes
47 // <RK length> (2 bytes) , <RK>, 0 (one byte CF length), <CQ>, <TS> (8 btes), <TYPE> ( 1 byte)
48 if (offset < Bytes.SIZEOF_SHORT) {
49 // assign locally
50 int rowlen = rowLength;
51 byte b = (byte) rowlen;
52 if (offset == 0) {
53 rowlen >>= 8;
54 b = (byte) rowlen;
56 return b;
58 int refLen = Bytes.SIZEOF_SHORT + rowLength;
59 if (offset < refLen) {
60 return PrivateCellUtil.getRowByte(t, offset - Bytes.SIZEOF_SHORT);
62 if (offset == refLen) {
63 // The fam length should return 0 assuming there is no column family.
64 // Because for ROWCOL blooms family is not considered
65 return 0;
67 refLen += qualLength + Bytes.SIZEOF_BYTE;
68 // skip the family len because actual cells may have family also
69 if (offset < refLen) {
70 return PrivateCellUtil.getQualifierByte(t,
71 offset - (Bytes.SIZEOF_SHORT + rowLength + Bytes.SIZEOF_BYTE));
73 // TODO : check if ts and type can be removed
74 refLen += KeyValue.TIMESTAMP_SIZE;
75 if (offset < refLen) {
76 return LATEST_TS[offset - (Bytes.SIZEOF_SHORT + rowLength + qualLength + Bytes.SIZEOF_BYTE)];
78 return MAX_TYPE;
81 @Override
82 public int length() {
83 // For ROW_COL blooms we use bytes
84 // <RK length> (2 bytes) , <RK>, 0 (one byte CF length), <CQ>, <TS> (8 btes), <TYPE> ( 1 byte)
85 return KeyValue.ROW_LENGTH_SIZE + this.t.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE
86 + this.t.getQualifierLength() + KeyValue.TIMESTAMP_TYPE_SIZE;