HBASE-21843 RegionGroupingProvider breaks the meta wal file name pattern which may...
[hbase.git] / hbase-server / src / main / java / org / apache / hadoop / hbase / util / BloomContext.java
blob31394e8a97b5c0767d632c70764b80baa4030468
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 java.io.IOException;
22 import org.apache.hadoop.hbase.Cell;
23 import org.apache.hadoop.hbase.CellComparator;
24 import org.apache.yetus.audience.InterfaceAudience;
25 import org.apache.hadoop.hbase.io.hfile.HFile;
27 /**
28 * The bloom context that is used by the StorefileWriter to add the bloom details
29 * per cell
31 @InterfaceAudience.Private
32 public abstract class BloomContext {
34 protected BloomFilterWriter bloomFilterWriter;
35 protected CellComparator comparator;
37 public BloomContext(BloomFilterWriter bloomFilterWriter, CellComparator comparator) {
38 this.bloomFilterWriter = bloomFilterWriter;
39 this.comparator = comparator;
42 public Cell getLastCell() {
43 return this.bloomFilterWriter.getPrevCell();
46 /**
47 * Bloom information from the cell is retrieved
48 * @param cell
49 * @throws IOException
51 public void writeBloom(Cell cell) throws IOException {
52 // only add to the bloom filter on a new, unique key
53 if (isNewKey(cell)) {
54 sanityCheck(cell);
55 bloomFilterWriter.append(cell);
59 private void sanityCheck(Cell cell) throws IOException {
60 if (this.getLastCell() != null) {
61 if (comparator.compare(cell, this.getLastCell()) <= 0) {
62 throw new IOException("Added a key not lexically larger than" + " previous. Current cell = "
63 + cell + ", prevCell = " + this.getLastCell());
68 /**
69 * Adds the last bloom key to the HFile Writer as part of StorefileWriter close.
70 * @param writer
71 * @throws IOException
73 public abstract void addLastBloomKey(HFile.Writer writer) throws IOException;
75 /**
76 * Returns true if the cell is a new key as per the bloom type
77 * @param cell the cell to be verified
78 * @return true if a new key else false
80 protected abstract boolean isNewKey(Cell cell);