You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by uj...@apache.org on 2015/04/12 21:46:31 UTC

[2/6] accumulo git commit: ACCUMULO-3718 Avoid copying underlying Mutation data when possible and added documention to the behavior of Mutation#toThrift

ACCUMULO-3718 Avoid copying underlying Mutation data when possible and added documention to the behavior of Mutation#toThrift


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

Branch: refs/heads/1.6
Commit: 91326110532008b4fb307690cd77cff4d7fa28b8
Parents: 73ce9cf
Author: Bill Slacum <uj...@apache.org>
Authored: Sun Apr 12 13:50:56 2015 -0400
Committer: Bill Slacum <uj...@apache.org>
Committed: Sun Apr 12 13:50:56 2015 -0400

----------------------------------------------------------------------
 .../org/apache/accumulo/core/data/Mutation.java | 28 ++++++++++++--------
 1 file changed, 17 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/91326110/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/data/Mutation.java b/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
index 81ad531..27b590e 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
@@ -197,11 +197,11 @@ public class Mutation implements Writable {
    * called previously. Otherwise, this.data will be returned since the buffer is
    * null and will not change.
    */
-  private byte[] serializedSnapshot() {
+  private java.nio.ByteBuffer serializedSnapshot() {
     if (buffer != null) {
-      return buffer.toArray();
+      return java.nio.ByteBuffer.wrap(this.buffer.data, 0, this.buffer.offset);
     } else {
-      return this.data;
+      return java.nio.ByteBuffer.wrap(this.data);
     }
   }
 
@@ -709,9 +709,9 @@ public class Mutation implements Writable {
   }
 
   public boolean equals(Mutation m) {
-    byte[] myData = serializedSnapshot();
-    byte[] otherData = m.serializedSnapshot();
-    if (Arrays.equals(row, m.row) && entries == m.entries && Arrays.equals(myData, otherData)) {
+    java.nio.ByteBuffer myData = serializedSnapshot();
+    java.nio.ByteBuffer otherData = m.serializedSnapshot();
+    if (Arrays.equals(row, m.row) && entries == m.entries && myData.equals(otherData)) {
       if (values == null && m.values == null)
         return true;
 
@@ -729,19 +729,25 @@ public class Mutation implements Writable {
     return false;
   }
 
+  /**
+   * Creates a {@link org.apache.accumulo.core.data.thrift.TMutation} object
+   * containing this Mutation's data.
+   *
+   * Note that this method will move the Mutation into a "serialized" state
+   * that will prevent users from adding more data via Mutation#put().
+   *
+   * @return a thrift form of this Mutation
+   */
   public TMutation toThrift() {
     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);
+    java.nio.ByteBuffer data = serializedSnapshot();
+    return new TMutation(java.nio.ByteBuffer.wrap(row), data, ByteBufferUtil.toByteBuffers(values), entries);
   }
 
   protected SERIALIZED_FORMAT getSerializedFormat() {