Skip to content

Commit 683d045

Browse files
authored
Revert "Backport "HBASE-27563 ChaosMonkey sometimes generates invalid boundaries for random item selection" to branch-2.4 (#4962)"
This reverts commit f245c64.
1 parent f245c64 commit 683d045

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

hbase-it/src/test/java/org/apache/hadoop/hbase/chaos/monkies/PolicyBasedChaosMonkey.java

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package org.apache.hadoop.hbase.chaos.monkies;
1919

20-
import java.util.ArrayList;
2120
import java.util.Arrays;
2221
import java.util.Collection;
2322
import java.util.Collections;
@@ -31,16 +30,13 @@
3130
import org.apache.hadoop.hbase.IntegrationTestingUtility;
3231
import org.apache.hadoop.hbase.chaos.policies.Policy;
3332
import org.apache.hadoop.hbase.util.Pair;
34-
import org.slf4j.Logger;
35-
import org.slf4j.LoggerFactory;
3633

3734
import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
3835

3936
/**
4037
* Chaos monkey that given multiple policies will run actions against the cluster.
4138
*/
4239
public class PolicyBasedChaosMonkey extends ChaosMonkey {
43-
private static final Logger LOG = LoggerFactory.getLogger(PolicyBasedChaosMonkey.class);
4440

4541
private static final long ONE_SEC = 1000;
4642
private static final long ONE_MIN = 60 * ONE_SEC;
@@ -120,31 +116,13 @@ public static <T> T selectWeightedRandomItem(List<Pair<T, Integer>> items) {
120116

121117
/** Selects and returns ceil(ratio * items.length) random items from the given array */
122118
public static <T> List<T> selectRandomItems(T[] items, float ratio) {
123-
/*
124-
* N.b. `ratio` values are not validated. Be aware of excessive values and floating point
125-
* arithmetic rounding. Guard against negative input to Random#next() and exceeding boundaries
126-
* in call to List#subList.
127-
*/
119+
int selectedNumber = (int) Math.ceil(items.length * ratio);
128120

129-
// clamp ratio to [0.0,1.0]
130-
ratio = Math.max(Math.min(ratio, 1.0f), 0.0f);
121+
List<T> originalItems = Arrays.asList(items);
122+
Collections.shuffle(originalItems);
131123

132-
final int selectedNumber = (int) Math.ceil(items.length * ratio);
133-
134-
// shuffle a copy of the input, not the input.
135-
final List<T> shuffledItems = new ArrayList<>(items.length);
136-
shuffledItems.addAll(Arrays.asList(items));
137-
Collections.shuffle(shuffledItems);
138-
139-
if (selectedNumber >= items.length) {
140-
return shuffledItems;
141-
}
142-
143-
// apply basic sanity check on sublist selection range.
144-
final int startIndex =
145-
Math.max(0, ThreadLocalRandom.current().nextInt(items.length - selectedNumber));
146-
final int endIndex = Math.min(items.length, startIndex + selectedNumber);
147-
return shuffledItems.subList(startIndex, endIndex);
124+
int startIndex = ThreadLocalRandom.current().nextInt(items.length - selectedNumber);
125+
return originalItems.subList(startIndex, startIndex + selectedNumber);
148126
}
149127

150128
@Override
@@ -173,10 +151,7 @@ public boolean isStopped() {
173151

174152
@Override
175153
public void waitForStop() throws InterruptedException {
176-
if (!monkeyThreadPool.awaitTermination(1, TimeUnit.MINUTES)) {
177-
LOG.warn("Some pool threads failed to terminate. Forcing. {}", monkeyThreadPool);
178-
monkeyThreadPool.shutdownNow();
179-
}
154+
monkeyThreadPool.awaitTermination(1, TimeUnit.MINUTES);
180155
}
181156

182157
@Override

0 commit comments

Comments
 (0)