1 /* 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 package org.apache.hadoop.hbase.util; 21 22 import org.apache.hadoop.hbase.classification.InterfaceAudience; 23 import org.apache.hadoop.hbase.KeyValue; 24 import org.apache.hadoop.hbase.KeyValue.KVComparator; 25 import org.apache.hadoop.hbase.KeyValueUtil; 26 27 @InterfaceAudience.Private 28 public class CompoundBloomFilterBase implements BloomFilterBase { 29 30 /** 31 * At read time, the total number of chunks. At write time, the number of 32 * chunks created so far. The first chunk has an ID of 0, and the current 33 * chunk has the ID of numChunks - 1. 34 */ 35 protected int numChunks; 36 37 /** 38 * The Bloom filter version. There used to be a DynamicByteBloomFilter which 39 * had version 2. 40 */ 41 public static final int VERSION = 3; 42 43 /** Target error rate for configuring the filter and for information */ 44 protected float errorRate; 45 46 /** The total number of keys in all chunks */ 47 protected long totalKeyCount; 48 protected long totalByteSize; 49 protected long totalMaxKeys; 50 51 /** Hash function type to use, as defined in {@link Hash} */ 52 protected int hashType; 53 54 /** Comparator used to compare Bloom filter keys */ 55 protected KVComparator comparator; 56 57 @Override 58 public long getMaxKeys() { 59 return totalMaxKeys; 60 } 61 62 @Override 63 public long getKeyCount() { 64 return totalKeyCount; 65 } 66 67 @Override 68 public long getByteSize() { 69 return totalByteSize; 70 } 71 72 private static final byte[] DUMMY = new byte[0]; 73 74 /** 75 * Prepare an ordered pair of row and qualifier to be compared using 76 * KeyValue.KeyComparator. This is only used for row-column Bloom 77 * filters. 78 */ 79 @Override 80 public byte[] createBloomKey(byte[] row, int roffset, int rlength, 81 byte[] qualifier, int qoffset, int qlength) { 82 if (qualifier == null) 83 qualifier = DUMMY; 84 85 // Make sure this does not specify a timestamp so that the default maximum 86 // (most recent) timestamp is used. 87 KeyValue kv = KeyValueUtil.createFirstOnRow(row, roffset, rlength, DUMMY, 0, 0, 88 qualifier, qoffset, qlength); 89 return kv.getKey(); 90 } 91 92 @Override 93 public KVComparator getComparator() { 94 return comparator; 95 } 96 97 }