diff --git a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/WALPlayer.java b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/WALPlayer.java index 3c34942d262..52518877c79 100644 --- a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/WALPlayer.java +++ b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/WALPlayer.java @@ -364,7 +364,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/AbstractProtobufLogWriter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractProtobufLogWriter.java index ae084a438e9..ff2864d533f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractProtobufLogWriter.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractProtobufLogWriter.java @@ -80,7 +80,8 @@ public abstract class AbstractProtobufLogWriter { builder.setWriterClsName(getWriterClassName()); } 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 34d83f7817a..5aa943f1d84 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 @@ -24,7 +24,6 @@ import java.io.OutputStream; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.PrivateCellUtil; import org.apache.hadoop.hbase.KeyValue; @@ -82,8 +81,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); } /** @@ -102,7 +101,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 }); @@ -121,7 +120,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 9391a85f4af..6add84fa7a3 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 @@ -64,4 +64,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); + } }