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


Java ClusterState.metaData方法代码示例

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


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

示例1: getRelevantIndicesOnDataOnlyNode

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public static Set<Index> getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, Set<Index> previouslyWrittenIndices) {
    RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
    if (newRoutingNode == null) {
        throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state");
    }
    Set<Index> indices = new HashSet<>();
    for (ShardRouting routing : newRoutingNode) {
        indices.add(routing.index());
    }
    // we have to check the meta data also: closed indices will not appear in the routing table, but we must still write the state if we have it written on disk previously
    for (IndexMetaData indexMetaData : state.metaData()) {
        boolean isOrWasClosed = indexMetaData.getState().equals(IndexMetaData.State.CLOSE);
        // if the index is open we might still have to write the state if it just transitioned from closed to open
        // so we have to check for that as well.
        IndexMetaData previousMetaData = previousState.metaData().index(indexMetaData.getIndex());
        if (previousMetaData != null) {
            isOrWasClosed = isOrWasClosed || previousMetaData.getState().equals(IndexMetaData.State.CLOSE);
        }
        if (previouslyWrittenIndices.contains(indexMetaData.getIndex()) && isOrWasClosed) {
            indices.add(indexMetaData.getIndex());
        }
    }
    return indices;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:GatewayMetaState.java

示例2: findNextDelayedAllocation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
/**
 * Finds the next (closest) delay expiration of an delayed shard in nanoseconds based on current time.
 * Returns 0 if delay is negative.
 * Returns -1 if no delayed shard is found.
 */
public static long findNextDelayedAllocation(long currentNanoTime, ClusterState state) {
    MetaData metaData = state.metaData();
    RoutingTable routingTable = state.routingTable();
    long nextDelayNanos = Long.MAX_VALUE;
    for (ShardRouting shard : routingTable.shardsWithState(ShardRoutingState.UNASSIGNED)) {
        UnassignedInfo unassignedInfo = shard.unassignedInfo();
        if (unassignedInfo.isDelayed()) {
            Settings indexSettings = metaData.index(shard.index()).getSettings();
            // calculate next time to schedule
            final long newComputedLeftDelayNanos = unassignedInfo.getRemainingDelay(currentNanoTime, indexSettings);
            if (newComputedLeftDelayNanos < nextDelayNanos) {
                nextDelayNanos = newComputedLeftDelayNanos;
            }
        }
    }
    return nextDelayNanos == Long.MAX_VALUE ? -1L : nextDelayNanos;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:UnassignedInfo.java

示例3: applyRerouteResult

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
private void applyRerouteResult(ClusterState newClusterState) {
    ClusterState previousClusterState = this.clusterState;
    ClusterState.Builder builder = ClusterState.builder(newClusterState).incrementVersion();
    if (previousClusterState.routingTable() != newClusterState.routingTable()) {
        builder.routingTable(RoutingTable.builder(newClusterState.routingTable()).version(newClusterState.routingTable().version() + 1)
                .build());
    }
    if (previousClusterState.metaData() != newClusterState.metaData()) {
        builder.metaData(MetaData.builder(newClusterState.metaData()).version(newClusterState.metaData().version() + 1));
    }
    this.clusterState = builder.build();
    final ClusterStateHealth clusterHealth = new ClusterStateHealth(clusterState);
    logger.info("applied reroute. active shards: p [{}], t [{}], init shards: [{}], relocating: [{}]",
            clusterHealth.getActivePrimaryShards(), clusterHealth.getActiveShards(),
            clusterHealth.getInitializingShards(), clusterHealth.getRelocatingShards());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:PrimaryTermsTests.java

示例4: getRelevantIndicesOnDataOnlyNode

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public static Set<String> getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, ImmutableSet<String> previouslyWrittenIndices) {
    RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().localNodeId());
    if (newRoutingNode == null) {
        throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state");
    }
    Set<String> indices = new HashSet<>();
    for (ShardRouting routing : newRoutingNode) {
        indices.add(routing.index());
    }
    // we have to check the meta data also: closed indices will not appear in the routing table, but we must still write the state if we have it written on disk previously
    for (IndexMetaData indexMetaData : state.metaData()) {
        boolean isOrWasClosed = indexMetaData.getState().equals(IndexMetaData.State.CLOSE);
        // if the index is open we might still have to write the state if it just transitioned from closed to open
        // so we have to check for that as well.
        IndexMetaData previousMetaData = previousState.metaData().getIndices().get(indexMetaData.getIndex());
        if (previousMetaData != null) {
            isOrWasClosed = isOrWasClosed || previousMetaData.getState().equals(IndexMetaData.State.CLOSE);
        }
        if (previouslyWrittenIndices.contains(indexMetaData.getIndex()) && isOrWasClosed) {
            indices.add(indexMetaData.getIndex());
        }
    }
    return indices;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:GatewayMetaState.java

示例5: getRelevantIndicesForMasterEligibleNode

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public static Set<Index> getRelevantIndicesForMasterEligibleNode(ClusterState state) {
    Set<Index> relevantIndices;
    relevantIndices = new HashSet<>();
    // we have to iterate over the metadata to make sure we also capture closed indices
    for (IndexMetaData indexMetaData : state.metaData()) {
        relevantIndices.add(indexMetaData.getIndex());
    }
    return relevantIndices;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:GatewayMetaState.java

示例6: RoutingAllocation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
/**
 * Creates a new {@link RoutingAllocation}
 *  @param deciders {@link AllocationDeciders} to used to make decisions for routing allocations
 * @param routingNodes Routing nodes in the current cluster
 * @param clusterState cluster state before rerouting
 * @param currentNanoTime the nano time to use for all delay allocation calculation (typically {@link System#nanoTime()})
 */
public RoutingAllocation(AllocationDeciders deciders, RoutingNodes routingNodes, ClusterState clusterState, ClusterInfo clusterInfo,
                         long currentNanoTime, boolean retryFailed) {
    this.deciders = deciders;
    this.routingNodes = routingNodes;
    this.metaData = clusterState.metaData();
    this.routingTable = clusterState.routingTable();
    this.nodes = clusterState.nodes();
    this.customs = clusterState.customs();
    this.clusterInfo = clusterInfo;
    this.currentNanoTime = currentNanoTime;
    this.retryFailed = retryFailed;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:RoutingAllocation.java

示例7: getRelevantIndicesForMasterEligibleNode

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public static Set<String> getRelevantIndicesForMasterEligibleNode(ClusterState state) {
    Set<String> relevantIndices;
    relevantIndices = new HashSet<>();
    // we have to iterate over the metadata to make sure we also capture closed indices
    for (IndexMetaData indexMetaData : state.metaData()) {
        relevantIndices.add(indexMetaData.getIndex());
    }
    return relevantIndices;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:GatewayMetaState.java

示例8: masterOperation

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
@Override
protected void masterOperation(final RolloverRequest rolloverRequest, final ClusterState state,
                               final ActionListener<RolloverResponse> listener) {
    final MetaData metaData = state.metaData();
    validate(metaData, rolloverRequest);
    final AliasOrIndex aliasOrIndex = metaData.getAliasAndIndexLookup().get(rolloverRequest.getAlias());
    final IndexMetaData indexMetaData = aliasOrIndex.getIndices().get(0);
    final String sourceProvidedName = indexMetaData.getSettings().get(IndexMetaData.SETTING_INDEX_PROVIDED_NAME,
        indexMetaData.getIndex().getName());
    final String sourceIndexName = indexMetaData.getIndex().getName();
    final String unresolvedName = (rolloverRequest.getNewIndexName() != null)
        ? rolloverRequest.getNewIndexName()
        : generateRolloverIndexName(sourceProvidedName, indexNameExpressionResolver);
    final String rolloverIndexName = indexNameExpressionResolver.resolveDateMathExpression(unresolvedName);
    MetaDataCreateIndexService.validateIndexName(rolloverIndexName, state); // will fail if the index already exists
    client.admin().indices().prepareStats(sourceIndexName).clear().setDocs(true).execute(
        new ActionListener<IndicesStatsResponse>() {
            @Override
            public void onResponse(IndicesStatsResponse statsResponse) {
                final Set<Condition.Result> conditionResults = evaluateConditions(rolloverRequest.getConditions(),
                    statsResponse.getTotal().getDocs(), metaData.index(sourceIndexName));

                if (rolloverRequest.isDryRun()) {
                    listener.onResponse(
                        new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, true, false, false, false));
                    return;
                }
                if (conditionResults.size() == 0 || conditionResults.stream().anyMatch(result -> result.matched)) {
                    CreateIndexClusterStateUpdateRequest updateRequest = prepareCreateIndexRequest(unresolvedName, rolloverIndexName,
                        rolloverRequest);
                    createIndexService.createIndex(updateRequest, ActionListener.wrap(createIndexClusterStateUpdateResponse -> {
                        // switch the alias to point to the newly created index
                        indexAliasesService.indicesAliases(
                            prepareRolloverAliasesUpdateRequest(sourceIndexName, rolloverIndexName,
                                rolloverRequest),
                            ActionListener.wrap(aliasClusterStateUpdateResponse -> {
                                if (aliasClusterStateUpdateResponse.isAcknowledged()) {
                                    activeShardsObserver.waitForActiveShards(rolloverIndexName,
                                        rolloverRequest.getCreateIndexRequest().waitForActiveShards(),
                                        rolloverRequest.masterNodeTimeout(),
                                        isShardsAcked -> listener.onResponse(new RolloverResponse(sourceIndexName, rolloverIndexName,
                                                                                conditionResults, false, true, true, isShardsAcked)),
                                        listener::onFailure);
                                } else {
                                    listener.onResponse(new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults,
                                                                                false, true, false, false));
                                }
                            }, listener::onFailure));
                    }, listener::onFailure));
                } else {
                    // conditions not met
                    listener.onResponse(
                        new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, false, false, false, false)
                    );
                }
            }

            @Override
            public void onFailure(Exception e) {
                listener.onFailure(e);
            }
        }
    );
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:65,代码来源:TransportRolloverAction.java

示例9: testEnableClusterBalanceNoReplicas

import org.elasticsearch.cluster.ClusterState; //导入方法依赖的package包/类
public void testEnableClusterBalanceNoReplicas() {
    final boolean useClusterSetting = randomBoolean();
    Settings build = Settings.builder()
            .put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), useClusterSetting ? Rebalance.NONE: RandomPicks.randomFrom(random(), Rebalance.values())) // index settings override cluster settings
            .put(ConcurrentRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE_SETTING.getKey(), 3)
            .build();
    ClusterSettings clusterSettings = new ClusterSettings(build, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    AllocationService strategy = createAllocationService(build, clusterSettings, random());
    Settings indexSettings = useClusterSetting ? Settings.EMPTY : Settings.builder().put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), Rebalance.NONE).build();

    logger.info("Building initial routing table");
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT).put(indexSettings)).numberOfShards(6).numberOfReplicas(0))
            .build();

    RoutingTable initialRoutingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test"))
            .build();

    ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(initialRoutingTable).build();

    logger.info("--> adding one nodes and do rerouting");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
            .add(newNode("node1"))
            .add(newNode("node2"))
    ).build();
    clusterState = strategy.reroute(clusterState, "reroute");
    assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(6));
    logger.info("--> start the shards (primaries)");
    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(6));
    assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));

    logger.info("--> adding one nodes and do rerouting");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
            .add(newNode("node1"))
            .add(newNode("node2"))
            .add(newNode("node3"))
    ).build();
    clusterState = strategy.reroute(clusterState, "reroute");
    assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(6));
    assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(0));
    metaData = clusterState.metaData();
    if (useClusterSetting) {
        clusterState = ClusterState.builder(clusterState).metaData(MetaData.builder(metaData).transientSettings(Settings.builder()
                .put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), randomBoolean() ? Rebalance.PRIMARIES : Rebalance.ALL)
                .build())).build();
    } else {
        IndexMetaData meta = clusterState.getMetaData().index("test");
        clusterState = ClusterState.builder(clusterState).metaData(MetaData.builder(metaData).removeAllIndices()
                .put(IndexMetaData.builder(meta).settings(Settings.builder().put(meta.getSettings()).put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), randomBoolean() ? Rebalance.PRIMARIES : Rebalance.ALL).build()))).build();
    }
    clusterSettings.applySettings(clusterState.metaData().settings());
    clusterState = strategy.reroute(clusterState, "reroute");
    assertThat("expected 4 primaries to be started and 2 to relocate useClusterSettings: " + useClusterSetting, clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(4));
    assertThat("expected 2 primaries to relocate useClusterSettings: " + useClusterSetting, clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(2));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:59,代码来源:EnableAllocationTests.java


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