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:58:01 UTC
[hbase] branch branch-2.4 updated: Revert "Backport "HBASE-27563 ChaosMonkey sometimes generates invalid boundaries for random item selection" to branch-2.4 (#4962)"
This is an automated email from the ASF dual-hosted git repository.
ndimiduk pushed a commit to branch branch-2.4
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.4 by this push:
new 849332d2179 Revert "Backport "HBASE-27563 ChaosMonkey sometimes generates invalid boundaries for random item selection" to branch-2.4 (#4962)"
849332d2179 is described below
commit 849332d21795237b6f19723becfe2f7862c8baa7
Author: Nick Dimiduk <nd...@gmail.com>
AuthorDate: Thu Jan 12 17:57:31 2023 +0100
Revert "Backport "HBASE-27563 ChaosMonkey sometimes generates invalid boundaries for random item selection" to branch-2.4 (#4962)"
This reverts commit f245c64993d3e16f214dc5417546a023d486f611.
---
.../chaos/monkies/PolicyBasedChaosMonkey.java | 37 ++++------------------
1 file changed, 6 insertions(+), 31 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 28f87664f7f..ead5ccea51b 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
@@ -17,7 +17,6 @@
*/
package org.apache.hadoop.hbase.chaos.monkies;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -31,8 +30,6 @@ 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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -40,7 +37,6 @@ 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;
@@ -120,31 +116,13 @@ 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) {
- /*
- * N.b. `ratio` values are not validated. Be aware of excessive values and floating point
- * arithmetic rounding. Guard against negative input to Random#next() and exceeding boundaries
- * in call to List#subList.
- */
+ int selectedNumber = (int) Math.ceil(items.length * ratio);
- // clamp ratio to [0.0,1.0]
- ratio = Math.max(Math.min(ratio, 1.0f), 0.0f);
+ List<T> originalItems = Arrays.asList(items);
+ Collections.shuffle(originalItems);
- final int selectedNumber = (int) Math.ceil(items.length * ratio);
-
- // shuffle a copy of the input, not the input.
- final List<T> shuffledItems = new ArrayList<>(items.length);
- shuffledItems.addAll(Arrays.asList(items));
- Collections.shuffle(shuffledItems);
-
- if (selectedNumber >= items.length) {
- return shuffledItems;
- }
-
- // apply basic sanity check on sublist selection range.
- final int startIndex =
- Math.max(0, ThreadLocalRandom.current().nextInt(items.length - selectedNumber));
- final int endIndex = Math.min(items.length, startIndex + selectedNumber);
- return shuffledItems.subList(startIndex, endIndex);
+ int startIndex = ThreadLocalRandom.current().nextInt(items.length - selectedNumber);
+ return originalItems.subList(startIndex, startIndex + selectedNumber);
}
@Override
@@ -173,10 +151,7 @@ public class PolicyBasedChaosMonkey extends ChaosMonkey {
@Override
public void waitForStop() throws InterruptedException {
- if (!monkeyThreadPool.awaitTermination(1, TimeUnit.MINUTES)) {
- LOG.warn("Some pool threads failed to terminate. Forcing. {}", monkeyThreadPool);
- monkeyThreadPool.shutdownNow();
- }
+ monkeyThreadPool.awaitTermination(1, TimeUnit.MINUTES);
}
@Override