[
https://issues.apache.org/jira/browse/ZOOKEEPER-2572?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16152030#comment-16152030
]
ASF GitHub Bot commented on ZOOKEEPER-2572:
-------------------------------------------
Github user maoling commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/356#discussion_r136732115
--- Diff: src/java/main/org/apache/zookeeper/server/quorum/Learner.java ---
@@ -395,11 +395,12 @@ else if (qp.getType() == Leader.SNAP) {
//we need to truncate the log to the lastzxid of the leader
LOG.warn("Truncating log to get in sync with the leader 0x"
+ Long.toHexString(qp.getZxid()));
- boolean
truncated=zk.getZKDatabase().truncateLog(qp.getZxid());
- if (!truncated) {
+ try {
+ zk.getZKDatabase().truncateLog(qp.getZxid());
+ } catch (IOException e) {
// not able to truncate the log
- LOG.error("Not able to truncate the log "
- + Long.toHexString(qp.getZxid()));
+ LOG.error("Not able to truncate the log {}, Unexpected
exception "
+ + Long.toHexString(qp.getZxid()), e);
System.exit(13);
--- End diff --
this format of log is right?
> 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
> Assignee: gaoshu
> Fix For: 3.5.4, 3.6.0, 3.4.11
>
>
> 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.4.14#64029)