|
|
@@ -19,7 +19,6 @@
|
|
|
|
|
|
package org.elasticsearch.action.admin.indices.create;
|
|
|
|
|
|
-import org.apache.lucene.index.CorruptIndexException;
|
|
|
import org.apache.lucene.search.Sort;
|
|
|
import org.apache.lucene.search.SortField;
|
|
|
import org.apache.lucene.search.SortedSetSelector;
|
|
|
@@ -29,6 +28,8 @@ import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse;
|
|
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
|
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
|
|
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
|
|
|
+import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
|
|
+import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
|
|
import org.elasticsearch.action.index.IndexRequest;
|
|
|
import org.elasticsearch.action.support.ActiveShardCount;
|
|
|
import org.elasticsearch.client.Client;
|
|
|
@@ -36,10 +37,8 @@ import org.elasticsearch.cluster.ClusterInfoService;
|
|
|
import org.elasticsearch.cluster.InternalClusterInfoService;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
|
-import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
|
|
import org.elasticsearch.cluster.routing.Murmur3HashFunction;
|
|
|
import org.elasticsearch.cluster.routing.RoutingTable;
|
|
|
-import org.elasticsearch.cluster.routing.ShardRouting;
|
|
|
import org.elasticsearch.cluster.routing.UnassignedInfo;
|
|
|
import org.elasticsearch.common.Priority;
|
|
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|
|
@@ -48,8 +47,8 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.index.Index;
|
|
|
import org.elasticsearch.index.IndexService;
|
|
|
import org.elasticsearch.index.query.TermsQueryBuilder;
|
|
|
+import org.elasticsearch.index.seqno.SeqNoStats;
|
|
|
import org.elasticsearch.index.shard.IndexShard;
|
|
|
-import org.elasticsearch.index.shard.ShardId;
|
|
|
import org.elasticsearch.indices.IndicesService;
|
|
|
import org.elasticsearch.plugins.Plugin;
|
|
|
import org.elasticsearch.test.ESIntegTestCase;
|
|
|
@@ -58,15 +57,11 @@ import org.elasticsearch.test.VersionUtils;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
-import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.stream.Collectors;
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
|
|
-import static org.hamcrest.CoreMatchers.not;
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
|
|
@@ -233,7 +228,8 @@ public class ShrinkIndexIT extends ESIntegTestCase {
|
|
|
.put("number_of_shards", randomIntBetween(2, 7))
|
|
|
.put("index.version.created", version)
|
|
|
).get();
|
|
|
- for (int i = 0; i < 20; i++) {
|
|
|
+ final int docs = randomIntBetween(0, 128);
|
|
|
+ for (int i = 0; i < docs; i++) {
|
|
|
client().prepareIndex("source", "type")
|
|
|
.setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
|
|
|
}
|
|
|
@@ -252,13 +248,26 @@ public class ShrinkIndexIT extends ESIntegTestCase {
|
|
|
.put("index.routing.allocation.require._name", mergeNode)
|
|
|
.put("index.blocks.write", true)).get();
|
|
|
ensureGreen();
|
|
|
+
|
|
|
+ final IndicesStatsResponse sourceStats = client().admin().indices().prepareStats("source").get();
|
|
|
+ final long maxSeqNo =
|
|
|
+ Arrays.stream(sourceStats.getShards()).map(ShardStats::getSeqNoStats).mapToLong(SeqNoStats::getMaxSeqNo).max().getAsLong();
|
|
|
// now merge source into a single shard index
|
|
|
|
|
|
final boolean createWithReplicas = randomBoolean();
|
|
|
assertAcked(client().admin().indices().prepareShrinkIndex("source", "target")
|
|
|
.setSettings(Settings.builder().put("index.number_of_replicas", createWithReplicas ? 1 : 0).build()).get());
|
|
|
ensureGreen();
|
|
|
- assertHitCount(client().prepareSearch("target").setSize(100).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 20);
|
|
|
+
|
|
|
+ final IndicesStatsResponse targetStats = client().admin().indices().prepareStats("target").get();
|
|
|
+ for (final ShardStats shardStats : targetStats.getShards()) {
|
|
|
+ final SeqNoStats seqNoStats = shardStats.getSeqNoStats();
|
|
|
+ assertThat(seqNoStats.getMaxSeqNo(), equalTo(maxSeqNo));
|
|
|
+ assertThat(seqNoStats.getLocalCheckpoint(), equalTo(maxSeqNo));
|
|
|
+ }
|
|
|
+
|
|
|
+ final int size = docs > 0 ? 2 * docs : 1;
|
|
|
+ assertHitCount(client().prepareSearch("target").setSize(size).setQuery(new TermsQueryBuilder("foo", "bar")).get(), docs);
|
|
|
|
|
|
if (createWithReplicas == false) {
|
|
|
// bump replicas
|
|
|
@@ -266,16 +275,16 @@ public class ShrinkIndexIT extends ESIntegTestCase {
|
|
|
.setSettings(Settings.builder()
|
|
|
.put("index.number_of_replicas", 1)).get();
|
|
|
ensureGreen();
|
|
|
- assertHitCount(client().prepareSearch("target").setSize(100).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 20);
|
|
|
+ assertHitCount(client().prepareSearch("target").setSize(size).setQuery(new TermsQueryBuilder("foo", "bar")).get(), docs);
|
|
|
}
|
|
|
|
|
|
- for (int i = 20; i < 40; i++) {
|
|
|
+ for (int i = docs; i < 2 * docs; i++) {
|
|
|
client().prepareIndex("target", "type")
|
|
|
.setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get();
|
|
|
}
|
|
|
flushAndRefresh();
|
|
|
- assertHitCount(client().prepareSearch("target").setSize(100).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 40);
|
|
|
- assertHitCount(client().prepareSearch("source").setSize(100).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 20);
|
|
|
+ assertHitCount(client().prepareSearch("target").setSize(2 * size).setQuery(new TermsQueryBuilder("foo", "bar")).get(), 2 * docs);
|
|
|
+ assertHitCount(client().prepareSearch("source").setSize(size).setQuery(new TermsQueryBuilder("foo", "bar")).get(), docs);
|
|
|
GetSettingsResponse target = client().admin().indices().prepareGetSettings("target").get();
|
|
|
assertEquals(version, target.getIndexToSettings().get("target").getAsVersion("index.version.created", null));
|
|
|
}
|