Skip to content

Commit

Permalink
Fixing forbiddenApisTest task failure
Browse files Browse the repository at this point in the history
Signed-off-by: Sagar Upadhyaya <sagar.upadhyaya.121@gmail.com>
  • Loading branch information
sgup432 committed May 6, 2024
1 parent 3f1bf8d commit a53e2be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.metrics.CounterMetric;
import org.opensearch.core.common.bytes.BytesReference;
import org.opensearch.indices.IndicesRequestCache;

/**
* Tracks the portion of the request cache in use for a particular shard.
Expand Down Expand Up @@ -80,8 +79,12 @@ public void onRemoval(long keyRamBytesUsed, BytesReference value, boolean evicte
dec += value.ramBytesUsed();
}
if ((totalMetric.count() - dec) < 0) {
logger.warn("Ignoring the operation to deduct memory: {} from RequestStats memory_size metric as it will " +
"go negative. Current memory: {}. This is a bug.", dec, totalMetric.count());
logger.warn(
"Ignoring the operation to deduct memory: {} from RequestStats memory_size metric as it will "
+ "go negative. Current memory: {}. This is a bug.",
dec,
totalMetric.count()
);
} else {
totalMetric.dec(dec);
}
Expand All @@ -104,8 +107,12 @@ public void onRemoval(Accountable key, BytesReference value, boolean evicted) {
dec += value.ramBytesUsed();
}
if ((totalMetric.count() - dec) < 0) {
logger.warn("Ignoring the operation to deduct memory: {} from RequestStats memory_size metric as it will " +
"go negative. Current memory: {}. This is a bug.", dec, totalMetric.count());
logger.warn(
"Ignoring the operation to deduct memory: {} from RequestStats memory_size metric as it will "
+ "go negative. Current memory: {}. This is a bug.",
dec,
totalMetric.count()
);
} else {
totalMetric.dec(dec);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -1300,9 +1299,8 @@ public void testGetOrComputeConcurrentlyWithMultipleIndices() throws Exception {
public static String generateString(int length) {
String characters = "abcdefghijklmnopqrstuvwxyz";
StringBuilder sb = new StringBuilder(length);
Random random = new Random();
for (int i = 0; i < length; i++) {
int index = random.nextInt(characters.length());
int index = randomInt(characters.length() - 1);
sb.append(characters.charAt(index));
}
return sb.toString();
Expand Down

0 comments on commit a53e2be

Please sign in to comment.