|
@@ -24,7 +24,11 @@ import org.elasticsearch.cluster.routing.HashFunction;
|
|
|
import org.elasticsearch.cluster.routing.SimpleHashFunction;
|
|
|
import org.elasticsearch.common.component.AbstractComponent;
|
|
|
import org.elasticsearch.common.inject.Inject;
|
|
|
+import org.elasticsearch.common.logging.ESLogger;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
+import com.google.common.collect.ImmutableSet;
|
|
|
+
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* This service is responsible for upgrading legacy index metadata to the current version
|
|
@@ -73,28 +77,28 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
|
|
|
/**
|
|
|
* Checks that the index can be upgraded to the current version of the master node.
|
|
|
*
|
|
|
- * If the index does need upgrade it returns the index metadata unchanged, otherwise it returns a modified index metadata. If index cannot be
|
|
|
+ * If the index does not need upgrade it returns the index metadata unchanged, otherwise it returns a modified index metadata. If index cannot be
|
|
|
* updated the method throws an exception.
|
|
|
*/
|
|
|
public IndexMetaData upgradeIndexMetaData(IndexMetaData indexMetaData) throws Exception {
|
|
|
- IndexMetaData newMetaData = indexMetaData;
|
|
|
- newMetaData = checkSupportedVersion(newMetaData);
|
|
|
- newMetaData = upgradeLegacyRoutingSettings(newMetaData);
|
|
|
+ // Throws an exception if there are too-old segments:
|
|
|
+ checkSupportedVersion(indexMetaData);
|
|
|
+ IndexMetaData newMetaData = upgradeLegacyRoutingSettings(indexMetaData);
|
|
|
+ newMetaData = addDefaultUnitsIfNeeded(newMetaData);
|
|
|
return newMetaData;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Elasticsearch 2.0 deprecated no longer supports indices with pre Lucene v4.0 segments. All indices
|
|
|
+ * Elasticsearch 2.0 no longer supports indices with pre Lucene v4.0 (Elasticsearch v 0.90.0) segments. All indices
|
|
|
* that were created before Elasticsearch v0.90.0 should be upgraded using upgrade plugin before they can
|
|
|
* be open by this version of elasticsearch.
|
|
|
*/
|
|
|
- private IndexMetaData checkSupportedVersion(IndexMetaData indexMetaData) throws Exception {
|
|
|
+ private void checkSupportedVersion(IndexMetaData indexMetaData) throws Exception {
|
|
|
if (indexMetaData.getState() == IndexMetaData.State.OPEN && isSupportedVersion(indexMetaData) == false) {
|
|
|
throw new IllegalStateException("The index [" + indexMetaData.getIndex() + "] was created before v0.90.0 and wasn't upgraded."
|
|
|
+ " This index should be open using a version before " + Version.CURRENT.minimumCompatibilityVersion()
|
|
|
+ " and upgraded using the upgrade API.");
|
|
|
}
|
|
|
- return indexMetaData;
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -131,4 +135,96 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
|
|
|
return indexMetaData;
|
|
|
}
|
|
|
|
|
|
+ /** All known byte-sized settings for an index. */
|
|
|
+ public static final Set<String> INDEX_BYTES_SIZE_SETTINGS = ImmutableSet.of(
|
|
|
+ "index.buffer_size",
|
|
|
+ "index.merge.policy.floor_segment",
|
|
|
+ "index.merge.policy.max_merged_segment",
|
|
|
+ "index.merge.policy.max_merge_size",
|
|
|
+ "index.merge.policy.min_merge_size",
|
|
|
+ "index.shard.recovery.file_chunk_size",
|
|
|
+ "index.shard.recovery.translog_size",
|
|
|
+ "index.store.throttle.max_bytes_per_sec",
|
|
|
+ "index.translog.flush_threshold_size",
|
|
|
+ "index.translog.fs.buffer_size",
|
|
|
+ "index.version_map_size");
|
|
|
+
|
|
|
+ /** All known time settings for an index. */
|
|
|
+ public static final Set<String> INDEX_TIME_SETTINGS = ImmutableSet.of(
|
|
|
+ "index.gateway.wait_for_mapping_update_post_recovery",
|
|
|
+ "index.gc_deletes",
|
|
|
+ "index.indexing.slowlog.threshold.index.debug",
|
|
|
+ "index.indexing.slowlog.threshold.index.info",
|
|
|
+ "index.indexing.slowlog.threshold.index.trace",
|
|
|
+ "index.indexing.slowlog.threshold.index.warn",
|
|
|
+ "index.refresh_interval",
|
|
|
+ "index.search.slowlog.threshold.fetch.debug",
|
|
|
+ "index.search.slowlog.threshold.fetch.info",
|
|
|
+ "index.search.slowlog.threshold.fetch.trace",
|
|
|
+ "index.search.slowlog.threshold.fetch.warn",
|
|
|
+ "index.search.slowlog.threshold.query.debug",
|
|
|
+ "index.search.slowlog.threshold.query.info",
|
|
|
+ "index.search.slowlog.threshold.query.trace",
|
|
|
+ "index.search.slowlog.threshold.query.warn",
|
|
|
+ "index.shadow.wait_for_initial_commit",
|
|
|
+ "index.store.stats_refresh_interval",
|
|
|
+ "index.translog.flush_threshold_period",
|
|
|
+ "index.translog.interval",
|
|
|
+ "index.translog.sync_interval");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Elasticsearch 2.0 requires units on byte/memory and time settings; this method adds the default unit to any such settings that are
|
|
|
+ * missing units.
|
|
|
+ */
|
|
|
+ private IndexMetaData addDefaultUnitsIfNeeded(IndexMetaData indexMetaData) {
|
|
|
+ if (indexMetaData.getCreationVersion().before(Version.V_2_0_0)) {
|
|
|
+ // Created lazily if we find any settings that are missing units:
|
|
|
+ Settings settings = indexMetaData.settings();
|
|
|
+ Settings.Builder newSettings = null;
|
|
|
+ for(String byteSizeSetting : INDEX_BYTES_SIZE_SETTINGS) {
|
|
|
+ String value = settings.get(byteSizeSetting);
|
|
|
+ if (value != null) {
|
|
|
+ try {
|
|
|
+ Double.parseDouble(value);
|
|
|
+ } catch (NumberFormatException nfe) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // It's a naked number; add default unit (b for bytes):
|
|
|
+ logger.warn("byte-sized setting [{}] with value [{}] is missing units; now adding default units (b)", byteSizeSetting, value);
|
|
|
+ if (newSettings == null) {
|
|
|
+ newSettings = Settings.builder();
|
|
|
+ newSettings.put(settings);
|
|
|
+ }
|
|
|
+ newSettings.put(byteSizeSetting, value + "b");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String timeSetting : INDEX_TIME_SETTINGS) {
|
|
|
+ String value = settings.get(timeSetting);
|
|
|
+ if (value != null) {
|
|
|
+ try {
|
|
|
+ Double.parseDouble(value);
|
|
|
+ } catch (NumberFormatException nfe) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // It's a naked number; add default unit (ms for msec):
|
|
|
+ logger.warn("time setting [{}] with value [{}] is missing units; now adding default units (ms)", timeSetting, value);
|
|
|
+ if (newSettings == null) {
|
|
|
+ newSettings = Settings.builder();
|
|
|
+ newSettings.put(settings);
|
|
|
+ }
|
|
|
+ newSettings.put(timeSetting, value + "ms");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (newSettings != null) {
|
|
|
+ // At least one setting was changed:
|
|
|
+ return IndexMetaData.builder(indexMetaData)
|
|
|
+ .version(indexMetaData.version())
|
|
|
+ .settings(newSettings.build())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // No changes:
|
|
|
+ return indexMetaData;
|
|
|
+ }
|
|
|
}
|