HBASE-21012 Revert the change of serializing TimeRangeTracker

Signed-off-by: Michael Stack <stack@apache.org>
Signed-off-by: zhangduo <zhangduo@apache.org>
Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
brandboat 2018-08-09 12:27:25 +08:00 committed by Chia-Ping Tsai
parent 5e12d6a98e
commit 873d9f5082
2 changed files with 32 additions and 7 deletions

View File

@ -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();
}
}
}
/**

View File

@ -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