Skip to content

Commit

Permalink
partitioning over the length of the names, added changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
janheise committed Dec 17, 2024
1 parent 39ed3b5 commit b53226e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions changelog/unreleased/pr-21208.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type = "f"
message = "batching request for index block status if the combined length of the indices exceed the max possible URL length "

pulls = ["21208"]
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.github.joschi.jadconfig.util.Duration;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import jakarta.inject.Inject;
import org.graylog.shaded.opensearch2.org.opensearch.action.admin.cluster.health.ClusterHealthRequest;
import org.graylog.shaded.opensearch2.org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
Expand Down Expand Up @@ -85,6 +84,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -110,7 +110,9 @@ public class IndicesAdapterOS2 implements IndicesAdapter {
private final ClusterStateApi clusterStateApi;
private final IndexTemplateAdapter indexTemplateAdapter;

private final int MAX_INDICES = 20;
// this is the maximum amount of bytes that the index list is supposed to fill in a request, it assumes that these don't
// need url encoding
private final int MAX_INDICES_URL_PART_LENGTH = 3000;

@Inject
public IndicesAdapterOS2(OpenSearchClient client,
Expand Down Expand Up @@ -434,14 +436,31 @@ public List<ShardsInfo> getShardsInfo(String indexName) {
return catApi.getShardsInfo(indexName);
}


private List<List<String>> partition(final List<String> indices) {
List<List<String>> partitions = new ArrayList<>();
List<String> partition = new ArrayList<>();
int length = 0;
for(String index: indices) {
if(length > MAX_INDICES_URL_PART_LENGTH) {
partitions.add(partition);
partition = new ArrayList<>();
}
length += index.length();
partition.add(index);
}
partitions.add(partition);
return partitions;
}

@Override
public IndicesBlockStatus getIndicesBlocksStatus(final List<String> indices) {
if (indices == null || indices.isEmpty()) {
throw new IllegalArgumentException("Expecting list of indices with at least one index present.");
}

IndicesBlockStatus result = new IndicesBlockStatus();
Lists.partition(indices, MAX_INDICES).forEach(i -> {
partition(indices).forEach(i -> {
final GetSettingsRequest getSettingsRequest = new GetSettingsRequest()
.indices(i.toArray(new String[]{}))
.indicesOptions(IndicesOptions.fromOptions(false, true, true, true))
Expand Down

0 comments on commit b53226e

Please sign in to comment.