private static boolean clusterHas5xIndices(ClusterState state) { final Iterator<IndexMetaData> indices = state.metaData().indices().valuesIt(); for(;indices.hasNext();) { final IndexMetaData indexMetaData = indices.next(); if(indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1)) { return true; } } return false; } }
ShardSplittingQuery(IndexMetaData indexMetaData, int shardId, boolean hasNested) { if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_rc2)) { throw new IllegalArgumentException("Splitting query can only be executed on an index created with version " + Version.V_6_0_0_rc2 + " or higher"); } this.indexMetaData = indexMetaData; this.shardId = shardId; this.nestedParentBitSetProducer = hasNested ? newParentDocBitSetProducer(indexMetaData.getCreationVersion()) : null; } @Override
private static boolean isSupportedVersion(IndexMetaData indexMetaData, Version minimumIndexCompatibilityVersion) { return indexMetaData.getCreationVersion().onOrAfter(minimumIndexCompatibilityVersion); }
/** * Ensures that all indices are compatible with the given node version. This will ensure that all indices in the given metadata * will not be created with a newer version of elasticsearch as well as that all indices are newer or equal to the minimum index * compatibility version. * @see Version#minimumIndexCompatibilityVersion() * @throws IllegalStateException if any index is incompatible with the given version */ static void ensureIndexCompatibility(final Version nodeVersion, MetaData metaData) { Version supportedIndexVersion = nodeVersion.minimumIndexCompatibilityVersion(); // we ensure that all indices in the cluster we join are compatible with us no matter if they are // closed or not we can't read mappings of these indices so we need to reject the join... for (IndexMetaData idxMetaData : metaData) { if (idxMetaData.getCreationVersion().after(nodeVersion)) { throw new IllegalStateException("index " + idxMetaData.getIndex() + " version not supported: " + idxMetaData.getCreationVersion() + " the node version is: " + nodeVersion); } if (idxMetaData.getCreationVersion().before(supportedIndexVersion)) { throw new IllegalStateException("index " + idxMetaData.getIndex() + " version not supported: " + idxMetaData.getCreationVersion() + " minimum compatible index version is: " + supportedIndexVersion); } } }
/** * Elasticsearch v6.0 no longer supports indices created pre v5.0. All indices * that were created before Elasticsearch v5.0 should be re-indexed in Elasticsearch 5.x * before they can be opened by this version of elasticsearch. */ private void checkSupportedVersion(IndexMetaData indexMetaData, Version minimumIndexCompatibilityVersion) { if (indexMetaData.getState() == IndexMetaData.State.OPEN && isSupportedVersion(indexMetaData, minimumIndexCompatibilityVersion) == false) { throw new IllegalStateException("The index [" + indexMetaData.getIndex() + "] was created with version [" + indexMetaData.getCreationVersion() + "] but the minimum compatible version is [" + minimumIndexCompatibilityVersion + "]. It should be re-indexed in Elasticsearch " + minimumIndexCompatibilityVersion.major + ".x before upgrading to " + Version.CURRENT + "."); } }
static void validateSplitIndex(ClusterState state, String sourceIndex, Set<String> targetIndexMappingsTypes, String targetIndexName, Settings targetIndexSettings) { IndexMetaData sourceMetaData = validateResize(state, sourceIndex, targetIndexMappingsTypes, targetIndexName, targetIndexSettings); IndexMetaData.selectSplitShard(0, sourceMetaData, IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings)); if (sourceMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1)) { // ensure we have a single type since this would make the splitting code considerably more complex // and a 5.x index would not be splittable unless it has been shrunk before so rather opt out of the complexity // since in 5.x we don't have a setting to artificially set the number of routing shards throw new IllegalStateException("source index created version is too old to apply a split operation"); } }
final boolean hasNested = indexShard.mapperService().hasNested(); final boolean isSplit = sourceMetaData.getNumberOfShards() < indexShard.indexSettings().getNumberOfShards(); assert isSplit == false || sourceMetaData.getCreationVersion().onOrAfter(Version.V_6_0_0_alpha1) : "for split we require a " + "single type but the index is created before 6.0.0"; return executeRecovery(indexShard, () -> {
@Override public ClusterState execute(ClusterState currentState) { MetaData.Builder metaDataBuilder = MetaData.builder(currentState.metaData()); for (Map.Entry<String, Tuple<Version, String>> entry : request.versions().entrySet()) { String index = entry.getKey(); IndexMetaData indexMetaData = metaDataBuilder.get(index); if (indexMetaData != null) { if (Version.CURRENT.equals(indexMetaData.getCreationVersion()) == false) { // no reason to pollute the settings, we didn't really upgrade anything metaDataBuilder.put( IndexMetaData .builder(indexMetaData) .settings( Settings .builder() .put(indexMetaData.getSettings()) .put(IndexMetaData.SETTING_VERSION_UPGRADED, entry.getValue().v1())) .settingsVersion(1 + indexMetaData.getSettingsVersion())); } } } return ClusterState.builder(currentState).metaData(metaDataBuilder).build(); } });
.put(IndexMetaData.SETTING_INDEX_VERSION_CREATED.getKey(), sourceMetaData.getCreationVersion()) .put(IndexMetaData.SETTING_VERSION_UPGRADED, sourceMetaData.getUpgradedVersion()) .put(builder.build())
&& currentIndexMetaData.getCreationVersion().onOrAfter(Version.V_6_5_0)) { final long currentSettingsVersion = currentIndexMetaData.getSettingsVersion(); final long newSettingsVersion = newIndexMetaData.getSettingsVersion();
StringBuilder sb = new StringBuilder(); for (IndexMetaData indexMetaData : request.indices) { if (indexMetaData.getCreationVersion().before(minIndexCompatibilityVersion)) { logger.warn("ignoring dangled index [{}] on node [{}]" + " since it's created version [{}] is not supported by at least one node in the cluster minVersion [{}]", indexMetaData.getIndex(), request.fromNode, indexMetaData.getCreationVersion(), minIndexCompatibilityVersion); continue;
if (Assertions.ENABLED && currentIndexMetaData != null && currentIndexMetaData.getCreationVersion().onOrAfter(Version.V_6_5_0)) { if (currentIndexMetaData.getMappingVersion() == newIndexMetaData.getMappingVersion()) {
final IndexMetaData indexMetaData = metaData.index(concreteIndex); MappingMetaData mappingMd = indexMetaData.mappingOrDefault(indexRequest.type()); Version indexCreated = indexMetaData.getCreationVersion(); indexRequest.resolveRouting(metaData); indexRequest.process(indexCreated, mappingMd, concreteIndex.getName());
ShardSplittingQuery(IndexMetaData indexMetaData, int shardId, boolean hasNested) { if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_rc2)) { throw new IllegalArgumentException("Splitting query can only be executed on an index created with version " + Version.V_6_0_0_rc2 + " or higher"); } this.indexMetaData = indexMetaData; this.shardId = shardId; this.nestedParentBitSetProducer = hasNested ? newParentDocBitSetProducer(indexMetaData.getCreationVersion()) : null; } @Override
ShardSplittingQuery(IndexMetaData indexMetaData, int shardId, boolean hasNested) { if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_rc2)) { throw new IllegalArgumentException("Splitting query can only be executed on an index created with version " + Version.V_6_0_0_rc2 + " or higher"); } this.indexMetaData = indexMetaData; this.shardId = shardId; this.nestedParentBitSetProducer = hasNested ? newParentDocBitSetProducer(indexMetaData.getCreationVersion()) : null; } @Override
private static boolean isSupportedVersion(IndexMetaData indexMetaData, Version minimumIndexCompatibilityVersion) { return indexMetaData.getCreationVersion().onOrAfter(minimumIndexCompatibilityVersion); }
private static boolean clusterHas5xIndices(ClusterState state) { final Iterator<IndexMetaData> indices = state.metaData().indices().valuesIt(); for(;indices.hasNext();) { final IndexMetaData indexMetaData = indices.next(); if(indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1)) { return true; } } return false; } }
static void validateSplitIndex(ClusterState state, String sourceIndex, Set<String> targetIndexMappingsTypes, String targetIndexName, Settings targetIndexSettings) { IndexMetaData sourceMetaData = validateResize(state, sourceIndex, targetIndexMappingsTypes, targetIndexName, targetIndexSettings); IndexMetaData.selectSplitShard(0, sourceMetaData, IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings)); if (sourceMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1)) { // ensure we have a single type since this would make the splitting code considerably more complex // and a 5.x index would not be splittable unless it has been shrunk before so rather opt out of the complexity // since in 5.x we don't have a setting to artificially set the number of routing shards throw new IllegalStateException("source index created version is too old to apply a split operation"); } }
private static boolean isSupportedVersion(IndexMetaData indexMetaData) { if (indexMetaData.getCreationVersion().onOrAfter(Version.V_0_90_0_Beta1)) { // The index was created with elasticsearch that was using Lucene 4.0 return true; } if (indexMetaData.getMinimumCompatibleVersion() != null && indexMetaData.getMinimumCompatibleVersion().onOrAfter(org.apache.lucene.util.Version.LUCENE_4_0_0)) { //The index was upgraded we can work with it return true; } return false; }
IndexMetaData metaData = context.getPrimary().indexSettings().getIndexMetaData(); MappingMetaData mappingMd = metaData.mappingOrDefault(indexRequest.type()); indexRequest.process(metaData.getCreationVersion(), mappingMd, updateRequest.concreteIndex()); context.setRequestToExecute(indexRequest); break;