diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java index 1ff64d5..183f549 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java @@ -315,7 +315,8 @@ public final class ConnectionUtils { return result; } Cell[] rawCells = result.rawCells(); - int index = Arrays.binarySearch(rawCells, keepCellsAfter, CellComparator::compareWithoutRow); + int index = + Arrays.binarySearch(rawCells, keepCellsAfter, CellComparator.COMPARATOR::compareWithoutRow); if (index < 0) { index = -index - 1; } else { diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparator.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparator.java index 567b10c..c5364b2 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparator.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparator.java @@ -18,9 +18,6 @@ package org.apache.hadoop.hbase; -import java.io.Serializable; -import java.util.Comparator; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.KeyValue.Type; @@ -47,10 +44,8 @@ import org.apache.hadoop.hbase.shaded.com.google.common.primitives.Longs; justification="Findbugs doesn't like the way we are negating the result of a compare in below") @InterfaceAudience.Private @InterfaceStability.Evolving -public class CellComparator implements Comparator, Serializable { +public class CellComparator implements CoprocessorCellComparator { static final Log LOG = LogFactory.getLog(CellComparator.class); - private static final long serialVersionUID = -8760041766259623329L; - /** * Comparator for plain key/values; i.e. non-catalog table key/values. Works on Key portion * of KeyValue only. @@ -69,7 +64,7 @@ public class CellComparator implements Comparator, Serializable { /** * Compares only the key portion of a cell. It does not include the sequence id/mvcc of the - * cell + * cell * @param left * @param right * @return an int greater than 0 if left > than right @@ -136,7 +131,7 @@ public class CellComparator implements Comparator, Serializable { * @param right the right cell * @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise */ - public final static int compareColumns(final Cell left, final Cell right) { + public final int compareColumns(final Cell left, final Cell right) { int diff = compareFamilies(left, right); if (diff != 0) { return diff; @@ -158,7 +153,8 @@ public class CellComparator implements Comparator, Serializable { * @param right * @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise */ - public final static int compareFamilies(Cell left, Cell right) { + @Override + public final int compareFamilies(Cell left, Cell right) { if (left instanceof ByteBufferCell && right instanceof ByteBufferCell) { return ByteBufferUtils.compareTo(((ByteBufferCell) left).getFamilyByteBuffer(), ((ByteBufferCell) left).getFamilyPosition(), left.getFamilyLength(), @@ -200,7 +196,8 @@ public class CellComparator implements Comparator, Serializable { * @param right * @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise */ - public final static int compareQualifiers(Cell left, Cell right) { + @Override + public final int compareQualifiers(Cell left, Cell right) { if (left instanceof ByteBufferCell && right instanceof ByteBufferCell) { return ByteBufferUtils .compareTo(((ByteBufferCell) left).getQualifierByteBuffer(), @@ -323,6 +320,7 @@ public class CellComparator implements Comparator, Serializable { * @param right * @return 0 if both cells are equal, 1 if left cell is bigger than right, -1 otherwise */ + @Override public int compareRows(final Cell left, final Cell right) { // left and right can be exactly the same at the beginning of a row if (left == right) { @@ -378,7 +376,8 @@ public class CellComparator implements Comparator, Serializable { roffset, rlength); } - public static int compareWithoutRow(final Cell left, final Cell right) { + @Override + public final int compareWithoutRow(final Cell left, final Cell right) { // If the column is not specified, the "minimum" key type appears the // latest in the sorted order, regardless of the timestamp. This is used // for specifying the last key/value in a given row, because there is no @@ -426,7 +425,8 @@ public class CellComparator implements Comparator, Serializable { * -1 if left's timestamp > right's timestamp * 0 if both timestamps are equal */ - public static int compareTimestamps(final Cell left, final Cell right) { + @Override + public int compareTimestamps(final Cell left, final Cell right) { return compareTimestamps(left.getTimestamp(), right.getTimestamp()); } @@ -434,7 +434,7 @@ public class CellComparator implements Comparator, Serializable { * Used to compare two cells based on the column hint provided. This is specifically * used when we need to optimize the seeks based on the next indexed key. This is an * advanced usage API specifically needed for some optimizations. - * @param nextIndexedCell the next indexed cell + * @param nextIndexedCell the next indexed cell * @param currentCell the cell to be compared * @param foff the family offset of the currentCell * @param flen the family length of the currentCell @@ -505,7 +505,8 @@ public class CellComparator implements Comparator, Serializable { * -1 if left timestamp > right timestamp * 0 if both timestamps are equal */ - public static int compareTimestamps(final long ltimestamp, final long rtimestamp) { + @Override + public int compareTimestamps(final long ltimestamp, final long rtimestamp) { if (ltimestamp < rtimestamp) { return 1; } else if (ltimestamp > rtimestamp) { diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java index 58ebc33..f9fa7e6 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java @@ -2241,7 +2241,7 @@ public final class CellUtil { } public static boolean matchingTimestamp(Cell a, Cell b) { - return CellComparator.compareTimestamps(a.getTimestamp(), b.getTimestamp()) == 0; + return CellComparator.COMPARATOR.compareTimestamps(a.getTimestamp(), b.getTimestamp()) == 0; } public static boolean matchingType(Cell a, Cell b) { diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/CoprocessorCellComparator.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/CoprocessorCellComparator.java new file mode 100644 index 0000000..c963d0d --- /dev/null +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/CoprocessorCellComparator.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase; + +import java.util.Comparator; + +import org.apache.yetus.audience.InterfaceAudience; +import org.apache.yetus.audience.InterfaceStability; +/** + * Used by CPs for comparing cells and has some specialized methods that allows comparing individual + * cell components like row, family, qualifier and timestamp + */ +@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) +@InterfaceStability.Evolving +public interface CoprocessorCellComparator extends Comparator { + + /** + * Lexographically compares two cells. The key part of the cell is taken for comparison which + * includes row, family, qualifier, timestamp and type + * @param leftCell the left hand side cell + * @param rightCell the right hand side cell + * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both + * cells are equal + */ + int compare(Cell leftCell, Cell rightCell); + + /** + * Lexographically compares the rows of two cells. + * @param leftCell the left hand side cell + * @param rightCell the right hand side cell + * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both + * cells are equal + */ + int compareRows(Cell leftCell, Cell rightCell); + + /** + * Lexographically compares the two cells excluding the row part. It compares family, qualifier, + * timestamp and the type + * @param leftCell the left hand side cell + * @param rightCell the right hand side cell + * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both + * cells are equal + */ + int compareWithoutRow(Cell leftCell, Cell rightCell); + + /** + * Lexographically compares the families of the two cells + * @param leftCell the left hand side cell + * @param rightCell the right hand side cell + * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both + * cells are equal + */ + int compareFamilies(Cell leftCell, Cell rightCell); + + /** + * Lexographically compares the qualifiers of the two cells + * @param leftCell the left hand side cell + * @param rightCell the right hand side cell + * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both + * cells are equal + */ + int compareQualifiers(Cell leftCell, Cell rightCell); + + /** + * Compares cell's timestamps in DESCENDING order. The below older timestamps sorting ahead of + * newer timestamps looks wrong but it is intentional. This way, newer timestamps are first found + * when we iterate over a memstore and newer versions are the first we trip over when reading from + * a store file. + * @param leftCell the left hand side cell + * @param rightCell the right hand side cell + * @return 1 if left's timestamp < right's timestamp -1 if left's timestamp > right's + * timestamp 0 if both timestamps are equal + */ + int compareTimestamps(Cell leftCell, Cell rightCell); + + /** + * Compares cell's timestamps in DESCENDING order. The below older timestamps sorting ahead of + * newer timestamps looks wrong but it is intentional. This way, newer timestamps are first found + * when we iterate over a memstore and newer versions are the first we trip over when reading from + * a store file. + * @param leftCellts the left cell's timestamp + * @param rightCellts the right cell's timestamp + * @return 1 if left's timestamp < right's timestamp -1 if left's timestamp > right's + * timestamp 0 if both timestamps are equal + */ + int compareTimestamps(long leftCellts, long rightCellts); +} diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index 66ff72a..c998b9e 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -28,7 +28,6 @@ import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -1854,7 +1853,7 @@ public class KeyValue implements ExtendedCell { } public int compareTimestamps(final Cell left, final Cell right) { - return CellComparator.compareTimestamps(left, right); + return CellComparator.COMPARATOR.compareTimestamps(left, right); } /** @@ -1884,7 +1883,7 @@ public class KeyValue implements ExtendedCell { int compareColumns(final Cell left, final short lrowlength, final Cell right, final short rrowlength) { - return CellComparator.compareColumns(left, right); + return CellComparator.COMPARATOR.compareColumns(left, right); } protected int compareColumns( diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java index bc905e5..b911895 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/BufferedDataBlockEncoder.java @@ -880,7 +880,7 @@ abstract class BufferedDataBlockEncoder extends AbstractDataBlockEncoder { qualCommonPrefix); comp = compareCommonQualifierPrefix(seekCell, keyOnlyKV, qualCommonPrefix); if (comp == 0) { - comp = CellComparator.compareTimestamps(seekCell, keyOnlyKV); + comp = CellComparator.COMPARATOR.compareTimestamps(seekCell, keyOnlyKV); if (comp == 0) { // Compare types. Let the delete types sort ahead of puts; // i.e. types diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java index dbb6adb..7b4036c 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/DataBlockEncoder.java @@ -100,8 +100,7 @@ public interface DataBlockEncoder { * @param decodingCtx * @return A newly created seeker. */ - EncodedSeeker createSeeker(CellComparator comparator, - HFileBlockDecodingContext decodingCtx); + EncodedSeeker createSeeker(CellComparator comparator, HFileBlockDecodingContext decodingCtx); /** * Creates a encoder specific encoding context diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java index 2831b93..5d6de46 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java @@ -53,7 +53,7 @@ public class TestCellComparator { kv1 = new KeyValue(row1, fam2, qual1, val); kv2 = new KeyValue(row1, fam1, qual1, val); - assertTrue((CellComparator.compareFamilies(kv1, kv2) > 0)); + assertTrue((CellComparator.COMPARATOR.compareFamilies(kv1, kv2) > 0)); kv1 = new KeyValue(row1, fam1, qual1, 1l, val); kv2 = new KeyValue(row1, fam1, qual1, 2l, val); @@ -105,14 +105,14 @@ public class TestCellComparator { kv = new KeyValue(r2, f1, q1, v); buffer = ByteBuffer.wrap(kv.getBuffer()); Cell bbCell2 = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); - assertEquals(0, CellComparator.compareColumns(bbCell1, bbCell2)); - assertEquals(0, CellComparator.compareColumns(bbCell1, kv)); + assertEquals(0, CellComparator.COMPARATOR.compareColumns(bbCell1, bbCell2)); + assertEquals(0, CellComparator.COMPARATOR.compareColumns(bbCell1, kv)); kv = new KeyValue(r2, f1, q2, v); buffer = ByteBuffer.wrap(kv.getBuffer()); Cell bbCell3 = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); - assertEquals(0, CellComparator.compareFamilies(bbCell2, bbCell3)); - assertTrue(CellComparator.compareQualifiers(bbCell2, bbCell3) < 0); - assertTrue(CellComparator.compareColumns(bbCell2, bbCell3) < 0); + assertEquals(0, CellComparator.COMPARATOR.compareFamilies(bbCell2, bbCell3)); + assertTrue(CellComparator.COMPARATOR.compareQualifiers(bbCell2, bbCell3) < 0); + assertTrue(CellComparator.COMPARATOR.compareColumns(bbCell2, bbCell3) < 0); assertEquals(0, CellComparator.COMPARATOR.compareRows(bbCell2, bbCell3)); assertTrue(CellComparator.COMPARATOR.compareRows(bbCell1, bbCell2) < 0); diff --git a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/SyncTable.java b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/SyncTable.java index c72a0c3..c113828 100644 --- a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/SyncTable.java +++ b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/SyncTable.java @@ -52,7 +52,6 @@ import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.hbase.shaded.com.google.common.base.Throwables; -import org.apache.hadoop.hbase.shaded.com.google.common.collect.Iterators; public class SyncTable extends Configured implements Tool { @@ -588,18 +587,18 @@ public class SyncTable extends Configured implements Tool { return -1; // target missing cell } - int result = CellComparator.compareFamilies(c1, c2); + int result = CellComparator.COMPARATOR.compareFamilies(c1, c2); if (result != 0) { return result; } - result = CellComparator.compareQualifiers(c1, c2); + result = CellComparator.COMPARATOR.compareQualifiers(c1, c2); if (result != 0) { return result; } // note timestamp comparison is inverted - more recent cells first - return CellComparator.compareTimestamps(c1, c2); + return CellComparator.COMPARATOR.compareTimestamps(c1, c2); } @Override diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java index eed73df..3fad6f5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePrettyPrinter.java @@ -424,7 +424,7 @@ public class HFilePrettyPrinter extends Configured implements Tool { + "\n\tfilename -> " + file + "\n\tkeyvalue -> " + CellUtil.getCellKeyAsString(cell)); } - if (pCell != null && CellComparator.compareFamilies(pCell, cell) != 0) { + if (pCell != null && CellComparator.COMPARATOR.compareFamilies(pCell, cell) != 0) { err.println("WARNING, previous kv has different family" + " compared to current key\n\tfilename -> " + file + "\n\tprevious -> " + CellUtil.getCellKeyAsString(pCell) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileWriterImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileWriterImpl.java index 5b25bed..ccf14c5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileWriterImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileWriterImpl.java @@ -399,7 +399,7 @@ public class HFileWriterImpl implements HFile.Writer { return CellUtil.createFirstOnRow(midRow); } // Rows are same. Compare on families. - diff = CellComparator.compareFamilies(left, right); + diff = comparator.compareFamilies(left, right); if (diff > 0) { throw new IllegalArgumentException("Left family sorts after right family; left=" + CellUtil.getCellKeyAsString(left) + ", right=" + CellUtil.getCellKeyAsString(right)); @@ -421,7 +421,7 @@ public class HFileWriterImpl implements HFile.Writer { return CellUtil.createFirstOnRowFamily(right, midRow, 0, midRow.length); } // Families are same. Compare on qualifiers. - diff = CellComparator.compareQualifiers(left, right); + diff = comparator.compareQualifiers(left, right); if (diff > 0) { throw new IllegalArgumentException("Left qualifier sorts after right qualifier; left=" + CellUtil.getCellKeyAsString(left) + ", right=" + CellUtil.getCellKeyAsString(right)); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 2d35fb9..ef79551 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -33,7 +33,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -80,6 +79,7 @@ import org.apache.hadoop.fs.LocatedFileStatus; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellBuilderType; +import org.apache.hadoop.hbase.CoprocessorCellComparator; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellScanner; import org.apache.hadoop.hbase.CellUtil; @@ -5818,7 +5818,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } else { this.filter = null; } - this.comparator = region.getCellComparator(); + this.comparator = (CellComparator) region.getCellComparator(); /** * By default, calls to next/nextRaw must enforce the batch limit. Thus, construct a default * scanner context that can be used to enforce the batch limit in the event that a @@ -7500,7 +7500,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi // we won't be able to find the existing values if the cells are not specified in order by the // client since cells are in an array list. // TODO: I don't get why we are sorting. St.Ack 20150107 - sort(coordinates, store.getComparator()); + sort(coordinates, (CellComparator) store.getComparator()); Get get = new Get(mutation.getRow()); if (isolation != null) { get.setIsolationLevel(isolation); @@ -7518,7 +7518,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi /** * @return Sorted list of cells using comparator */ - private static List sort(List cells, final Comparator comparator) { + private static List sort(List cells, final CellComparator comparator) { Collections.sort(cells, comparator); return cells; } @@ -8055,7 +8055,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } @Override - public CellComparator getCellComparator() { + public CoprocessorCellComparator getCellComparator() { return this.getRegionInfo().isMetaRegion() ? CellComparator.META_COMPARATOR : CellComparator.COMPARATOR; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java index d2009e3..3f0931d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HStore.java @@ -55,6 +55,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.CoprocessorCellComparator; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CompoundConfiguration; @@ -252,7 +253,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat this.dataBlockEncoder = new HFileDataBlockEncoderImpl(family.getDataBlockEncoding()); - this.comparator = region.getCellComparator(); + this.comparator = (CellComparator)region.getCellComparator(); // used by ScanQueryMatcher long timeToPurgeDeletes = Math.max(conf.getLong("hbase.hstore.time.to.purge.deletes", 0), 0); @@ -777,7 +778,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat + CellUtil.getCellKeyAsString(prevCell) + " current=" + CellUtil.getCellKeyAsString(cell)); } - if (CellComparator.compareFamilies(prevCell, cell) != 0) { + if (CellComparator.COMPARATOR.compareFamilies(prevCell, cell) != 0) { throw new InvalidHFileException("Previous key had different" + " family compared to current key: path=" + srcPath + " previous=" @@ -2332,7 +2333,7 @@ public class HStore implements Store, HeapSize, StoreConfigInformation, Propagat } @Override - public CellComparator getComparator() { + public CoprocessorCellComparator getComparator() { return comparator; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java index e3ba2fa..496b41a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Region.java @@ -24,7 +24,7 @@ import java.util.Map; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.CellComparator; +import org.apache.hadoop.hbase.CoprocessorCellComparator; import org.apache.hadoop.hbase.CompareOperator; import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.HDFSBlocksDistribution; @@ -462,7 +462,7 @@ public interface Region extends ConfigurationObserver { RegionScanner getScanner(Scan scan, List additionalScanners) throws IOException; /** The comparator to be used with the region */ - CellComparator getCellComparator(); + CoprocessorCellComparator getCellComparator(); /** * Perform one or more increment operations on a row. diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java index 6f6f31c..9741ba8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java @@ -19,12 +19,11 @@ package org.apache.hadoop.hbase.regionserver; import java.io.IOException; import java.util.Collection; -import java.util.Comparator; import java.util.OptionalDouble; import java.util.OptionalLong; import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.CoprocessorCellComparator; import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; @@ -49,7 +48,7 @@ public interface Store { int NO_PRIORITY = Integer.MIN_VALUE; // General Accessors - Comparator getComparator(); + CoprocessorCellComparator getComparator(); Collection getStorefiles(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java index c11c8a3..01c9592 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java @@ -18,12 +18,12 @@ package org.apache.hadoop.hbase.regionserver; import java.io.IOException; -import java.util.Comparator; import java.util.Optional; import java.util.OptionalLong; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.CoprocessorCellComparator; import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.HDFSBlocksDistribution; import org.apache.yetus.audience.InterfaceAudience; @@ -54,7 +54,7 @@ public interface StoreFile { /** * Get the comparator for comparing two cells. */ - Comparator getComparator(); + CoprocessorCellComparator getComparator(); /** * Get max of the MemstoreTS in the KV's in this store file. diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java index 588211c..0fdfec0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java @@ -254,7 +254,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner this.storeOffset = scan.getRowOffsetPerColumnFamily(); addCurrentScanners(scanners); // Combine all seeked scanners with a heap - resetKVHeap(scanners, store.getComparator()); + resetKVHeap(scanners, (CellComparator)store.getComparator()); } catch (IOException e) { // remove us from the HStore#changedReaderObservers here or we'll have no chance to // and might cause memory leak @@ -318,7 +318,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner seekScanners(scanners, matcher.getStartKey(), false, parallelSeekEnabled); addCurrentScanners(scanners); // Combine all seeked scanners with a heap - resetKVHeap(scanners, store.getComparator()); + resetKVHeap(scanners, (CellComparator)store.getComparator()); } private void seekAllScanner(ScanInfo scanInfo, List scanners) @@ -554,7 +554,8 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner } // Only do a sanity-check if store and comparator are available. - CellComparator comparator = store.map(s -> s.getComparator()).orElse(null); + CellComparator comparator = + store.map(s -> (CellComparator) s.getComparator()).orElse(null); int count = 0; long totalBytesRead = 0; @@ -901,7 +902,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner // add the newly created scanners on the flushed files and the current active memstore scanner addCurrentScanners(scanners); // Combine all seeked scanners with a heap - resetKVHeap(this.currentScanners, store.getComparator()); + resetKVHeap(this.currentScanners, (CellComparator) store.getComparator()); resetQueryMatcher(lastTop); if (heap.peek() == null || store.getComparator().compareRows(lastTop, this.heap.peek()) != 0) { LOG.info("Storescanner.peek() is changed where before = " + lastTop.toString() + @@ -1008,7 +1009,7 @@ public class StoreScanner extends NonReversedNonLazyKeyValueScanner newCurrentScanners = new ArrayList<>(fileScanners.size() + memstoreScanners.size()); newCurrentScanners.addAll(fileScanners); newCurrentScanners.addAll(memstoreScanners); - newHeap = new KeyValueHeap(newCurrentScanners, store.getComparator()); + newHeap = new KeyValueHeap(newCurrentScanners, (CellComparator)store.getComparator()); } catch (Exception e) { LOG.warn("failed to switch to stream read", e); if (fileScanners != null) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StripeStoreFlusher.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StripeStoreFlusher.java index c858f8f..0248917 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StripeStoreFlusher.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/StripeStoreFlusher.java @@ -68,8 +68,8 @@ public class StripeStoreFlusher extends StoreFlusher { } // Let policy select flush method. - StripeFlushRequest req = this.policy.selectFlush(store.getComparator(), this.stripes, - cellsCount); + StripeFlushRequest req = this.policy.selectFlush((CellComparator) store.getComparator(), + this.stripes, cellsCount); boolean success = false; StripeMultiFileWriter mw = null; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/StripeCompactor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/StripeCompactor.java index f4836a8..b6a0f30 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/StripeCompactor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/compactions/StripeCompactor.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.regionserver.HStore; import org.apache.hadoop.hbase.regionserver.InternalScanner; import org.apache.hadoop.hbase.regionserver.ScanType; @@ -94,7 +95,8 @@ public class StripeCompactor extends AbstractMultiOutputCompactor !CellUtil.matchingFamily(v, WALEdit.METAFAMILY)) - .collect(toCollection(() -> new TreeSet<>(CellComparator::compareFamilies))) + .collect(toCollection(() -> new TreeSet<>(CellComparator.COMPARATOR::compareFamilies))) .stream() .map(CellUtil::cloneFamily) .collect(toCollection(() -> new TreeSet<>(Bytes.BYTES_COMPARATOR))); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityScanDeleteTracker.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityScanDeleteTracker.java index 318ae57..f01c800 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityScanDeleteTracker.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityScanDeleteTracker.java @@ -246,7 +246,7 @@ public class VisibilityScanDeleteTracker extends ScanDeleteTracker { } } if (deleteCell != null) { - int ret = CellComparator.compareQualifiers(cell, deleteCell); + int ret = CellComparator.COMPARATOR.compareQualifiers(cell, deleteCell); if (ret == 0) { if (deleteType == KeyValue.Type.DeleteColumn.getCode()) { if (visibilityTagsDeleteColumns != null) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScannerHeartbeatMessages.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScannerHeartbeatMessages.java index 7907e13..6d2b55b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScannerHeartbeatMessages.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScannerHeartbeatMessages.java @@ -501,9 +501,11 @@ public class TestScannerHeartbeatMessages { @Override protected void initializeKVHeap(List scanners, List joinedScanners, HRegion region) throws IOException { - this.storeHeap = new HeartbeatReversedKVHeap(scanners, region.getCellComparator()); + this.storeHeap = + new HeartbeatReversedKVHeap(scanners, (CellComparator) region.getCellComparator()); if (!joinedScanners.isEmpty()) { - this.joinedHeap = new HeartbeatReversedKVHeap(joinedScanners, region.getCellComparator()); + this.joinedHeap = new HeartbeatReversedKVHeap(joinedScanners, + (CellComparator) region.getCellComparator()); } } } @@ -528,9 +530,11 @@ public class TestScannerHeartbeatMessages { @Override protected void initializeKVHeap(List scanners, List joinedScanners, HRegion region) throws IOException { - this.storeHeap = new HeartbeatKVHeap(scanners, region.getCellComparator()); + this.storeHeap = + new HeartbeatKVHeap(scanners, (CellComparator) region.getCellComparator()); if (!joinedScanners.isEmpty()) { - this.joinedHeap = new HeartbeatKVHeap(joinedScanners, region.getCellComparator()); + this.joinedHeap = + new HeartbeatKVHeap(joinedScanners, (CellComparator) region.getCellComparator()); } } }