use of org.elasticsearch.index.shard.IndexShardClosedException in project elasticsearch by elastic.
the class RecoverySourceHandler method finalizeRecovery.
/*
* finalizes the recovery process
*/
public void finalizeRecovery() {
if (shard.state() == IndexShardState.CLOSED) {
throw new IndexShardClosedException(request.shardId());
}
cancellableThreads.checkForCancel();
StopWatch stopWatch = new StopWatch().start();
logger.trace("finalizing recovery");
cancellableThreads.execute(() -> {
shard.markAllocationIdAsInSync(recoveryTarget.getTargetAllocationId());
recoveryTarget.finalizeRecovery(shard.getGlobalCheckpoint());
});
if (request.isPrimaryRelocation()) {
// state. This means that no new recovery can be completed based on information of a newer cluster state than the current one.
try (Releasable ignored = delayNewRecoveries.apply("primary relocation hand-off in progress or completed for " + shardId)) {
final long currentClusterStateVersion = currentClusterStateVersionSupplier.get();
logger.trace("waiting on remote node to have cluster state with version [{}]", currentClusterStateVersion);
cancellableThreads.execute(() -> recoveryTarget.ensureClusterStateVersion(currentClusterStateVersion));
logger.trace("performing relocation hand-off");
cancellableThreads.execute(() -> shard.relocated("to " + request.targetNode()));
}
/*
* if the recovery process fails after setting the shard state to RELOCATED, both relocation source and
* target are failed (see {@link IndexShard#updateRoutingEntry}).
*/
}
stopWatch.stop();
logger.trace("finalizing recovery took [{}]", stopWatch.totalTime());
}
use of org.elasticsearch.index.shard.IndexShardClosedException in project elasticsearch by elastic.
the class RecoverySourceHandler method sendSnapshot.
/**
* Send the given snapshot's operations with a sequence number greater than the specified staring sequence number to this handler's
* target node.
* <p>
* Operations are bulked into a single request depending on an operation count limit or size-in-bytes limit.
*
* @param startingSeqNo the sequence number for which only operations with a sequence number greater than this will be sent
* @param snapshot the translog snapshot to replay operations from
* @return the total number of translog operations that were sent
* @throws IOException if an I/O exception occurred reading the translog snapshot
*/
protected int sendSnapshot(final long startingSeqNo, final Translog.Snapshot snapshot) throws IOException {
int ops = 0;
long size = 0;
int totalOperations = 0;
final List<Translog.Operation> operations = new ArrayList<>();
if (snapshot.totalOperations() == 0) {
logger.trace("no translog operations to send");
}
// send operations in batches
Translog.Operation operation;
while ((operation = snapshot.next()) != null) {
if (shard.state() == IndexShardState.CLOSED) {
throw new IndexShardClosedException(request.shardId());
}
cancellableThreads.checkForCancel();
// if we are doing a sequence-number-based recovery, we have to skip older ops for which no sequence number was assigned, and
// any ops before the starting sequence number
final long seqNo = operation.seqNo();
if (startingSeqNo >= 0 && (seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO || seqNo < startingSeqNo))
continue;
operations.add(operation);
ops++;
size += operation.estimateSize();
totalOperations++;
// check if this request is past bytes threshold, and if so, send it off
if (size >= chunkSizeInBytes) {
cancellableThreads.execute(() -> recoveryTarget.indexTranslogOperations(operations, snapshot.totalOperations()));
if (logger.isTraceEnabled()) {
logger.trace("sent batch of [{}][{}] (total: [{}]) translog operations", ops, new ByteSizeValue(size), snapshot.totalOperations());
}
ops = 0;
size = 0;
operations.clear();
}
}
// send the leftover operations
if (!operations.isEmpty()) {
cancellableThreads.execute(() -> recoveryTarget.indexTranslogOperations(operations, snapshot.totalOperations()));
}
if (logger.isTraceEnabled()) {
logger.trace("sent final batch of [{}][{}] (total: [{}]) translog operations", ops, new ByteSizeValue(size), snapshot.totalOperations());
}
return totalOperations;
}
use of org.elasticsearch.index.shard.IndexShardClosedException in project elasticsearch by elastic.
the class SearchPhaseExecutionExceptionTests method testToXContent.
public void testToXContent() throws IOException {
SearchPhaseExecutionException exception = new SearchPhaseExecutionException("test", "all shards failed", new ShardSearchFailure[] { new ShardSearchFailure(new ParsingException(1, 2, "foobar", null), new SearchShardTarget("node_1", new Index("foo", "_na_"), 0)), new ShardSearchFailure(new IndexShardClosedException(new ShardId(new Index("foo", "_na_"), 1)), new SearchShardTarget("node_2", new Index("foo", "_na_"), 1)), new ShardSearchFailure(new ParsingException(5, 7, "foobar", null), new SearchShardTarget("node_3", new Index("foo", "_na_"), 2)) });
// Failures are grouped (by default)
assertEquals("{" + "\"type\":\"search_phase_execution_exception\"," + "\"reason\":\"all shards failed\"," + "\"phase\":\"test\"," + "\"grouped\":true," + "\"failed_shards\":[" + "{" + "\"shard\":0," + "\"index\":\"foo\"," + "\"node\":\"node_1\"," + "\"reason\":{" + "\"type\":\"parsing_exception\"," + "\"reason\":\"foobar\"," + "\"line\":1," + "\"col\":2" + "}" + "}," + "{" + "\"shard\":1," + "\"index\":\"foo\"," + "\"node\":\"node_2\"," + "\"reason\":{" + "\"type\":\"index_shard_closed_exception\"," + "\"reason\":\"CurrentState[CLOSED] Closed\"," + "\"index_uuid\":\"_na_\"," + "\"shard\":\"1\"," + "\"index\":\"foo\"" + "}" + "}" + "]}", Strings.toString(exception));
// Failures are NOT grouped
ToXContent.MapParams params = new ToXContent.MapParams(singletonMap("group_shard_failures", "false"));
try (XContentBuilder builder = jsonBuilder()) {
builder.startObject();
exception.toXContent(builder, params);
builder.endObject();
assertEquals("{" + "\"type\":\"search_phase_execution_exception\"," + "\"reason\":\"all shards failed\"," + "\"phase\":\"test\"," + "\"grouped\":false," + "\"failed_shards\":[" + "{" + "\"shard\":0," + "\"index\":\"foo\"," + "\"node\":\"node_1\"," + "\"reason\":{" + "\"type\":\"parsing_exception\"," + "\"reason\":\"foobar\"," + "\"line\":1," + "\"col\":2" + "}" + "}," + "{" + "\"shard\":1," + "\"index\":\"foo\"," + "\"node\":\"node_2\"," + "\"reason\":{" + "\"type\":\"index_shard_closed_exception\"," + "\"reason\":\"CurrentState[CLOSED] Closed\"," + "\"index_uuid\":\"_na_\"," + "\"shard\":\"1\"," + "\"index\":\"foo\"" + "}" + "}," + "{" + "\"shard\":2," + "\"index\":\"foo\"," + "\"node\":\"node_3\"," + "\"reason\":{" + "\"type\":\"parsing_exception\"," + "\"reason\":\"foobar\"," + "\"line\":5," + "\"col\":7" + "}" + "}" + "]}", builder.string());
}
}
Aggregations