From 6c06b1e923474c608914d6fd376ee0532a157881 Mon Sep 17 00:00:00 2001 From: BELUGA BEHR Date: Tue, 27 Nov 2018 08:57:06 -0800 Subject: [PATCH] HBASE-21492 CellCodec Written To WAL Before It's Verified Conflicts: hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractProtobufLogWriter.java --- .../org/apache/hadoop/hbase/mapreduce/WALPlayer.java | 2 +- .../hbase/regionserver/wal/ProtobufLogWriter.java | 2 +- .../hadoop/hbase/regionserver/wal/WALCellCodec.java | 8 ++++---- .../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 377b6eabf7..bff110cc3b 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 cb9e5a53f1..2e4226f17d 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 5c62ef2ce2..11b6120e59 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 7f48f9b046..c5200b48c4 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); + } } -- 2.19.0