THUMarkLau commented on code in PR #12476:
URL: https://github.com/apache/iotdb/pull/12476#discussion_r1642256536


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/buffer/WALBuffer.java:
##########
@@ -535,12 +535,13 @@ public void run() {
       memTableIdsOfWal
           .computeIfAbsent(currentWALFileVersion, memTableIds -> new 
HashSet<>())
           .addAll(info.metaData.getMemTablesId());
-      
checkpointManager.updateCostOfActiveMemTables(info.memTableId2WalDiskUsage);
+      
checkpointManager.updateCostOfActiveMemTables(info.memTableId2WalDiskUsage, 
compressionRate);
 
       boolean forceSuccess = false;
       // try to roll log writer
       if (info.rollWALFileWriterListener != null
-          || (forceFlag && currentWALFileWriter.size() >= 
config.getWalFileSizeThresholdInByte())) {
+          || (forceFlag
+              && currentWALFileWriter.originalSize() >= 
config.getWalFileSizeThresholdInByte())) {

Review Comment:
   Done



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/LogWriter.java:
##########
@@ -43,23 +45,75 @@ public abstract class LogWriter implements ILogWriter {
   protected final File logFile;
   protected final FileOutputStream logStream;
   protected final FileChannel logChannel;
-  protected long size;
+  protected long size = 0;
+  protected long originalSize = 0;
+  private final ByteBuffer headerBuffer = ByteBuffer.allocate(Integer.BYTES * 
2 + 1);
+  private static final CompressionType compressionAlg =
+      IoTDBDescriptor.getInstance().getConfig().getWALCompressionAlgorithm();
+  private final ICompressor compressor = 
ICompressor.getCompressor(compressionAlg);
+  private final ByteBuffer compressedByteBuffer;
+  // Minimum size to compress, default is 32 KB
+  private static final long MIN_COMPRESS_SIZE = 0;
 
-  protected LogWriter(File logFile) throws FileNotFoundException {
+  protected LogWriter(File logFile) throws IOException {
     this.logFile = logFile;
     this.logStream = new FileOutputStream(logFile, true);
     this.logChannel = this.logStream.getChannel();
+    if (!logFile.exists() || logFile.length() == 0) {
+      
this.logChannel.write(ByteBuffer.wrap(WALWriter.MAGIC_STRING.getBytes()));
+      size += logChannel.position();
+    }
+    if (compressionAlg != CompressionType.UNCOMPRESSED) {
+      compressedByteBuffer =
+          ByteBuffer.allocate(
+              compressor.getMaxBytesForCompression(
+                  
IoTDBDescriptor.getInstance().getConfig().getWalBufferSize()));

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to