You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by nd...@apache.org on 2023/01/12 16:54:40 UTC
[hbase] branch master updated: HBASE-27563 ChaosMonkey sometimes generates invalid boundaries for random item selection
This is an automated email from the ASF dual-hosted git repository.
ndimiduk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push:
new 2a7c69d30e1 HBASE-27563 ChaosMonkey sometimes generates invalid boundaries for random item selection
2a7c69d30e1 is described below
commit 2a7c69d30e18671d938e12ab23ec1563aed6a417
Author: Nick Dimiduk <nd...@apache.org>
AuthorDate: Tue Jan 10 14:29:17 2023 +0100
HBASE-27563 ChaosMonkey sometimes generates invalid boundaries for random item selection
Signed-off-by: Duo Zhang <zh...@apache.org>
---
.../chaos/monkies/PolicyBasedChaosMonkey.java | 24 ++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/PolicyBasedChaosMonkey.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/PolicyBasedChaosMonkey.java
index ead5ccea51b..f5af796b575 100644
--- a/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/PolicyBasedChaosMonkey.java
+++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/PolicyBasedChaosMonkey.java
@@ -30,6 +30,9 @@ import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.IntegrationTestingUtility;
import org.apache.hadoop.hbase.chaos.policies.Policy;
import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.hbase.util.ReservoirSample;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -37,6 +40,7 @@ import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFacto
* Chaos monkey that given multiple policies will run actions against the cluster.
*/
public class PolicyBasedChaosMonkey extends ChaosMonkey {
+ private static final Logger LOG = LoggerFactory.getLogger(PolicyBasedChaosMonkey.class);
private static final long ONE_SEC = 1000;
private static final long ONE_MIN = 60 * ONE_SEC;
@@ -116,13 +120,14 @@ public class PolicyBasedChaosMonkey extends ChaosMonkey {
/** Selects and returns ceil(ratio * items.length) random items from the given array */
public static <T> List<T> selectRandomItems(T[] items, float ratio) {
- int selectedNumber = (int) Math.ceil(items.length * ratio);
-
- List<T> originalItems = Arrays.asList(items);
- Collections.shuffle(originalItems);
-
- int startIndex = ThreadLocalRandom.current().nextInt(items.length - selectedNumber);
- return originalItems.subList(startIndex, startIndex + selectedNumber);
+ // clamp ratio to [0.0,1.0]
+ ratio = Math.max(Math.min(ratio, 1.0f), 0.0f);
+ final int selectedNumber = (int) Math.ceil(items.length * ratio);
+ final ReservoirSample<T> sample = new ReservoirSample<>(selectedNumber);
+ sample.add(Arrays.stream(items));
+ final List<T> shuffledItems = sample.getSamplingResult();
+ Collections.shuffle(shuffledItems);
+ return shuffledItems;
}
@Override
@@ -151,7 +156,10 @@ public class PolicyBasedChaosMonkey extends ChaosMonkey {
@Override
public void waitForStop() throws InterruptedException {
- monkeyThreadPool.awaitTermination(1, TimeUnit.MINUTES);
+ if (!monkeyThreadPool.awaitTermination(1, TimeUnit.MINUTES)) {
+ LOG.warn("Some pool threads failed to terminate. Forcing. {}", monkeyThreadPool);
+ monkeyThreadPool.shutdownNow();
+ }
}
@Override