Package org.elasticsearch.common.thread

Examples of org.elasticsearch.common.thread.LoggingRunnable


            return;
        }

        // we only write the local metadata if this is a possible master node
        if (event.state().nodes().localNode().masterNode() && event.metaDataChanged()) {
            executor.execute(new LoggingRunnable(logger, new PersistMetaData(event)));
        }

        if (event.state().nodes().localNode().dataNode() && event.routingTableChanged()) {
            LocalGatewayStartedShards.Builder builder = LocalGatewayStartedShards.builder();
            if (currentStartedShards != null) {
                builder.state(currentStartedShards);
            }
            builder.version(event.state().version());

            boolean changed = false;

            // remove from the current state all the shards that are primary and started somewhere, we won't need them anymore
            // and if they are still here, we will add them in the next phase

            // Also note, this works well when closing an index, since a closed index will have no routing shards entries
            // so they won't get removed (we want to keep the fact that those shards are allocated on this node if needed)
            for (IndexRoutingTable indexRoutingTable : event.state().routingTable()) {
                for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
                    if (indexShardRoutingTable.countWithState(ShardRoutingState.STARTED) == indexShardRoutingTable.size()) {
                        changed |= builder.remove(indexShardRoutingTable.shardId());
                    }
                }
            }
            // remove deleted indices from the started shards
            for (ShardId shardId : builder.build().shards().keySet()) {
                if (!event.state().metaData().hasIndex(shardId.index().name())) {
                    changed |= builder.remove(shardId);
                }
            }
            // now, add all the ones that are active and on this node
            RoutingNode routingNode = event.state().readOnlyRoutingNodes().node(event.state().nodes().localNodeId());
            if (routingNode != null) {
                // out node is not in play yet...
                for (MutableShardRouting shardRouting : routingNode) {
                    if (shardRouting.active()) {
                        changed |= builder.put(shardRouting.shardId(), shardRouting.version());
                    }
                }
            }

            // only write if something changed...
            if (changed) {
                final LocalGatewayStartedShards stateToWrite = builder.build();
                executor.execute(new LoggingRunnable(logger, new PersistShards(event, stateToWrite)));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.thread.LoggingRunnable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.