Skip to content

Commit

Permalink
DWL is truncated everytime there are tail segments in queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii0lomakin authored and tglman committed Feb 19, 2024
1 parent 4d0977c commit c50e5d6
Showing 1 changed file with 4 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.orientechnologies.common.directmemory.ODirectMemoryAllocator;
import com.orientechnologies.common.directmemory.ODirectMemoryAllocator.Intention;
import com.orientechnologies.common.directmemory.OPointer;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.io.OIOUtils;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.util.ORawPair;
Expand Down Expand Up @@ -61,7 +60,6 @@ public class DoubleWriteLogGL implements DoubleWriteLog {
private FileChannel currentFile;
private long currentSegment;

private long currentLogSize;
private final long maxSegSize;

private int blockSize;
Expand Down Expand Up @@ -119,7 +117,6 @@ public void open(final String storageName, final Path storagePath, int pageSize)

Path path = createLogFilePath();
this.currentFile = createLogFile(path);
this.currentLogSize = calculateLogSize();

blockSize = OIOUtils.calculateBlockSize(path.toAbsolutePath().toString());
if (blockSize == -1) {
Expand Down Expand Up @@ -150,7 +147,7 @@ private FileChannel createLogFile(Path path) throws IOException {
path, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW, StandardOpenOption.SYNC);
}

private Path createLogFilePath() throws IOException {
private Path createLogFilePath() {
return storagePath.resolve(generateSegmentsName(currentSegment));
}

Expand Down Expand Up @@ -238,13 +235,12 @@ public boolean write(final ByteBuffer[] buffers, final int[] fileIds, final int[
bytesWritten = ((bytesWritten + blockSize - 1) / blockSize) * blockSize;
currentFile.position(bytesWritten + filePosition);

this.currentLogSize += bytesWritten;
} finally {
ALLOCATOR.deallocate(pageContainer);
}

// we can not truncate log in restore mode because we remove all restore information
return !restoreMode && !tailSegments.isEmpty();
return !restoreMode && !tailSegments.isEmpty() && checkpointCounter == 0;
}
}

Expand All @@ -266,7 +262,6 @@ public void truncate() throws IOException {
return;
}

//noinspection resource
tailSegments.stream()
.map(this::generateSegmentsName)
.forEach(
Expand All @@ -285,30 +280,10 @@ public void truncate() throws IOException {
}
});

this.currentLogSize = calculateLogSize();
tailSegments.clear();
}
}

private long calculateLogSize() throws IOException {
try (final Stream<Path> stream = Files.list(storagePath)) {
return stream
.filter(DoubleWriteLogGL::fileFilter)
.mapToLong(
path -> {
try {
return Files.size(path);
} catch (IOException e) {
throw OException.wrapException(
new OStorageException(
"Can not calculate size of file " + path.toAbsolutePath()),
e);
}
})
.sum();
}
}

@Override
public OPointer loadPage(int fileId, int pageIndex, OByteBufferPool bufferPool)
throws IOException {
Expand Down Expand Up @@ -403,7 +378,6 @@ public void restoreModeOn() throws IOException {
// sort to fetch the
final Path[] segments;
try (final Stream<Path> stream = Files.list(storagePath)) {
//noinspection resource
segments =
stream
.filter(DoubleWriteLogGL::fileFilter)
Expand Down Expand Up @@ -471,7 +445,7 @@ public void restoreModeOn() throws IOException {
}

position +=
(long) ((METADATA_SIZE + compressedLen + blockSize - -1) / blockSize) * blockSize;
(long) ((METADATA_SIZE + compressedLen + blockSize - 1) / blockSize) * blockSize;
}
}
}
Expand Down Expand Up @@ -502,7 +476,7 @@ public void close() throws IOException {
Files.delete(path);
} catch (IOException e) {
throw new OStorageException(
"Can not delete file " + path.toString() + " in storage " + storageName);
"Can not delete file " + path + " in storage " + storageName);
}
});
}
Expand Down

0 comments on commit c50e5d6

Please sign in to comment.