@Override public void close() { if (closed.compareAndSet(false, true) && locks != null) { for (Lock lock : locks) { try { logger.trace("releasing lock [{}]", lock); lock.close(); } catch (IOException e) { logger.trace(() -> new ParameterizedMessage("failed to release lock [{}]", lock), e); } } } }
@Override public void close() throws IOException { try { delegate.close(); } finally { emittedLocks.remove( this ); } }
@Override public void close() throws IOException { try { delegate.close(); } finally { emittedLocks.remove( this ); } }
@Override public void clearLock(String name) throws IOException { Lock lock = this.locks.remove(this.baseName + ":" + name); lock.close(); System.out.println("### LOCK CLEARED: " + name); }
@Override public void close() { if (closed.compareAndSet(false, true) && locks != null) { for (Lock lock : locks) { try { logger.trace("releasing lock [{}]", lock); lock.close(); } catch (IOException e) { logger.trace((Supplier<?>) () -> new ParameterizedMessage("failed to release lock [{}]", lock), e); } } } }
@Override public void close() { if (closed.compareAndSet(false, true) && locks != null) { for (Lock lock : locks) { try { logger.trace("releasing lock [{}]", lock); lock.close(); } catch (IOException e) { logger.trace(() -> new ParameterizedMessage("failed to release lock [{}]", lock), e); } } } }
/** * Returns <code>true</code> iff the index in the named directory is * currently locked. * @param directory the directory to check for a lock * @throws IOException if there is a low-level IO error * @deprecated Use of this method can only lead to race conditions. Try * to actually obtain a lock instead. */ @Deprecated public static boolean isLocked(Directory directory) throws IOException { try { directory.obtainLock(WRITE_LOCK_NAME).close(); return false; } catch (LockObtainFailedException failed) { return true; } }
/** * Returns <code>true</code> iff the index in the named directory is * currently locked. * @param directory the directory to check for a lock * @throws IOException if there is a low-level IO error * @deprecated Use of this method can only lead to race conditions. Try * to actually obtain a lock instead. */ @Deprecated public static boolean isLocked(Directory directory) throws IOException { try { directory.obtainLock(WRITE_LOCK_NAME).close(); return false; } catch (LockObtainFailedException failed) { return true; } }
@Override public void close() { if (closed.compareAndSet(false, true) && locks != null) { for (Lock lock : locks) { try { logger.trace("releasing lock [{}]", lock); lock.close(); } catch (IOException e) { logger.trace("failed to release lock [{}]", e, lock); } } } }
public static boolean isLocked(Directory directory) throws IOException { try { directory.obtainLock( org.apache.lucene.index.IndexWriter.WRITE_LOCK_NAME ).close(); return false; } catch (LockObtainFailedException failed) { return true; } }
private static boolean isLocked(Directory directory) throws IOException { try { directory.obtainLock(IndexWriter.WRITE_LOCK_NAME).close(); return false; } catch (LockObtainFailedException failed) { return true; } }
for ( Lock emittedLock : emittedLocks ) emittedLock.close();
for ( Lock emittedLock : emittedLocks ) emittedLock.close();
/** * This is returning as soon as the lock is available, or after 10 seconds. * * @return true if the lock is free at the time of returning. */ private boolean waitForAvailabilityInternal() { final Directory directory = indexManager.getDirectoryProvider().getDirectory(); try { Lock lock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME); lock.close(); return true; } catch (LockObtainFailedException lofe) { return false; } catch (IOException e) { log.error(e); return false; } }
/** * This is returning as soon as the lock is available, or after 10 seconds. * * @return true if the lock is free at the time of returning. */ private boolean waitForAvailabilityInternal() { final Directory directory = indexManager.getDirectoryProvider().getDirectory(); try { Lock lock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME); lock.close(); return true; } catch (LockObtainFailedException lofe) { return false; } catch (IOException e) { log.error(e); return false; } }
private boolean isIndexWriterLocked(IndexManager indexManager) { Directory directory = ( (DirectoryBasedIndexManager) indexManager ).getDirectoryProvider().getDirectory(); Lock lock = null; 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; }
@Test public void testLuceneIndexLocking() throws IOException { assertFalse(isLocked(directory1)); Lock obtainedLock = directory1.obtainLock(IndexWriter.WRITE_LOCK_NAME); assertTrue(isLocked(directory1)); assertTrue(isLocked(directory2)); assertFalse(isLocked(directory3)); obtainedLock.ensureValid(); //will throw an exception on failure obtainedLock.close(); assertFalse(isLocked(directory1)); assertFalse(isLocked(directory2)); assertFalse(isLocked(directory3)); }