Search in sources :

Example 11 with RecoveryState

use of org.elasticsearch.indices.recovery.RecoveryState in project elasticsearch by elastic.

the class RecoveriesCollectionTests method startRecovery.

long startRecovery(RecoveriesCollection collection, DiscoveryNode sourceNode, IndexShard indexShard, PeerRecoveryTargetService.RecoveryListener listener, TimeValue timeValue) {
    final DiscoveryNode rNode = getDiscoveryNode(indexShard.routingEntry().currentNodeId());
    indexShard.markAsRecovering("remote", new RecoveryState(indexShard.routingEntry(), sourceNode, rNode));
    indexShard.prepareForIndexRecovery();
    return collection.startRecovery(indexShard, sourceNode, listener, timeValue);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState)

Example 12 with RecoveryState

use of org.elasticsearch.indices.recovery.RecoveryState in project elasticsearch by elastic.

the class RestRecoveryAction method buildRecoveryTable.

/**
     * buildRecoveryTable will build a table of recovery information suitable
     * for displaying at the command line.
     *
     * @param request  A Rest request
     * @param response A recovery status response
     * @return A table containing index, shardId, node, target size, recovered size and percentage for each recovering replica
     */
public Table buildRecoveryTable(RestRequest request, RecoveryResponse response) {
    Table t = getTableWithHeader(request);
    for (String index : response.shardRecoveryStates().keySet()) {
        List<RecoveryState> shardRecoveryStates = response.shardRecoveryStates().get(index);
        if (shardRecoveryStates.size() == 0) {
            continue;
        }
        // Sort ascending by shard id for readability
        CollectionUtil.introSort(shardRecoveryStates, new Comparator<RecoveryState>() {

            @Override
            public int compare(RecoveryState o1, RecoveryState o2) {
                int id1 = o1.getShardId().id();
                int id2 = o2.getShardId().id();
                if (id1 < id2) {
                    return -1;
                } else if (id1 > id2) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });
        for (RecoveryState state : shardRecoveryStates) {
            t.startRow();
            t.addCell(index);
            t.addCell(state.getShardId().id());
            t.addCell(new TimeValue(state.getTimer().time()));
            t.addCell(state.getRecoverySource().getType().toString().toLowerCase(Locale.ROOT));
            t.addCell(state.getStage().toString().toLowerCase(Locale.ROOT));
            t.addCell(state.getSourceNode() == null ? "n/a" : state.getSourceNode().getHostName());
            t.addCell(state.getSourceNode() == null ? "n/a" : state.getSourceNode().getName());
            t.addCell(state.getTargetNode().getHostName());
            t.addCell(state.getTargetNode().getName());
            t.addCell(state.getRecoverySource() == null || state.getRecoverySource().getType() != RecoverySource.Type.SNAPSHOT ? "n/a" : ((SnapshotRecoverySource) state.getRecoverySource()).snapshot().getRepository());
            t.addCell(state.getRecoverySource() == null || state.getRecoverySource().getType() != RecoverySource.Type.SNAPSHOT ? "n/a" : ((SnapshotRecoverySource) state.getRecoverySource()).snapshot().getSnapshotId().getName());
            t.addCell(state.getIndex().totalRecoverFiles());
            t.addCell(state.getIndex().recoveredFileCount());
            t.addCell(String.format(Locale.ROOT, "%1.1f%%", state.getIndex().recoveredFilesPercent()));
            t.addCell(state.getIndex().totalFileCount());
            t.addCell(state.getIndex().totalRecoverBytes());
            t.addCell(state.getIndex().recoveredBytes());
            t.addCell(String.format(Locale.ROOT, "%1.1f%%", state.getIndex().recoveredBytesPercent()));
            t.addCell(state.getIndex().totalBytes());
            t.addCell(state.getTranslog().totalOperations());
            t.addCell(state.getTranslog().recoveredOperations());
            t.addCell(String.format(Locale.ROOT, "%1.1f%%", state.getTranslog().recoveredPercent()));
            t.endRow();
        }
    }
    return t;
}
Also used : Table(org.elasticsearch.common.Table) SnapshotRecoverySource(org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 13 with RecoveryState

use of org.elasticsearch.indices.recovery.RecoveryState in project elasticsearch by elastic.

the class RecoveryResponse method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeVInt(shardRecoveryStates.size());
    for (Map.Entry<String, List<RecoveryState>> entry : shardRecoveryStates.entrySet()) {
        out.writeString(entry.getKey());
        out.writeVInt(entry.getValue().size());
        for (RecoveryState recoveryState : entry.getValue()) {
            recoveryState.writeTo(out);
        }
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState)

Example 14 with RecoveryState

use of org.elasticsearch.indices.recovery.RecoveryState in project elasticsearch by elastic.

the class RecoveryResponse method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    if (hasRecoveries()) {
        for (String index : shardRecoveryStates.keySet()) {
            List<RecoveryState> recoveryStates = shardRecoveryStates.get(index);
            if (recoveryStates == null || recoveryStates.size() == 0) {
                continue;
            }
            builder.startObject(index);
            builder.startArray("shards");
            for (RecoveryState recoveryState : recoveryStates) {
                builder.startObject();
                recoveryState.toXContent(builder, params);
                builder.endObject();
            }
            builder.endArray();
            builder.endObject();
        }
    }
    return builder;
}
Also used : RecoveryState(org.elasticsearch.indices.recovery.RecoveryState)

Example 15 with RecoveryState

use of org.elasticsearch.indices.recovery.RecoveryState in project elasticsearch by elastic.

the class IndicesClusterStateService method removeShards.

/**
     * Removes shards that are currently loaded by indicesService but have disappeared from the routing table of the current node.
     * Also removes shards where the recovery source node has changed.
     * This method does not delete the shard data.
     *
     * @param state new cluster state
     */
private void removeShards(final ClusterState state) {
    final RoutingTable routingTable = state.routingTable();
    final DiscoveryNodes nodes = state.nodes();
    final String localNodeId = state.nodes().getLocalNodeId();
    assert localNodeId != null;
    // remove shards based on routing nodes (no deletion of data)
    RoutingNode localRoutingNode = state.getRoutingNodes().node(localNodeId);
    for (AllocatedIndex<? extends Shard> indexService : indicesService) {
        for (Shard shard : indexService) {
            ShardRouting currentRoutingEntry = shard.routingEntry();
            ShardId shardId = currentRoutingEntry.shardId();
            ShardRouting newShardRouting = localRoutingNode == null ? null : localRoutingNode.getByShardId(shardId);
            if (newShardRouting == null) {
                // we can just remove the shard without cleaning it locally, since we will clean it in IndicesStore
                // once all shards are allocated
                logger.debug("{} removing shard (not allocated)", shardId);
                indexService.removeShard(shardId.id(), "removing shard (not allocated)");
            } else if (newShardRouting.isSameAllocation(currentRoutingEntry) == false) {
                logger.debug("{} removing shard (stale allocation id, stale {}, new {})", shardId, currentRoutingEntry, newShardRouting);
                indexService.removeShard(shardId.id(), "removing shard (stale copy)");
            } else if (newShardRouting.initializing() && currentRoutingEntry.active()) {
                // this can happen if the node was isolated/gc-ed, rejoins the cluster and a new shard with the same allocation id
                // is assigned to it. Batch cluster state processing or if shard fetching completes before the node gets a new cluster
                // state may result in a new shard being initialized while having the same allocation id as the currently started shard.
                logger.debug("{} removing shard (not active, current {}, new {})", shardId, currentRoutingEntry, newShardRouting);
                indexService.removeShard(shardId.id(), "removing shard (stale copy)");
            } else {
                // remove shards where recovery source has changed. This re-initializes shards later in createOrUpdateShards
                if (newShardRouting.recoverySource() != null && newShardRouting.recoverySource().getType() == Type.PEER) {
                    RecoveryState recoveryState = shard.recoveryState();
                    final DiscoveryNode sourceNode = findSourceNodeForPeerRecovery(logger, routingTable, nodes, newShardRouting);
                    if (recoveryState.getSourceNode().equals(sourceNode) == false) {
                        if (recoveryTargetService.cancelRecoveriesForShard(shardId, "recovery source node changed")) {
                            // getting here means that the shard was still recovering
                            logger.debug("{} removing shard (recovery source changed), current [{}], global [{}], shard [{}])", shardId, recoveryState.getSourceNode(), sourceNode, newShardRouting);
                            indexService.removeShard(shardId.id(), "removing shard (recovery source node changed)");
                        }
                    }
                }
            }
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) IndexShard(org.elasticsearch.index.shard.IndexShard) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Aggregations

RecoveryState (org.elasticsearch.indices.recovery.RecoveryState)29 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)16 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)9 Settings (org.elasticsearch.common.settings.Settings)7 Store (org.elasticsearch.index.store.Store)6 IOException (java.io.IOException)5 TestShardRouting (org.elasticsearch.cluster.routing.TestShardRouting)5 RecoveryResponse (org.elasticsearch.action.admin.indices.recovery.RecoveryResponse)4 UnassignedInfo (org.elasticsearch.cluster.routing.UnassignedInfo)4 EngineException (org.elasticsearch.index.engine.EngineException)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Version (org.elasticsearch.Version)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 IndexService (org.elasticsearch.index.IndexService)3 IndexShard (org.elasticsearch.index.shard.IndexShard)3 Path (java.nio.file.Path)2