Skip to content

Commit

Permalink
int is enough.
Browse files Browse the repository at this point in the history
  • Loading branch information
henningandersen committed Apr 13, 2021
1 parent 1596b6d commit 6c5ecde
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public String name() {
@Override
public AutoscalingDeciderResult scale(Settings configuration, AutoscalingDeciderContext context) {
// we assume that nodes do not grow beyond 64GB here.
long shards = countFrozenShards(context.state().metadata());
int shards = countFrozenShards(context.state().metadata());
long memory = shards * MEMORY_PER_SHARD.get(configuration).getBytes();
return new AutoscalingDeciderResult(AutoscalingCapacity.builder().total(null, memory).build(), new FrozenShardsReason(shards));
}

static long countFrozenShards(Metadata metadata) {
static int countFrozenShards(Metadata metadata) {
return StreamSupport.stream(metadata.spliterator(), false)
.filter(imd -> isFrozenIndex(imd.getSettings()))
.mapToLong(IndexMetadata::getTotalNumberOfShards)
.mapToInt(IndexMetadata::getTotalNumberOfShards)
.sum();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public void testIsFrozenIndex() {

public void testCountFrozenShards() {
final Metadata.Builder builder = Metadata.builder();
long count = 0;
int count = 0;
for (int i = 0; i < randomInt(20); ++i) {
int shards = between(1, 3);
int replicas = between(0, 2);
String tierPreference = randomBoolean() ? DataTier.DATA_FROZEN : randomNonFrozenTierPreference();
if (Objects.equals(tierPreference, DataTier.DATA_FROZEN)) {
count += (long) shards * (replicas + 1);
count += shards * (replicas + 1);
}
builder.put(
IndexMetadata.builder("index" + i).settings(indexSettings(tierPreference)).numberOfShards(shards).numberOfReplicas(replicas)
Expand Down

0 comments on commit 6c5ecde

Please sign in to comment.