Repository: hbase
Updated Branches:
  refs/heads/branch-2.1 5e12d6a98 -> 873d9f508


HBASE-21012 Revert the change of serializing TimeRangeTracker

Signed-off-by: Michael Stack <st...@apache.org>
Signed-off-by: zhangduo <zhang...@apache.org>
Signed-off-by: Chia-Ping Tsai <chia7...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/873d9f50
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/873d9f50
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/873d9f50

Branch: refs/heads/branch-2.1
Commit: 873d9f50822aceec70bf3703362185e6498d1c91
Parents: 5e12d6a
Author: brandboat <brandb...@gmail.com>
Authored: Thu Aug 9 12:27:25 2018 +0800
Committer: Chia-Ping Tsai <chia7...@gmail.com>
Committed: Sat Aug 11 22:28:49 2018 +0800

----------------------------------------------------------------------
 .../hbase/regionserver/TimeRangeTracker.java    | 27 +++++++++++++++-----
 src/main/asciidoc/_chapters/upgrading.adoc      | 12 +++++++++
 2 files changed, 32 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/873d9f50/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/TimeRangeTracker.java
----------------------------------------------------------------------
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..d995fc6 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
+   * forward compatibility 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 DataOutput. For more information, please check 
HBASE-21012.
+   * @param tracker TimeRangeTracker needed to be serialized.
+   * @return byte array filled with serialized TimeRangeTracker.
+   * @throws IOException if something goes wrong in writeLong.
+   */
+  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();
+      }
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/873d9f50/src/main/asciidoc/_chapters/upgrading.adoc
----------------------------------------------------------------------
diff --git a/src/main/asciidoc/_chapters/upgrading.adoc 
b/src/main/asciidoc/_chapters/upgrading.adoc
index bc2ec1c..6dc788a 100644
--- a/src/main/asciidoc/_chapters/upgrading.adoc
+++ b/src/main/asciidoc/_chapters/upgrading.adoc
@@ -588,6 +588,18 @@ 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.compatability]]
+.HFile lose forward compatability
+
+HFiles generated by 2.0.0, 2.0.1, 2.1.0 are not forward compatible to 1.4.6-, 
1.3.2.1-, 1.2.6.1-,
+and other inactive releases. 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. 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.
+For more information, please check
+link:https://jira.apache.org/jira/browse/HBASE-21008[HBASE-21008].
+
 [[upgrade2.0.perf]]
 .Performance
 

Reply via email to