Skip to content

Commit

Permalink
Use the smallest version rather than the default version
Browse files Browse the repository at this point in the history
The minimum version comparison was always using the default version
sicne the comparison was flipped.

Closes #11474
  • Loading branch information
s1monw committed Jun 3, 2015
1 parent e21d87a commit 8c740eb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/elasticsearch/index/shard/IndexShard.java
Expand Up @@ -756,13 +756,13 @@ public org.apache.lucene.util.Version upgrade(UpgradeRequest upgrade) {
}

public org.apache.lucene.util.Version minimumCompatibleVersion() {
org.apache.lucene.util.Version luceneVersion = org.apache.lucene.util.Version.LUCENE_3_6;
org.apache.lucene.util.Version luceneVersion = null;
for(Segment segment : engine().segments()) {
if (luceneVersion.onOrAfter(segment.getVersion())) {
if (luceneVersion == null || luceneVersion.onOrAfter(segment.getVersion())) {
luceneVersion = segment.getVersion();
}
}
return luceneVersion;
return luceneVersion == null ? Version.indexCreated(indexSettings).luceneVersion : luceneVersion;
}

public SnapshotIndexCommit snapshotIndex() throws EngineException {
Expand Down
17 changes: 16 additions & 1 deletion src/test/java/org/elasticsearch/index/shard/IndexShardTests.java
Expand Up @@ -37,6 +37,7 @@

import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_VERSION_CREATED;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -148,5 +149,19 @@ public void testDeleteByQueryBWC() {
assertEquals(numDocs, searcher.reader().numDocs());
}
}


public void testMinimumCompatVersion() {
Version versionCreated = randomVersion();
assertAcked(client().admin().indices().prepareCreate("test")
.setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0, SETTING_VERSION_CREATED, versionCreated.id));
client().prepareIndex("test", "test").setSource("{}").get();
ensureGreen("test");
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
IndexShard test = indicesService.indexService("test").shard(0);
assertEquals(versionCreated.luceneVersion, test.minimumCompatibleVersion());
client().prepareIndex("test", "test").setSource("{}").get();
assertEquals(versionCreated.luceneVersion, test.minimumCompatibleVersion());
test.engine().flush();
assertEquals(Version.CURRENT.luceneVersion, test.minimumCompatibleVersion());
}
}
Expand Up @@ -19,7 +19,11 @@

package org.elasticsearch.rest.action.admin.indices.upgrade;

import org.elasticsearch.Version;
import org.elasticsearch.bwcompat.StaticIndexBackwardCompatibilityTest;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.indices.IndicesService;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;

Expand All @@ -28,20 +32,23 @@ public class UpgradeReallyOldIndexTest extends StaticIndexBackwardCompatibilityT
public void testUpgrade_0_20() throws Exception {
String indexName = "test";
loadIndex("index-0.20.zip", indexName);

assertMinVersion(indexName, org.apache.lucene.util.Version.parse("3.6.2"));
assertTrue(UpgradeTest.hasAncientSegments(client(), indexName));
UpgradeTest.assertNotUpgraded(client(), indexName);
assertNoFailures(client().admin().indices().prepareUpgrade(indexName).setUpgradeOnlyAncientSegments(true).get());
assertFalse(UpgradeTest.hasAncientSegments(client(), indexName));

// This index has entirely ancient segments so the whole index should now be upgraded:
UpgradeTest.assertUpgraded(client(), indexName);
assertEquals(Version.CURRENT.luceneVersion.toString(), client().admin().indices().prepareGetSettings(indexName).get().getSetting(indexName, IndexMetaData.SETTING_VERSION_MINIMUM_COMPATIBLE));
assertMinVersion(indexName, Version.CURRENT.luceneVersion);

}

public void testUpgradeMixed_0_20_6_and_0_90_6() throws Exception {
String indexName = "index-0.20.6-and-0.90.6";
loadIndex(indexName + ".zip", indexName);

assertMinVersion(indexName, org.apache.lucene.util.Version.parse("3.6.2"));
// Has ancient segments?:
assertTrue(UpgradeTest.hasAncientSegments(client(), indexName));

Expand All @@ -59,5 +66,18 @@ public void testUpgradeMixed_0_20_6_and_0_90_6() throws Exception {

// We succeeded in upgrading only the ancient segments but leaving the "merely old" ones untouched:
assertTrue(UpgradeTest.hasOldButNotAncientSegments(client(), indexName));
assertEquals(org.apache.lucene.util.Version.LUCENE_4_5_1.toString(), client().admin().indices().prepareGetSettings(indexName).get().getSetting(indexName, IndexMetaData.SETTING_VERSION_MINIMUM_COMPATIBLE));
assertMinVersion(indexName, org.apache.lucene.util.Version.LUCENE_4_5_1);

}

private void assertMinVersion(String index, org.apache.lucene.util.Version version) {
for (IndicesService services : internalCluster().getInstances(IndicesService.class)) {
IndexService indexService = services.indexService(index);
if (indexService != null) {
assertEquals(version, indexService.shard(0).minimumCompatibleVersion());
}
}

}
}

0 comments on commit 8c740eb

Please sign in to comment.