use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.TMP_SUFFIX in project ignite by apache.
the class FileWriteAheadLogManager method formatWorkSegments.
/**
* Formatting working segments to {@link DataStorageConfiguration#getWalSegmentSize()} for work in a mmap or fsync case.
*
* @throws StorageException If an error occurs when formatting.
*/
private void formatWorkSegments() throws StorageException {
assert isArchiverEnabled();
if (mode == WALMode.FSYNC || mmap) {
List<FileDescriptor> toFormat = Arrays.stream(scan(walWorkDir.listFiles(WAL_SEGMENT_FILE_FILTER))).filter(fd -> fd.file().length() < dsCfg.getWalSegmentSize()).collect(toList());
if (!toFormat.isEmpty()) {
if (log.isInfoEnabled()) {
log.info("WAL segments in working directory should have the same size: '" + U.humanReadableByteCount(dsCfg.getWalSegmentSize()) + "'. Segments that need reformat " + "found: " + F.viewReadOnly(toFormat, fd -> fd.file().getName()) + '.');
}
for (int i = 0, j = 0; i < toFormat.size(); i++) {
FileDescriptor fd = toFormat.get(i);
File tmpDst = new File(fd.file().getName() + TMP_SUFFIX);
try {
Files.copy(fd.file().toPath(), tmpDst.toPath());
if (log.isDebugEnabled()) {
log.debug("Start formatting WAL segment [filePath=" + tmpDst.getAbsolutePath() + ", fileSize=" + U.humanReadableByteCount(tmpDst.length()) + ", toSize=" + U.humanReadableByteCount(dsCfg.getWalSegmentSize()) + ']');
}
try (FileIO fileIO = ioFactory.create(tmpDst, CREATE, READ, WRITE)) {
int left = (int) (dsCfg.getWalSegmentSize() - tmpDst.length());
fileIO.position(tmpDst.length());
while (left > 0) left -= fileIO.writeFully(FILL_BUF, 0, Math.min(FILL_BUF.length, left));
fileIO.force();
}
Files.move(tmpDst.toPath(), fd.file().toPath(), REPLACE_EXISTING, ATOMIC_MOVE);
if (log.isDebugEnabled())
log.debug("WAL segment formatted: " + fd.file().getAbsolutePath());
// Batch output.
if (log.isInfoEnabled() && (i == toFormat.size() - 1 || (i != 0 && i % 9 == 0))) {
log.info("WAL segments formatted: " + toFormat.get(j).file().getName() + (i == j ? "" : " - " + fileName(i)));
j = i + 1;
}
} catch (IOException e) {
throw new StorageException("Failed to format WAL segment: " + fd.file().getAbsolutePath(), e);
}
}
}
}
}
Aggregations