From a9cd6bc61df0b5602fdeb93820207ea5fc4628f3 Mon Sep 17 00:00:00 2001 From: Benoit Sigoure Date: Sat, 14 Jan 2012 20:39:27 -0800 Subject: [PATCH 3/3] Change the code used when serializing `HTableDescriptor[]'. In HBASE-451 this class was carelessly inserted in the middle of the map, which shifted all the codes by one and makes backwards compatibility even more of a nightmare than it already is. --- .../hadoop/hbase/io/HbaseObjectWritable.java | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java b/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java index 0c598cf..ecd474c 100644 --- a/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java +++ b/src/main/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java @@ -121,6 +121,14 @@ public class HbaseObjectWritable implements Writable, WritableWithSize, Configur // sending of the class name using reflection, etc. private static final byte NOT_ENCODED = 0; static { + //////////////////////////////////////////////////////////////////////////// + // WARNING: Please do not insert, remove or swap any line in this static // + // block. Doing so would change or shift all the codes used to serialize // + // objects, which makes backwards compatibility very hard for clients. // + // New codes should always be added at the end. Codes removed should be // + // replaced with another class. // + //////////////////////////////////////////////////////////////////////////// + int code = NOT_ENCODED + 1; // Primitive types. addToMap(Boolean.TYPE, code++); @@ -163,7 +171,6 @@ public class HbaseObjectWritable implements Writable, WritableWithSize, Configur addToMap(HServerAddress.class, code++); addToMap(HServerInfo.class, code++); addToMap(HTableDescriptor.class, code++); - addToMap(HTableDescriptor[].class, code++); addToMap(MapWritable.class, code++); // @@ -220,7 +227,7 @@ public class HbaseObjectWritable implements Writable, WritableWithSize, Configur addToMap(Increment.class, code++); addToMap(KeyOnlyFilter.class, code++); - + // serializable addToMap(Serializable.class, code++); @@ -231,9 +238,10 @@ public class HbaseObjectWritable implements Writable, WritableWithSize, Configur addToMap(ColumnRangeFilter.class, code++); addToMap(HServerLoad.class, code++); - + addToMap(RegionOpeningState.class, code++); - + + addToMap(HTableDescriptor[].class, code++); } private Class declaredClass; @@ -588,7 +596,7 @@ public class HbaseObjectWritable implements Writable, WritableWithSize, Configur in.readFully(objectBytes); ByteArrayInputStream bis = null; ObjectInputStream ois = null; - try { + try { bis = new ByteArrayInputStream(objectBytes); ois = new ObjectInputStream(bis); instance = ois.readObject(); -- 1.7.9.rc0.24.ga04fb