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 7264fd4 commit d621b16
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/main/java/org/elasticsearch/index/shard/IndexShard.java
Expand Up @@ -23,8 +23,6 @@
import com.google.common.base.Preconditions;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.index.CheckIndex;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.join.BitDocIdSetFilter;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.ThreadInterruptedException;
Expand All @@ -41,14 +39,11 @@
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.metrics.MeanMetric;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
Expand Down Expand Up @@ -720,13 +715,13 @@ public org.apache.lucene.util.Version upgrade(UpgradeRequest upgrade) {
}

public org.apache.lucene.util.Version minimumCompatibleVersion() {
org.apache.lucene.util.Version luceneVersion = Version.LUCENE_3_EMULATION_VERSION;
org.apache.lucene.util.Version luceneVersion = null;
for(Segment segment : engine().segments(false)) {
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(boolean flushFirst) throws EngineException {
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/elasticsearch/index/shard/IndexShardTests.java
Expand Up @@ -50,6 +50,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.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_VERSION_CREATED;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -362,4 +363,19 @@ public void testDeleteByQueryBWC() {
assertEquals(numDocs, searcher.reader().numDocs());
}
}

public void testMinimumCompatVersion() {
Version versionCreated = VersionUtils.randomVersion(random());
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 @@ -29,13 +33,26 @@ public void testUpgrade_0_90_6() throws Exception {
String indexName = "index-0.90.6";

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

assertFalse(UpgradeTest.hasAncientSegments(client(), "index-0.90.6"));
// This index has only ancient segments, so it should now be fully 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);
}

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 d621b16

Please sign in to comment.