From 98dba262cf3e81d405c8a372983942d59f993557 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Tue, 3 May 2016 11:31:56 +0200 Subject: [PATCH] Use object equality to compare versions in IndexSettings (#18103) Fixes an issue where updating index metadata on a index from a version that it does not have in its static list of known versions fails. --- .../main/java/org/elasticsearch/index/IndexSettings.java | 2 +- .../java/org/elasticsearch/index/IndexSettingsTests.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java index 31e10e4d7ec..7c8cb4ff8c8 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -382,7 +382,7 @@ public final class IndexSettings { */ synchronized boolean updateIndexMetaData(IndexMetaData indexMetaData) { final Settings newSettings = indexMetaData.getSettings(); - if (Version.indexCreated(newSettings) != version) { + if (version.equals(Version.indexCreated(newSettings)) == false) { throw new IllegalArgumentException("version mismatch on settings update expected: " + version + " but was: " + Version.indexCreated(newSettings)); } final String newUUID = newSettings.get(IndexMetaData.SETTING_INDEX_UUID, IndexMetaData.INDEX_UUID_NA_VALUE); diff --git a/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java b/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java index 07962153d13..9c5040589ae 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexSettingsTests.java @@ -110,6 +110,15 @@ public class IndexSettingsTests extends ESTestCase { assertTrue(ex.getMessage(), ex.getMessage().startsWith("version mismatch on settings update expected: ")); } + // use version number that is unknown + metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.fromId(999999)) + .build()); + settings = new IndexSettings(metaData, Settings.EMPTY); + assertEquals(Version.fromId(999999), settings.getIndexVersionCreated()); + assertEquals("_na_", settings.getUUID()); + settings.updateIndexMetaData(newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, + Version.fromId(999999)).put("index.test.setting.int", 42).build())); + metaData = newIndexMeta("index", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetaData.SETTING_INDEX_UUID, "0xdeadbeef").build()); settings = new IndexSettings(metaData, Settings.EMPTY);