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.classification.InterfaceAudience;
23 import org.apache.hadoop.hbase.KeyValue;
24 import org.apache.hadoop.io.RawComparator;
25
26 @InterfaceAudience.Private
27 public class CompoundBloomFilterBase implements BloomFilterBase {
28
29 /**
30 * At read time, the total number of chunks. At write time, the number of
31 * chunks created so far. The first chunk has an ID of 0, and the current
32 * chunk has the ID of numChunks - 1.
33 */
34 protected int numChunks;
35
36 /**
37 * The Bloom filter version. There used to be a DynamicByteBloomFilter which
38 * had version 2.
39 */
40 public static final int VERSION = 3;
41
42 /** Target error rate for configuring the filter and for information */
43 protected float errorRate;
44
45 /** The total number of keys in all chunks */
46 protected long totalKeyCount;
47 protected long totalByteSize;
48 protected long totalMaxKeys;
49
50 /** Hash function type to use, as defined in {@link Hash} */
51 protected int hashType;
52
53 /** Comparator used to compare Bloom filter keys */
54 protected RawComparator<byte[]> comparator;
55
56 @Override
57 public long getMaxKeys() {
58 return totalMaxKeys;
59 }
60
61 @Override
62 public long getKeyCount() {
63 return totalKeyCount;
64 }
65
66 @Override
67 public long getByteSize() {
68 return totalByteSize;
69 }
70
71 private static final byte[] DUMMY = new byte[0];
72
73 /**
74 * Prepare an ordered pair of row and qualifier to be compared using
75 * KeyValue.KeyComparator. This is only used for row-column Bloom
76 * filters.
77 */
78 @Override
79 public byte[] createBloomKey(byte[] row, int roffset, int rlength,
80 byte[] qualifier, int qoffset, int qlength) {
81 if (qualifier == null)
82 qualifier = DUMMY;
83
84 // Make sure this does not specify a timestamp so that the default maximum
85 // (most recent) timestamp is used.
86 KeyValue kv = KeyValue.createFirstOnRow(row, roffset, rlength, DUMMY, 0, 0,
87 qualifier, qoffset, qlength);
88 return kv.getKey();
89 }
90
91 @Override
92 public RawComparator<byte[]> getComparator() {
93 return comparator;
94 }
95
96 }