Search in sources :

Example 11 with LockObtainFailedException

use of org.apache.lucene.store.LockObtainFailedException in project elasticsearch by elastic.

the class StreamOutput method writeException.

public void writeException(Throwable throwable) throws IOException {
    if (throwable == null) {
        writeBoolean(false);
    } else {
        writeBoolean(true);
        boolean writeCause = true;
        boolean writeMessage = true;
        if (throwable instanceof CorruptIndexException) {
            writeVInt(1);
            writeOptionalString(((CorruptIndexException) throwable).getOriginalMessage());
            writeOptionalString(((CorruptIndexException) throwable).getResourceDescription());
            writeMessage = false;
        } else if (throwable instanceof IndexFormatTooNewException) {
            writeVInt(2);
            writeOptionalString(((IndexFormatTooNewException) throwable).getResourceDescription());
            writeInt(((IndexFormatTooNewException) throwable).getVersion());
            writeInt(((IndexFormatTooNewException) throwable).getMinVersion());
            writeInt(((IndexFormatTooNewException) throwable).getMaxVersion());
            writeMessage = false;
            writeCause = false;
        } else if (throwable instanceof IndexFormatTooOldException) {
            writeVInt(3);
            IndexFormatTooOldException t = (IndexFormatTooOldException) throwable;
            writeOptionalString(t.getResourceDescription());
            if (t.getVersion() == null) {
                writeBoolean(false);
                writeOptionalString(t.getReason());
            } else {
                writeBoolean(true);
                writeInt(t.getVersion());
                writeInt(t.getMinVersion());
                writeInt(t.getMaxVersion());
            }
            writeMessage = false;
            writeCause = false;
        } else if (throwable instanceof NullPointerException) {
            writeVInt(4);
            writeCause = false;
        } else if (throwable instanceof NumberFormatException) {
            writeVInt(5);
            writeCause = false;
        } else if (throwable instanceof IllegalArgumentException) {
            writeVInt(6);
        } else if (throwable instanceof AlreadyClosedException) {
            writeVInt(7);
        } else if (throwable instanceof EOFException) {
            writeVInt(8);
            writeCause = false;
        } else if (throwable instanceof SecurityException) {
            writeVInt(9);
        } else if (throwable instanceof StringIndexOutOfBoundsException) {
            writeVInt(10);
            writeCause = false;
        } else if (throwable instanceof ArrayIndexOutOfBoundsException) {
            writeVInt(11);
            writeCause = false;
        } else if (throwable instanceof FileNotFoundException) {
            writeVInt(12);
            writeCause = false;
        } else if (throwable instanceof FileSystemException) {
            writeVInt(13);
            if (throwable instanceof NoSuchFileException) {
                writeVInt(0);
            } else if (throwable instanceof NotDirectoryException) {
                writeVInt(1);
            } else if (throwable instanceof DirectoryNotEmptyException) {
                writeVInt(2);
            } else if (throwable instanceof AtomicMoveNotSupportedException) {
                writeVInt(3);
            } else if (throwable instanceof FileAlreadyExistsException) {
                writeVInt(4);
            } else if (throwable instanceof AccessDeniedException) {
                writeVInt(5);
            } else if (throwable instanceof FileSystemLoopException) {
                writeVInt(6);
            } else {
                writeVInt(7);
            }
            writeOptionalString(((FileSystemException) throwable).getFile());
            writeOptionalString(((FileSystemException) throwable).getOtherFile());
            writeOptionalString(((FileSystemException) throwable).getReason());
            writeCause = false;
        } else if (throwable instanceof IllegalStateException) {
            writeVInt(14);
        } else if (throwable instanceof LockObtainFailedException) {
            writeVInt(15);
        } else if (throwable instanceof InterruptedException) {
            writeVInt(16);
            writeCause = false;
        } else if (throwable instanceof IOException) {
            writeVInt(17);
        } else {
            ElasticsearchException ex;
            if (throwable instanceof ElasticsearchException && ElasticsearchException.isRegistered(throwable.getClass(), version)) {
                ex = (ElasticsearchException) throwable;
            } else {
                ex = new NotSerializableExceptionWrapper(throwable);
            }
            writeVInt(0);
            writeVInt(ElasticsearchException.getId(ex.getClass()));
            ex.writeTo(this);
            return;
        }
        if (writeMessage) {
            writeOptionalString(throwable.getMessage());
        }
        if (writeCause) {
            writeException(throwable.getCause());
        }
        ElasticsearchException.writeStackTraces(throwable, this);
    }
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) AccessDeniedException(java.nio.file.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) ElasticsearchException(org.elasticsearch.ElasticsearchException) FileSystemException(java.nio.file.FileSystemException) NotDirectoryException(java.nio.file.NotDirectoryException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) EOFException(java.io.EOFException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IOException(java.io.IOException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) FileSystemLoopException(java.nio.file.FileSystemLoopException)

Example 12 with LockObtainFailedException

use of org.apache.lucene.store.LockObtainFailedException in project elasticsearch by elastic.

the class TruncateTranslogIT method testCorruptTranslogTruncation.

public void testCorruptTranslogTruncation() throws Exception {
    internalCluster().startNodes(1, Settings.EMPTY);
    assertAcked(prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.refresh_interval", "-1").put(MockEngineSupport.DISABLE_FLUSH_ON_CLOSE.getKey(), // never flush - always recover from translog
    true)));
    ensureYellow();
    // Index some documents
    int numDocs = scaledRandomIntBetween(100, 1000);
    IndexRequestBuilder[] builders = new IndexRequestBuilder[numDocs];
    for (int i = 0; i < builders.length; i++) {
        builders[i] = client().prepareIndex("test", "type").setSource("foo", "bar");
    }
    disableTranslogFlush("test");
    indexRandom(false, false, false, Arrays.asList(builders));
    Set<Path> translogDirs = getTranslogDirs("test");
    TruncateTranslogCommand ttc = new TruncateTranslogCommand();
    MockTerminal t = new MockTerminal();
    OptionParser parser = ttc.getParser();
    for (Path translogDir : translogDirs) {
        OptionSet options = parser.parse("-d", translogDir.toAbsolutePath().toString(), "-b");
        // Try running it before the shard is closed, it should flip out because it can't acquire the lock
        try {
            logger.info("--> running truncate while index is open on [{}]", translogDir.toAbsolutePath());
            ttc.execute(t, options, null);
            fail("expected the truncate command to fail not being able to acquire the lock");
        } catch (Exception e) {
            assertThat(e.getMessage(), containsString("Failed to lock shard's directory"));
        }
    }
    // Corrupt the translog file(s)
    logger.info("--> corrupting translog");
    corruptRandomTranslogFiles("test");
    // Restart the single node
    logger.info("--> restarting node");
    internalCluster().fullRestart();
    client().admin().cluster().prepareHealth().setWaitForYellowStatus().setTimeout(new TimeValue(1000, TimeUnit.MILLISECONDS)).setWaitForEvents(Priority.LANGUID).get();
    try {
        client().prepareSearch("test").setQuery(matchAllQuery()).get();
        fail("all shards should be failed due to a corrupted translog");
    } catch (SearchPhaseExecutionException e) {
    // Good, all shards should be failed because there is only a
    // single shard and its translog is corrupt
    }
    // Close the index so we can actually truncate the translog
    logger.info("--> closing 'test' index");
    client().admin().indices().prepareClose("test").get();
    for (Path translogDir : translogDirs) {
        final Path idxLocation = translogDir.getParent().resolve("index");
        assertBusy(() -> {
            logger.info("--> checking that lock has been released for {}", idxLocation);
            try (Directory dir = FSDirectory.open(idxLocation, NativeFSLockFactory.INSTANCE);
                Lock writeLock = dir.obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
            // Great, do nothing, we just wanted to obtain the lock
            } catch (LockObtainFailedException lofe) {
                logger.info("--> failed acquiring lock for {}", idxLocation);
                fail("still waiting for lock release at [" + idxLocation + "]");
            } catch (IOException ioe) {
                fail("Got an IOException: " + ioe);
            }
        });
        OptionSet options = parser.parse("-d", translogDir.toAbsolutePath().toString(), "-b");
        logger.info("--> running truncate translog command for [{}]", translogDir.toAbsolutePath());
        ttc.execute(t, options, null);
        logger.info("--> output:\n{}", t.getOutput());
    }
    // Re-open index
    logger.info("--> opening 'test' index");
    client().admin().indices().prepareOpen("test").get();
    ensureYellow("test");
    // Run a search and make sure it succeeds
    SearchResponse resp = client().prepareSearch("test").setQuery(matchAllQuery()).get();
    ElasticsearchAssertions.assertNoFailures(resp);
}
Also used : Path(java.nio.file.Path) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) IOException(java.io.IOException) MockTerminal(org.elasticsearch.cli.MockTerminal) OptionParser(joptsimple.OptionParser) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) IOException(java.io.IOException) Lock(org.apache.lucene.store.Lock) SearchResponse(org.elasticsearch.action.search.SearchResponse) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) OptionSet(joptsimple.OptionSet) TimeValue(org.elasticsearch.common.unit.TimeValue) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Example 13 with LockObtainFailedException

use of org.apache.lucene.store.LockObtainFailedException in project elasticsearch by elastic.

the class ExceptionSerializationTests method testWriteThrowable.

public void testWriteThrowable() throws IOException {
    final QueryShardException queryShardException = new QueryShardException(new Index("foo", "_na_"), "foobar", null);
    final UnknownException unknownException = new UnknownException("this exception is unknown", queryShardException);
    final Exception[] causes = new Exception[] { new IllegalStateException("foobar"), new IllegalArgumentException("alalaal"), new NullPointerException("boom"), new EOFException("dadada"), new ElasticsearchSecurityException("nono!"), new NumberFormatException("not a number"), new CorruptIndexException("baaaam booom", "this is my resource"), new IndexFormatTooNewException("tooo new", 1, 2, 3), new IndexFormatTooOldException("tooo new", 1, 2, 3), new IndexFormatTooOldException("tooo new", "very old version"), new ArrayIndexOutOfBoundsException("booom"), new StringIndexOutOfBoundsException("booom"), new FileNotFoundException("booom"), new NoSuchFileException("booom"), new AlreadyClosedException("closed!!", new NullPointerException()), new LockObtainFailedException("can't lock directory", new NullPointerException()), unknownException };
    for (final Exception cause : causes) {
        ElasticsearchException ex = new ElasticsearchException("topLevel", cause);
        ElasticsearchException deserialized = serialize(ex);
        assertEquals(deserialized.getMessage(), ex.getMessage());
        assertTrue("Expected: " + deserialized.getCause().getMessage() + " to contain: " + ex.getCause().getClass().getName() + " but it didn't", deserialized.getCause().getMessage().contains(ex.getCause().getMessage()));
        if (ex.getCause().getClass() != UnknownException.class) {
            // unknown exception is not directly mapped
            assertEquals(deserialized.getCause().getClass(), ex.getCause().getClass());
        } else {
            assertEquals(deserialized.getCause().getClass(), NotSerializableExceptionWrapper.class);
        }
        assertArrayEquals(deserialized.getStackTrace(), ex.getStackTrace());
        assertTrue(deserialized.getStackTrace().length > 1);
        assertVersionSerializable(VersionUtils.randomVersion(random()), cause);
        assertVersionSerializable(VersionUtils.randomVersion(random()), ex);
        assertVersionSerializable(VersionUtils.randomVersion(random()), deserialized);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) Index(org.elasticsearch.index.Index) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) 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) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException) EOFException(java.io.EOFException) QueryShardException(org.elasticsearch.index.query.QueryShardException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException)

Example 14 with LockObtainFailedException

use of org.apache.lucene.store.LockObtainFailedException in project lucene-solr by apache.

the class TestIndexWriterWithThreads method testOpenTwoIndexWritersOnDifferentThreads.

//  LUCENE-3365: Test adding two documents with the same field from two different IndexWriters 
//  that we attempt to open at the same time.  As long as the first IndexWriter completes
//  and closes before the second IndexWriter time's out trying to get the Lock,
//  we should see both documents
public void testOpenTwoIndexWritersOnDifferentThreads() throws IOException, InterruptedException {
    final Directory dir = newDirectory();
    CountDownLatch oneIWConstructed = new CountDownLatch(1);
    DelayedIndexAndCloseRunnable thread1 = new DelayedIndexAndCloseRunnable(dir, oneIWConstructed);
    DelayedIndexAndCloseRunnable thread2 = new DelayedIndexAndCloseRunnable(dir, oneIWConstructed);
    thread1.start();
    thread2.start();
    oneIWConstructed.await();
    thread1.startIndexing();
    thread2.startIndexing();
    thread1.join();
    thread2.join();
    // TODO: can we improve this in LuceneTestCase? I dont know what the logic would be...
    try {
        assumeFalse("aborting test: timeout obtaining lock", thread1.failure instanceof LockObtainFailedException);
        assumeFalse("aborting test: timeout obtaining lock", thread2.failure instanceof LockObtainFailedException);
        assertFalse("Failed due to: " + thread1.failure, thread1.failed);
        assertFalse("Failed due to: " + thread2.failure, thread2.failed);
        // now verify that we have two documents in the index
        IndexReader reader = DirectoryReader.open(dir);
        assertEquals("IndexReader should have one document per thread running", 2, reader.numDocs());
        reader.close();
    } finally {
        dir.close();
    }
}
Also used : LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) CountDownLatch(java.util.concurrent.CountDownLatch) Directory(org.apache.lucene.store.Directory)

Example 15 with LockObtainFailedException

use of org.apache.lucene.store.LockObtainFailedException in project lucene-solr by apache.

the class SolrCore method initIndex.

void initIndex(boolean passOnPreviousState, boolean reload) throws IOException {
    String indexDir = getNewIndexDir();
    boolean indexExists = getDirectoryFactory().exists(indexDir);
    boolean firstTime;
    synchronized (SolrCore.class) {
        firstTime = dirs.add(getDirectoryFactory().normalize(indexDir));
    }
    initIndexReaderFactory();
    if (indexExists && firstTime && !passOnPreviousState) {
        final String lockType = getSolrConfig().indexConfig.lockType;
        Directory dir = directoryFactory.get(indexDir, DirContext.DEFAULT, lockType);
        try {
            if (isWriterLocked(dir)) {
                log.error(logid + "Solr index directory '{}' is locked (lockType={}).  Throwing exception.", indexDir, lockType);
                throw new LockObtainFailedException("Index dir '" + indexDir + "' of core '" + name + "' is already locked. " + "The most likely cause is another Solr server (or another solr core in this server) " + "also configured to use this directory; other possible causes may be specific to lockType: " + lockType);
            }
        } finally {
            directoryFactory.release(dir);
        }
    }
    // Create the index if it doesn't exist.
    if (!indexExists) {
        log.debug(logid + "Solr index directory '" + new File(indexDir) + "' doesn't exist." + " Creating new index...");
        SolrIndexWriter writer = SolrIndexWriter.create(this, "SolrCore.initIndex", indexDir, getDirectoryFactory(), true, getLatestSchema(), solrConfig.indexConfig, solrDelPolicy, codec);
        writer.close();
    }
    cleanupOldIndexDirectories(reload);
}
Also used : SolrIndexWriter(org.apache.solr.update.SolrIndexWriter) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) File(java.io.File) Directory(org.apache.lucene.store.Directory)

Aggregations

LockObtainFailedException (org.apache.lucene.store.LockObtainFailedException)15 IOException (java.io.IOException)11 Directory (org.apache.lucene.store.Directory)6 Path (java.nio.file.Path)4 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)4 Lock (org.apache.lucene.store.Lock)4 ElasticsearchException (org.elasticsearch.ElasticsearchException)4 EOFException (java.io.EOFException)3 FileNotFoundException (java.io.FileNotFoundException)3 AccessDeniedException (java.nio.file.AccessDeniedException)3 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)3 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 FileSystemException (java.nio.file.FileSystemException)3 FileSystemLoopException (java.nio.file.FileSystemLoopException)3 NoSuchFileException (java.nio.file.NoSuchFileException)3 NotDirectoryException (java.nio.file.NotDirectoryException)3 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)3 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)3 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)3