Example usage for org.apache.lucene.index IndexWriter WRITE_LOCK_NAME

List of usage examples for org.apache.lucene.index IndexWriter WRITE_LOCK_NAME

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexWriter WRITE_LOCK_NAME.

Prototype

String WRITE_LOCK_NAME

To view the source code for org.apache.lucene.index IndexWriter WRITE_LOCK_NAME.

Click Source Link

Document

Name of the write lock in the index.

Usage

From source file:org.elasticsearch.test.OldIndexUtils.java

License:Apache License

public static void copyIndex(final ESLogger logger, final Path src, final String indexName, final Path... dests)
        throws IOException {
    for (Path dest : dests) {
        Path indexDir = dest.resolve(indexName);
        assertFalse(Files.exists(indexDir));
        Files.createDirectories(indexDir);
    }//from  w ww.  j  a  v  a  2s.c  o m
    Files.walkFileTree(src, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            Path relativeDir = src.relativize(dir);
            for (Path dest : dests) {
                Path destDir = dest.resolve(indexName).resolve(relativeDir);
                Files.createDirectories(destDir);
            }
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            if (file.getFileName().toString().equals(IndexWriter.WRITE_LOCK_NAME)) {
                // skip lock file, we don't need it
                logger.trace("Skipping lock file: " + file.toString());
                return FileVisitResult.CONTINUE;
            }

            Path relativeFile = src.relativize(file);
            Path destFile = dests[randomInt(dests.length - 1)].resolve(indexName).resolve(relativeFile);
            logger.trace("--> Moving " + relativeFile.toString() + " to " + destFile.toString());
            Files.move(file, destFile);
            assertFalse(Files.exists(file));
            assertTrue(Files.exists(destFile));
            return FileVisitResult.CONTINUE;
        }
    });
}

From source file:org.hibernate.search.test.indexmanager.DirectoryBasedIndexManagerTest.java

License:LGPL

private boolean isIndexWriterLocked(IndexManager indexManager) {
    Directory directory = ((DirectoryBasedIndexManager) indexManager).getDirectoryProvider().getDirectory();
    Lock lock = null;//from  www . j  av  a  2  s .  c o  m
    try {
        lock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME);
    } catch (IOException e) {
        return true;
    } finally {
        if (lock != null) {
            try {
                lock.close();
            } catch (Exception ignored) {
            }
        }

    }
    return false;
}

From source file:org.neo4j.kernel.api.impl.index.backup.ReadOnlyIndexSnapshotFileIteratorTest.java

License:Open Source License

private static Set<String> listDir(Directory dir) throws IOException {
    String[] files = dir.listAll();
    return Stream.of(files).filter(file -> !IndexWriter.WRITE_LOCK_NAME.equals(file)).collect(toSet());
}

From source file:org.xerela.provider.configstore.ConfigSearch.java

License:Mozilla Public License

private void checkIndexIntegrity() {
    try {//from   w  w w . j av a  2  s.c  o  m
        boolean shouldCreate = !indexFile.exists();

        if (!shouldCreate) {
            // Clear any prior write locks
            File writeLock = new File(indexFile, IndexWriter.WRITE_LOCK_NAME);
            if (writeLock.exists()) {
                writeLock.delete();
            }
        }

        Directory directory = FSDirectory.getDirectory(indexFile);
        writer = new IndexWriter(directory, new ZLuceneAnalyzer(), shouldCreate);

        indexDirty.set(true);
    } catch (CorruptIndexException e) {
        LOGGER.error(Messages.ConfigSearch_luceneCorrupt, e);
        throw new RuntimeException(e);
    } catch (LockObtainFailedException e) {
        LOGGER.error(Messages.ConfigSearch_luceneLockFailure, e);
        throw new RuntimeException(e);
    } catch (IOException e) {
        LOGGER.error(Messages.ConfigSearch_errorAccessingLucene, e);
        throw new RuntimeException(e);
    }
}

From source file:stroom.index.server.IndexShardWriterImpl.java

License:Apache License

@Override
public synchronized boolean check() {
    boolean success = false;

    // Don't clean deleted indexes.
    if (!IndexShardStatus.DELETED.equals(indexShard.getStatus())) {
        try {//from  w  w w  . ja  v  a  2 s  .com
            // Output some debug.
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Checking index - " + indexShard);
            }
            // Mark the index as closed.
            setStatus(IndexShardStatus.CLOSED);

            if (Files.isDirectory(dir) && Files.list(dir).count() > 0) {
                // The directory exists and contains files so make sure it
                // is unlocked.
                try {
                    final Path lockFile = dir.resolve(IndexWriter.WRITE_LOCK_NAME);
                    if (Files.isRegularFile(lockFile)) {
                        Files.delete(lockFile);
                    }
                } catch (final IOException e) {
                    // There is no lock file so ignore.
                }

                // Sync the DB.
                sync();
                success = true;
            } else {
                if (!Files.isDirectory(dir)) {
                    throw new IndexException("Unable to find index shard directory: " + dir.toString());
                } else {
                    throw new IndexException(
                            "Unable to find any index shard data in directory: " + dir.toString());
                }
            }
        } catch (final Throwable t) {
            LOGGER.error(t.getMessage(), t);
        }
    }

    return success;
}