7 Replies Latest reply on Mar 31, 2008 12:17 PM by Manik Surtani

    FileCacheLoader failing with EOFException with fix

    Sanjay Prasad Newbie

      File cache loader in a cluster was failing with EOF exception while restoring an object, under load. It looks like the original hash map was not getting written properly. The original code is given below:

      protected void storeAttributes(Fqn fqn, Map attrs) throws Exception
      {
      File f = getDirectory(fqn, true);
      File child = new File(f, DATA);
      if (!child.exists())
      if (!child.createNewFile())
      throw new IOException("Unable to create file: " + child);
      FileOutputStream out = new FileOutputStream(child);
      ObjectOutputStream output = new ObjectOutputStream(out);
      output.writeObject(attrs);
      out.close();
      }

      Changing the code as given below seems to fix the issue.

      protected void storeAttributes(Fqn fqn, Map attrs) throws Exception
      {
      File f = getDirectory(fqn, true);
      File child = new File(f, DATA);
      if (!child.exists())
      if (!child.createNewFile())
      throw new IOException("Unable to create file: " + child);
      FileOutputStream out = new FileOutputStream(child);
      try
      {
      MarshalledValueOutputStream output =
      new MarshalledValueOutputStream(out);
      output.writeObject(attrs);
      output.close();
      out = null;
      }
      finally
      {
      if(out != null)
      out.close();
      }
      }