001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.util; 019 020import org.apache.hadoop.hbase.Cell; 021import org.apache.hadoop.hbase.KeyValue; 022import org.apache.hadoop.hbase.PrivateCellUtil; 023import org.apache.yetus.audience.InterfaceAudience; 024 025/** 026 * An hash key for ROWCOL bloom. This assumes the cells to be serialized in the Keyvalue 027 * serialization format with Empty column family. Note that the byte representing the family length 028 * is considered to be 0 029 */ 030@InterfaceAudience.Private 031public class RowColBloomHashKey extends CellHashKey { 032 033 private final int rowLength; 034 private final int qualLength; 035 036 public RowColBloomHashKey(Cell cell) { 037 super(cell); 038 rowLength = cell.getRowLength(); 039 // We don't consider the family length for ROWCOL bloom. So subtract the famLen from the 040 // length calculation. Timestamp and type are of no relevance here 041 qualLength = cell.getQualifierLength(); 042 } 043 044 @Override 045 public byte get(int offset) { 046 // For ROW_COL blooms we use bytes 047 // <RK length> (2 bytes) , <RK>, 0 (one byte CF length), <CQ>, <TS> (8 btes), <TYPE> ( 1 byte) 048 if (offset < Bytes.SIZEOF_SHORT) { 049 // assign locally 050 int rowlen = rowLength; 051 byte b = (byte) rowlen; 052 if (offset == 0) { 053 rowlen >>= 8; 054 b = (byte) rowlen; 055 } 056 return b; 057 } 058 int refLen = Bytes.SIZEOF_SHORT + rowLength; 059 if (offset < refLen) { 060 return PrivateCellUtil.getRowByte(t, offset - Bytes.SIZEOF_SHORT); 061 } 062 if (offset == refLen) { 063 // The fam length should return 0 assuming there is no column family. 064 // Because for ROWCOL blooms family is not considered 065 return 0; 066 } 067 refLen += qualLength + Bytes.SIZEOF_BYTE; 068 // skip the family len because actual cells may have family also 069 if (offset < refLen) { 070 return PrivateCellUtil.getQualifierByte(t, 071 offset - (Bytes.SIZEOF_SHORT + rowLength + Bytes.SIZEOF_BYTE)); 072 } 073 // TODO : check if ts and type can be removed 074 refLen += KeyValue.TIMESTAMP_SIZE; 075 if (offset < refLen) { 076 return LATEST_TS[offset - (Bytes.SIZEOF_SHORT + rowLength + qualLength + Bytes.SIZEOF_BYTE)]; 077 } 078 return MAX_TYPE; 079 } 080 081 @Override 082 public int length() { 083 // For ROW_COL blooms we use bytes 084 // <RK length> (2 bytes) , <RK>, 0 (one byte CF length), <CQ>, <TS> (8 btes), <TYPE> ( 1 byte) 085 return KeyValue.ROW_LENGTH_SIZE + this.t.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE 086 + this.t.getQualifierLength() + KeyValue.TIMESTAMP_TYPE_SIZE; 087 } 088}