Java Code Examples for org.elasticsearch.cluster.metadata.IndexMetaData#getState()

The following examples show how to use org.elasticsearch.cluster.metadata.IndexMetaData#getState() . 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: ClusterBlocks.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public Builder addBlocks(IndexMetaData indexMetaData) {
    if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
        addIndexBlock(indexMetaData.getIndex(), MetaDataIndexStateService.INDEX_CLOSED_BLOCK);
    }
    if (indexMetaData.getSettings().getAsBoolean(IndexMetaData.SETTING_READ_ONLY, false)) {
        addIndexBlock(indexMetaData.getIndex(), IndexMetaData.INDEX_READ_ONLY_BLOCK);
    }
    if (indexMetaData.getSettings().getAsBoolean(IndexMetaData.SETTING_BLOCKS_READ, false)) {
        addIndexBlock(indexMetaData.getIndex(), IndexMetaData.INDEX_READ_BLOCK);
    }
    if (indexMetaData.getSettings().getAsBoolean(IndexMetaData.SETTING_BLOCKS_WRITE, false)) {
        addIndexBlock(indexMetaData.getIndex(), IndexMetaData.INDEX_WRITE_BLOCK);
    }
    if (indexMetaData.getSettings().getAsBoolean(IndexMetaData.SETTING_BLOCKS_METADATA, false)) {
        addIndexBlock(indexMetaData.getIndex(), IndexMetaData.INDEX_METADATA_BLOCK);
    }
    return this;
}
 
Example 2
Source File: ClusterBlocks.java    From crate with Apache License 2.0 6 votes vote down vote up
public Builder addBlocks(IndexMetaData indexMetaData) {
    String indexName = indexMetaData.getIndex().getName();
    if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
        addIndexBlock(indexName, IndexMetaData.INDEX_CLOSED_BLOCK);
    }
    if (IndexMetaData.INDEX_READ_ONLY_SETTING.get(indexMetaData.getSettings())) {
        addIndexBlock(indexName, IndexMetaData.INDEX_READ_ONLY_BLOCK);
    }
    if (IndexMetaData.INDEX_BLOCKS_READ_SETTING.get(indexMetaData.getSettings())) {
        addIndexBlock(indexName, IndexMetaData.INDEX_READ_BLOCK);
    }
    if (IndexMetaData.INDEX_BLOCKS_WRITE_SETTING.get(indexMetaData.getSettings())) {
        addIndexBlock(indexName, IndexMetaData.INDEX_WRITE_BLOCK);
    }
    if (IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.get(indexMetaData.getSettings())) {
        addIndexBlock(indexName, IndexMetaData.INDEX_METADATA_BLOCK);
    }
    if (IndexMetaData.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.get(indexMetaData.getSettings())) {
        addIndexBlock(indexName, IndexMetaData.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK);
    }
    return this;
}
 
Example 3
Source File: IndicesClusterStateService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void applyDeletedShards(final ClusterChangedEvent event) {
    RoutingNodes.RoutingNodeIterator routingNode = event.state().getRoutingNodes().routingNodeIter(event.state().nodes().localNodeId());
    if (routingNode == null) {
        return;
    }
    IntHashSet newShardIds = new IntHashSet();
    for (IndexService indexService : indicesService) {
        String index = indexService.index().name();
        IndexMetaData indexMetaData = event.state().metaData().index(index);
        if (indexMetaData == null) {
            continue;
        }
        // now, go over and delete shards that needs to get deleted
        newShardIds.clear();
        for (ShardRouting shard : routingNode) {
            if (shard.index().equals(index)) {
                newShardIds.add(shard.id());
            }
        }
        for (Integer existingShardId : indexService.shardIds()) {
            if (!newShardIds.contains(existingShardId)) {
                if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("[{}][{}] removing shard (index is closed)", index, existingShardId);
                    }
                    indexService.removeShard(existingShardId, "removing shard (index is closed)");
                } else {
                    // we can just remove the shard, without cleaning it locally, since we will clean it
                    // when all shards are allocated in the IndicesStore
                    if (logger.isDebugEnabled()) {
                        logger.debug("[{}][{}] removing shard (not allocated)", index, existingShardId);
                    }
                    indexService.removeShard(existingShardId, "removing shard (not allocated)");
                }
            }
        }
    }
}
 
Example 4
Source File: RoutingTable.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Builder addAsNew(IndexMetaData indexMetaData) {
    if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
        IndexRoutingTable.Builder indexRoutingBuilder = new IndexRoutingTable.Builder(indexMetaData.getIndex())
                .initializeAsNew(indexMetaData);
        add(indexRoutingBuilder);
    }
    return this;
}
 
Example 5
Source File: RoutingTable.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Builder addAsRecovery(IndexMetaData indexMetaData) {
    if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
        IndexRoutingTable.Builder indexRoutingBuilder = new IndexRoutingTable.Builder(indexMetaData.getIndex())
                .initializeAsRecovery(indexMetaData);
        add(indexRoutingBuilder);
    }
    return this;
}
 
Example 6
Source File: RoutingTable.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Builder addAsFromDangling(IndexMetaData indexMetaData) {
    if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
        IndexRoutingTable.Builder indexRoutingBuilder = new IndexRoutingTable.Builder(indexMetaData.getIndex())
                .initializeAsFromDangling(indexMetaData);
        add(indexRoutingBuilder);
    }
    return this;
}
 
Example 7
Source File: RoutingTable.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Builder addAsFromCloseToOpen(IndexMetaData indexMetaData) {
    if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
        IndexRoutingTable.Builder indexRoutingBuilder = new IndexRoutingTable.Builder(indexMetaData.getIndex())
                .initializeAsFromCloseToOpen(indexMetaData);
        add(indexRoutingBuilder);
    }
    return this;
}
 
Example 8
Source File: TransportBulkAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private boolean addFailureIfIndexIsUnavailable(DocumentRequest request, BulkRequest bulkRequest, AtomicArray<BulkItemResponse> responses, int idx,
                                          final ConcreteIndices concreteIndices,
                                          final MetaData metaData) {
    String concreteIndex = concreteIndices.getConcreteIndex(request.index());
    Exception unavailableException = null;
    if (concreteIndex == null) {
        try {
            concreteIndex = concreteIndices.resolveIfAbsent(request);
        } catch (IndexClosedException | IndexNotFoundException ex) {
            // Fix for issue where bulk request references an index that
            // cannot be auto-created see issue #8125
            unavailableException = ex;
        }
    }
    if (unavailableException == null) {
        IndexMetaData indexMetaData = metaData.index(concreteIndex);
        if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
            unavailableException = new IndexClosedException(new Index(metaData.index(request.index()).getIndex()));
        }
    }
    if (unavailableException != null) {
        BulkItemResponse.Failure failure = new BulkItemResponse.Failure(request.index(), request.type(), request.id(),
                unavailableException);
        String operationType = "unknown";
        if (request instanceof IndexRequest) {
            operationType = "index";
        } else if (request instanceof DeleteRequest) {
            operationType = "delete";
        } else if (request instanceof UpdateRequest) {
            operationType = "update";
        }
        BulkItemResponse bulkItemResponse = new BulkItemResponse(idx, operationType, failure);
        responses.set(idx, bulkItemResponse);
        // make sure the request gets never processed again
        bulkRequest.requests.set(idx, null);
        return true;
    }
    return false;
}
 
Example 9
Source File: RoutingTable.java    From crate with Apache License 2.0 5 votes vote down vote up
public Builder addAsNew(IndexMetaData indexMetaData) {
    if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
        IndexRoutingTable.Builder indexRoutingBuilder = new IndexRoutingTable.Builder(indexMetaData.getIndex())
                .initializeAsNew(indexMetaData);
        add(indexRoutingBuilder);
    }
    return this;
}
 
Example 10
Source File: RoutingTable.java    From crate with Apache License 2.0 5 votes vote down vote up
public Builder addAsRecovery(IndexMetaData indexMetaData) {
    if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
        IndexRoutingTable.Builder indexRoutingBuilder = new IndexRoutingTable.Builder(indexMetaData.getIndex())
                .initializeAsRecovery(indexMetaData);
        add(indexRoutingBuilder);
    }
    return this;
}
 
Example 11
Source File: RoutingTable.java    From crate with Apache License 2.0 5 votes vote down vote up
public Builder addAsFromDangling(IndexMetaData indexMetaData) {
    if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
        IndexRoutingTable.Builder indexRoutingBuilder = new IndexRoutingTable.Builder(indexMetaData.getIndex())
                .initializeAsFromDangling(indexMetaData);
        add(indexRoutingBuilder);
    }
    return this;
}
 
Example 12
Source File: RoutingTable.java    From crate with Apache License 2.0 5 votes vote down vote up
public Builder addAsFromCloseToOpen(IndexMetaData indexMetaData) {
    if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
        IndexRoutingTable.Builder indexRoutingBuilder = new IndexRoutingTable.Builder(indexMetaData.getIndex())
                .initializeAsFromCloseToOpen(indexMetaData);
        add(indexRoutingBuilder);
    }
    return this;
}
 
Example 13
Source File: InternalBlobTableInfoFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public BlobTableInfo create(RelationName ident, ClusterState clusterState) {
    IndexMetaData indexMetaData = resolveIndexMetaData(ident.name(), clusterState);
    Settings settings = indexMetaData.getSettings();
    return new BlobTableInfo(
        ident,
        indexMetaData.getIndex().getName(),
        indexMetaData.getNumberOfShards(),
        NumberOfReplicas.fromSettings(settings),
        settings,
        blobsPath(settings),
        IndexMetaData.SETTING_INDEX_VERSION_CREATED.get(settings),
        settings.getAsVersion(IndexMetaData.SETTING_VERSION_UPGRADED, null),
        indexMetaData.getState() == IndexMetaData.State.CLOSE);
}
 
Example 14
Source File: DDLClusterStateHelpers.java    From crate with Apache License 2.0 5 votes vote down vote up
static Set<IndexMetaData> indexMetaDataSetFromIndexNames(MetaData metaData,
                                                         String[] indices,
                                                         IndexMetaData.State state) {
    Set<IndexMetaData> indicesMetaData = new HashSet<>();
    for (String indexName : indices) {
        IndexMetaData indexMetaData = metaData.index(indexName);
        if (indexMetaData != null && indexMetaData.getState() != state) {
            indicesMetaData.add(indexMetaData);
        }
    }
    return indicesMetaData;
}
 
Example 15
Source File: DocIndexMetaData.java    From crate with Apache License 2.0 5 votes vote down vote up
public static boolean isClosed(IndexMetaData indexMetaData, Map<String, Object> mappingMap, boolean isPartitioned) {
    // Checking here for whether the closed flag exists on the template metadata, as partitioned tables that are
    // empty (and thus have no indexes who have states) need a way to set their state.
    if (isPartitioned) {
        return Maps.getOrDefault(
            Maps.getOrDefault(mappingMap, "_meta", null),
            SETTING_CLOSED,
            false);
    }
    return indexMetaData.getState() == IndexMetaData.State.CLOSE;
}