Merge pull request #16168 from s1monw/upgrade_on_any_version
Run Metadata upgrade tool on every version
This commit is contained in:
commit
9110f4f654
|
@ -72,21 +72,25 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
|
||||||
public IndexMetaData upgradeIndexMetaData(IndexMetaData indexMetaData) {
|
public IndexMetaData upgradeIndexMetaData(IndexMetaData indexMetaData) {
|
||||||
// Throws an exception if there are too-old segments:
|
// Throws an exception if there are too-old segments:
|
||||||
if (isUpgraded(indexMetaData)) {
|
if (isUpgraded(indexMetaData)) {
|
||||||
return archiveBrokenIndexSettings(indexMetaData);
|
assert indexMetaData == archiveBrokenIndexSettings(indexMetaData) : "all settings must have been upgraded before";
|
||||||
|
return indexMetaData;
|
||||||
}
|
}
|
||||||
checkSupportedVersion(indexMetaData);
|
checkSupportedVersion(indexMetaData);
|
||||||
IndexMetaData newMetaData = indexMetaData;
|
IndexMetaData newMetaData = indexMetaData;
|
||||||
|
// we have to run this first otherwise in we try to create IndexSettings
|
||||||
|
// with broken settings and fail in checkMappingsCompatibility
|
||||||
|
newMetaData = archiveBrokenIndexSettings(newMetaData);
|
||||||
|
// only run the check with the upgraded settings!!
|
||||||
checkMappingsCompatibility(newMetaData);
|
checkMappingsCompatibility(newMetaData);
|
||||||
newMetaData = markAsUpgraded(newMetaData);
|
return markAsUpgraded(newMetaData);
|
||||||
return archiveBrokenIndexSettings(newMetaData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the index was already opened by this version of Elasticsearch and doesn't require any additional checks.
|
* Checks if the index was already opened by this version of Elasticsearch and doesn't require any additional checks.
|
||||||
*/
|
*/
|
||||||
private boolean isUpgraded(IndexMetaData indexMetaData) {
|
boolean isUpgraded(IndexMetaData indexMetaData) {
|
||||||
return indexMetaData.getUpgradedVersion().onOrAfter(Version.V_3_0_0); // TODO should this be Version.CURRENT?
|
return indexMetaData.getUpgradedVersion().onOrAfter(Version.CURRENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.elasticsearch.common.settings.IndexScopedSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.indices.mapper.MapperRegistry;
|
import org.elasticsearch.indices.mapper.MapperRegistry;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
import org.elasticsearch.test.VersionUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
@ -54,6 +55,28 @@ public class MetaDataIndexUpgradeServiceTests extends ESTestCase {
|
||||||
assertSame(indexMetaData, src);
|
assertSame(indexMetaData, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testUpgrade() {
|
||||||
|
MetaDataIndexUpgradeService service = new MetaDataIndexUpgradeService(Settings.EMPTY, new MapperRegistry(Collections.emptyMap(), Collections.emptyMap()), IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
|
||||||
|
IndexMetaData src = newIndexMeta("foo", Settings.builder().put("index.refresh_interval", "-200").build());
|
||||||
|
assertFalse(service.isUpgraded(src));
|
||||||
|
src = service.upgradeIndexMetaData(src);
|
||||||
|
assertTrue(service.isUpgraded(src));
|
||||||
|
assertEquals("-200", src.getSettings().get("archived.index.refresh_interval"));
|
||||||
|
assertNull(src.getSettings().get("index.refresh_interval"));
|
||||||
|
assertSame(src, service.upgradeIndexMetaData(src)); // no double upgrade
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIsUpgraded() {
|
||||||
|
MetaDataIndexUpgradeService service = new MetaDataIndexUpgradeService(Settings.EMPTY, new MapperRegistry(Collections.emptyMap(), Collections.emptyMap()), IndexScopedSettings.DEFAULT_SCOPED_SETTINGS);
|
||||||
|
IndexMetaData src = newIndexMeta("foo", Settings.builder().put("index.refresh_interval", "-200").build());
|
||||||
|
assertFalse(service.isUpgraded(src));
|
||||||
|
Version version = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), VersionUtils.getPreviousVersion());
|
||||||
|
src = newIndexMeta("foo", Settings.builder().put(IndexMetaData.SETTING_VERSION_UPGRADED, version).build());
|
||||||
|
assertFalse(service.isUpgraded(src));
|
||||||
|
src = newIndexMeta("foo", Settings.builder().put(IndexMetaData.SETTING_VERSION_UPGRADED, Version.CURRENT).build());
|
||||||
|
assertTrue(service.isUpgraded(src));
|
||||||
|
}
|
||||||
|
|
||||||
public static IndexMetaData newIndexMeta(String name, Settings indexSettings) {
|
public static IndexMetaData newIndexMeta(String name, Settings indexSettings) {
|
||||||
Settings build = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
Settings build = Settings.settingsBuilder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
|
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
|
||||||
|
|
Loading…
Reference in New Issue