diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java index f1090f5b2b5..14ed7660957 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java @@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.MetaCellComparator; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.RegionLocations; import org.apache.hadoop.hbase.RegionTooBusyException; @@ -683,7 +684,7 @@ public class TestClientNoCluster extends Configured implements Tool { * Comparator for meta row keys. */ private static class MetaRowsComparator implements Comparator { - private final CellComparatorImpl delegate = CellComparatorImpl.META_COMPARATOR; + private final CellComparatorImpl delegate = MetaCellComparator.META_COMPARATOR; @Override public int compare(byte[] left, byte[] right) { return delegate.compareRows(new KeyValue.KeyOnlyKeyValue(left), right, 0, right.length); diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparatorImpl.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparatorImpl.java index e6c8e3ded62..4af035a94f1 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparatorImpl.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellComparatorImpl.java @@ -17,16 +17,12 @@ */ package org.apache.hadoop.hbase; -import java.nio.ByteBuffer; import java.util.Comparator; import org.apache.hadoop.hbase.KeyValue.Type; import org.apache.hadoop.hbase.util.ByteBufferUtils; import org.apache.hadoop.hbase.util.Bytes; import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceStability; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.hbase.thirdparty.com.google.common.primitives.Longs; /** * Compare two HBase cells. Do not use this method comparing -ROOT- or @@ -48,7 +44,6 @@ import org.apache.hbase.thirdparty.com.google.common.primitives.Longs; @InterfaceAudience.Private @InterfaceStability.Evolving public class CellComparatorImpl implements CellComparator { - static final Logger LOG = LoggerFactory.getLogger(CellComparatorImpl.class); /** * Comparator for plain key/values; i.e. non-catalog table key/values. Works on Key portion @@ -56,12 +51,6 @@ public class CellComparatorImpl implements CellComparator { */ public static final CellComparatorImpl COMPARATOR = new CellComparatorImpl(); - /** - * A {@link CellComparatorImpl} for hbase:meta catalog table - * {@link KeyValue}s. - */ - public static final CellComparatorImpl META_COMPARATOR = new MetaCellComparator(); - @Override public final int compare(final Cell a, final Cell b) { return compare(a, b, false); @@ -213,7 +202,7 @@ public class CellComparatorImpl implements CellComparator { /** * Compares the row part of the cell with a simple plain byte[] like the * stopRow in Scan. This should be used with context where for hbase:meta - * cells the {{@link #META_COMPARATOR} should be used + * cells the {{@link MetaCellComparator#META_COMPARATOR} should be used * * @param left * the cell to be compared @@ -291,117 +280,6 @@ public class CellComparatorImpl implements CellComparator { return Long.compare(rtimestamp, ltimestamp); } - /** - * A {@link CellComparatorImpl} for hbase:meta catalog table - * {@link KeyValue}s. - */ - public static class MetaCellComparator extends CellComparatorImpl { - // TODO: Do we need a ByteBufferKeyValue version of this? - @Override - public int compareRows(final Cell left, final Cell right) { - return compareRows(left.getRowArray(), left.getRowOffset(), left.getRowLength(), - right.getRowArray(), right.getRowOffset(), right.getRowLength()); - } - - @Override - public int compareRows(Cell left, byte[] right, int roffset, int rlength) { - return compareRows(left.getRowArray(), left.getRowOffset(), left.getRowLength(), right, - roffset, rlength); - } - - @Override - public int compare(final Cell a, final Cell b, boolean ignoreSequenceid) { - int diff = compareRows(a, b); - if (diff != 0) { - return diff; - } - - diff = compareWithoutRow(a, b); - if (diff != 0) { - return diff; - } - - // Negate following comparisons so later edits show up first mvccVersion: later sorts first - return ignoreSequenceid? diff: Longs.compare(b.getSequenceId(), a.getSequenceId()); - } - - private static int compareRows(byte[] left, int loffset, int llength, byte[] right, int roffset, - int rlength) { - int leftDelimiter = Bytes.searchDelimiterIndex(left, loffset, llength, HConstants.DELIMITER); - int rightDelimiter = Bytes - .searchDelimiterIndex(right, roffset, rlength, HConstants.DELIMITER); - // Compare up to the delimiter - int lpart = (leftDelimiter < 0 ? llength : leftDelimiter - loffset); - int rpart = (rightDelimiter < 0 ? rlength : rightDelimiter - roffset); - int result = Bytes.compareTo(left, loffset, lpart, right, roffset, rpart); - if (result != 0) { - return result; - } else { - if (leftDelimiter < 0 && rightDelimiter >= 0) { - return -1; - } else if (rightDelimiter < 0 && leftDelimiter >= 0) { - return 1; - } else if (leftDelimiter < 0) { - return 0; - } - } - // Compare middle bit of the row. - // Move past delimiter - leftDelimiter++; - rightDelimiter++; - int leftFarDelimiter = Bytes.searchDelimiterIndexInReverse(left, leftDelimiter, llength - - (leftDelimiter - loffset), HConstants.DELIMITER); - int rightFarDelimiter = Bytes.searchDelimiterIndexInReverse(right, rightDelimiter, rlength - - (rightDelimiter - roffset), HConstants.DELIMITER); - // Now compare middlesection of row. - lpart = (leftFarDelimiter < 0 ? llength + loffset : leftFarDelimiter) - leftDelimiter; - rpart = (rightFarDelimiter < 0 ? rlength + roffset : rightFarDelimiter) - rightDelimiter; - result = Bytes.compareTo(left, leftDelimiter, lpart, right, rightDelimiter, rpart); - if (result != 0) { - return result; - } else { - if (leftDelimiter < 0 && rightDelimiter >= 0) { - return -1; - } else if (rightDelimiter < 0 && leftDelimiter >= 0) { - return 1; - } else if (leftDelimiter < 0) { - return 0; - } - } - // Compare last part of row, the rowid. - leftFarDelimiter++; - rightFarDelimiter++; - result = Bytes.compareTo(left, leftFarDelimiter, llength - (leftFarDelimiter - loffset), - right, rightFarDelimiter, rlength - (rightFarDelimiter - roffset)); - return result; - } - - @Override - public int compareRows(ByteBuffer row, Cell cell) { - byte [] array; - int offset; - int len = row.remaining(); - if (row.hasArray()) { - array = row.array(); - offset = row.position() + row.arrayOffset(); - } else { - // We copy the row array if offheap just so we can do a compare. We do this elsewhere too - // in BBUtils when Cell is backed by an offheap ByteBuffer. Needs fixing so no copy. TODO. - array = new byte[len]; - offset = 0; - ByteBufferUtils.copyFromBufferToArray(array, row, row.position(), - 0, len); - } - // Reverse result since we swap the order of the params we pass below. - return -compareRows(cell, array, offset, len); - } - - @Override - public Comparator getSimpleComparator() { - return this; - } - } - @Override public Comparator getSimpleComparator() { return new BBKVComparator(this); @@ -424,6 +302,6 @@ public class CellComparatorImpl implements CellComparator { public static CellComparator getCellComparator(byte [] tableName) { // FYI, TableName.toBytes does not create an array; just returns existing array pointer. return Bytes.equals(tableName, TableName.META_TABLE_NAME.toBytes())? - CellComparatorImpl.META_COMPARATOR: CellComparatorImpl.COMPARATOR; + MetaCellComparator.META_COMPARATOR: CellComparatorImpl.COMPARATOR; } } 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 ff09ea6c457..b7ddbab6c90 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 @@ -104,7 +104,8 @@ public class KeyValue implements ExtendedCell, Cloneable { /** * A {@link KVComparator} for hbase:meta catalog table * {@link KeyValue}s. - * @deprecated Use {@link CellComparatorImpl#META_COMPARATOR} instead. Deprecated for hbase 2.0, remove for hbase 3.0. + * @deprecated Use {@link MetaCellComparator#META_COMPARATOR} instead. + * Deprecated for hbase 2.0, remove for hbase 3.0. */ @Deprecated public static final KVComparator META_COMPARATOR = new MetaComparator(); @@ -1606,7 +1607,8 @@ public class KeyValue implements ExtendedCell, Cloneable { /** * A {@link KVComparator} for hbase:meta catalog table * {@link KeyValue}s. - * @deprecated : {@link CellComparatorImpl#META_COMPARATOR} to be used. Deprecated for hbase 2.0, remove for hbase 3.0. + * @deprecated : {@link MetaCellComparator#META_COMPARATOR} to be used. + * Deprecated for hbase 2.0, remove for hbase 3.0. */ @Deprecated public static class MetaComparator extends KVComparator { @@ -1616,7 +1618,8 @@ public class KeyValue implements ExtendedCell, Cloneable { */ @Override public int compare(final Cell left, final Cell right) { - return PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.META_COMPARATOR, left, right); + return PrivateCellUtil.compareKeyIgnoresMvcc(MetaCellComparator.META_COMPARATOR, left, + right); } @Override diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/MetaCellComparator.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/MetaCellComparator.java new file mode 100644 index 00000000000..4c18cfe79d2 --- /dev/null +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/MetaCellComparator.java @@ -0,0 +1,150 @@ +/* + * 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.nio.ByteBuffer; +import java.util.Comparator; + +import org.apache.hadoop.hbase.util.ByteBufferUtils; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.yetus.audience.InterfaceAudience; +import org.apache.yetus.audience.InterfaceStability; + +import org.apache.hbase.thirdparty.com.google.common.primitives.Longs; + +/** + * A {@link CellComparatorImpl} for hbase:meta catalog table + * {@link KeyValue}s. + */ +@InterfaceAudience.Private +@InterfaceStability.Evolving +public class MetaCellComparator extends CellComparatorImpl { + + /** + * A {@link MetaCellComparator} for hbase:meta catalog table + * {@link KeyValue}s. + */ + public static final MetaCellComparator META_COMPARATOR = new MetaCellComparator(); + + // TODO: Do we need a ByteBufferKeyValue version of this? + @Override + public int compareRows(final Cell left, final Cell right) { + return compareRows(left.getRowArray(), left.getRowOffset(), left.getRowLength(), + right.getRowArray(), right.getRowOffset(), right.getRowLength()); + } + + @Override + public int compareRows(Cell left, byte[] right, int roffset, int rlength) { + return compareRows(left.getRowArray(), left.getRowOffset(), left.getRowLength(), right, roffset, + rlength); + } + + @Override + public int compare(final Cell a, final Cell b, boolean ignoreSequenceid) { + int diff = compareRows(a, b); + if (diff != 0) { + return diff; + } + + diff = compareWithoutRow(a, b); + if (diff != 0) { + return diff; + } + + // Negate following comparisons so later edits show up first mvccVersion: later sorts first + return ignoreSequenceid ? diff : Longs.compare(b.getSequenceId(), a.getSequenceId()); + } + + private static int compareRows(byte[] left, int loffset, int llength, byte[] right, int roffset, + int rlength) { + int leftDelimiter = Bytes.searchDelimiterIndex(left, loffset, llength, HConstants.DELIMITER); + int rightDelimiter = Bytes.searchDelimiterIndex(right, roffset, rlength, HConstants.DELIMITER); + // Compare up to the delimiter + int lpart = (leftDelimiter < 0 ? llength : leftDelimiter - loffset); + int rpart = (rightDelimiter < 0 ? rlength : rightDelimiter - roffset); + int result = Bytes.compareTo(left, loffset, lpart, right, roffset, rpart); + if (result != 0) { + return result; + } else { + if (leftDelimiter < 0 && rightDelimiter >= 0) { + return -1; + } else if (rightDelimiter < 0 && leftDelimiter >= 0) { + return 1; + } else if (leftDelimiter < 0) { + return 0; + } + } + // Compare middle bit of the row. + // Move past delimiter + leftDelimiter++; + rightDelimiter++; + int leftFarDelimiter = Bytes + .searchDelimiterIndexInReverse(left, leftDelimiter, llength - (leftDelimiter - loffset), + HConstants.DELIMITER); + int rightFarDelimiter = Bytes + .searchDelimiterIndexInReverse(right, rightDelimiter, rlength - (rightDelimiter - roffset), + HConstants.DELIMITER); + // Now compare middlesection of row. + lpart = (leftFarDelimiter < 0 ? llength + loffset : leftFarDelimiter) - leftDelimiter; + rpart = (rightFarDelimiter < 0 ? rlength + roffset : rightFarDelimiter) - rightDelimiter; + result = Bytes.compareTo(left, leftDelimiter, lpart, right, rightDelimiter, rpart); + if (result != 0) { + return result; + } else { + if (leftDelimiter < 0 && rightDelimiter >= 0) { + return -1; + } else if (rightDelimiter < 0 && leftDelimiter >= 0) { + return 1; + } else if (leftDelimiter < 0) { + return 0; + } + } + // Compare last part of row, the rowid. + leftFarDelimiter++; + rightFarDelimiter++; + result = Bytes.compareTo(left, leftFarDelimiter, llength - (leftFarDelimiter - loffset), right, + rightFarDelimiter, rlength - (rightFarDelimiter - roffset)); + return result; + } + + @Override + public int compareRows(ByteBuffer row, Cell cell) { + byte[] array; + int offset; + int len = row.remaining(); + if (row.hasArray()) { + array = row.array(); + offset = row.position() + row.arrayOffset(); + } else { + // We copy the row array if offheap just so we can do a compare. We do this elsewhere too + // in BBUtils when Cell is backed by an offheap ByteBuffer. Needs fixing so no copy. TODO. + array = new byte[len]; + offset = 0; + ByteBufferUtils.copyFromBufferToArray(array, row, row.position(), 0, len); + } + // Reverse result since we swap the order of the params we pass below. + return -compareRows(cell, array, offset, len); + } + + @Override + public Comparator getSimpleComparator() { + return this; + } + +} 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 a3185158324..7762330a45b 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 @@ -146,7 +146,7 @@ public class TestCellComparator { Bytes.toBytes("TestScanMultipleVersions,row_0500,1236020145502"), now)); Cell bbb = createByteBufferKeyValueFromKeyValue(new KeyValue( Bytes.toBytes("TestScanMultipleVersions,,99999999999999"), now)); - CellComparator c = CellComparatorImpl.META_COMPARATOR; + CellComparator c = MetaCellComparator.META_COMPARATOR; assertTrue(c.compare(bbb, aaa) < 0); Cell ccc = createByteBufferKeyValueFromKeyValue( @@ -177,7 +177,7 @@ public class TestCellComparator { @Test public void testMetaComparisons2() { long now = System.currentTimeMillis(); - CellComparator c = CellComparatorImpl.META_COMPARATOR; + CellComparator c = MetaCellComparator.META_COMPARATOR; assertTrue(c.compare(createByteBufferKeyValueFromKeyValue(new KeyValue( Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",a,,0,1"), now)), createByteBufferKeyValueFromKeyValue(new KeyValue( @@ -240,7 +240,7 @@ public class TestCellComparator { } assertTrue(assertion); // Make set with good comparator - set = new TreeSet<>(CellComparatorImpl.META_COMPARATOR); + set = new TreeSet<>(MetaCellComparator.META_COMPARATOR); Collections.addAll(set, keys); count = 0; for (Cell k: set) { diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java index 305c524e843..ab574cff7a9 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java @@ -151,7 +151,7 @@ public class TestKeyValue { Bytes.toBytes("TestScanMultipleVersions,row_0500,1236020145502"), now); KeyValue bbb = new KeyValue( Bytes.toBytes("TestScanMultipleVersions,,99999999999999"), now); - CellComparator c = CellComparatorImpl.META_COMPARATOR; + CellComparator c = MetaCellComparator.META_COMPARATOR; assertTrue(c.compare(bbb, aaa) < 0); KeyValue aaaa = new KeyValue(Bytes.toBytes("TestScanMultipleVersions,,1236023996656"), @@ -166,14 +166,14 @@ public class TestKeyValue { Bytes.toBytes("info"), Bytes.toBytes("regioninfo"), 1236034574912L, (byte[])null); assertTrue(c.compare(x, y) < 0); - comparisons(CellComparatorImpl.META_COMPARATOR); + comparisons(MetaCellComparator.META_COMPARATOR); comparisons(CellComparatorImpl.COMPARATOR); - metacomparisons(CellComparatorImpl.META_COMPARATOR); + metacomparisons(MetaCellComparator.META_COMPARATOR); } @Test public void testMetaComparatorTableKeysWithCommaOk() { - CellComparator c = CellComparatorImpl.META_COMPARATOR; + CellComparator c = MetaCellComparator.META_COMPARATOR; long now = System.currentTimeMillis(); // meta keys values are not quite right. A users can enter illegal values // from shell when scanning meta. @@ -194,13 +194,13 @@ public class TestKeyValue { Bytes.toBytes("fam"), Bytes.toBytes(""), Long.MAX_VALUE, (byte[])null); KeyValue rowB = new KeyValue(Bytes.toBytes("testtable,www.hbase.org/%20,99999"), Bytes.toBytes("fam"), Bytes.toBytes(""), Long.MAX_VALUE, (byte[])null); - assertTrue(CellComparatorImpl.META_COMPARATOR.compare(rowA, rowB) < 0); + assertTrue(MetaCellComparator.META_COMPARATOR.compare(rowA, rowB) < 0); rowA = new KeyValue(Bytes.toBytes("testtable,,1234"), Bytes.toBytes("fam"), Bytes.toBytes(""), Long.MAX_VALUE, (byte[])null); rowB = new KeyValue(Bytes.toBytes("testtable,$www.hbase.org/,99999"), Bytes.toBytes("fam"), Bytes.toBytes(""), Long.MAX_VALUE, (byte[])null); - assertTrue(CellComparatorImpl.META_COMPARATOR.compare(rowA, rowB) < 0); + assertTrue(MetaCellComparator.META_COMPARATOR.compare(rowA, rowB) < 0); } private void metacomparisons(final CellComparatorImpl c) { @@ -264,7 +264,7 @@ public class TestKeyValue { } assertTrue(assertion); // Make set with good comparator - set = new TreeSet<>(CellComparatorImpl.META_COMPARATOR); + set = new TreeSet<>(MetaCellComparator.META_COMPARATOR); Collections.addAll(set, keys); count = 0; for (KeyValue k : set) { @@ -519,7 +519,7 @@ public class TestKeyValue { @Test public void testMetaKeyComparator() { - CellComparator c = CellComparatorImpl.META_COMPARATOR; + CellComparator c = MetaCellComparator.META_COMPARATOR; long now = System.currentTimeMillis(); KeyValue a = new KeyValue(Bytes.toBytes("table1"), now); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java index 35fb2818e63..cae284a1d40 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java @@ -29,8 +29,8 @@ import java.nio.ByteBuffer; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellComparatorImpl; -import org.apache.hadoop.hbase.CellComparatorImpl.MetaCellComparator; import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.MetaCellComparator; import org.apache.hadoop.hbase.io.compress.Compression; import org.apache.hadoop.hbase.util.Bytes; import org.apache.yetus.audience.InterfaceAudience; @@ -613,8 +613,7 @@ public class FixedFileTrailer { comparatorKlass = CellComparatorImpl.class; } else if (comparatorClassName.equals(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName()) || comparatorClassName.equals(KeyValue.META_COMPARATOR.getClass().getName()) - || (comparatorClassName - .equals("org.apache.hadoop.hbase.CellComparator$MetaCellComparator"))) { + || (comparatorClassName.equals("org.apache.hadoop.hbase.MetaCellComparator"))) { comparatorKlass = MetaCellComparator.class; } else if (comparatorClassName.equals("org.apache.hadoop.hbase.KeyValue$RawBytesComparator") || comparatorClassName.equals("org.apache.hadoop.hbase.util.Bytes$ByteArrayComparator")) { @@ -636,8 +635,8 @@ public class FixedFileTrailer { if (comparatorClassName.equals(CellComparatorImpl.COMPARATOR.getClass().getName())) { return CellComparatorImpl.COMPARATOR; } else if (comparatorClassName.equals( - CellComparatorImpl.META_COMPARATOR.getClass().getName())) { - return CellComparatorImpl.META_COMPARATOR; + MetaCellComparator.META_COMPARATOR.getClass().getName())) { + return MetaCellComparator.META_COMPARATOR; } try { Class comparatorClass = getComparatorClass(comparatorClassName); 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 dd05963c26e..3f56379dc8e 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 @@ -33,10 +33,10 @@ import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hbase.ByteBufferExtendedCell; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparator; -import org.apache.hadoop.hbase.CellComparatorImpl.MetaCellComparator; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValueUtil; +import org.apache.hadoop.hbase.MetaCellComparator; import org.apache.hadoop.hbase.PrivateCellUtil; import org.apache.hadoop.hbase.io.compress.Compression; import org.apache.hadoop.hbase.io.crypto.Encryption; 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 2cffa32c57c..1e1bc6a53db 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 @@ -82,7 +82,6 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellBuilderType; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellComparatorImpl; -import org.apache.hadoop.hbase.CellComparatorImpl.MetaCellComparator; import org.apache.hadoop.hbase.CellScanner; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.CompareOperator; @@ -94,6 +93,7 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants.OperationStatusCode; import org.apache.hadoop.hbase.HDFSBlocksDistribution; import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.MetaCellComparator; import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.NotServingRegionException; import org.apache.hadoop.hbase.PrivateCellUtil; @@ -780,8 +780,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi this.conf = new CompoundConfiguration().add(confParam).addBytesMap(htd.getValues()); this.cellComparator = htd.isMetaTable() || conf.getBoolean(USE_META_CELL_COMPARATOR, DEFAULT_USE_META_CELL_COMPARATOR) ? - CellComparatorImpl.META_COMPARATOR : - CellComparatorImpl.COMPARATOR; + MetaCellComparator.META_COMPARATOR : CellComparatorImpl.COMPARATOR; this.lock = new ReentrantReadWriteLock(conf.getBoolean(FAIR_REENTRANT_CLOSE_LOCK, DEFAULT_FAIR_REENTRANT_CLOSE_LOCK)); this.flushCheckInterval = conf.getInt(MEMSTORE_PERIODIC_FLUSH_INTERVAL, diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/BoundedRecoveredHFilesOutputSink.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/BoundedRecoveredHFilesOutputSink.java index ea78cf2ee4e..cf5713da020 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/BoundedRecoveredHFilesOutputSink.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/BoundedRecoveredHFilesOutputSink.java @@ -32,6 +32,7 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparatorImpl; import org.apache.hadoop.hbase.CellUtil; +import org.apache.hadoop.hbase.MetaCellComparator; import org.apache.hadoop.hbase.PrivateCellUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.io.hfile.CacheConfig; @@ -91,7 +92,7 @@ public class BoundedRecoveredHFilesOutputSink extends OutputSink { familyCells .computeIfAbsent(familyName, key -> new CellSet( - isMetaTable ? CellComparatorImpl.META_COMPARATOR : CellComparatorImpl.COMPARATOR)) + isMetaTable ? MetaCellComparator.META_COMPARATOR : CellComparatorImpl.COMPARATOR)) .add(cell); familySeqIds.compute(familyName, (k, v) -> v == null ? seqId : Math.max(v, seqId)); } @@ -201,7 +202,7 @@ public class BoundedRecoveredHFilesOutputSink extends OutputSink { withChecksumType(HStore.getChecksumType(walSplitter.conf)). withBytesPerCheckSum(HStore.getBytesPerChecksum(walSplitter.conf)). withCellComparator(isMetaTable? - CellComparatorImpl.META_COMPARATOR: CellComparatorImpl.COMPARATOR).build(); + MetaCellComparator.META_COMPARATOR: CellComparatorImpl.COMPARATOR).build(); return writerBuilder.withFileContext(hFileContext).build(); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/MetaMockingUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/MetaMockingUtil.java index 66c6f95171a..eb616bb1d28 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/MetaMockingUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/MetaMockingUtil.java @@ -100,7 +100,7 @@ public class MetaMockingUtil { } //important: sort the kvs so that binary search work - Collections.sort(kvs, CellComparatorImpl.META_COMPARATOR); + Collections.sort(kvs, MetaCellComparator.META_COMPARATOR); return Result.create(kvs); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestFixedFileTrailer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestFixedFileTrailer.java index 14006a822cf..a5215bfe1d9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestFixedFileTrailer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestFixedFileTrailer.java @@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.CellComparatorImpl; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.MetaCellComparator; import org.apache.hadoop.hbase.shaded.protobuf.generated.HFileProtos; import org.apache.hadoop.hbase.testclassification.IOTests; import org.apache.hadoop.hbase.testclassification.SmallTests; @@ -109,7 +110,7 @@ public class TestFixedFileTrailer { assertEquals(CellComparatorImpl.COMPARATOR.getClass().getName(), t.getComparatorClassName()); HFileProtos.FileTrailerProto pb = t.toProtobuf(); assertEquals(KeyValue.COMPARATOR.getClass().getName(), pb.getComparatorClassName()); - t.setComparatorClass(CellComparatorImpl.MetaCellComparator.META_COMPARATOR.getClass()); + t.setComparatorClass(MetaCellComparator.META_COMPARATOR.getClass()); pb = t.toProtobuf(); assertEquals(KeyValue.META_COMPARATOR.getClass().getName(), pb.getComparatorClassName()); @@ -125,16 +126,16 @@ public class TestFixedFileTrailer { t.createComparator(KeyValue.COMPARATOR.getClass().getName()).getClass()); assertEquals(CellComparatorImpl.class, t.createComparator(CellComparator.class.getName()).getClass()); - assertEquals(CellComparatorImpl.MetaCellComparator.class, + assertEquals(MetaCellComparator.class, t.createComparator(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName()).getClass()); - assertEquals(CellComparatorImpl.MetaCellComparator.class, + assertEquals(MetaCellComparator.class, t.createComparator(KeyValue.META_COMPARATOR.getClass().getName()).getClass()); - assertEquals(CellComparatorImpl.MetaCellComparator.class, t.createComparator( - CellComparatorImpl.MetaCellComparator.META_COMPARATOR.getClass().getName()).getClass()); - assertEquals(CellComparatorImpl.META_COMPARATOR.getClass(), t.createComparator( - CellComparatorImpl.MetaCellComparator.META_COMPARATOR.getClass().getName()).getClass()); + assertEquals(MetaCellComparator.class, t.createComparator( + MetaCellComparator.META_COMPARATOR.getClass().getName()).getClass()); + assertEquals(MetaCellComparator.META_COMPARATOR.getClass(), t.createComparator( + MetaCellComparator.META_COMPARATOR.getClass().getName()).getClass()); assertEquals(CellComparatorImpl.COMPARATOR.getClass(), t.createComparator( - CellComparatorImpl.MetaCellComparator.COMPARATOR.getClass().getName()).getClass()); + MetaCellComparator.COMPARATOR.getClass().getName()).getClass()); assertNull(t.createComparator(Bytes.BYTES_RAWCOMPARATOR.getClass().getName())); assertNull(t.createComparator("org.apache.hadoop.hbase.KeyValue$RawBytesComparator")); } catch (IOException e) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java index 1ec5929c936..1b5018ce352 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java @@ -60,6 +60,7 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue.Type; import org.apache.hadoop.hbase.KeyValueUtil; +import org.apache.hadoop.hbase.MetaCellComparator; import org.apache.hadoop.hbase.PrivateCellUtil; import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.io.ByteBuffAllocator; @@ -736,7 +737,7 @@ public class TestHFile { // optimization done. left = CellUtil.createCell(Bytes.toBytes("g"), Bytes.toBytes("a"), Bytes.toBytes("a")); right = CellUtil.createCell(Bytes.toBytes("i"), Bytes.toBytes("a"), Bytes.toBytes("a")); - mid = HFileWriterImpl.getMidpoint(CellComparatorImpl.META_COMPARATOR, left, right); + mid = HFileWriterImpl.getMidpoint(MetaCellComparator.META_COMPARATOR, left, right); assertTrue(PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.COMPARATOR, left, mid) < 0); assertTrue(PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.COMPARATOR, mid, right) == 0); @@ -788,7 +789,7 @@ public class TestHFile { assertTrue(newKey.getTypeByte() == Type.Maximum.getCode()); // verify metaKeyComparator's getShortMidpointKey output - final CellComparatorImpl metaKeyComparator = CellComparatorImpl.META_COMPARATOR; + final CellComparatorImpl metaKeyComparator = MetaCellComparator.META_COMPARATOR; kv1 = new KeyValue(Bytes.toBytes("ilovehbase123"), family, qualA, 5, Type.Put); kv2 = new KeyValue(Bytes.toBytes("ilovehbase234"), family, qualA, 0, Type.Put); newKey = HFileWriterImpl.getMidpoint(metaKeyComparator, kv1, kv2);