Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4E91B10429 for ; Fri, 10 Apr 2015 01:15:42 +0000 (UTC) Received: (qmail 32471 invoked by uid 500); 10 Apr 2015 01:15:42 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 32443 invoked by uid 500); 10 Apr 2015 01:15:42 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 32434 invoked by uid 99); 10 Apr 2015 01:15:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Apr 2015 01:15:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E7544E01FB; Fri, 10 Apr 2015 01:15:41 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ujustgotbilld@apache.org To: commits@accumulo.apache.org Date: Fri, 10 Apr 2015 01:15:46 -0000 Message-Id: <3800ff8302024e64ada19961927a0237@git.apache.org> In-Reply-To: <0647f924e42c4eb99d7aff2a54a8526d@git.apache.org> References: <0647f924e42c4eb99d7aff2a54a8526d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [6/6] accumulo git commit: Merge branch '1.6' Merge branch '1.6' Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/9c8dcaf0 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/9c8dcaf0 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/9c8dcaf0 Branch: refs/heads/master Commit: 9c8dcaf0aa9ddf0a9fd068290d0cb4237318ffaa Parents: aac619c 6fa2090 Author: Bill Slacum Authored: Thu Apr 9 21:11:13 2015 -0400 Committer: Bill Slacum Committed: Thu Apr 9 21:11:13 2015 -0400 ---------------------------------------------------------------------- .../org/apache/accumulo/core/data/Mutation.java | 35 ++++++++++++++++---- .../apache/accumulo/core/data/MutationTest.java | 28 ++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/9c8dcaf0/core/src/main/java/org/apache/accumulo/core/data/Mutation.java ---------------------------------------------------------------------- diff --cc core/src/main/java/org/apache/accumulo/core/data/Mutation.java index ed51204,233a12e..f532a52 --- a/core/src/main/java/org/apache/accumulo/core/data/Mutation.java +++ b/core/src/main/java/org/apache/accumulo/core/data/Mutation.java @@@ -97,11 -79,21 +97,25 @@@ public class Mutation implements Writab } } + /* This is so hashCode & equals can be called without changing this object. + * + * It will return a copy of the current data buffer if serialized has not been + * called previously. Otherwise, this.data will be returned since the buffer is + * null and will not change. + */ + private byte[] serializedSnapshot() { + if (buffer != null) { + return buffer.toArray(); + } else { + return this.data; + } + } + /** + * Creates a new mutation. A defensive copy is made. + * + * @param row + * row ID * @since 1.5.0 */ public Mutation(byte[] row) { @@@ -1101,14 -613,9 +1115,13 @@@ } private boolean equalMutation(Mutation m) { - serialize(); - m.serialize(); - if (Arrays.equals(row, m.row) && entries == m.entries && Arrays.equals(data, m.data)) { + byte[] myData = serializedSnapshot(); + byte[] otherData = m.serializedSnapshot(); + if (Arrays.equals(row, m.row) && entries == m.entries && Arrays.equals(myData, otherData)) { + // If two mutations don't have the same + if (!replicationSources.equals(m.replicationSources)) { + return false; + } - if (values == null && m.values == null) return true; @@@ -1126,25 -633,21 +1139,35 @@@ return false; } + /** + * Converts this mutation to Thrift. + * + * @return Thrift mutation + */ public TMutation toThrift() { - serialize(); + return toThrift(true); + } + + private TMutation toThrift(boolean serialize) { + byte[] data; + if (serialize) { + this.serialize(); + data = this.data; + } else { + data = serializedSnapshot(); + } - return new TMutation(java.nio.ByteBuffer.wrap(row), java.nio.ByteBuffer.wrap(data), ByteBufferUtil.toByteBuffers(values), entries); + TMutation tmutation = new TMutation(java.nio.ByteBuffer.wrap(row), java.nio.ByteBuffer.wrap(data), ByteBufferUtil.toByteBuffers(values), entries); + if (!this.replicationSources.isEmpty()) { + tmutation.setSources(new ArrayList<>(replicationSources)); + } + return tmutation; } + /** + * Gets the serialization format used to (de)serialize this mutation. + * + * @return serialization format + */ protected SERIALIZED_FORMAT getSerializedFormat() { return this.useOldDeserialize ? SERIALIZED_FORMAT.VERSION1 : SERIALIZED_FORMAT.VERSION2; } http://git-wip-us.apache.org/repos/asf/accumulo/blob/9c8dcaf0/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java ----------------------------------------------------------------------