This is an automated email from the ASF dual-hosted git repository.

zhangduo pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-3 by this push:
     new eea740cf5cf HBASE-28478 Remove the hbase1 compatible code in 
FixedFileTrailer (#5788)
eea740cf5cf is described below

commit eea740cf5cf35b09badf6f9f3e03fe0416659816
Author: Duo Zhang <zhang...@apache.org>
AuthorDate: Sun Apr 7 18:40:13 2024 +0800

    HBASE-28478 Remove the hbase1 compatible code in FixedFileTrailer (#5788)
    
    Signed-off-by: Bryan Beaudreault <bbeaudrea...@apache.org>
    (cherry picked from commit eeebbdfa723dd49aeaf4a6bc061382752002c5a6)
---
 .../hadoop/hbase/io/hfile/FixedFileTrailer.java    | 42 +-----------
 .../hbase/io/hfile/TestFixedFileTrailer.java       | 76 +++++++---------------
 2 files changed, 27 insertions(+), 91 deletions(-)

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 2a405197a48..eaf79f31103 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
@@ -26,7 +26,6 @@ import java.io.IOException;
 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.InnerStoreCellComparator;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.MetaCellComparator;
@@ -206,8 +205,7 @@ public class FixedFileTrailer {
       
.setTotalUncompressedBytes(totalUncompressedBytes).setDataIndexCount(dataIndexCount)
       .setMetaIndexCount(metaIndexCount).setEntryCount(entryCount)
       
.setNumDataIndexLevels(numDataIndexLevels).setFirstDataBlockOffset(firstDataBlockOffset)
-      .setLastDataBlockOffset(lastDataBlockOffset)
-      .setComparatorClassName(getHBase1CompatibleName(comparatorClassName))
+      
.setLastDataBlockOffset(lastDataBlockOffset).setComparatorClassName(comparatorClassName)
       .setCompressionCodec(compressionCodec.ordinal());
     if (encryptionKey != null) {
       builder.setEncryptionKey(UnsafeByteOperations.unsafeWrap(encryptionKey));
@@ -216,8 +214,7 @@ public class FixedFileTrailer {
   }
 
   /**
-   * Write trailer data as protobuf. NOTE: we run a translation on the 
comparator name and will
-   * serialize the old hbase-1.x where it makes sense. See {@link 
#getHBase1CompatibleName(String)}.
+   * Write trailer data as protobuf.
    */
   void serializeAsPB(DataOutputStream output) throws IOException {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -553,41 +550,6 @@ public class FixedFileTrailer {
     }
   }
 
-  /**
-   * If a 'standard' Comparator, write the old name for the Comparator when we 
serialize rather than
-   * the new name; writing the new name will make it so newly-written hfiles 
are not parseable by
-   * hbase-1.x, a facility we'd like to preserve across rolling upgrade and 
hbase-1.x clusters
-   * reading hbase-2.x produce.
-   * <p>
-   * The Comparators in hbase-2.x work the same as they did in hbase-1.x; they 
compare KeyValues. In
-   * hbase-2.x they were renamed making use of the more generic 'Cell' 
nomenclature to indicate that
-   * we intend to move away from KeyValues post hbase-2. A naming change is 
not reason enough to
-   * make it so hbase-1.x cannot read hbase-2.x files given the structure goes 
unchanged (hfile v3).
-   * So, lets write the old names for Comparators into the hfile tails in 
hbase-2. Here is where we
-   * do the translation. {@link #getComparatorClass(String)} does translation 
going the other way.
-   * <p>
-   * The translation is done on the serialized Protobuf only.
-   * </p>
-   * @param comparator String class name of the Comparator used in this hfile.
-   * @return What to store in the trailer as our comparator name.
-   * @see #getComparatorClass(String)
-   * @since hbase-2.0.0.
-   * @deprecated Since hbase-2.0.0. Will be removed in hbase-3.0.0.
-   */
-  @Deprecated
-  private String getHBase1CompatibleName(final String comparator) {
-    if (
-      comparator.equals(CellComparatorImpl.class.getName())
-        || comparator.equals(InnerStoreCellComparator.class.getName())
-    ) {
-      return KeyValue.COMPARATOR.getClass().getName();
-    }
-    if (comparator.equals(MetaCellComparator.class.getName())) {
-      return KeyValue.META_COMPARATOR.getClass().getName();
-    }
-    return comparator;
-  }
-
   @SuppressWarnings("unchecked")
   private static Class<? extends CellComparator> getComparatorClass(String 
comparatorClassName)
     throws IOException {
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 442f62e505d..3bad8d46a14 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
@@ -17,8 +17,10 @@
  */
 package org.apache.hadoop.hbase.io.hfile;
 
+import static 
org.apache.hadoop.hbase.io.hfile.FixedFileTrailer.createComparator;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -46,18 +48,14 @@ import 
org.apache.hadoop.hbase.testclassification.SmallTests;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.Before;
 import org.junit.ClassRule;
-import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
-import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.hadoop.hbase.shaded.protobuf.generated.HFileProtos;
-
 @RunWith(Parameterized.class)
 @Category({ IOTests.class, SmallTests.class })
 public class TestFixedFileTrailer {
@@ -88,9 +86,6 @@ public class TestFixedFileTrailer {
     this.version = version;
   }
 
-  @Rule
-  public ExpectedException expectedEx = ExpectedException.none();
-
   @Parameters
   public static Collection<Object[]> getParameters() {
     List<Object[]> versionsToTest = new ArrayList<>();
@@ -104,54 +99,33 @@ public class TestFixedFileTrailer {
     fs = FileSystem.get(util.getConfiguration());
   }
 
-  @Test
-  public void testComparatorIsHBase1Compatible() {
-    FixedFileTrailer t = new FixedFileTrailer(version, 
HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION);
-    t.setComparatorClass(CellComparatorImpl.COMPARATOR.getClass());
-    assertEquals(CellComparatorImpl.COMPARATOR.getClass().getName(), 
t.getComparatorClassName());
-    HFileProtos.FileTrailerProto pb = t.toProtobuf();
-    assertEquals(KeyValue.COMPARATOR.getClass().getName(), 
pb.getComparatorClassName());
-    t.setComparatorClass(MetaCellComparator.META_COMPARATOR.getClass());
-    pb = t.toProtobuf();
-    assertEquals(KeyValue.META_COMPARATOR.getClass().getName(), 
pb.getComparatorClassName());
-  }
-
   @Test
   public void testCreateComparator() throws IOException {
-    FixedFileTrailer t = new FixedFileTrailer(version, 
HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION);
-    try {
-      assertEquals(InnerStoreCellComparator.class,
-        
t.createComparator(KeyValue.COMPARATOR.getLegacyKeyComparatorName()).getClass());
-      assertEquals(InnerStoreCellComparator.class,
-        
t.createComparator(KeyValue.COMPARATOR.getClass().getName()).getClass());
-      assertEquals(InnerStoreCellComparator.class,
-        t.createComparator(CellComparator.class.getName()).getClass());
-      assertEquals(MetaCellComparator.class,
-        
t.createComparator(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName()).getClass());
-      assertEquals(MetaCellComparator.class,
-        
t.createComparator(KeyValue.META_COMPARATOR.getClass().getName()).getClass());
-      assertEquals(MetaCellComparator.class,
-        
t.createComparator("org.apache.hadoop.hbase.CellComparator$MetaCellComparator").getClass());
-      assertEquals(MetaCellComparator.class,
-        
t.createComparator("org.apache.hadoop.hbase.CellComparatorImpl$MetaCellComparator")
-          .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(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) {
-      fail("Unexpected exception while testing 
FixedFileTrailer#createComparator(), "
-        + e.getMessage());
-    }
+    assertEquals(InnerStoreCellComparator.class,
+      
createComparator(KeyValue.COMPARATOR.getLegacyKeyComparatorName()).getClass());
+    assertEquals(InnerStoreCellComparator.class,
+      createComparator(KeyValue.COMPARATOR.getClass().getName()).getClass());
+    assertEquals(InnerStoreCellComparator.class,
+      createComparator(CellComparator.class.getName()).getClass());
+    assertEquals(MetaCellComparator.class,
+      
createComparator(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName()).getClass());
+    assertEquals(MetaCellComparator.class,
+      
createComparator(KeyValue.META_COMPARATOR.getClass().getName()).getClass());
+    assertEquals(MetaCellComparator.class,
+      
createComparator("org.apache.hadoop.hbase.CellComparator$MetaCellComparator").getClass());
+    assertEquals(MetaCellComparator.class,
+      
createComparator("org.apache.hadoop.hbase.CellComparatorImpl$MetaCellComparator").getClass());
+    assertEquals(MetaCellComparator.class,
+      
createComparator(MetaCellComparator.META_COMPARATOR.getClass().getName()).getClass());
+    assertEquals(MetaCellComparator.META_COMPARATOR.getClass(),
+      
createComparator(MetaCellComparator.META_COMPARATOR.getClass().getName()).getClass());
+    assertEquals(CellComparatorImpl.COMPARATOR.getClass(),
+      
createComparator(MetaCellComparator.COMPARATOR.getClass().getName()).getClass());
+    
assertNull(createComparator(Bytes.BYTES_RAWCOMPARATOR.getClass().getName()));
+    
assertNull(createComparator("org.apache.hadoop.hbase.KeyValue$RawBytesComparator"));
 
     // Test an invalid comparatorClassName
-    expectedEx.expect(IOException.class);
-    t.createComparator("");
-
+    assertThrows(IOException.class, () -> createComparator(""));
   }
 
   @Test

Reply via email to