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

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


The following commit(s) were added to refs/heads/branch-1.3 by this push:
     new ef58d78  HBASE-21492 CellCodec Written To WAL Before It's Verified
ef58d78 is described below

commit ef58d789921283022d05371bb68a9d2950f6857f
Author: BELUGA BEHR <[email protected]>
AuthorDate: Tue Nov 27 08:57:06 2018 -0800

    HBASE-21492 CellCodec Written To WAL Before It's Verified
    
    Conflicts:
        
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractProtobufLogWriter.java
---
 .../java/org/apache/hadoop/hbase/mapreduce/WALPlayer.java     |  2 +-
 .../hadoop/hbase/regionserver/wal/ProtobufLogWriter.java      |  2 +-
 .../apache/hadoop/hbase/regionserver/wal/WALCellCodec.java    |  8 ++++----
 .../hadoop/hbase/regionserver/wal/TestCustomWALCellCodec.java | 11 +++++++++++
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/WALPlayer.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/WALPlayer.java
index 377b6ea..bff110c 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/WALPlayer.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/WALPlayer.java
@@ -295,7 +295,7 @@ public class WALPlayer extends Configured implements Tool {
       // No reducers.
       job.setNumReduceTasks(0);
     }
-    String codecCls = WALCellCodec.getWALCellCodecClass(conf);
+    String codecCls = WALCellCodec.getWALCellCodecClass(conf).getName();
     try {
       TableMapReduceUtil.addDependencyJarsForClasses(job.getConfiguration(), 
Class.forName(codecCls));
     } catch (Exception e) {
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/ProtobufLogWriter.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/ProtobufLogWriter.java
index 42abeae..436df87 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/ProtobufLogWriter.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/ProtobufLogWriter.java
@@ -69,7 +69,7 @@ public class ProtobufLogWriter extends WriterBase {
       builder.setWriterClsName(ProtobufLogWriter.class.getSimpleName());
     }
     if (!builder.hasCellCodecClsName()) {
-      builder.setCellCodecClsName(WALCellCodec.getWALCellCodecClass(conf));
+      
builder.setCellCodecClsName(WALCellCodec.getWALCellCodecClass(conf).getName());
     }
     return builder.build();
   }
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALCellCodec.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALCellCodec.java
index 5c62ef2..11b6120 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALCellCodec.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALCellCodec.java
@@ -79,8 +79,8 @@ public class WALCellCodec implements Codec {
     this.compression = compression;
   }
 
-  public static String getWALCellCodecClass(Configuration conf) {
-    return conf.get(WAL_CELL_CODEC_CLASS_KEY, WALCellCodec.class.getName());
+  public static Class<?> getWALCellCodecClass(Configuration conf) {
+    return conf.getClass(WAL_CELL_CODEC_CLASS_KEY, WALCellCodec.class);
   }
 
   /**
@@ -98,7 +98,7 @@ public class WALCellCodec implements Codec {
   public static WALCellCodec create(Configuration conf, String 
cellCodecClsName,
       CompressionContext compression) throws UnsupportedOperationException {
     if (cellCodecClsName == null) {
-      cellCodecClsName = getWALCellCodecClass(conf);
+      cellCodecClsName = getWALCellCodecClass(conf).getName();
     }
     return ReflectionUtils.instantiateWithCustomCtor(cellCodecClsName, new 
Class[]
         { Configuration.class, CompressionContext.class }, new Object[] { 
conf, compression });
@@ -117,7 +117,7 @@ public class WALCellCodec implements Codec {
    */
   public static WALCellCodec create(Configuration conf,
       CompressionContext compression) throws UnsupportedOperationException {
-    String cellCodecClsName = getWALCellCodecClass(conf);
+    String cellCodecClsName = getWALCellCodecClass(conf).getName();
     return ReflectionUtils.instantiateWithCustomCtor(cellCodecClsName, new 
Class[]
         { Configuration.class, CompressionContext.class }, new Object[] { 
conf, compression });
   }
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestCustomWALCellCodec.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestCustomWALCellCodec.java
index 7f48f9b..c5200b4 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestCustomWALCellCodec.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestCustomWALCellCodec.java
@@ -58,4 +58,15 @@ public class TestCustomWALCellCodec {
     assertEquals("Custom codec didn't get initialized with the right 
compression context!", null,
       codec.context);
   }
+
+  /**
+   * Test that a custom {@link WALCellCodec} will fail if provided an invalid
+   * code class.
+   */
+  @Test(expected = RuntimeException.class)
+  public void testCreatePreparesCodecInvalidClass() throws Exception {
+    Configuration conf = new Configuration(false);
+    conf.setStrings(WALCellCodec.WAL_CELL_CODEC_CLASS_KEY, 
"org.apache.hbase.wal.NoSuchClass");
+    WALCellCodec.create(conf, null, null);
+  }
 }

Reply via email to