You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2019/01/24 01:28:47 UTC

[hbase] branch branch-1.3 updated: HBASE-21475 Put mutation (having TTL set) added via co-processor is retrieved even after TTL expires

This is an automated email from the ASF dual-hosted git repository.

apurtell pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-1.3 by this push:
     new d4d7efb  HBASE-21475 Put mutation (having TTL set) added via co-processor is retrieved even after TTL expires
d4d7efb is described below

commit d4d7efb80c082b12e901c811ef7ff11676eef460
Author: Nihal Jain <ni...@gmail.com>
AuthorDate: Tue Nov 13 23:25:13 2018 +0530

    HBASE-21475 Put mutation (having TTL set) added via co-processor is retrieved even after TTL expires
    
    Signed-off-by: Andrew Purtell <ap...@apache.org>
    
    Conflicts:
    	hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
    	hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverForAddingMutationsFromCoprocessors.java
    
    Amending-Author: Andrew Purtell <ap...@apache.org>
---
 .../apache/hadoop/hbase/regionserver/HRegion.java  | 11 +++++----
 ...ObserverForAddingMutationsFromCoprocessors.java | 28 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 5 deletions(-)

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 71785fd..a2cbe84 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
@@ -3300,14 +3300,15 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
             }
             // Else Coprocessor added more Mutations corresponding to the Mutation at this index.
             for (int j = 0; j < cpMutations.length; j++) {
-              Mutation cpMutation = cpMutations[j];
-              Map<byte[], List<Cell>> cpFamilyMap = cpMutation.getFamilyCellMap();
-              checkAndPrepareMutation(cpMutation, isInReplay, cpFamilyMap, now);
+              Mutation mutation = cpMutations[j];
+              Map<byte[], List<Cell>> cpFamilyMap = mutation.getFamilyCellMap();
+              rewriteCellTags(cpFamilyMap, mutation);
+              checkAndPrepareMutation(mutation, isInReplay, cpFamilyMap, now);
 
               // Acquire row locks. If not, the whole batch will fail.
-              acquiredRowLocks.add(getRowLockInternal(cpMutation.getRow(), true, true, null));
+              acquiredRowLocks.add(getRowLockInternal(mutation.getRow(), true, true, null));
 
-              if (cpMutation.getDurability() == Durability.SKIP_WAL) {
+              if (mutation.getDurability() == Durability.SKIP_WAL) {
                 recordMutationWithoutWal(cpFamilyMap);
               }
 
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverForAddingMutationsFromCoprocessors.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverForAddingMutationsFromCoprocessors.java
index 0663b0b..93d777f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverForAddingMutationsFromCoprocessors.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverForAddingMutationsFromCoprocessors.java
@@ -194,6 +194,34 @@ public class TestRegionObserverForAddingMutationsFromCoprocessors {
     }
   }
 
+  @Test
+  public void testPutWithTTL() throws Exception {
+    createTable(TestPutWithTTLCoprocessor.class.getName());
+
+    try (Table t = util.getConnection().getTable(tableName)) {
+      t.put(new Put(row1).addColumn(test, dummy, dummy).setTTL(3000));
+      assertRowCount(t, 2);
+      // wait long enough for the TTL to expire
+      Thread.sleep(5000);
+      assertRowCount(t, 0);
+    }
+  }
+
+  public static class TestPutWithTTLCoprocessor extends BaseRegionObserver  {
+    @Override
+    public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
+        MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
+      Mutation mut = miniBatchOp.getOperation(0);
+      List<Cell> cells = mut.getFamilyCellMap().get(test);
+      Put[] puts = new Put[] {
+          new Put(Bytes.toBytes("cpPut")).addColumn(test, dummy, cells.get(0).getTimestamp(),
+            Bytes.toBytes("cpdummy")).setTTL(mut.getTTL())
+          };
+      LOG.info("Putting:" + Arrays.toString(puts));
+      miniBatchOp.addOperationsFromCP(0, puts);
+    }
+  }
+
   public static class TestMultiMutationCoprocessor extends BaseRegionObserver {
     @Override
     public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,