Failed to delete the .lg file.

Help
2003-12-12
2013-06-03
  • Roubik Manoukian

    I found this problem when I created RecordManager for an exiting database and after calling the close method of RecordManager I was not able to delete the .lg file.
    I found one place when the .lg file is not closed.
    In the TransactionManager.recover method FileInputStream is not closed when method returns. The logFile.delete() is not deleting the .lg file becasue there is an open connection to that file. This method should have a try/finally clause where fis is closed before the method returns.

     
    • tonyschwartz

      tonyschwartz - 2007-08-24

      I found the exact same thing.  And it's 4 years later.  I don't see many posts to this forum, is JDBM still being actively worked on?

      Here is how I fixed the problem (might not be ideal, but it's down and dirty)...

      from TransactionManager.java ...

      /** Startup recovery on all files */
          private void recover() throws IOException {
              String logName = makeLogName();
              File logFile = new File(logName);
              if (!logFile.exists())
                  return;
              if (logFile.length() == 0) {
                  logFile.delete();
                  return;
              }

              FileInputStream fis = null;

              ObjectInputStream ois = null;

          try {
              fis = new FileInputStream(logFile);
              ois = new ObjectInputStream(fis);
              try {
                  if (ois.readShort() != Magic.LOGFILE_HEADER)
                      throw new Error("Bad magic on log file");
              } catch (IOException e) {
                  // corrupted/empty logfile
                  logFile.delete();
                  return;
              }

              while (true) {
                  ArrayList blocks = null;
                  try {
                      blocks = (ArrayList) ois.readObject();
                  } catch (ClassNotFoundException e) {
                      throw new Error("Unexcepted exception: " + e);
                  } catch (IOException e) {
                      // corrupted logfile, ignore rest of transactions
                      break;
                  }
                  synchronizeBlocks(blocks.iterator(), false);

                  // ObjectInputStream must match exactly each
                  // ObjectOutputStream created during writes
                  try {
                      ois = new ObjectInputStream(fis);
                  } catch (IOException e) {
                      // corrupted logfile, ignore rest of transactions
                      break;
                  }
              }
          }
          finally {
              try { owner.sync(); } catch ( Exception ex ) {}
              try { ois.close(); } catch ( Exception ex ) {}
              try { fis.close(); } catch ( Exception ex ) {}
              try { logFile.delete(); } catch ( Exception ex ) {}
             }
          }

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks