From 0a95b8c24d2327c8bb02808a26a784b0d3ce027f Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Mon, 10 Jun 2019 16:47:40 -0500 Subject: [PATCH] Fixing handling of auto slices in bulk scroll requests (#43050) (#43063) * Fixing handling of auto slices in bulk scroll requests * adjusting assertions for tests --- .../index/reindex/BulkByScrollParallelizationHelper.java | 2 +- .../index/reindex/DeleteByQueryBasicTests.java | 9 +++++++++ .../elasticsearch/index/reindex/ReindexBasicTests.java | 8 ++++++++ .../index/reindex/UpdateByQueryBasicTests.java | 9 +++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java index 2eca1433935..dfb8deac58c 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollParallelizationHelper.java @@ -112,7 +112,7 @@ class BulkByScrollParallelizationHelper { (sum, term) -> sum + term )); Set counts = new HashSet<>(countsByIndex.values()); - int leastShards = Collections.min(counts); + int leastShards = counts.isEmpty() ? 1 : Collections.min(counts); return Math.min(leastShards, AUTO_SLICE_CEILING); } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java index 5bef735be5e..c6a53fdcfae 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/DeleteByQueryBasicTests.java @@ -306,4 +306,13 @@ public class DeleteByQueryBasicTests extends ReindexTestCase { } + public void testMissingSources() { + BulkByScrollResponse response = updateByQuery() + .source("missing-index-*") + .refresh(true) + .setSlices(AbstractBulkByScrollRequest.AUTO_SLICES) + .get(); + assertThat(response, matcher().deleted(0).slices(hasSize(0))); + } + } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java index 9159f39708f..d95ab555914 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java @@ -157,5 +157,13 @@ public class ReindexBasicTests extends ReindexTestCase { assertHitCount(client().prepareSearch("dest").setSize(0).get(), allDocs.size()); } + public void testMissingSources() { + BulkByScrollResponse response = updateByQuery() + .source("missing-index-*") + .refresh(true) + .setSlices(AbstractBulkByScrollRequest.AUTO_SLICES) + .get(); + assertThat(response, matcher().created(0).slices(hasSize(0))); + } } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/UpdateByQueryBasicTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/UpdateByQueryBasicTests.java index 91a92005c2c..7351f3eb062 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/UpdateByQueryBasicTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/UpdateByQueryBasicTests.java @@ -160,4 +160,13 @@ public class UpdateByQueryBasicTests extends ReindexTestCase { assertEquals(2, client().prepareGet(index, "test", Integer.toString(randomDoc)).get().getVersion()); } } + + public void testMissingSources() { + BulkByScrollResponse response = updateByQuery() + .source("missing-index-*") + .refresh(true) + .setSlices(AbstractBulkByScrollRequest.AUTO_SLICES) + .get(); + assertThat(response, matcher().updated(0).slices(hasSize(0))); + } }