Java Code Examples for org.elasticsearch.cluster.metadata.MetaData#hasIndex()

The following examples show how to use org.elasticsearch.cluster.metadata.MetaData#hasIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportDeleteAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static void resolveAndValidateRouting(final MetaData metaData, String concreteIndex, DeleteRequest request) {
    request.routing(metaData.resolveIndexRouting(request.routing(), request.index()));
    if (metaData.hasIndex(concreteIndex)) {
        // check if routing is required, if so, throw error if routing wasn't specified
        MappingMetaData mappingMd = metaData.index(concreteIndex).mappingOrDefault(request.type());
        if (mappingMd != null && mappingMd.routing().required()) {
            if (request.routing() == null) {
                if (request.versionType() != VersionType.INTERNAL) {
                    // TODO: implement this feature
                    throw new IllegalArgumentException("routing value is required for deleting documents of type [" + request.type()
                        + "] while using version_type [" + request.versionType() + "]");
                }
                throw new RoutingMissingException(concreteIndex, request.type(), request.id());
            }
        }
    }
}
 
Example 2
Source File: SnapshotsService.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Returns list of indices with missing shards, and list of indices that are closed
 *
 * @param shards list of shard statuses
 * @return list of failed and closed indices
 */
private static Tuple<Set<String>, Set<String>> indicesWithMissingShards(
    ImmutableOpenMap<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shards, MetaData metaData) {
    Set<String> missing = new HashSet<>();
    Set<String> closed = new HashSet<>();
    for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> entry : shards) {
        if (entry.value.state() == ShardState.MISSING) {
            if (metaData.hasIndex(entry.key.getIndex().getName()) &&
                metaData.getIndexSafe(entry.key.getIndex()).getState() == IndexMetaData.State.CLOSE) {
                closed.add(entry.key.getIndex().getName());
            } else {
                missing.add(entry.key.getIndex().getName());
            }
        }
    }
    return new Tuple<>(missing, closed);
}
 
Example 3
Source File: InsertFromValues.java    From crate with Apache License 2.0 6 votes vote down vote up
private static CompletableFuture<AcknowledgedResponse> createIndices(TransportCreatePartitionsAction
                                                                         createPartitionsAction,
                                                                     Set<String> indices,
                                                                     ClusterService clusterService,
                                                                     UUID jobId) {
    MetaData metaData = clusterService.state().getMetaData();
    List<String> indicesToCreate = new ArrayList<>();
    for (var index : indices) {
        if (IndexParts.isPartitioned(index) && metaData.hasIndex(index) == false) {
            indicesToCreate.add(index);
        }
    }

    FutureActionListener<AcknowledgedResponse, AcknowledgedResponse> listener = new FutureActionListener<>(r -> r);
    createPartitionsAction.execute(new CreatePartitionsRequest(indicesToCreate, jobId), listener);
    return listener;
}
 
Example 4
Source File: BlobIndices.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void removeIndexLocationsForDeletedIndices(ClusterChangedEvent event, MetaData currentMetaData) {
    MetaData newMetaData = event.state().metaData();
    for (IndexMetaData current : currentMetaData) {
        String index = current.getIndex();
        if (!newMetaData.hasIndex(index) && isBlobIndex(index)) {
            deleteBlobIndexLocation(current, index);
        }
    }
}
 
Example 5
Source File: DanglingIndicesState.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Cleans dangling indices if they are already allocated on the provided meta data.
 */
void cleanupAllocatedDangledIndices(MetaData metaData) {
    for (String danglingIndex : danglingIndices.keySet()) {
        if (metaData.hasIndex(danglingIndex)) {
            logger.debug("[{}] no longer dangling (created), removing from dangling list", danglingIndex);
            danglingIndices.remove(danglingIndex);
        }
    }
}
 
Example 6
Source File: DanglingIndicesState.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Finds new dangling indices by iterating over the indices and trying to find indices
 * that have state on disk, but are not part of the provided meta data, or not detected
 * as dangled already.
 */
Map<String, IndexMetaData> findNewDanglingIndices(MetaData metaData) {
    final Set<String> indices;
    try {
        indices = nodeEnv.findAllIndices();
    } catch (Throwable e) {
        logger.warn("failed to list dangling indices", e);
        return ImmutableMap.of();
    }

    Map<String, IndexMetaData>  newIndices = Maps.newHashMap();
    for (String indexName : indices) {
        if (metaData.hasIndex(indexName) == false && danglingIndices.containsKey(indexName) == false) {
            try {
                IndexMetaData indexMetaData = metaStateService.loadIndexState(indexName);
                if (indexMetaData != null) {
                    logger.info("[{}] dangling index, exists on local file system, but not in cluster metadata, auto import to cluster state", indexName);
                    if (!indexMetaData.getIndex().equals(indexName)) {
                        logger.info("dangled index directory name is [{}], state name is [{}], renaming to directory name", indexName, indexMetaData.getIndex());
                        indexMetaData = IndexMetaData.builder(indexMetaData).index(indexName).build();
                    }
                    newIndices.put(indexName, indexMetaData);
                } else {
                    logger.debug("[{}] dangling index directory detected, but no state found", indexName);
                }
            } catch (Throwable t) {
                logger.warn("[{}] failed to load index state for detected dangled index", t, indexName);
            }
        }
    }
    return newIndices;
}
 
Example 7
Source File: IndexRoutingTable.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public void validate(RoutingTableValidation validation, MetaData metaData) {
    if (!metaData.hasIndex(index())) {
        validation.addIndexFailure(index(), "Exists in routing does not exists in metadata");
        return;
    }
    IndexMetaData indexMetaData = metaData.index(index());
    for (String failure : validate(indexMetaData)) {
        validation.addIndexFailure(index, failure);
    }

}
 
Example 8
Source File: SnapshotsService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Returns list of indices with missing shards, and list of indices that are closed
 *
 * @param shards list of shard statuses
 * @return list of failed and closed indices
 */
private Tuple<Set<String>, Set<String>> indicesWithMissingShards(ImmutableMap<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shards, MetaData metaData) {
    Set<String> missing = newHashSet();
    Set<String> closed = newHashSet();
    for (ImmutableMap.Entry<ShardId, SnapshotsInProgress.ShardSnapshotStatus> entry : shards.entrySet()) {
        if (entry.getValue().state() == State.MISSING) {
            if (metaData.hasIndex(entry.getKey().getIndex()) && metaData.index(entry.getKey().getIndex()).getState() == IndexMetaData.State.CLOSE) {
                closed.add(entry.getKey().getIndex());
            } else {
                missing.add(entry.getKey().getIndex());
            }
        }
    }
    return new Tuple<>(missing, closed);
}
 
Example 9
Source File: TransportIndexAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void resolveRequest(MetaData metaData, String concreteIndex, IndexRequest request) {
    MappingMetaData mappingMd = null;
    if (metaData.hasIndex(concreteIndex)) {
        mappingMd = metaData.index(concreteIndex).mappingOrDefault(request.type());
    }
    request.process(metaData, mappingMd, allowIdGeneration, concreteIndex);
    ShardId shardId = clusterService.operationRouting().shardId(clusterService.state(), concreteIndex, request.type(), request.id(), request.routing());
    request.setShardId(shardId);
}
 
Example 10
Source File: DanglingIndicesState.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Finds new dangling indices by iterating over the indices and trying to find indices
 * that have state on disk, but are not part of the provided meta data, or not detected
 * as dangled already.
 */
Map<Index, IndexMetaData> findNewDanglingIndices(final MetaData metaData) {
    final Set<String> excludeIndexPathIds = new HashSet<>(metaData.indices().size() + danglingIndices.size());
    for (ObjectCursor<IndexMetaData> cursor : metaData.indices().values()) {
        excludeIndexPathIds.add(cursor.value.getIndex().getUUID());
    }
    excludeIndexPathIds.addAll(danglingIndices.keySet().stream().map(Index::getUUID).collect(Collectors.toList()));
    try {
        final List<IndexMetaData> indexMetaDataList = metaStateService.loadIndicesStates(excludeIndexPathIds::contains);
        Map<Index, IndexMetaData> newIndices = new HashMap<>(indexMetaDataList.size());
        final IndexGraveyard graveyard = metaData.indexGraveyard();
        for (IndexMetaData indexMetaData : indexMetaDataList) {
            if (metaData.hasIndex(indexMetaData.getIndex().getName())) {
                LOGGER.warn("[{}] can not be imported as a dangling index, as index with same name already exists in cluster metadata",
                    indexMetaData.getIndex());
            } else if (graveyard.containsIndex(indexMetaData.getIndex())) {
                LOGGER.warn("[{}] can not be imported as a dangling index, as an index with the same name and UUID exist in the " +
                            "index tombstones.  This situation is likely caused by copying over the data directory for an index " +
                            "that was previously deleted.", indexMetaData.getIndex());
            } else {
                LOGGER.info("[{}] dangling index exists on local file system, but not in cluster metadata, " +
                            "auto import to cluster state", indexMetaData.getIndex());
                newIndices.put(indexMetaData.getIndex(), indexMetaData);
            }
        }
        return newIndices;
    } catch (IOException e) {
        LOGGER.warn("failed to list dangling indices", e);
        return emptyMap();
    }
}
 
Example 11
Source File: TransportCreateViewAction.java    From crate with Apache License 2.0 4 votes vote down vote up
private static boolean conflictsWithTable(RelationName viewName, MetaData indexMetaData) {
    return indexMetaData.hasIndex(viewName.indexNameOrAlias())
           || indexMetaData.templates().containsKey(PartitionName.templateName(viewName.schema(), viewName.name()));
}