HBASE-21315 The getActiveMinProcId and getActiveMaxProcId of BitSetNode are incorrect if there are no active procedure
This commit is contained in:
parent
cfe875d3d2
commit
85c3ec3fb4
|
@ -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;
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue