Search in sources :

Example 6 with ShardLockObtainFailedException

use of org.elasticsearch.env.ShardLockObtainFailedException in project elasticsearch by elastic.

the class PrimaryShardAllocator method buildNodeShardsResult.

/**
     * Builds a list of nodes. If matchAnyShard is set to false, only nodes that have an allocation id matching
     * inSyncAllocationIds are added to the list. Otherwise, any node that has a shard is added to the list, but
     * entries with matching allocation id are always at the front of the list.
     */
protected static NodeShardsResult buildNodeShardsResult(ShardRouting shard, boolean matchAnyShard, Set<String> ignoreNodes, Set<String> inSyncAllocationIds, FetchResult<NodeGatewayStartedShards> shardState, Logger logger) {
    List<NodeGatewayStartedShards> nodeShardStates = new ArrayList<>();
    int numberOfAllocationsFound = 0;
    for (NodeGatewayStartedShards nodeShardState : shardState.getData().values()) {
        DiscoveryNode node = nodeShardState.getNode();
        String allocationId = nodeShardState.allocationId();
        if (ignoreNodes.contains(node.getId())) {
            continue;
        }
        if (nodeShardState.storeException() == null) {
            if (allocationId == null) {
                logger.trace("[{}] on node [{}] has no shard state information", shard, nodeShardState.getNode());
            } else {
                logger.trace("[{}] on node [{}] has allocation id [{}]", shard, nodeShardState.getNode(), allocationId);
            }
        } else {
            final String finalAllocationId = allocationId;
            if (nodeShardState.storeException() instanceof ShardLockObtainFailedException) {
                logger.trace((Supplier<?>) () -> new ParameterizedMessage("[{}] on node [{}] has allocation id [{}] but the store can not be opened as it's locked, treating as valid shard", shard, nodeShardState.getNode(), finalAllocationId), nodeShardState.storeException());
            } else {
                logger.trace((Supplier<?>) () -> new ParameterizedMessage("[{}] on node [{}] has allocation id [{}] but the store can not be opened, treating as no allocation id", shard, nodeShardState.getNode(), finalAllocationId), nodeShardState.storeException());
                allocationId = null;
            }
        }
        if (allocationId != null) {
            assert nodeShardState.storeException() == null || nodeShardState.storeException() instanceof ShardLockObtainFailedException : "only allow store that can be opened or that throws a ShardLockObtainFailedException while being opened but got a store throwing " + nodeShardState.storeException();
            numberOfAllocationsFound++;
            if (matchAnyShard || inSyncAllocationIds.contains(nodeShardState.allocationId())) {
                nodeShardStates.add(nodeShardState);
            }
        }
    }
    // allocation preference
    final Comparator<NodeGatewayStartedShards> comparator;
    if (matchAnyShard) {
        // prefer shards with matching allocation ids
        Comparator<NodeGatewayStartedShards> matchingAllocationsFirst = Comparator.comparing((NodeGatewayStartedShards state) -> inSyncAllocationIds.contains(state.allocationId())).reversed();
        comparator = matchingAllocationsFirst.thenComparing(NO_STORE_EXCEPTION_FIRST_COMPARATOR).thenComparing(PRIMARY_FIRST_COMPARATOR);
    } else {
        comparator = NO_STORE_EXCEPTION_FIRST_COMPARATOR.thenComparing(PRIMARY_FIRST_COMPARATOR);
    }
    nodeShardStates.sort(comparator);
    if (logger.isTraceEnabled()) {
        logger.trace("{} candidates for allocation: {}", shard, nodeShardStates.stream().map(s -> s.getNode().getName()).collect(Collectors.joining(", ")));
    }
    return new NodeShardsResult(nodeShardStates, numberOfAllocationsFound);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ArrayList(java.util.ArrayList) NodeGatewayStartedShards(org.elasticsearch.gateway.TransportNodesListGatewayStartedShards.NodeGatewayStartedShards) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException)

Example 7 with ShardLockObtainFailedException

use of org.elasticsearch.env.ShardLockObtainFailedException in project elasticsearch by elastic.

the class InternalTestCluster method assertAfterTest.

@Override
public void assertAfterTest() throws IOException {
    super.assertAfterTest();
    assertRequestsFinished();
    for (NodeAndClient nodeAndClient : nodes.values()) {
        NodeEnvironment env = nodeAndClient.node().getNodeEnvironment();
        Set<ShardId> shardIds = env.lockedShards();
        for (ShardId id : shardIds) {
            try {
                env.shardLock(id, TimeUnit.SECONDS.toMillis(5)).close();
            } catch (ShardLockObtainFailedException ex) {
                fail("Shard " + id + " is still locked after 5 sec waiting");
            }
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException)

Example 8 with ShardLockObtainFailedException

use of org.elasticsearch.env.ShardLockObtainFailedException in project elasticsearch by elastic.

the class ExceptionSerializationTests method testBWCShardLockObtainFailedException.

public void testBWCShardLockObtainFailedException() throws IOException {
    ShardId shardId = new ShardId("foo", "_na_", 1);
    ShardLockObtainFailedException orig = new ShardLockObtainFailedException(shardId, "boom");
    Exception ex = serialize((Exception) orig, randomFrom(Version.V_5_0_0, Version.V_5_0_1));
    assertThat(ex, instanceOf(NotSerializableExceptionWrapper.class));
    assertEquals("shard_lock_obtain_failed_exception: [foo][1]: boom", ex.getMessage());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) NotSerializableExceptionWrapper(org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) IllegalShardRoutingStateException(org.elasticsearch.cluster.routing.IllegalShardRoutingStateException) ActionTransportException(org.elasticsearch.transport.ActionTransportException) SearchContextMissingException(org.elasticsearch.search.SearchContextMissingException) SnapshotException(org.elasticsearch.snapshots.SnapshotException) AccessDeniedException(java.nio.file.AccessDeniedException) SearchException(org.elasticsearch.search.SearchException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) RecoverFilesRecoveryException(org.elasticsearch.indices.recovery.RecoverFilesRecoveryException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) NotDirectoryException(java.nio.file.NotDirectoryException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) IOException(java.io.IOException) IndexTemplateMissingException(org.elasticsearch.indices.IndexTemplateMissingException) NoSuchFileException(java.nio.file.NoSuchFileException) FailedNodeException(org.elasticsearch.action.FailedNodeException) SearchParseException(org.elasticsearch.search.SearchParseException) URISyntaxException(java.net.URISyntaxException) AliasesNotFoundException(org.elasticsearch.rest.action.admin.indices.AliasesNotFoundException) RecoveryEngineException(org.elasticsearch.index.engine.RecoveryEngineException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) TimestampParsingException(org.elasticsearch.action.TimestampParsingException) RoutingMissingException(org.elasticsearch.action.RoutingMissingException) RepositoryException(org.elasticsearch.repositories.RepositoryException) AlreadyExpiredException(org.elasticsearch.index.AlreadyExpiredException) InvalidIndexTemplateException(org.elasticsearch.indices.InvalidIndexTemplateException) QueryShardException(org.elasticsearch.index.query.QueryShardException) FileSystemException(java.nio.file.FileSystemException) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) ActionNotFoundTransportException(org.elasticsearch.transport.ActionNotFoundTransportException) ParsingException(org.elasticsearch.common.ParsingException) FileSystemLoopException(java.nio.file.FileSystemLoopException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException)

Example 9 with ShardLockObtainFailedException

use of org.elasticsearch.env.ShardLockObtainFailedException in project elasticsearch by elastic.

the class IndicesServiceTests method testPendingTasks.

public void testPendingTasks() throws Exception {
    IndicesService indicesService = getIndicesService();
    IndexService test = createIndex("test");
    assertTrue(test.hasShard(0));
    ShardPath path = test.getShardOrNull(0).shardPath();
    assertTrue(test.getShardOrNull(0).routingEntry().started());
    ShardPath shardPath = ShardPath.loadShardPath(logger, getNodeEnvironment(), new ShardId(test.index(), 0), test.getIndexSettings());
    assertEquals(shardPath, path);
    try {
        indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS));
        fail("can't get lock");
    } catch (ShardLockObtainFailedException ex) {
    }
    assertTrue(path.exists());
    int numPending = 1;
    if (randomBoolean()) {
        indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings());
    } else {
        if (randomBoolean()) {
            numPending++;
            indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings());
        }
        indicesService.addPendingDelete(test.index(), test.getIndexSettings());
    }
    assertAcked(client().admin().indices().prepareClose("test"));
    assertTrue(path.exists());
    assertEquals(indicesService.numPendingDeletes(test.index()), numPending);
    assertTrue(indicesService.hasUncompletedPendingDeletes());
    // shard lock released... we can now delete
    indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS));
    assertEquals(indicesService.numPendingDeletes(test.index()), 0);
    assertFalse(indicesService.hasUncompletedPendingDeletes());
    assertFalse(path.exists());
    if (randomBoolean()) {
        indicesService.addPendingDelete(new ShardId(test.index(), 0), test.getIndexSettings());
        indicesService.addPendingDelete(new ShardId(test.index(), 1), test.getIndexSettings());
        indicesService.addPendingDelete(new ShardId("bogus", "_na_", 1), test.getIndexSettings());
        assertEquals(indicesService.numPendingDeletes(test.index()), 2);
        assertTrue(indicesService.hasUncompletedPendingDeletes());
        // shard lock released... we can now delete
        indicesService.processPendingDeletes(test.index(), test.getIndexSettings(), new TimeValue(0, TimeUnit.MILLISECONDS));
        assertEquals(indicesService.numPendingDeletes(test.index()), 0);
        // "bogus" index has not been removed
        assertTrue(indicesService.hasUncompletedPendingDeletes());
    }
    assertAcked(client().admin().indices().prepareOpen("test"));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexService(org.elasticsearch.index.IndexService) ShardPath(org.elasticsearch.index.shard.ShardPath) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) TimeValue(org.elasticsearch.common.unit.TimeValue)

Aggregations

ShardLockObtainFailedException (org.elasticsearch.env.ShardLockObtainFailedException)9 ShardId (org.elasticsearch.index.shard.ShardId)5 IOException (java.io.IOException)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)2 RoutingAllocation (org.elasticsearch.cluster.routing.allocation.RoutingAllocation)2 TimeValue (org.elasticsearch.common.unit.TimeValue)2 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)2 ShardPath (org.elasticsearch.index.shard.ShardPath)2 Closeable (java.io.Closeable)1 EOFException (java.io.EOFException)1 FileNotFoundException (java.io.FileNotFoundException)1 URISyntaxException (java.net.URISyntaxException)1 AccessDeniedException (java.nio.file.AccessDeniedException)1 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)1 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 FileSystemException (java.nio.file.FileSystemException)1 FileSystemLoopException (java.nio.file.FileSystemLoopException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1