accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [1/2] accumulo git commit: ACCUMULO-2945 Add mutation buffer size hinting
Date Thu, 19 Mar 2015 17:14:29 GMT
Repository: accumulo
Updated Branches:
  refs/heads/master ed7d962ac -> a6fd86cfc


ACCUMULO-2945 Add mutation buffer size hinting


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

Branch: refs/heads/master
Commit: 35a7f55e907ceeff298d3c8d6d637842d573c622
Parents: bddb007
Author: Christopher Tubbs <ctubbsii@apache.org>
Authored: Wed Mar 18 17:23:24 2015 -0400
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Wed Mar 18 17:23:24 2015 -0400

----------------------------------------------------------------------
 .../org/apache/accumulo/core/data/Mutation.java | 60 +++++++++++++++++++-
 .../apache/accumulo/core/data/MutationTest.java | 42 ++++++++++++++
 2 files changed, 101 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/35a7f55e/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 4b1a812..ed51204 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
@@ -112,6 +112,19 @@ public class Mutation implements Writable {
    * Creates a new mutation. A defensive copy is made.
    *
    * @param row
+   *          row ID
+   * @param initialBufferSize
+   *          the initial size, in bytes, of the internal buffer for serializing
+   * @since 1.7.0
+   */
+  public Mutation(byte[] row, int initialBufferSize) {
+    this(row, 0, row.length, initialBufferSize);
+  }
+
+  /**
+   * Creates a new mutation. A defensive copy is made.
+   *
+   * @param row
    *          byte array containing row ID
    * @param start
    *          starting index of row ID in byte array
@@ -122,9 +135,28 @@ public class Mutation implements Writable {
    * @since 1.5.0
    */
   public Mutation(byte[] row, int start, int length) {
+    this(row, start, length, 64);
+  }
+
+  /**
+   * Creates a new mutation. A defensive copy is made.
+   *
+   * @param row
+   *          byte array containing row ID
+   * @param start
+   *          starting index of row ID in byte array
+   * @param length
+   *          length of row ID in byte array
+   * @param initialBufferSize
+   *          the initial size, in bytes, of the internal buffer for serializing
+   * @throws IndexOutOfBoundsException
+   *           if start or length is invalid
+   * @since 1.7.0
+   */
+  public Mutation(byte[] row, int start, int length, int initialBufferSize) {
     this.row = new byte[length];
     System.arraycopy(row, start, this.row, 0, length);
-    buffer = new UnsynchronizedBuffer.Writer();
+    buffer = new UnsynchronizedBuffer.Writer(initialBufferSize);
   }
 
   /**
@@ -138,6 +170,19 @@ public class Mutation implements Writable {
   }
 
   /**
+   * Creates a new mutation. A defensive copy is made.
+   *
+   * @param row
+   *          row ID
+   * @param initialBufferSize
+   *          the initial size, in bytes, of the internal buffer for serializing
+   * @since 1.7.0
+   */
+  public Mutation(Text row, int initialBufferSize) {
+    this(row.getBytes(), 0, row.getLength(), initialBufferSize);
+  }
+
+  /**
    * Creates a new mutation.
    *
    * @param row
@@ -149,6 +194,19 @@ public class Mutation implements Writable {
 
   /**
    * Creates a new mutation.
+   *
+   * @param row
+   *          row ID
+   * @param initialBufferSize
+   *          the initial size, in bytes, of the internal buffer for serializing
+   * @since 1.7.0
+   */
+  public Mutation(CharSequence row, int initialBufferSize) {
+    this(new Text(row.toString()), initialBufferSize);
+  }
+
+  /**
+   * Creates a new mutation.
    */
   public Mutation() {}
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/35a7f55e/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java b/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
index 8b50788..6607c6e 100644
--- a/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.accumulo.core.data;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -520,6 +521,47 @@ public class MutationTest {
     verifyColumnUpdate(m2.getUpdates().get(3), "cf2", "big", "", 0l, false, false, bigVal.toString());
   }
 
+  // populate for testInitialBufferSizesEquals method
+  private static void populate(Mutation... muts) {
+    for (Mutation m : muts) {
+      m.put("cf1", "cq1", "v1");
+      m.put("cf1", "cq1", new ColumnVisibility("A&B"), "v2");
+      m.put("cf1", "cq1", 3, "v3");
+      m.put("cf1", "cq1", new ColumnVisibility("A&B&C"), 4, "v4");
+      m.putDelete("cf2", "cf3");
+      m.putDelete("cf2", "cf4", 3);
+      m.putDelete("cf2", "cf4", new ColumnVisibility("A&B&C"), 3);
+    }
+  }
+
+  @Test
+  public void testInitialBufferSizesEquals() {
+    // m1 uses CharSequence constructor
+    Mutation m1 = new Mutation("r1");
+    // m2 uses a different buffer size
+    Mutation m2 = new Mutation("r1", 4242);
+    // m3 uses Text constructor
+    Mutation m3 = new Mutation(new Text("r1"));
+    // m4 uses a different buffer size
+    Mutation m4 = new Mutation(new Text("r1"), 4242);
+    // m5 uses bytes constructor with offset/length
+    byte[] r1Bytes = "r1".getBytes(UTF_8);
+    Mutation m5 = new Mutation(r1Bytes);
+    // m6 uses a different buffer size
+    Mutation m6 = new Mutation(r1Bytes, 4242);
+    // m7 uses bytes constructor with offset/length
+    Mutation m7 = new Mutation(r1Bytes, 0, r1Bytes.length);
+    // m8 uses a different buffer size
+    Mutation m8 = new Mutation(r1Bytes, 0, r1Bytes.length, 4242);
+
+    Mutation[] muts = new Mutation[] {m1, m2, m3, m4, m5, m6, m7, m8};
+    populate(muts);
+
+    for (Mutation m : muts) {
+      assertEquals(m1, m);
+    }
+  }
+
   @Test
   public void testEquals() {
     Mutation m1 = new Mutation("r1");


Mime
View raw message