use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project ignite by apache.
the class IgniteWithoutArchiverWalIteratorInvalidCrcTest method nodeShouldNotStartIfLastCheckpointRecordCorrupted.
/**
* Last start checkpoint record was corrupted.
* -----||------|X|-------->
* We stop the node.
*/
@Test
public void nodeShouldNotStartIfLastCheckpointRecordCorrupted() throws Exception {
startNodeAndPopulate();
stopGrid(0, true);
IgniteWriteAheadLogManager walMgr = ignite.context().cache().context().wal();
File walDir = U.field(walMgr, "walWorkDir");
IgniteWalIteratorFactory iterFactory = new IgniteWalIteratorFactory();
List<FileDescriptor> walFiles = getWalFiles(walDir, iterFactory);
Random corruptLastRecord = null;
FileDescriptor lastWalFile = walFiles.get(walFiles.size() - 1);
WalTestUtils.corruptWalSegmentFile(lastWalFile, iterFactory, corruptLastRecord);
GridTestUtils.assertThrows(log, () -> startGrid(0), Exception.class, null);
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class IgniteWalIteratorFactory method resolveWalFiles.
/**
* 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 iteratorParametersBuilder IteratorParametersBuilder.
* @return list of file descriptors with checked header records, having correct file index is set
*/
public List<FileDescriptor> resolveWalFiles(IteratorParametersBuilder iteratorParametersBuilder) {
File[] filesOrDirs = iteratorParametersBuilder.filesOrDirs;
if (filesOrDirs == null || filesOrDirs.length == 0)
return Collections.emptyList();
final TreeSet<FileDescriptor> descriptors = new TreeSet<>();
for (File file : filesOrDirs) {
if (file.isDirectory()) {
try {
walkFileTree(file.toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
addFileDescriptor(path.toFile(), descriptors, iteratorParametersBuilder);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
if (exc instanceof NoSuchFileException)
return FileVisitResult.CONTINUE;
return super.visitFileFailed(file, exc);
}
});
} catch (IOException e) {
U.error(log, "Failed to walk directories from root [" + file + "]. Skipping this directory.", e);
}
continue;
}
addFileDescriptor(file, descriptors, iteratorParametersBuilder);
}
return new ArrayList<>(descriptors);
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class IgniteWalIteratorFactory method hasGaps.
/**
* @param descriptors File descriptors.
* @return List of tuples, low and high index segments with gap.
*/
public List<T2<Long, Long>> hasGaps(@NotNull List<FileDescriptor> descriptors) throws IllegalArgumentException {
List<T2<Long, Long>> gaps = new ArrayList<>();
Iterator<FileDescriptor> it = descriptors.iterator();
FileDescriptor prevFd = null;
while (it.hasNext()) {
FileDescriptor nextFd = it.next();
if (prevFd == null) {
prevFd = nextFd;
continue;
}
if (prevFd.idx() + 1 != nextFd.idx())
gaps.add(new T2<>(prevFd.idx(), nextFd.idx()));
prevFd = nextFd;
}
return gaps;
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class IgniteWalIteratorFactory method readFileDescriptor.
/**
* @param file File to read.
* @param ioFactory IO factory.
*/
private FileDescriptor readFileDescriptor(File file, FileIOFactory ioFactory) {
FileDescriptor ds = new FileDescriptor(file);
try (SegmentIO fileIO = ds.toReadOnlyIO(ioFactory);
ByteBufferExpander buf = new ByteBufferExpander(HEADER_RECORD_SIZE, ByteOrder.nativeOrder())) {
final DataInput in = segmentFileInputFactory.createFileInput(fileIO, buf);
// Header record must be agnostic to the serializer version.
final int type = in.readUnsignedByte();
if (type == RecordType.STOP_ITERATION_RECORD_TYPE) {
if (log.isInfoEnabled())
log.info("Reached logical end of the segment for file " + file);
return null;
}
FileWALPointer ptr = readPosition(in);
return new FileDescriptor(file, ptr.index());
} catch (IOException e) {
U.warn(log, "Failed to scan index from file [" + file + "]. Skipping this file during iteration", e);
return null;
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor in project gridgain by gridgain.
the class IgniteWithoutArchiverWalIteratorInvalidCrcTest method nodeShouldNotStartIfLastCheckpointRecordCorrupted.
/**
* Last start checkpoint record was corrupted.
* -----||------|X|-------->
* We stop the node.
*/
@Test
public void nodeShouldNotStartIfLastCheckpointRecordCorrupted() throws Exception {
startNodeAndPopulate();
stopGrid(0, true);
IgniteWriteAheadLogManager walMgr = ignite.context().cache().context().wal();
File walDir = U.field(walMgr, "walWorkDir");
IgniteWalIteratorFactory iterFactory = new IgniteWalIteratorFactory();
List<FileDescriptor> walFiles = getWalFiles(walDir, iterFactory);
Random corruptLastRecord = null;
FileDescriptor lastWalFile = walFiles.get(walFiles.size() - 1);
WalTestUtils.corruptRandomWalRecord(lastWalFile, iterFactory, corruptLastRecord);
GridTestUtils.assertThrows(log, () -> startGrid(0), Exception.class, null);
}
Aggregations