hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anoopsamj...@apache.org
Subject git commit: HBASE-12082 Find a way to set timestamp on Cells on the server.
Date Mon, 29 Sep 2014 05:52:37 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 8895ee694 -> df2ce0c38


HBASE-12082 Find a way to set timestamp on Cells on the server.


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

Branch: refs/heads/master
Commit: df2ce0c3896bec9fe128a13490b05f7fea0757c9
Parents: 8895ee6
Author: anoopsjohn <anoopsamjohn@gmail.com>
Authored: Mon Sep 29 11:22:12 2014 +0530
Committer: anoopsjohn <anoopsamjohn@gmail.com>
Committed: Mon Sep 29 11:22:12 2014 +0530

----------------------------------------------------------------------
 .../java/org/apache/hadoop/hbase/CellUtil.java  | 64 ++++++++++++++++++++
 .../java/org/apache/hadoop/hbase/KeyValue.java  | 12 +++-
 .../apache/hadoop/hbase/SettableTimestamp.java  | 41 +++++++++++++
 .../hadoop/hbase/regionserver/HRegion.java      | 42 ++++++-------
 .../regionserver/MultiRowMutationProcessor.java |  2 +-
 .../visibility/VisibilityController.java        | 10 ++-
 6 files changed, 140 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/df2ce0c3/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java
index 03cfe4d..f6b2475 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java
@@ -570,6 +570,70 @@ public final class CellUtil {
   }
 
   /**
+   * Sets the given timestamp to the cell.
+   * @param cell
+   * @param ts
+   * @throws IOException when the passed cell is not of type {@link SettableTimestamp}
+   */
+  public static void setTimestamp(Cell cell, long ts) throws IOException {
+    if (cell instanceof SettableTimestamp) {
+      ((SettableTimestamp) cell).setTimestamp(ts);
+    } else {
+      throw new IOException(new UnsupportedOperationException("Cell is not of type "
+          + SettableTimestamp.class.getName()));
+    }
+  }
+
+  /**
+   * Sets the given timestamp to the cell.
+   * @param cell
+   * @param ts buffer containing the timestamp value
+   * @param tsOffset offset to the new timestamp
+   * @throws IOException when the passed cell is not of type {@link SettableTimestamp}
+   */
+  public static void setTimestamp(Cell cell, byte[] ts, int tsOffset) throws IOException
{
+    if (cell instanceof SettableTimestamp) {
+      ((SettableTimestamp) cell).setTimestamp(ts, tsOffset);
+    } else {
+      throw new IOException(new UnsupportedOperationException("Cell is not of type "
+          + SettableTimestamp.class.getName()));
+    }
+  }
+
+  /**
+   * Sets the given timestamp to the cell iff current timestamp is
+   * {@link HConstants#LATEST_TIMESTAMP}.
+   * @param cell
+   * @param ts
+   * @return True if cell timestamp is modified.
+   * @throws IOException when the passed cell is not of type {@link SettableTimestamp}
+   */
+  public static boolean updateLatestStamp(Cell cell, long ts) throws IOException {
+    if (cell.getTimestamp() == HConstants.LATEST_TIMESTAMP) {
+      setTimestamp(cell, ts);
+      return true;
+    }
+    return false;
+  }
+
+  /**
+   * Sets the given timestamp to the cell iff current timestamp is
+   * {@link HConstants#LATEST_TIMESTAMP}.
+   * @param cell
+   * @param ts buffer containing the timestamp value
+   * @param tsOffset offset to the new timestamp
+   * @return True if cell timestamp is modified.
+   * @throws IOException when the passed cell is not of type {@link SettableTimestamp}
+   */
+  public static boolean updateLatestStamp(Cell cell, byte[] ts, int tsOffset) throws IOException
{
+    if (cell.getTimestamp() == HConstants.LATEST_TIMESTAMP) {
+      setTimestamp(cell, ts, tsOffset);
+      return true;
+    }
+    return false;
+  }
+
+  /**
    * Estimation of total number of bytes used by the cell to store its key, value and tags.
When the
    * cell is a {@link KeyValue} we include the extra infrastructure size used by it.
    * @param cell

http://git-wip-us.apache.org/repos/asf/hbase/blob/df2ce0c3/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java
index 15ab4b8..cae7580 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java
@@ -79,7 +79,7 @@ import com.google.common.annotations.VisibleForTesting;
  * and actual tag bytes length.
  */
 @InterfaceAudience.Private
-public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId {
+public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId, SettableTimestamp
{
   private static final ArrayList<Tag> EMPTY_ARRAY_LIST = new ArrayList<Tag>();
 
   static final Log LOG = LogFactory.getLog(KeyValue.class);
@@ -1426,6 +1426,16 @@ public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId
{
     return false;
   }
 
+  @Override
+  public void setTimestamp(long ts) {
+    Bytes.putBytes(this.bytes, this.getTimestampOffset(), Bytes.toBytes(ts), 0, Bytes.SIZEOF_LONG);
+  }
+
+  @Override
+  public void setTimestamp(byte[] ts, int tsOffset) {
+    Bytes.putBytes(this.bytes, this.getTimestampOffset(), ts, tsOffset, Bytes.SIZEOF_LONG);
+  }
+
   //---------------------------------------------------------------------------
   //
   //  Methods that return copies of fields

http://git-wip-us.apache.org/repos/asf/hbase/blob/df2ce0c3/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableTimestamp.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableTimestamp.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableTimestamp.java
new file mode 100644
index 0000000..c9675c2
--- /dev/null
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/SettableTimestamp.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import org.apache.hadoop.hbase.classification.InterfaceAudience;
+
+/**
+ * Using this Interface one can mark a Cell as timestamp changeable. <br>
+ * Note : Server side Cell implementations in write path must implement this.
+ */
+@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
+public interface SettableTimestamp {
+
+  /**
+   * Sets with the given timestamp.
+   * @param ts
+   */
+  void setTimestamp(long ts);
+
+  /**
+   * Sets with the given timestamp.
+   * @param ts buffer containing the timestamp value
+   * @param tsOffset offset to the new timestamp
+   */
+  void setTimestamp(byte[] ts, int tsOffset);
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/df2ce0c3/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
index 561a3f3..2fd03de 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
@@ -2187,11 +2187,10 @@ public class HRegion implements HeapSize { // , Writable{
       int listSize = cells.size();
       for (int i=0; i < listSize; i++) {
         Cell cell = cells.get(i);
-        KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
         //  Check if time is LATEST, change to time of most recent addition if so
         //  This is expensive.
-        if (kv.isLatestTimestamp() && CellUtil.isDeleteType(kv)) {
-          byte[] qual = CellUtil.cloneQualifier(kv);
+        if (cell.getTimestamp() == HConstants.LATEST_TIMESTAMP && CellUtil.isDeleteType(cell))
{
+          byte[] qual = CellUtil.cloneQualifier(cell);
           if (qual == null) qual = HConstants.EMPTY_BYTE_ARRAY;
 
           Integer count = kvCount.get(qual);
@@ -2202,39 +2201,38 @@ public class HRegion implements HeapSize { // , Writable{
           }
           count = kvCount.get(qual);
 
-          Get get = new Get(CellUtil.cloneRow(kv));
+          Get get = new Get(CellUtil.cloneRow(cell));
           get.setMaxVersions(count);
           get.addColumn(family, qual);
           if (coprocessorHost != null) {
             if (!coprocessorHost.prePrepareTimeStampForDeleteVersion(mutation, cell,
                 byteNow, get)) {
-              updateDeleteLatestVersionTimeStamp(kv, get, count, byteNow);
+              updateDeleteLatestVersionTimeStamp(cell, get, count, byteNow);
             }
           } else {
-            updateDeleteLatestVersionTimeStamp(kv, get, count, byteNow);
+            updateDeleteLatestVersionTimeStamp(cell, get, count, byteNow);
           }
         } else {
-          kv.updateLatestStamp(byteNow);
+          CellUtil.updateLatestStamp(cell, byteNow, 0);
         }
       }
     }
   }
 
-  void updateDeleteLatestVersionTimeStamp(KeyValue kv, Get get, int count, byte[] byteNow)
+  void updateDeleteLatestVersionTimeStamp(Cell cell, Get get, int count, byte[] byteNow)
       throws IOException {
     List<Cell> result = get(get, false);
 
     if (result.size() < count) {
       // Nothing to delete
-      kv.updateLatestStamp(byteNow);
+      CellUtil.updateLatestStamp(cell, byteNow, 0);
       return;
     }
     if (result.size() > count) {
       throw new RuntimeException("Unexpected size: " + result.size());
     }
-    KeyValue getkv = KeyValueUtil.ensureKeyValue(result.get(count - 1));
-    Bytes.putBytes(kv.getBuffer(), kv.getTimestampOffset(), getkv.getBuffer(),
-        getkv.getTimestampOffset(), Bytes.SIZEOF_LONG);
+    Cell getCell = result.get(count - 1);
+    CellUtil.setTimestamp(cell, getCell.getTimestamp());
   }
 
   /**
@@ -2623,7 +2621,7 @@ public class HRegion implements HeapSize { // , Writable{
 
         Mutation mutation = batchOp.getMutation(i);
         if (mutation instanceof Put) {
-          updateKVTimestamps(familyMaps[i].values(), byteNow);
+          updateCellTimestamps(familyMaps[i].values(), byteNow);
           noOfPuts++;
         } else {
           prepareDeleteTimestamps(mutation, familyMaps[i], byteNow);
@@ -3087,16 +3085,16 @@ public class HRegion implements HeapSize { // , Writable{
   /**
    * Replaces any KV timestamps set to {@link HConstants#LATEST_TIMESTAMP} with the
    * provided current timestamp.
+   * @throws IOException
    */
-  void updateKVTimestamps(final Iterable<List<Cell>> keyLists, final byte[] now)
{
-    for (List<Cell> cells: keyLists) {
+  void updateCellTimestamps(final Iterable<List<Cell>> cellItr, final byte[]
now)
+      throws IOException {
+    for (List<Cell> cells: cellItr) {
       if (cells == null) continue;
       assert cells instanceof RandomAccess;
       int listSize = cells.size();
-      for (int i=0; i < listSize; i++) {
-        Cell cell = cells.get(i);
-        KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
-        kv.updateLatestStamp(now);
+      for (int i = 0; i < listSize; i++) {
+        CellUtil.updateLatestStamp(cells.get(i), now, 0);
       }
     }
   }
@@ -5412,10 +5410,8 @@ public class HRegion implements HeapSize { // , Writable{
               } else {
                 // Append's KeyValue.Type==Put and ts==HConstants.LATEST_TIMESTAMP,
                 // so only need to update the timestamp to 'now'
-                // TODO get rid of KeyValueUtil.ensureKeyValue
-                KeyValue newKV = KeyValueUtil.ensureKeyValue(cell);
-                newKV.updateLatestStamp(Bytes.toBytes(now));
-                newCell = newKV;
+                CellUtil.updateLatestStamp(cell, now);
+                newCell = cell;
              }
               CellUtil.setSequenceId(newCell, mvccNum);
               // Give coprocessors a chance to update the new cell

http://git-wip-us.apache.org/repos/asf/hbase/blob/df2ce0c3/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MultiRowMutationProcessor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MultiRowMutationProcessor.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MultiRowMutationProcessor.java
index 08579f1..62ef064 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MultiRowMutationProcessor.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MultiRowMutationProcessor.java
@@ -80,7 +80,7 @@ MultiRowMutationProcessorResponse> {
         Map<byte[], List<Cell>> familyMap = m.getFamilyCellMap();
         region.checkFamilies(familyMap.keySet());
         region.checkTimestamps(familyMap, now);
-        region.updateKVTimestamps(familyMap.values(), byteNow);
+        region.updateCellTimestamps(familyMap.values(), byteNow);
       } else if (m instanceof Delete) {
         Delete d = (Delete) m;
         region.prepareDelete(d);

http://git-wip-us.apache.org/repos/asf/hbase/blob/df2ce0c3/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java
index 859efa8..4986e0f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java
@@ -45,7 +45,6 @@ import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.KeyValue.Type;
-import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.Tag;
 import org.apache.hadoop.hbase.MetaTableAccessor;
@@ -346,7 +345,6 @@ public class VisibilityController extends BaseMasterAndRegionObserver
implements
   public void prePrepareTimeStampForDeleteVersion(
       ObserverContext<RegionCoprocessorEnvironment> ctx, Mutation delete, Cell cell,
       byte[] byteNow, Get get) throws IOException {
-    KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
     CellVisibility cellVisibility = null;
     try {
       cellVisibility = delete.getCellVisibility();
@@ -371,16 +369,16 @@ public class VisibilityController extends BaseMasterAndRegionObserver
implements
 
     if (result.size() < get.getMaxVersions()) {
       // Nothing to delete
-      kv.updateLatestStamp(Bytes.toBytes(Long.MIN_VALUE));
+      CellUtil.updateLatestStamp(cell, Long.MIN_VALUE);
       return;
     }
     if (result.size() > get.getMaxVersions()) {
       throw new RuntimeException("Unexpected size: " + result.size()
           + ". Results more than the max versions obtained.");
     }
-    KeyValue getkv = KeyValueUtil.ensureKeyValue(result.get(get.getMaxVersions() - 1));
-    Bytes.putBytes(kv.getBuffer(), kv.getTimestampOffset(), getkv.getBuffer(),
-        getkv.getTimestampOffset(), Bytes.SIZEOF_LONG);
+    Cell getCell = result.get(get.getMaxVersions() - 1);
+    CellUtil.setTimestamp(cell, getCell.getTimestamp());
+
     // We are bypassing here because in the HRegion.updateDeleteLatestVersionTimeStamp we
would
     // update with the current timestamp after again doing a get. As the hook as already
determined
     // the needed timestamp we need to bypass here.


Mime
View raw message