use of org.apache.ignite.internal.processors.cache.persistence.wal.FileInput in project ignite by apache.
the class RecordV1Serializer method readWithCrc.
/**
* Reads record from file {@code in0} and validates CRC of record.
*
* @param in0 File input.
* @param expPtr Expected WAL pointer for record. Used to validate actual position against expected from the file.
* @param reader Record reader I/O interface.
* @return WAL record.
* @throws EOFException In case of end of file.
* @throws IgniteCheckedException If it's unable to read record.
*/
static WALRecord readWithCrc(FileInput in0, WALPointer expPtr, RecordIO reader) throws EOFException, IgniteCheckedException {
long startPos = -1;
try (FileInput.Crc32CheckingFileInput in = in0.startRead(skipCrc)) {
startPos = in0.position();
WALRecord res = reader.readWithHeaders(in, expPtr);
assert res != null;
// Account for CRC which will be read afterwards.
res.size((int) (in0.position() - startPos + CRC_SIZE));
return res;
} catch (EOFException | SegmentEofException | WalSegmentTailReachedException e) {
throw e;
} catch (Exception e) {
throw new IgniteCheckedException("Failed to read WAL record at position: " + startPos, e);
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileInput in project ignite by apache.
the class StandaloneWalRecordsIterator method scanIndexesFromFileHeaders.
/**
* This methods checks all provided files to be correct WAL segment.
* Header record and its position is checked. WAL position is used to determine real index.
* File index from file name is ignored.
*
* @param allFiles files to scan.
* @return list of file descriptors with checked header records, having correct file index is set
*/
private List<FileWriteAheadLogManager.FileDescriptor> scanIndexesFromFileHeaders(@Nullable final File[] allFiles) {
if (allFiles == null || allFiles.length == 0)
return Collections.emptyList();
final List<FileWriteAheadLogManager.FileDescriptor> resultingDescs = new ArrayList<>();
for (File file : allFiles) {
if (file.length() < HEADER_RECORD_SIZE)
// filter out this segment as it is too short
continue;
FileWALPointer ptr;
try (FileIO fileIO = ioFactory.create(file);
ByteBufferExpander buf = new ByteBufferExpander(HEADER_RECORD_SIZE, ByteOrder.nativeOrder())) {
final DataInput in = new FileInput(fileIO, buf);
// Header record must be agnostic to the serializer version.
final int type = in.readUnsignedByte();
if (type == WALRecord.RecordType.STOP_ITERATION_RECORD_TYPE) {
if (log.isInfoEnabled())
log.info("Reached logical end of the segment for file " + file);
// filter out this segment
continue;
}
ptr = RecordV1Serializer.readPosition(in);
} catch (IOException e) {
U.warn(log, "Failed to scan index from file [" + file + "]. Skipping this file during iteration", e);
// filter out this segment
continue;
}
resultingDescs.add(new FileWriteAheadLogManager.FileDescriptor(file, ptr.index()));
}
Collections.sort(resultingDescs);
return resultingDescs;
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileInput in project ignite by apache.
the class IgniteDataIntegrityTests method setUp.
/**
* {@inheritDoc}
*/
@Override
protected void setUp() throws Exception {
super.setUp();
File file = File.createTempFile("integrity", "dat");
file.deleteOnExit();
expBuf = new ByteBufferExpander(1024, ByteOrder.BIG_ENDIAN);
FileIOFactory factory = new RandomAccessFileIOFactory();
fileInput = new FileInput(factory.create(file), expBuf);
ByteBuffer buf = ByteBuffer.allocate(1024);
ThreadLocalRandom curr = ThreadLocalRandom.current();
for (int i = 0; i < 1024; i += 16) {
buf.putInt(curr.nextInt());
buf.putInt(curr.nextInt());
buf.putInt(curr.nextInt());
buf.position(i);
buf.putInt(PureJavaCrc32.calcCrc32(buf, 12));
}
buf.rewind();
fileInput.io().write(buf);
fileInput.io().force();
}
Aggregations