当前位置: 首页>>代码示例>>Java>>正文


Java IndexService.removeShard方法代码示例

本文整理汇总了Java中org.elasticsearch.index.IndexService.removeShard方法的典型用法代码示例。如果您正苦于以下问题:Java IndexService.removeShard方法的具体用法?Java IndexService.removeShard怎么用?Java IndexService.removeShard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.index.IndexService的用法示例。


在下文中一共展示了IndexService.removeShard方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applyDeletedShards

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
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)");
                }
            }
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:39,代码来源:IndicesClusterStateService.java

示例2: failAndRemoveShard

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
private void failAndRemoveShard(ShardRouting shardRouting, IndexService indexService, boolean sendShardFailure, String message, @Nullable Throwable failure) {
    if (indexService.hasShard(shardRouting.getId())) {
        try {
            indexService.removeShard(shardRouting.getId(), message);
        } catch (ShardNotFoundException e) {
            // the node got closed on us, ignore it
        } catch (Throwable e1) {
            logger.warn("[{}][{}] failed to remove shard after failure ([{}])", e1, shardRouting.getIndex(), shardRouting.getId(), message);
        }
    }
    if (sendShardFailure) {
        sendFailShard(shardRouting, indexService.indexUUID(), message, failure);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:IndicesClusterStateService.java

示例3: testSnapshotCanceledOnRemovedShard

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
/**
 * This test ensures that when a shard is removed from a node (perhaps due to the node
 * leaving the cluster, then returning), all snapshotting of that shard is aborted, so
 * all Store references held onto by the snapshot are released.
 *
 * See https://github.com/elastic/elasticsearch/issues/20876
 */
public void testSnapshotCanceledOnRemovedShard() throws Exception {
    final int numPrimaries = 1;
    final int numReplicas = 1;
    final int numDocs = 100;
    final String repo = "test-repo";
    final String index = "test-idx";
    final String snapshot = "test-snap";

    assertAcked(prepareCreate(index, 1,
        Settings.builder().put("number_of_shards", numPrimaries).put("number_of_replicas", numReplicas)));

    logger.info("--> indexing some data");
    for (int i = 0; i < numDocs; i++) {
        index(index, "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();

    logger.info("--> creating repository");
    PutRepositoryResponse putRepositoryResponse =
        client().admin().cluster().preparePutRepository(repo).setType("mock").setSettings(Settings.builder()
            .put("location", randomRepoPath())
            .put("random", randomAsciiOfLength(10))
            .put("wait_after_unblock", 200)
        ).get();
    assertTrue(putRepositoryResponse.isAcknowledged());

    String blockedNode = blockNodeWithIndex(repo, index);

    logger.info("--> snapshot");
    client().admin().cluster().prepareCreateSnapshot(repo, snapshot)
        .setWaitForCompletion(false)
        .execute();

    logger.info("--> waiting for block to kick in on node [{}]", blockedNode);
    waitForBlock(blockedNode, repo, TimeValue.timeValueSeconds(10));

    logger.info("--> removing primary shard that is being snapshotted");
    ClusterState clusterState = internalCluster().clusterService(internalCluster().getMasterName()).state();
    IndexRoutingTable indexRoutingTable = clusterState.getRoutingTable().index(index);
    String nodeWithPrimary = clusterState.nodes().get(indexRoutingTable.shard(0).primaryShard().currentNodeId()).getName();
    assertNotNull("should be at least one node with a primary shard", nodeWithPrimary);
    IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeWithPrimary);
    IndexService indexService = indicesService.indexService(resolveIndex(index));
    indexService.removeShard(0, "simulate node removal");

    logger.info("--> unblocking blocked node [{}]", blockedNode);
    unblockNode(repo, blockedNode);

    logger.info("--> ensuring snapshot is aborted and the aborted shard was marked as failed");
    SnapshotInfo snapshotInfo = waitForCompletion(repo, snapshot, TimeValue.timeValueSeconds(10));
    assertEquals(1, snapshotInfo.shardFailures().size());
    assertEquals(0, snapshotInfo.shardFailures().get(0).shardId());
    assertEquals("IndexShardSnapshotFailedException[Aborted]", snapshotInfo.shardFailures().get(0).reason());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:62,代码来源:SharedClusterSnapshotRestoreIT.java

示例4: clusterChanged

import org.elasticsearch.index.IndexService; //导入方法依赖的package包/类
@Override
public void clusterChanged(final ClusterChangedEvent event) {
    if (!indicesService.changesAllowed()) {
        return;
    }

    if (!lifecycle.started()) {
        return;
    }

    synchronized (mutex) {
        // we need to clean the shards and indices we have on this node, since we
        // are going to recover them again once state persistence is disabled (no master / not recovered)
        // TODO: this feels a bit hacky here, a block disables state persistence, and then we clean the allocated shards, maybe another flag in blocks?
        if (event.state().blocks().disableStatePersistence()) {
            logger.info("cluster state have disable persistence state, so skip the state change and unload indecies");
            for (IndexService indexService : indicesService) {
                String index = indexService.index().getName();
                for (Integer shardId : indexService.shardIds()) {
                    logger.debug("[{}][{}] removing shard (disabled block persistence)", index, shardId);
                    try {
                        indexService.removeShard(shardId, "removing shard (disabled block persistence)");
                    } catch (Throwable e) {
                        logger.warn("[{}] failed to remove shard (disabled block persistence)", e, index);
                    }
                }
                removeIndex(index, "cleaning index (disabled block persistence)");
            }
            return;
        }
        logger.info("begin to apply cluster state to local indices service and mappings");

        cleanFailedShards(event);

        applyDeletedIndices(event);
        applyNewIndices(event);
        applyMappings(event);
        applyAliases(event);
        applyNewOrUpdatedShards(event);
        applyDeletedShards(event);
        applyCleanedIndices(event);
        applySettings(event);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:45,代码来源:IndicesClusterStateService.java


注:本文中的org.elasticsearch.index.IndexService.removeShard方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。