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


Java ClusterChangedEvent类代码示例

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


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

示例1: publish

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
/** end of {@link PingContextProvider } implementation */


    @Override
    public void publish(ClusterChangedEvent clusterChangedEvent, AckListener ackListener) {
        if (!clusterChangedEvent.state().getNodes().isLocalNodeElectedMaster()) {
            throw new IllegalStateException("Shouldn't publish state when not master");
        }
        try {
            publishClusterState.publish(clusterChangedEvent, electMaster.minimumMasterNodes(), ackListener);
        } catch (FailedToCommitClusterStateException t) {
            // cluster service logs a WARN message
            logger.debug("failed to publish cluster state version [{}] (not enough nodes acknowledged, min master nodes [{}])", clusterChangedEvent.state().version(), electMaster.minimumMasterNodes());
            submitRejoin("zen-disco-failed-to-publish");
            throw t;
        }

        // update the set of nodes to ping after the new cluster state has been published
        nodesFD.updateNodesAndPing(clusterChangedEvent.state());

        // clean the pending cluster queue - we are currently master, so any pending cluster state should be failed
        // note that we also clean the queue on master failure (see handleMasterGone) but a delayed cluster state publish
        // from a stale master can still make it in the queue during the election (but not be committed)
        publishClusterState.pendingStatesQueue().failAllStatesAndClear(new ElasticsearchException("elected as master"));
    }
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:ZenDiscovery.java

示例2: applyClusterState

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
@Override
public void applyClusterState(ClusterChangedEvent event) {
    try {
        if (event.localNodeMaster()) {
            if (event.nodesRemoved()) {
                processSnapshotsOnRemovedNodes(event);
            }
            if (event.routingTableChanged()) {
                processStartedShards(event);
            }
            finalizeSnapshotDeletionFromPreviousMaster(event);
        }
    } catch (Exception e) {
        logger.warn("Failed to update snapshot state ", e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SnapshotsService.java

示例3: waitingShardsStartedOrUnassigned

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
private boolean waitingShardsStartedOrUnassigned(ClusterChangedEvent event) {
    SnapshotsInProgress curr = event.state().custom(SnapshotsInProgress.TYPE);
    if (curr != null) {
        for (SnapshotsInProgress.Entry entry : curr.entries()) {
            if (entry.state() == State.STARTED && !entry.waitingIndices().isEmpty()) {
                for (ObjectCursor<String> index : entry.waitingIndices().keys()) {
                    if (event.indexRoutingTableChanged(index.value)) {
                        IndexRoutingTable indexShardRoutingTable = event.state().getRoutingTable().index(index.value);
                        for (ShardId shardId : entry.waitingIndices().get(index.value)) {
                            ShardRouting shardRouting = indexShardRoutingTable.shard(shardId.id()).primaryShard();
                            if (shardRouting != null && (shardRouting.started() || shardRouting.unassigned())) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:SnapshotsService.java

示例4: removedNodesCleanupNeeded

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
private boolean removedNodesCleanupNeeded(ClusterChangedEvent event) {
    SnapshotsInProgress snapshotsInProgress = event.state().custom(SnapshotsInProgress.TYPE);
    if (snapshotsInProgress == null) {
        return false;
    }
    // Check if we just became the master
    boolean newMaster = !event.previousState().nodes().isLocalNodeElectedMaster();
    for (SnapshotsInProgress.Entry snapshot : snapshotsInProgress.entries()) {
        if (newMaster && (snapshot.state() == State.SUCCESS || snapshot.state() == State.INIT)) {
            // We just replaced old master and snapshots in intermediate states needs to be cleaned
            return true;
        }
        for (DiscoveryNode node : event.nodesDelta().removedNodes()) {
            for (ObjectCursor<ShardSnapshotStatus> shardStatus : snapshot.shards().values()) {
                if (!shardStatus.value.state().completed() && node.getId().equals(shardStatus.value.nodeId())) {
                    // At least one shard was running on the removed node - we need to fail it
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:SnapshotsService.java

示例5: cleanupRestoreState

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
private void cleanupRestoreState(ClusterChangedEvent event) {
    ClusterState state = event.state();

    RestoreInProgress restoreInProgress = state.custom(RestoreInProgress.TYPE);
    if (restoreInProgress != null) {
        for (RestoreInProgress.Entry entry : restoreInProgress.entries()) {
            if (entry.state().completed()) {
                assert completed(entry.shards()) : "state says completed but restore entries are not";
                clusterService.submitStateUpdateTask(
                    "clean up snapshot restore state",
                    new CleanRestoreStateTaskExecutor.Task(entry.snapshot()),
                    ClusterStateTaskConfig.build(Priority.URGENT),
                    cleanRestoreStateTaskExecutor,
                    cleanRestoreStateTaskExecutor);
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:RestoreService.java

示例6: applyClusterState

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
@Override
public void applyClusterState(ClusterChangedEvent event) {
    try {
        SnapshotsInProgress prev = event.previousState().custom(SnapshotsInProgress.TYPE);
        SnapshotsInProgress curr = event.state().custom(SnapshotsInProgress.TYPE);

        if ((prev == null && curr != null) || (prev != null && prev.equals(curr) == false)) {
            processIndexShardSnapshots(event);
        }
        String masterNodeId = event.state().nodes().getMasterNodeId();
        if (masterNodeId != null && masterNodeId.equals(event.previousState().nodes().getMasterNodeId()) == false) {
            syncShardStatsOnNewMaster(event);
        }

    } catch (Exception e) {
        logger.warn("Failed to update snapshot state ", e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SnapshotShardsService.java

示例7: assertState

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
public void assertState(ClusterChangedEvent event,
                        boolean stateInMemory,
                        boolean expectMetaData) throws Exception {
    MetaData inMemoryMetaData = null;
    Set<Index> oldIndicesList = emptySet();
    if (stateInMemory) {
        inMemoryMetaData = event.previousState().metaData();
        oldIndicesList = GatewayMetaState.getRelevantIndices(event.previousState(), event.previousState(), oldIndicesList);
    }
    Set<Index> newIndicesList = GatewayMetaState.getRelevantIndices(event.state(),event.previousState(), oldIndicesList);
    // third, get the actual write info
    Iterator<GatewayMetaState.IndexMetaWriteInfo> indices = GatewayMetaState.resolveStatesToBeWritten(oldIndicesList, newIndicesList,
            inMemoryMetaData, event.state().metaData()).iterator();

    if (expectMetaData) {
        assertThat(indices.hasNext(), equalTo(true));
        assertThat(indices.next().getNewMetaData().getIndex().getName(), equalTo("test"));
        assertThat(indices.hasNext(), equalTo(false));
    } else {
        assertThat(indices.hasNext(), equalTo(false));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:GatewayMetaStateTests.java

示例8: clusterChanged

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
@Override
public void clusterChanged(ClusterChangedEvent event) {
    if (!event.metaDataChanged()) {
        return;
    }

    Set<String> newCurrentSchemas = getNewCurrentSchemas(event.state().metaData());
    synchronized (schemas) {
        Sets.SetView<String> nonBuiltInSchemas = Sets.difference(schemas.keySet(), builtInSchemas.keySet());
        Set<String> deleted = Sets.difference(nonBuiltInSchemas, newCurrentSchemas).immutableCopy();
        Set<String> added = Sets.difference(newCurrentSchemas, schemas.keySet()).immutableCopy();

        for (String deletedSchema : deleted) {
            try {
                schemas.remove(deletedSchema).close();
            } catch (Exception e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
        for (String addedSchema : added) {
            schemas.put(addedSchema, getCustomSchemaInfo(addedSchema));
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:ReferenceInfos.java

示例9: applyNewIndices

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
private void applyNewIndices(final ClusterChangedEvent event) {
    // we only create indices for shards that are allocated
    RoutingNodes.RoutingNodeIterator routingNode = event.state().getRoutingNodes().routingNodeIter(event.state().nodes().localNodeId());
    if (routingNode == null) {
        return;
    }
    for (ShardRouting shard : routingNode) {
        if (!indicesService.hasIndex(shard.index())) {
            final IndexMetaData indexMetaData = event.state().metaData().index(shard.index());
            if (logger.isDebugEnabled()) {
                logger.debug("[{}] creating index", indexMetaData.getIndex());
            }
            try {
                indicesService.createIndex(indexMetaData.getIndex(), indexMetaData.getSettings(), event.state().nodes().localNode().id());
            } catch (Throwable e) {
                sendFailShard(shard, indexMetaData.getIndexUUID(), "failed to create index", e);
            }
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:IndicesClusterStateService.java

示例10: applySettings

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
private void applySettings(ClusterChangedEvent event) {
    if (!event.metaDataChanged()) {
        return;
    }
    for (IndexMetaData indexMetaData : event.state().metaData()) {
        if (!indicesService.hasIndex(indexMetaData.getIndex())) {
            // we only create / update here
            continue;
        }
        // if the index meta data didn't change, no need check for refreshed settings
        if (!event.indexMetaDataChanged(indexMetaData)) {
            continue;
        }
        String index = indexMetaData.getIndex();
        IndexService indexService = indicesService.indexService(index);
        if (indexService == null) {
            // already deleted on us, ignore it
            continue;
        }
        IndexSettingsService indexSettingsService = indexService.injector().getInstance(IndexSettingsService.class);
        indexSettingsService.refreshSettings(indexMetaData.getSettings());
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:IndicesClusterStateService.java

示例11: applyAliases

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
private void applyAliases(ClusterChangedEvent event) {
    // check if aliases changed
    if (aliasesChanged(event)) {
        // go over and update aliases
        for (IndexMetaData indexMetaData : event.state().metaData()) {
            String index = indexMetaData.getIndex();
            IndexService indexService = indicesService.indexService(index);
            if (indexService == null) {
                // we only create / update here
                continue;
            }
            IndexAliasesService indexAliasesService = indexService.aliasesService();
            indexAliasesService.setAliases(indexMetaData.getAliases());
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:IndicesClusterStateService.java

示例12: publish

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
@Override
public void publish(ClusterChangedEvent clusterChangedEvent, final Discovery.AckListener ackListener) {
    if (!master) {
        throw new IllegalStateException("Shouldn't publish state when not master");
    }
    LocalDiscovery[] members = members();
    if (members.length > 0) {
        Set<DiscoveryNode> nodesToPublishTo = new HashSet<>(members.length);
        for (LocalDiscovery localDiscovery : members) {
            if (localDiscovery.master) {
                continue;
            }
            nodesToPublishTo.add(localDiscovery.localNode());
        }
        publish(members, clusterChangedEvent, new AckClusterStatePublishResponseHandler(nodesToPublishTo, ackListener));
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:LocalDiscovery.java

示例13: setReallocation

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
public void setReallocation(final ClusterService clusterService, final RoutingService routingService) {
    this.routingService = routingService;
    clusterService.add(new ClusterStateListener() {
        @Override
        public void clusterChanged(ClusterChangedEvent event) {
            boolean cleanCache = false;
            DiscoveryNode localNode = event.state().nodes().localNode();
            if (localNode != null) {
                if (localNode.masterNode() == true && event.localNodeMaster() == false) {
                    cleanCache = true;
                }
            } else {
                cleanCache = true;
            }
            if (cleanCache) {
                Releasables.close(asyncFetchStarted.values());
                asyncFetchStarted.clear();
                Releasables.close(asyncFetchStore.values());
                asyncFetchStore.clear();
            }
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:GatewayAllocator.java

示例14: waitingShardsStartedOrUnassigned

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
private boolean waitingShardsStartedOrUnassigned(ClusterChangedEvent event) {
    SnapshotsInProgress curr = event.state().custom(SnapshotsInProgress.TYPE);
    if (curr != null) {
        for (SnapshotsInProgress.Entry entry : curr.entries()) {
            if (entry.state() == State.STARTED && !entry.waitingIndices().isEmpty()) {
                for (String index : entry.waitingIndices().keySet()) {
                    if (event.indexRoutingTableChanged(index)) {
                        IndexRoutingTable indexShardRoutingTable = event.state().getRoutingTable().index(index);
                        for (ShardId shardId : entry.waitingIndices().get(index)) {
                            ShardRouting shardRouting = indexShardRoutingTable.shard(shardId.id()).primaryShard();
                            if (shardRouting != null && (shardRouting.started() || shardRouting.unassigned())) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:SnapshotsService.java

示例15: removedNodesCleanupNeeded

import org.elasticsearch.cluster.ClusterChangedEvent; //导入依赖的package包/类
private boolean removedNodesCleanupNeeded(ClusterChangedEvent event) {
    // Check if we just became the master
    boolean newMaster = !event.previousState().nodes().localNodeMaster();
    SnapshotsInProgress snapshotsInProgress = event.state().custom(SnapshotsInProgress.TYPE);
    if (snapshotsInProgress == null) {
        return false;
    }
    for (SnapshotsInProgress.Entry snapshot : snapshotsInProgress.entries()) {
        if (newMaster && (snapshot.state() == State.SUCCESS || snapshot.state() == State.INIT)) {
            // We just replaced old master and snapshots in intermediate states needs to be cleaned
            return true;
        }
        for (DiscoveryNode node : event.nodesDelta().removedNodes()) {
            for (ShardSnapshotStatus shardStatus : snapshot.shards().values()) {
                if (!shardStatus.state().completed() && node.getId().equals(shardStatus.nodeId())) {
                    // At least one shard was running on the removed node - we need to fail it
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:SnapshotsService.java


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