Search code examples
modeshape

Modeshape - removing node binary files


In our test server we want to delete nodes. We use below code

        Repository repository = .... ;
        Session session = null;
        session = repository.login(new SimpleCredentials(getApplicationName(), getPassword().toCharArray()));

        JcrTools jcrTools = new JcrTools();

        if (!session.nodeExists(fileInfo.getRealPath())) {
            return;
        }
        Node node = session.getNode(fileInfo.getRealPath());
        //delete children nodes if exists  
        jcrTools.removeAllChildren(node);
        //delete all properties include mixins  
        PropertyIterator pIt = node.getProperties();
        while (pIt.hasNext()) {
            javax.jcr.Property property = pIt.nextProperty();
            property.remove();
        }
        node.remove();
        session.save();
        session.logout();

The method works, we see that the files are deleted from modeshape-explorer web application. But we also see that binary files are in the binaries folder of the repository, so the nodes are not removed physically, the disk usage does not alter. What may be the problem?


Solution

  • Unused binary values will eventually be removed in a background thread, which by defaults executes once per day.

    You can easily configure this via the repository's JSON configuration. For example:

    {
      ...
      "garbageCollection" : {
        "threadPool" : "modeshape-gc-pool",
        "initialTime" : "00:00",
        "intervalInHours" : 24,
      }
      ...
    }
    

    The values shown above are the defaults, but obviously you can change them and include only those non-default fields that make sense.