hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkris...@apache.org
Subject hbase git commit: HBASE-14881 Provide a Put API that uses the provided row without coping (Xiang Li)
Date Mon, 01 Aug 2016 09:07:02 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 7e6f56275 -> 2c5a0fcf1


HBASE-14881 Provide a Put API that uses the provided row without coping
(Xiang Li)


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

Branch: refs/heads/master
Commit: 2c5a0fcf1f216ac5333a2047f6ce69797a5da14b
Parents: 7e6f5627
Author: Ramkrishna <ramkrishna.s.vasudevan@intel.com>
Authored: Mon Aug 1 14:35:49 2016 +0530
Committer: Ramkrishna <ramkrishna.s.vasudevan@intel.com>
Committed: Mon Aug 1 14:35:49 2016 +0530

----------------------------------------------------------------------
 .../org/apache/hadoop/hbase/client/Put.java     | 37 ++++++++++++++++++++
 .../org/apache/hadoop/hbase/client/TestPut.java | 16 +++++++++
 2 files changed, 53 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/2c5a0fcf/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java
index 6b06875..dbaf3a7 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java
@@ -117,6 +117,43 @@ public class Put extends Mutation implements HeapSize, Comparable<Row>
{
   }
 
   /**
+   * Create a Put operation for an immutable row key.
+   *
+   * @param row row key
+   * @param rowIsImmutable whether the input row is immutable.
+   *                       Set to true if the caller can guarantee that
+   *                       the row will not be changed for the Put duration.
+   */
+  public Put(byte [] row, boolean rowIsImmutable) {
+    this(row, HConstants.LATEST_TIMESTAMP, rowIsImmutable);
+  }
+
+  /**
+   * Create a Put operation for an immutable row key, using a given timestamp.
+   *
+   * @param row row key
+   * @param ts timestamp
+   * @param rowIsImmutable whether the input row is immutable.
+   *                       Set to true if the caller can guarantee that
+   *                       the row will not be changed for the Put duration.
+   */
+  public Put(byte[] row, long ts, boolean rowIsImmutable) {
+    // Check and set timestamp
+    if (ts < 0) {
+      throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + ts);
+    }
+    this.ts = ts;
+
+    // Deal with row according to rowIsImmutable
+    checkRow(row);
+    if (rowIsImmutable) {  // Row is immutable
+      this.row = row;  // Do not make a local copy, but point to the provided byte array
directly
+    } else {  // Row is not immutable
+      this.row = Bytes.copy(row, 0, row.length);  // Make a local copy
+    }
+  }
+
+  /**
    * Copy constructor.  Creates a Put operation cloned from the specified Put.
    * @param putToCopy put to copy
    */

http://git-wip-us.apache.org/repos/asf/hbase/blob/2c5a0fcf/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestPut.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestPut.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestPut.java
index 3a877dc..8603fe1 100644
--- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestPut.java
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestPut.java
@@ -23,6 +23,8 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
 public class TestPut {
   @Test
   public void testCopyConstructor() {
@@ -40,4 +42,18 @@ public class TestPut {
     assertNotEquals(origin.getCellList(family), clone.getCellList(family));
 
   }
+
+  // HBASE-14881
+  @Test
+  public void testRowIsImmutableOrNot() {
+    byte[] rowKey = Bytes.toBytes("immutable");
+
+    // Test when row key is immutable
+    Put putRowIsImmutable = new Put(rowKey, true);
+    assertTrue(rowKey == putRowIsImmutable.getRow());  // No local copy is made
+
+    // Test when row key is not immutable
+    Put putRowIsNotImmutable = new Put(rowKey, 1000L, false);
+    assertTrue(rowKey != putRowIsNotImmutable.getRow());  // A local copy is made
+  }
 }


Mime
View raw message