hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhang...@apache.org
Subject hbase git commit: HBASE-21315 The getActiveMinProcId and getActiveMaxProcId of BitSetNode are incorrect if there are no active procedure
Date Tue, 16 Oct 2018 07:46:31 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 0d9982901 -> fa652cc61


HBASE-21315 The getActiveMinProcId and getActiveMaxProcId of BitSetNode are incorrect if there
are no active procedure


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

Branch: refs/heads/master
Commit: fa652cc610a3c8b6c4c53ddcbbdc55b209f7d6a3
Parents: 0d99829
Author: Duo Zhang <zhangduo@apache.org>
Authored: Mon Oct 15 14:43:02 2018 +0800
Committer: Duo Zhang <zhangduo@apache.org>
Committed: Tue Oct 16 15:42:01 2018 +0800

----------------------------------------------------------------------
 .../hbase/procedure2/store/BitSetNode.java      |  9 +--
 .../procedure2/store/ProcedureStoreTracker.java |  4 +-
 .../hbase/procedure2/store/TestBitSetNode.java  | 59 ++++++++++++++++++++
 .../store/TestProcedureStoreTracker.java        | 15 +++++
 4 files changed, 81 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/fa652cc6/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/BitSetNode.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/BitSetNode.java
b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/BitSetNode.java
index efb806f..2030c8b 100644
--- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/BitSetNode.java
+++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/BitSetNode.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.procedure2.store;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import org.apache.hadoop.hbase.procedure2.Procedure;
 import org.apache.hadoop.hbase.procedure2.store.ProcedureStoreTracker.DeleteState;
 import org.apache.yetus.audience.InterfaceAudience;
 
@@ -346,12 +347,12 @@ class BitSetNode {
     long minProcId = start;
     for (int i = 0; i < deleted.length; ++i) {
       if (deleted[i] == 0) {
-        return (minProcId);
+        return minProcId;
       }
 
       if (deleted[i] != WORD_MASK) {
         for (int j = 0; j < BITS_PER_WORD; ++j) {
-          if ((deleted[i] & (1L << j)) != 0) {
+          if ((deleted[i] & (1L << j)) == 0) {
             return minProcId + j;
           }
         }
@@ -359,7 +360,7 @@ class BitSetNode {
 
       minProcId += BITS_PER_WORD;
     }
-    return minProcId;
+    return Procedure.NO_PROC_ID;
   }
 
   public long getActiveMaxProcId() {
@@ -378,7 +379,7 @@ class BitSetNode {
       }
       maxProcId -= BITS_PER_WORD;
     }
-    return maxProcId;
+    return Procedure.NO_PROC_ID;
   }
 
   // ========================================================================

http://git-wip-us.apache.org/repos/asf/hbase/blob/fa652cc6/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/ProcedureStoreTracker.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/ProcedureStoreTracker.java
b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/ProcedureStoreTracker.java
index f98c766..a5b5825 100644
--- a/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/ProcedureStoreTracker.java
+++ b/hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/store/ProcedureStoreTracker.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.stream.LongStream;
+import org.apache.hadoop.hbase.procedure2.Procedure;
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.yetus.audience.InterfaceStability;
 
@@ -278,9 +279,8 @@ public class ProcedureStoreTracker {
   }
 
   public long getActiveMinProcId() {
-    // TODO: Cache?
     Map.Entry<Long, BitSetNode> entry = map.firstEntry();
-    return entry == null ? 0 : entry.getValue().getActiveMinProcId();
+    return entry == null ? Procedure.NO_PROC_ID : entry.getValue().getActiveMinProcId();
   }
 
   public void setKeepDeletes(boolean keepDeletes) {

http://git-wip-us.apache.org/repos/asf/hbase/blob/fa652cc6/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/TestBitSetNode.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/TestBitSetNode.java
b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/TestBitSetNode.java
new file mode 100644
index 0000000..8d193d0
--- /dev/null
+++ b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/TestBitSetNode.java
@@ -0,0 +1,59 @@
+/**
+ * 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.procedure2.store;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.procedure2.Procedure;
+import org.apache.hadoop.hbase.testclassification.MasterTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category({ MasterTests.class, SmallTests.class })
+public class TestBitSetNode {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+    HBaseClassTestRule.forClass(TestBitSetNode.class);
+
+  @Test
+  public void testGetActiveMaxMinProcId() {
+    BitSetNode node = new BitSetNode(5L, false);
+    assertEquals(5L, node.getActiveMinProcId());
+    assertEquals(5L, node.getActiveMaxProcId());
+    node.insertOrUpdate(10L);
+    assertEquals(5L, node.getActiveMinProcId());
+    assertEquals(10L, node.getActiveMaxProcId());
+    node.insertOrUpdate(1L);
+    assertEquals(1L, node.getActiveMinProcId());
+    assertEquals(10L, node.getActiveMaxProcId());
+
+    node.delete(10L);
+    assertEquals(1L, node.getActiveMinProcId());
+    assertEquals(5L, node.getActiveMaxProcId());
+    node.delete(1L);
+    assertEquals(5L, node.getActiveMinProcId());
+    assertEquals(5L, node.getActiveMaxProcId());
+    node.delete(5L);
+    assertEquals(Procedure.NO_PROC_ID, node.getActiveMinProcId());
+    assertEquals(Procedure.NO_PROC_ID, node.getActiveMaxProcId());
+  }
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/fa652cc6/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/TestProcedureStoreTracker.java
----------------------------------------------------------------------
diff --git a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/TestProcedureStoreTracker.java
b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/TestProcedureStoreTracker.java
index 93fcbe9..ab448be 100644
--- a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/TestProcedureStoreTracker.java
+++ b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/TestProcedureStoreTracker.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
 
 import java.util.Random;
 import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.procedure2.Procedure;
 import org.apache.hadoop.hbase.testclassification.MasterTests;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.junit.ClassRule;
@@ -261,4 +262,18 @@ public class TestProcedureStoreTracker {
       assertEquals((2 * i + 1) * 10, activeProcIds[i]);
     }
   }
+
+  @Test
+  public void testGetActiveMinProcId() {
+    ProcedureStoreTracker tracker = new ProcedureStoreTracker();
+    assertEquals(Procedure.NO_PROC_ID, tracker.getActiveMinProcId());
+    for (int i = 100; i < 1000; i = 2 * i + 1) {
+      tracker.insert(i);
+    }
+    for (int i = 100; i < 1000; i = 2 * i + 1) {
+      assertEquals(i, tracker.getActiveMinProcId());
+      tracker.delete(i);
+    }
+    assertEquals(Procedure.NO_PROC_ID, tracker.getActiveMinProcId());
+  }
 }


Mime
View raw message