@Override public RAFLock lockOpen() throws IOException { return underlying.lockOpen(); }
/** * Lock the main RAF open to avoid the pooled fd being closed when we are * doing a major I/O operation involving many reads/writes. */ RAFLock lockRAF() throws IOException { return raf.lockOpen(); }
RAFLock lockRAFOpen() throws IOException { return raf.lockOpen(); }
/** * Lock the originalData RAF open to avoid the pooled fd being closed when * we are doing a major I/O operation involving many reads/writes. * * @throws IOException */ RAFLock lockUnderlying() throws IOException { return originalData.lockOpen(); }
@Override public RAFLock lockOpen() throws IOException { return raf.lockOpen(); }
@Override public RAFLock lockOpen() throws IOException { return underlyingBuffer.lockOpen(); }
@Override public RAFLock lockOpen() throws IOException { synchronized(this) { if(freed) throw new IOException("Already freed"); } return underlying.lockOpen(); }
@Override public RAFLock lockOpen() throws IOException { return underlying.lockOpen(); }
@Override public RAFLock lockOpen() throws IOException { try { lock.writeLock().lock(); if(closed || underlying == null) throw new IOException("Already closed"); RAFLock lock = new RAFLock() { @Override protected void innerUnlock() { externalUnlock(); } }; lockOpenCount++; if(lockOpenCount == 1) { assert(underlyingLock == null); underlyingLock = underlying.lockOpen(); } return lock; } finally { lock.writeLock().unlock(); } }
@Override public void writeTo(OutputStream os, ClientContext context) throws IOException { LockableRandomAccessBuffer.RAFLock lock = raf.lockOpen(); try { for(SplitFileFetcherSegmentStorage segment : segments) { segment.writeToInner(os); } os.close(); } catch (Throwable t) { Logger.error(this, "Failed to write stream: "+t, t); } finally { lock.unlock(); } }
void preadChecksummed(long fileOffset, byte[] buf, int offset, int length) throws IOException, ChecksumFailedException { byte[] checksumBuf = new byte[checksumLength]; RAFLock lock = raf.lockOpen(); try { raf.pread(fileOffset, buf, offset, length); raf.pread(fileOffset+length, checksumBuf, 0, checksumLength); } finally { lock.unlock(); } if(!checksumChecker.checkChecksum(buf, offset, length, checksumBuf)) { Arrays.fill(buf, offset, offset+length, (byte)0); throw new ChecksumFailedException(); } }
byte[] preadChecksummedWithLength(long fileOffset) throws IOException, ChecksumFailedException, StorageFormatException { byte[] checksumBuf = new byte[checksumLength]; RAFLock lock = raf.lockOpen(); byte[] lengthBuf = new byte[8]; byte[] buf; int length; try { raf.pread(fileOffset, lengthBuf, 0, lengthBuf.length); long len = new DataInputStream(new ByteArrayInputStream(lengthBuf)).readLong(); if(len + fileOffset > rafLength || len > Integer.MAX_VALUE || len < 0) throw new StorageFormatException("Bogus length "+len); length = (int)len; buf = new byte[length]; raf.pread(fileOffset+lengthBuf.length, buf, 0, length); raf.pread(fileOffset+length+lengthBuf.length, checksumBuf, 0, checksumLength); } finally { lock.unlock(); } if(!checksumChecker.checkChecksum(buf, 0, length, checksumBuf)) { Arrays.fill(buf, 0, length, (byte)0); throw new ChecksumFailedException(); } return buf; }
/** Migrate from one underlying LockableRandomAccessBuffer to another. */ protected final void migrate() throws IOException { try { lock.writeLock().lock(); if(closed) return; if(underlying == null) throw new IOException("Already freed"); LockableRandomAccessBuffer successor = innerMigrate(underlying); if(successor == null) throw new NullPointerException(); RAFLock newLock = null; if(lockOpenCount > 0) { try { newLock = successor.lockOpen(); } catch (IOException e) { successor.close(); successor.free(); throw e; } } if(lockOpenCount > 0) underlyingLock.unlock(); underlying.close(); underlying.free(); underlying = successor; underlyingLock = newLock; } finally { lock.writeLock().unlock(); } afterFreeUnderlying(); }
byte[] preadChecksummedWithLength(long fileOffset) throws IOException, ChecksumFailedException, StorageFormatException { byte[] checksumBuf = new byte[checker.checksumLength()]; RAFLock lock = raf.lockOpen(); byte[] lengthBuf = new byte[8]; byte[] buf; int length; try { raf.pread(fileOffset, lengthBuf, 0, lengthBuf.length); long len = new DataInputStream(new ByteArrayInputStream(lengthBuf)).readLong(); if(len + fileOffset > rafLength || len > Integer.MAX_VALUE || len < 0) throw new StorageFormatException("Bogus length "+len); length = (int)len; buf = new byte[length]; raf.pread(fileOffset+lengthBuf.length, buf, 0, length); raf.pread(fileOffset+length+lengthBuf.length, checksumBuf, 0, checker.checksumLength()); } finally { lock.unlock(); } if(!checker.checkChecksum(buf, 0, length, checksumBuf)) { Arrays.fill(buf, 0, length, (byte)0); throw new ChecksumFailedException(); } return buf; }
void preadChecksummed(long fileOffset, byte[] buf, int offset, int length) throws IOException, ChecksumFailedException { byte[] checksumBuf = new byte[checker.checksumLength()]; RAFLock lock = raf.lockOpen(); try { raf.pread(fileOffset, buf, offset, length); raf.pread(fileOffset+length, checksumBuf, 0, checker.checksumLength()); } finally { lock.unlock(); } if(!checker.checkChecksum(buf, offset, length, checksumBuf)) { Arrays.fill(buf, offset, offset+length, (byte)0); throw new ChecksumFailedException(); } }
@Override public boolean run(ClientContext context) { try { if(isFinishing()) return false; RAFLock lock = raf.lockOpen(); try { for(SplitFileInserterSegmentStorage segment : segments) { segment.storeStatus(false); } } finally { lock.unlock(); } writeOverallStatus(false); return false; } catch (IOException e) { if(isFinishing()) return false; Logger.error(this, "Failed writing metadata for "+SplitFileInserterStorage.this+": "+e, e); return false; } }
@Override public boolean run(ClientContext context) { try { if(isFinishing()) return false; RAFLock lock = raf.lockOpen(); try { for(SplitFileFetcherSegmentStorage segment : segments) { segment.writeMetadata(false); } keyListener.maybeWriteMainBloomFilter(offsetMainBloomFilter); } finally { lock.unlock(); } writeGeneralProgress(false); return false; } catch (IOException e) { if(isFinishing()) return false; Logger.error(this, "Failed writing metadata for "+SplitFileFetcherStorage.this+": "+e, e); return false; } }
raf = rafFactory.makeRAF(totalLength); RAFLock lock = raf.lockOpen(); try { for(int i=0;i<segments.length;i++) {