Skip to content

Commit

Permalink
fix review issue
Browse files Browse the repository at this point in the history
Signed-off-by: OneSizeFitQuorum <[email protected]>
  • Loading branch information
OneSizeFitsQuorum committed Jun 21, 2024
1 parent 60fd0d0 commit 42308b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,22 @@ public abstract class LogWriter implements ILogWriter {
protected final FileChannel logChannel;
protected long size = 0;
protected long originalSize = 0;

/**
* 1 byte for whether enable compression, 4 byte for compressedSize, 4 byte for uncompressedSize
*/
private final int COMPRESSED_HEADER_SIZE = Byte.BYTES + Integer.BYTES * 2;

/** 1 byte for whether enable compression, 4 byte for uncompressedSize */
private final int UN_COMPRESSED_HEADER_SIZE = Byte.BYTES + Integer.BYTES;

private final ByteBuffer headerBuffer = ByteBuffer.allocate(COMPRESSED_HEADER_SIZE);
private ICompressor compressor =
ICompressor.getCompressor(
IoTDBDescriptor.getInstance().getConfig().getWALCompressionAlgorithm());
private ByteBuffer compressedByteBuffer;

/** Minimum size to compress, default is 32 KB */
/** Minimum size to compress, use magic number 32 KB */
private static long MIN_COMPRESSION_SIZE = 32 * 1024L;

protected LogWriter(File logFile, WALFileVersion version) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public class WALInputStream extends InputStream implements AutoCloseable {

private static final Logger logger = LoggerFactory.getLogger(WALInputStream.class);
private final FileChannel channel;

/** 1 byte for whether enable compression, 4 byte for compressedSize */
private final ByteBuffer segmentHeaderWithoutCompressedSizeBuffer =
ByteBuffer.allocate(Integer.BYTES + Byte.BYTES);
private final ByteBuffer compressedSizeHeaderBuffer = ByteBuffer.allocate(Integer.BYTES);

private final ByteBuffer compressedSizeBuffer = ByteBuffer.allocate(Integer.BYTES);
private ByteBuffer dataBuffer = null;
private ByteBuffer compressedBuffer = null;
private final long fileSize;
Expand Down Expand Up @@ -335,10 +338,10 @@ private SegmentInfo getNextSegmentInfo() throws IOException {
CompressionType.deserialize(segmentHeaderWithoutCompressedSizeBuffer.get());
info.dataInDiskSize = segmentHeaderWithoutCompressedSizeBuffer.getInt();
if (info.compressionType != CompressionType.UNCOMPRESSED) {
compressedSizeHeaderBuffer.clear();
channel.read(compressedSizeHeaderBuffer);
compressedSizeHeaderBuffer.flip();
info.uncompressedSize = compressedSizeHeaderBuffer.getInt();
compressedSizeBuffer.clear();
channel.read(compressedSizeBuffer);
compressedSizeBuffer.flip();
info.uncompressedSize = compressedSizeBuffer.getInt();
} else {
info.uncompressedSize = info.dataInDiskSize;
}
Expand Down

0 comments on commit 42308b3

Please sign in to comment.