Skip to content

Commit

Permalink
OAK-2861 TARMK Cold Standby better binary decoding
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1678758 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
stillalex committed May 11, 2015
1 parent 8569d84 commit 7712579
Showing 1 changed file with 23 additions and 4 deletions.
Expand Up @@ -113,8 +113,18 @@ private Segment decodeSegment(ByteBuf in, int len, byte type) {
long msb = in.readLong();
long lsb = in.readLong();
long hash = in.readLong();
byte[] segment = new byte[len - 25];
in.readBytes(segment);

// #readBytes throws a 'REPLAY' exception if there are not enough bytes
// available for reading
ByteBuf data = in.readBytes(len - 25);
byte[] segment;
if (data.hasArray()) {
segment = data.array();
} else {
segment = new byte[len - 25];
in.readBytes(segment);
}

Hasher hasher = Hashing.murmur3_32().newHasher();
long check = hasher.putBytes(segment).hash().padToLong();
if (hash == check) {
Expand All @@ -135,8 +145,17 @@ private IdArrayBasedBlob decodeBlob(ByteBuf in, int length, byte type) {
String id = new String(bid, Charset.forName("UTF-8"));

long hash = in.readLong();
byte[] blob = new byte[length];
in.readBytes(blob);
// #readBytes throws a 'REPLAY' exception if there are not enough bytes
// available for reading
ByteBuf data = in.readBytes(length);
byte[] blob;
if (data.hasArray()) {
blob = data.array();
} else {
blob = new byte[length];
data.readBytes(blob);
}

Hasher hasher = Hashing.murmur3_32().newHasher();
long check = hasher.putBytes(blob).hash().padToLong();
if (hash == check) {
Expand Down

0 comments on commit 7712579

Please sign in to comment.