Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the smallest version rather than the default version #11475

Merged
merged 1 commit into from Jun 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the index is empty and just a commit point?

}
return luceneVersion;
return luceneVersion == null ? Version.indexCreated(indexSettings).luceneVersion : luceneVersion;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK but this indexCreated is an immutable thing in ES right? So this means a user can never upgrade an empty index?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there are no docs in the index it won't do anything here yes! in this case we should make this method more low level - I will fix that too


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());
}
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about this assert. especially given the comments above it. If this minimum version is a lucene version, should it not be the oldest lucene version? In this case the ancient segments will be upgraded, but the "merely old" ones will still be there, so I can't see it being CURRENT.

}