From 746e8e0f1a3123ebe402abdefb9f8d04879e8016 Mon Sep 17 00:00:00 2001 From: brandboat Date: Wed, 8 Aug 2018 16:21:59 +0800 Subject: [PATCH] Revert the change of serializing TimeRangeTracker --- .../hbase/regionserver/TimeRangeTracker.java | 27 ++++++++++++++++------ src/main/asciidoc/_chapters/upgrading.adoc | 10 ++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/TimeRangeTracker.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/TimeRangeTracker.java index 5c0eee5..22dc0dc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/TimeRangeTracker.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/TimeRangeTracker.java @@ -19,7 +19,9 @@ package org.apache.hadoop.hbase.regionserver; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.DataInputStream; +import java.io.DataOutputStream; import java.io.IOException; import java.util.concurrent.atomic.AtomicLong; @@ -206,13 +208,24 @@ public abstract class TimeRangeTracker { } } - public static byte[] toByteArray(TimeRangeTracker tracker) { - return ProtobufUtil.prependPBMagic( - HBaseProtos.TimeRangeTracker.newBuilder() - .setFrom(tracker.getMin()) - .setTo(tracker.getMax()) - .build() - .toByteArray()); + /** + * This method used to serialize TimeRangeTracker (TRT) by protobuf while this breaks the backward + * compatible on HFile.(See HBASE-21008) In previous hbase version ( < 2.0.0 ) we use DataOutput to + * serialize TRT, these old versions don't have capability to deserialize TRT which is serialized + * by protobuf. So we need to revert the change of serializing TimeRangeTracker back to DataOut. + * For more information, please check HBASE-21012. + * @param tracker TimeRangeTracker needed to be serialized. + * @return byte array filled with serialized TimeRangeTracker. + * @throws IOException + */ + public static byte[] toByteArray(TimeRangeTracker tracker) throws IOException { + try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { + try (DataOutputStream dos = new DataOutputStream(bos)) { + dos.writeLong(tracker.getMin()); + dos.writeLong(tracker.getMax()); + return bos.toByteArray(); + } + } } /** diff --git a/src/main/asciidoc/_chapters/upgrading.adoc b/src/main/asciidoc/_chapters/upgrading.adoc index bc2ec1c..24d867c 100644 --- a/src/main/asciidoc/_chapters/upgrading.adoc +++ b/src/main/asciidoc/_chapters/upgrading.adoc @@ -588,6 +588,16 @@ The internal changes to HBase during this upgrade were sufficient for compilatio If you previously relied on client side tracing integrated with HBase operations, it is recommended that you upgrade your usage to HTrace 4 as well. +[[upgrade2.0.hfile.backward.compatability]] +.HFile lose backward compatability + +HFiles generated by 2.0.0, 2.0.1, 2.1.0 are not backward compatible to 1.4.6-, 1.3.2.1-, 1.2.6.1-, and other +inactive releases. To solve this, We have to put link:https://jira.apache.org/jira/browse/HBASE-21012[HBASE-21012] +to 2.x and put link:https://jira.apache.org/jira/browse/HBASE-21013[HBASE-21013] in 1.x. Why HFile lose compatability is +hbase in new versions (2.0.0, 2.0.1, 2.1.0) use protobuf to serialize/deserialize TimeRangeTracker (TRT) while old +versions use DataInput/DataOutput. This breaks the HFile backward compatability. For more information, please check +link:https://jira.apache.org/jira/browse/HBASE-21008[HBASE-21008]. + [[upgrade2.0.perf]] .Performance -- 2.7.4