@Override public Location readPayload(DataInput dataIn) throws IOException { Location rc = new Location(); rc.setDataFileId(dataIn.readInt()); rc.setOffset(dataIn.readInt()); if (metadata.version >= 6) { rc.setSize(dataIn.readInt()); } return rc; }
public void readLocationDetails(Location location) throws IOException { Journal.WriteCommand asyncWrite = inflightWrites.get(new Journal.WriteKey(location)); if (asyncWrite != null) { location.setSize(asyncWrite.location.getSize()); location.setType(asyncWrite.location.getType()); } else { file.seek(location.getOffset()); location.setSize(file.readInt()); location.setType(file.readByte()); } }
@Override public Location storeItem(ByteSequence data, byte type, boolean sync) throws IOException { // Write the packet our internal buffer. int size = data.getLength() + RECORD_HEAD_SPACE; final Location location = new Location(); location.setSize(size); location.setType(type); Journal.WriteCommand write = new Journal.WriteCommand(location, data, sync); WriteBatch batch = enqueue(write); location.setBatch(batch); if (sync) { try { batch.latch.await(); } catch (InterruptedException e) { throw new InterruptedIOException(); } IOException exception = batch.exception.get(); if (exception != null) { throw exception; } } return location; }
@Override public Location storeItem(ByteSequence data, byte type, Runnable onComplete) throws IOException { // Write the packet our internal buffer. int size = data.getLength() + RECORD_HEAD_SPACE; final Location location = new Location(); location.setSize(size); location.setType(type); Journal.WriteCommand write = new Journal.WriteCommand(location, data, onComplete); location.setBatch(enqueue(write)); return location; }
@Override public Location storeItem(ByteSequence data, byte type, Runnable onComplete) throws IOException { checkClosed(); // Write the packet our internal buffer. int size = data.getLength() + Journal.RECORD_HEAD_SPACE; final Location location = new Location(); location.setSize(size); location.setType(type); Journal.WriteCommand write = new Journal.WriteCommand(location, data, onComplete); enqueueWrite(write); return location; }
public void corruptRecoveryLocation(Location recoveryPosition) throws IOException { DataFile dataFile = getDataFile(recoveryPosition); // with corruption on recovery we have no faith in the content - slip to the next batch record or eof DataFileAccessor reader = accessorPool.openDataFileAccessor(dataFile); try { RandomAccessFile randomAccessFile = reader.getRaf().getRaf(); randomAccessFile.seek(recoveryPosition.getOffset() + 1); byte[] data = new byte[getWriteBatchSize()]; ByteSequence bs = new ByteSequence(data, 0, randomAccessFile.read(data)); int nextOffset = 0; if (findNextBatchRecord(bs, randomAccessFile) >= 0) { nextOffset = Math.toIntExact(randomAccessFile.getFilePointer() - bs.remaining()); } else { nextOffset = Math.toIntExact(randomAccessFile.length()); } Sequence sequence = new Sequence(recoveryPosition.getOffset(), nextOffset - 1); LOG.warn("Corrupt journal records found in '{}' between offsets: {}", dataFile.getFile(), sequence); // skip corruption on getNextLocation recoveryPosition.setOffset(nextOffset); recoveryPosition.setSize(-1); dataFile.corruptedBlocks.add(sequence); } catch (IOException e) { } finally { accessorPool.closeDataFileAccessor(reader); } }
public Location getFirstLocation() throws IllegalStateException, IOException { if( dataFiles.isEmpty() ) { return null; } DataFile first = dataFiles.getHead(); Location cur = new Location(); cur.setDataFileId(first.getDataFileId()); cur.setOffset(0); cur.setSize(0); return getNextLocation(cur); }
@Override public Location storeItem(ByteSequence data, byte type, boolean sync) throws IOException { checkClosed(); // Write the packet our internal buffer. int size = data.getLength() + Journal.RECORD_HEAD_SPACE; final Location location = new Location(); location.setSize(size); location.setType(type); Journal.WriteCommand write = new Journal.WriteCommand(location, data, sync); enqueueWrite(write); if (sync) { writePendingBatch(); } return location; }
public ByteSequence readRecord(Location location) throws IOException { if (!location.isValid()) { throw new IOException("Invalid location: " + location); } Journal.WriteCommand asyncWrite = inflightWrites.get(new Journal.WriteKey(location)); if (asyncWrite != null) { return asyncWrite.data; } try { if (location.getSize() == Location.NOT_SET) { file.seek(location.getOffset()); location.setSize(file.readInt()); location.setType(file.readByte()); } else { file.seek(location.getOffset() + Journal.RECORD_HEAD_SPACE); } if ((long)location.getOffset() + location.getSize() > dataFile.length) { throw new IOException("Invalid location size: " + location + ", size: " + location.getSize()); } byte[] data = new byte[location.getSize() - Journal.RECORD_HEAD_SPACE]; file.readFully(data); return new ByteSequence(data, 0, data.length); } catch (RuntimeException e) { throw new IOException("Invalid location: " + location + " : " + e, e); } }
if (corruptedRange != null) { cur.setSize((int) corruptedRange.range()); } else if (cur.getSize() == EOF_INT && cur.getType() == EOF_EOT || (cur.getType() == 0 && cur.getSize() == 0)) { cur.setSize(EOF_RECORD.length); cur.setOffset(Math.max(maxFileLength, dataFile.getLength())); } else if (cur.getType() == USER_RECORD_TYPE) {
@Override public Location readPayload(DataInput dataIn) throws IOException { Location rc = new Location(); rc.setDataFileId(dataIn.readInt()); rc.setOffset(dataIn.readInt()); if (metadata.version >= 6) { rc.setSize(dataIn.readInt()); } return rc; }
@Override public Location readPayload(DataInput dataIn) throws IOException { Location rc = new Location(); rc.setDataFileId(dataIn.readInt()); rc.setOffset(dataIn.readInt()); if (metadata.version >= 6) { rc.setSize(dataIn.readInt()); } return rc; }
@Override public Location readPayload(DataInput dataIn) throws IOException { Location rc = new Location(); rc.setDataFileId(dataIn.readInt()); rc.setOffset(dataIn.readInt()); if (metadata.version >= 6) { rc.setSize(dataIn.readInt()); } return rc; }
public void readLocationDetails(Location location) throws IOException { Journal.WriteCommand asyncWrite = inflightWrites.get(new Journal.WriteKey(location)); if (asyncWrite != null) { location.setSize(asyncWrite.location.getSize()); location.setType(asyncWrite.location.getType()); } else { file.seek(location.getOffset()); location.setSize(file.readInt()); location.setType(file.readByte()); } }
public void readLocationDetails(Location location) throws IOException { Journal.WriteCommand asyncWrite = inflightWrites.get(new Journal.WriteKey(location)); if (asyncWrite != null) { location.setSize(asyncWrite.location.getSize()); location.setType(asyncWrite.location.getType()); } else { file.seek(location.getOffset()); location.setSize(file.readInt()); location.setType(file.readByte()); } }
@Override public Location storeItem(ByteSequence data, byte type, Runnable onComplete) throws IOException { checkClosed(); // Write the packet our internal buffer. int size = data.getLength() + Journal.RECORD_HEAD_SPACE; final Location location = new Location(); location.setSize(size); location.setType(type); Journal.WriteCommand write = new Journal.WriteCommand(location, data, onComplete); enqueueWrite(write); return location; }
@Override public Location storeItem(ByteSequence data, byte type, Runnable onComplete) throws IOException { // Write the packet our internal buffer. int size = data.getLength() + RECORD_HEAD_SPACE; final Location location = new Location(); location.setSize(size); location.setType(type); Journal.WriteCommand write = new Journal.WriteCommand(location, data, onComplete); location.setBatch(enqueue(write)); return location; }
@Override public Location storeItem(ByteSequence data, byte type, Runnable onComplete) throws IOException { checkClosed(); // Write the packet our internal buffer. int size = data.getLength() + Journal.RECORD_HEAD_SPACE; final Location location = new Location(); location.setSize(size); location.setType(type); Journal.WriteCommand write = new Journal.WriteCommand(location, data, onComplete); enqueueWrite(write); return location; }
@Override public Location storeItem(ByteSequence data, byte type, Runnable onComplete) throws IOException { // Write the packet our internal buffer. int size = data.getLength() + RECORD_HEAD_SPACE; final Location location = new Location(); location.setSize(size); location.setType(type); Journal.WriteCommand write = new Journal.WriteCommand(location, data, onComplete); location.setBatch(enqueue(write)); return location; }
public Location getFirstLocation() throws IllegalStateException, IOException { if( dataFiles.isEmpty() ) { return null; } DataFile first = dataFiles.getHead(); Location cur = new Location(); cur.setDataFileId(first.getDataFileId()); cur.setOffset(0); cur.setSize(0); return getNextLocation(cur); }