@Override public void ensureValid() throws IOException { lock.ensureValid(); }
/** Calls {@link #doBody} while <i>lock</i> is obtained. Blocks if lock * cannot be obtained immediately. Retries to obtain lock once per second * until it is obtained, or until it has tried ten times. Lock is released when * {@link #doBody} exits. */ public Object run() throws IOException { boolean locked = false; try { locked = lock.obtain(lockWaitTimeout); return doBody(); } finally { if (locked) lock.release(); } } }
@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); } } } }
/** Release the write lock, if needed. */ protected void finalize() throws IOException { if (writeLock != null) { writeLock.release(); // release write lock writeLock = null; } }
public boolean isLocked() { return lock.isLocked(); } }
public synchronized boolean obtain() throws LockObtainFailedException, IOException { return lock.obtain(); }
@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)); }
directoryName = "snapshot." + fmt.format(new Date()); lock = lockFactory.makeLock(directoryName + ".lock"); if (lock.isLocked()) return; snapShotDir = new File(snapDir, directoryName); if (!snapShotDir.mkdir()) { if (lock != null) { try { lock.release(); } catch (IOException e) { LOG.error("Unable to release snapshoot lock: " + directoryName + ".lock");
private void acquireTestLock() throws IOException { String randomLockName = "lucene-" + Long.toString(new Random().nextInt(), Character.MAX_RADIX) + "-test.lock"; Lock l = makeLock(randomLockName); try { l.obtain(); } catch (IOException e) { IOException e2 = new IOException("Failed to acquire random test lock; please verify filesystem for lock directory '" + lockDir + "' supports locking"); e2.initCause(e); throw e2; } l.release(); }
@Override public void close() throws IOException { try { delegate.close(); } finally { emittedLocks.remove( this ); } }
/** Release the write lock, if needed. */ protected final void finalize() throws IOException { if (writeLock != null) { writeLock.release(); // release write lock writeLock = null; } }
@Override public synchronized boolean isLocked() throws IOException { return lock.isLocked(); }
@Override public synchronized boolean obtain() throws IOException { return lock.obtain(); }
@Override public void copyFrom(Directory from, String src, String dest, IOContext context) throws IOException { writeLock.ensureValid(); in.copyFrom(from, src, dest, context); }
private void acquireTestLock() throws IOException { String randomLockName = "lucene-" + Long.toString(new Random().nextInt(), Character.MAX_RADIX) + "-test.lock"; Lock l = makeLock(randomLockName); try { l.obtain(); } catch (IOException e) { IOException e2 = new IOException("Failed to acquire random test lock; please verify filesystem for lock directory '" + lockDir + "' supports locking"); e2.initCause(e); throw e2; } l.release(); }
@Override public void close() throws IOException { try { delegate.close(); } finally { emittedLocks.remove( this ); } }
@Override public void release() throws IOException { lock.release(); }
public synchronized boolean isLocked() { return lock.isLocked(); }
public synchronized boolean obtain() throws LockObtainFailedException, IOException { return lock.obtain(); }
@Override public void close() throws IOException { try (Lock l = lock) { l.ensureValid(); verify((byte) 0); } }