[ https://issues.apache.org/jira/browse/ZOOKEEPER-2572?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15488886#comment-15488886 ]
Michael Han commented on ZOOKEEPER-2572: ---------------------------------------- bq. Does it make sense what I am saying? I think that is dead code, good catch. bq. what's the right way of dealing with being unable to truncate the log file? Currently if a file failed to truncate, the exception will bubble up and got caught in [Follower.java|https://github.com/apache/zookeeper/blob/master/src/java/main/org/apache/zookeeper/server/quorum/Follower.java#L93], so the error is handled - but we lose the original (IMO) better error message logging of {{LOG.error("Not able to truncate the log "+ Long.toHexString(qp.getZxid()));}}. Maybe we can catch the exception at syncWithLeader, log the detailed error with zxid, then rethrow it. And it certainly sounds odd that we have a boolean return signature which only return true... > Potential resource leak in FileTxnLog.truncate > ---------------------------------------------- > > Key: ZOOKEEPER-2572 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2572 > Project: ZooKeeper > Issue Type: Bug > Components: server > Affects Versions: 3.4.9, 3.5.2 > Reporter: Michael Han > Fix For: 3.4.10, 3.5.3 > > > In FileTxnLog.truncate, we have: > {code} > public boolean truncate(long zxid) throws IOException { > FileTxnIterator itr = null; > try { > itr = new FileTxnIterator(this.logDir, zxid); > PositionInputStream input = itr.inputStream; > if(input == null) { > throw new IOException("No log files found to truncate! This > could " + > "happen if you still have snapshots from an old setup > or " + > "log files were deleted accidentally or dataLogDir > was changed in zoo.cfg."); > } > long pos = input.getPosition(); > // now, truncate at the current position > RandomAccessFile raf=new RandomAccessFile(itr.logFile,"rw"); > raf.setLength(pos); > raf.close(); > while(itr.goToNextLog()) { > if (!itr.logFile.delete()) { > LOG.warn("Unable to truncate {}", itr.logFile); > } > } > } finally { > close(itr); > } > return true; > } > {code} > {{raf}} here can be potentially in a state of not closed after leaving the > method, if there is an (IO) exception thrown from setLength. -- This message was sent by Atlassian JIRA (v6.3.4#6332)