Skip to content

Commit

Permalink
Update error message when lucene document limit is breached
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyansh Ray <rayshrey@amazon.com>
  • Loading branch information
rayshrey committed Nov 23, 2023
1 parent 8673fa9 commit 46e23de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.opensearch.action.search.SearchResponse;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.index.Index;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.index.IndexSettings;
Expand Down Expand Up @@ -65,6 +67,7 @@
public class MaxDocsLimitIT extends OpenSearchIntegTestCase {

private static final AtomicInteger maxDocs = new AtomicInteger();
private static final ShardId shardId = new ShardId(new Index("test", "_na_"), 0);

public static class TestEnginePlugin extends Plugin implements EnginePlugin {
@Override
Expand Down Expand Up @@ -122,7 +125,10 @@ public void testMaxDocsLimit() throws Exception {
IllegalArgumentException.class,
() -> client().prepareDelete("test", "any-id").get()
);
assertThat(deleteError.getMessage(), containsString("Number of documents in the index can't exceed [" + maxDocs.get() + "]"));
assertThat(
deleteError.getMessage(),
containsString("Number of documents in shard " + shardId + " can't exceed [" + maxDocs.get() + "]")
);
client().admin().indices().prepareRefresh("test").get();
SearchResponse searchResponse = client().prepareSearch("test")
.setQuery(new MatchAllQueryBuilder())
Expand Down Expand Up @@ -208,7 +214,10 @@ static IndexingResult indexDocs(int numRequests, int numThreads) throws Exceptio
assertThat(resp.status(), equalTo(RestStatus.CREATED));
} catch (IllegalArgumentException e) {
numFailure.incrementAndGet();
assertThat(e.getMessage(), containsString("Number of documents in the index can't exceed [" + maxDocs.get() + "]"));
assertThat(
e.getMessage(),
containsString("Number of documents in shard " + shardId + " can't exceed [" + maxDocs.get() + "]")
);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ private Exception tryAcquireInFlightDocs(Operation operation, int addingDocs) {
final long totalDocs = indexWriter.getPendingNumDocs() + inFlightDocCount.addAndGet(addingDocs);
if (totalDocs > maxDocs) {
releaseInFlightDocs(addingDocs);
return new IllegalArgumentException("Number of documents in the index can't exceed [" + maxDocs + "]");
return new IllegalArgumentException("Number of documents in shard " + shardId + " can't exceed [" + maxDocs + "]");
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7801,7 +7801,7 @@ public void testMaxDocsOnPrimary() throws Exception {
assertNotNull(result.getFailure());
assertThat(
result.getFailure().getMessage(),
containsString("Number of documents in the index can't exceed [" + maxDocs + "]")
containsString("Number of documents in shard " + shardId + " can't exceed [" + maxDocs + "]")
);
assertThat(result.getSeqNo(), equalTo(UNASSIGNED_SEQ_NO));
assertThat(engine.getLocalCheckpointTracker().getMaxSeqNo(), equalTo(maxSeqNo));
Expand Down

0 comments on commit 46e23de

Please sign in to comment.