eolivelli commented on code in PR #2024: URL: https://github.com/apache/zookeeper/pull/2024#discussion_r1262049958
########## zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnLog.java: ########## @@ -376,6 +387,12 @@ public long getLastLoggedZxid() { public synchronized void commit() throws IOException { if (logStream != null) { logStream.flush(); + filePosition += unFlushedSize; + //It is the same as the FilePadding.calculateFileSizeWithPadding line_106. Review Comment: unfortunately "line_106" will move in the future, please remove this word. you can add a javadoc with a {@link } comment to the method ########## zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnLog.java: ########## @@ -289,22 +297,25 @@ public synchronized boolean append(TxnHeader hdr, Record txn, TxnDigest digest) logStream = new BufferedOutputStream(fos); oa = BinaryOutputArchive.getArchive(logStream); FileHeader fhdr = new FileHeader(TXNLOG_MAGIC, VERSION, dbId); + long dataSize = oa.getDataSize(); fhdr.serialize(oa, "fileheader"); // Make sure that the magic number is written before padding. logStream.flush(); - filePadding.setCurrentSize(fos.getChannel().position()); + filePosition += oa.getDataSize() - dataSize; + filePadding.setCurrentSize(filePosition); streamsToFlush.add(fos); } - filePadding.padFile(fos.getChannel()); + fileSize = filePadding.padFile(fos.getChannel(), filePosition); byte[] buf = Util.marshallTxnEntry(hdr, txn, digest); if (buf == null || buf.length == 0) { throw new IOException("Faulty serialization for header " + "and txn"); } + long dataSize = oa.getDataSize(); Checksum crc = makeChecksumAlgorithm(); crc.update(buf, 0, buf.length); oa.writeLong(crc.getValue(), "txnEntryCRC"); Util.writeTxnBytes(oa, buf); - + unFlushedSize += oa.getDataSize() - dataSize; Review Comment: please add a comment in the code, it is not straightforward ########## zookeeper-jute/src/main/java/org/apache/jute/ToStringOutputArchive.java: ########## @@ -32,6 +32,7 @@ public class ToStringOutputArchive implements OutputArchive { private PrintStream stream; private boolean isFirst = true; + private long dataSize; Review Comment: I don't understand this comment @hangc0276 the default value of a long is always 0 ########## zookeeper-server/src/main/java/org/apache/zookeeper/server/persistence/FileTxnLog.java: ########## @@ -289,22 +297,25 @@ public synchronized boolean append(TxnHeader hdr, Record txn, TxnDigest digest) logStream = new BufferedOutputStream(fos); oa = BinaryOutputArchive.getArchive(logStream); FileHeader fhdr = new FileHeader(TXNLOG_MAGIC, VERSION, dbId); + long dataSize = oa.getDataSize(); fhdr.serialize(oa, "fileheader"); // Make sure that the magic number is written before padding. logStream.flush(); - filePadding.setCurrentSize(fos.getChannel().position()); + filePosition += oa.getDataSize() - dataSize; Review Comment: can you please add a comment in the code @horizonzy ? -- 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: notifications-unsubscr...@zookeeper.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org