cancel
Showing results for 
Search instead for 
Did you mean: 

Contentstore caching, number of open files problem

sebgymn
Champ in-the-making
Champ in-the-making
Hello, this is my first post in this forum.

I have a relatively large alfresco repository of 300 gb and I want to export some of the files within it to local filesystem. I have written a code using jcr api, like this:


   private void recursiveExport (Node root, String exportDir) throws RepositoryException, IOException {
      if(root==null) {
         return;
      }
      String currentDir = String.format("%s%s%s", exportDir, File.separator, root.getName().substring(root.getName().lastIndexOf(":")+1));
      //folder
      if(root.getPrimaryNodeType().getName().equals("cm:folder")){
         new File(currentDir).mkdirs();
         for(NodeIterator iterator = root.getNodes(); iterator.hasNext(); ){
            Node child = iterator.nextNode();
            recursiveExport(child, currentDir+File.separator);
            child = null;
         }
      }
      //file
      else{
         FileOutputStream fos = new FileOutputStream(currentDir);
         Property prop = root.getProperty("cm:content");
         if(prop==null){
            return;
         }
         IOUtils.copy(prop.getStream(), fos);
         fos.close();
         prop.getStream().close();

         prop = null;
         root = null;
         fos = null;
      }
      logger.info(String.format("%s exported.", currentDir));
   }

I call this method with the root folder that I want to export. The code runs smoothly, however my problem is the number of open files while using this. Somehow alfresco does not close the file handles, leading to excess resource usage, as it can be checked with this command:
ls -1 /proc/`pidof java`/fd | wc -l 
The number of open files grows to high numbers (80000 in half an hour, my ulimit -n is 819200). I want this to exactly work like I have written the above code, opening the file, exporting it, and closing the streams, simple. I have checked which files are open, and they are *.bin files inside contentstore, so I suspect there is some configuration issues about it.

Can anybody lead me out of this situation? Thanks in advance
2 REPLIES 2

mitpatoliya
Star Collaborator
Star Collaborator
I think you need to use finally block.
and should close all the files and streams in that block.
this might help.
Also check and try to remove if any unnecessary IO operation you are doing.

sebgymn
Champ in-the-making
Champ in-the-making
Thanks for your reply, but that approach does not work. I have converted my code to use Foundation API, and problem gone. I guess this is a bug in JCR side.