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/10 03:15:46 UTC

[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 <uj...@apache.org>
Authored: Thu Apr 9 21:11:13 2015 -0400
Committer: Bill Slacum <uj...@apache.org>
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
----------------------------------------------------------------------