Uploaded image for project: 'ZooKeeper'
  1. ZooKeeper
  2. ZOOKEEPER-2572

Potential resource leak in FileTxnLog.truncate

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.4.9, 3.5.2, 3.4.11
    • None
    • server

    Description

      In FileTxnLog.truncate, we have:

      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;
          }
      

      raf here can be potentially in a state of not closed after leaving the method, if there is an (IO) exception thrown from setLength.

      Attachments

        Activity

          People

            maoling Ling Mao
            hanm Michael Han
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 10m
                10m