tisonkun commented on code in PR #2025: URL: https://github.com/apache/zookeeper/pull/2025#discussion_r1251503018
########## zookeeper-server/src/test/java/org/apache/zookeeper/server/persistence/FileTxnLogTest.java: ########## @@ -171,20 +171,37 @@ public void testGetCurrentLogSize() throws Exception { FileTxnLog log = new FileTxnLog(tmpDir); FileTxnLog.setPreallocSize(PREALLOCATE); CreateRequest record = new CreateRequest(null, new byte[NODE_SIZE], ZooDefs.Ids.OPEN_ACL_UNSAFE, 0); + long logSize = 16; + long position = 16; int zxid = 1; for (int i = 0; i < 4; i++) { log.append(new TxnHeader(0, 0, zxid++, 0, 0), record); - LOG.debug("Current log size: {}", log.getCurrentLogSize()); + logSize += PREALLOCATE; + assertEquals(logSize, log.getCurrentLogSize()); + assertEquals(position, log.fos.getChannel().position()); } log.commit(); - LOG.info("Current log size: {}", log.getCurrentLogSize()); + long totalSize = (8 + 4 + 1095 + 1) * 4 + 16; Review Comment: Could you elaborate a bit (or add a comment) on how this magic number is calculated? cc @horizonzy ########## zookeeper-server/src/test/java/org/apache/zookeeper/server/persistence/FileTxnLogTest.java: ########## @@ -171,20 +171,37 @@ public void testGetCurrentLogSize() throws Exception { FileTxnLog log = new FileTxnLog(tmpDir); FileTxnLog.setPreallocSize(PREALLOCATE); CreateRequest record = new CreateRequest(null, new byte[NODE_SIZE], ZooDefs.Ids.OPEN_ACL_UNSAFE, 0); + long logSize = 16; + long position = 16; int zxid = 1; for (int i = 0; i < 4; i++) { log.append(new TxnHeader(0, 0, zxid++, 0, 0), record); - LOG.debug("Current log size: {}", log.getCurrentLogSize()); + logSize += PREALLOCATE; + assertEquals(logSize, log.getCurrentLogSize()); + assertEquals(position, log.fos.getChannel().position()); } log.commit(); - LOG.info("Current log size: {}", log.getCurrentLogSize()); + long totalSize = (8 + 4 + 1095 + 1) * 4 + 16; + assertEquals(totalSize, log.getCurrentLogSize()); + assertEquals(totalSize, log.fos.getChannel().position()); assertTrue(log.getCurrentLogSize() > (zxid - 1) * NODE_SIZE); + logSize = FilePadding.calculateFileSizeWithPadding(log.fos.getChannel().position(), PREALLOCATE * 4, PREALLOCATE); + position = totalSize; + boolean recalculate = true; for (int i = 0; i < 4; i++) { log.append(new TxnHeader(0, 0, zxid++, 0, 0), record); - LOG.debug("Current log size: {}", log.getCurrentLogSize()); + if (recalculate) { + recalculate = false; + } else { + logSize += PREALLOCATE; + } + assertEquals(logSize, log.getCurrentLogSize()); + assertEquals(position, log.fos.getChannel().position()); } log.commit(); - LOG.info("Current log size: " + log.getCurrentLogSize()); + totalSize = (8 + 4 + 1095 + 1) * 8 + 16; Review Comment: ditto -- 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