cancel
Showing results for 
Search instead for 
Did you mean: 

Checking the content store integrity

freedev
Champ in-the-making
Champ in-the-making
Hi All,

I have written a simple application that look into AVM_NODES and check if the files present into alf_data/contentstore directory are present into AVM_NODES and viceversa.
Now all the files into AVM_NODES have a correspondence with the alf_data/contentstore but I have found a lot of file that are NOT into the AVM_NODES table.

Could you explain me why this happens?
There is some documentation on the structure of the virtual file system?

Regards,
Vincenzo


package client;

import java.io.File;
import java.util.List;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

import entity.AvmNode;

public class Client {

    private static Logger log = Logger.getLogger("Client");
   
    private static EntityManagerFactory emf;

    private static EntityManager em;
   
    private static String pathSeparator = System.getProperty("file.separator").toString();

    private static String baseDirectory = "/opt/alfresco-community-tomcat-2.1.0/alf_data/contentstore";

    public static void main(String[] args) {

        try {
            emf = Persistence.createEntityManagerFactory("alfresco-jpa-check-db");

            createEntityManager();

            log.info("Check the files:");
           
            checkFiles(new File(baseDirectory), true, "");

            log.info("Check the table:");

            checkAvmNodes(new File(baseDirectory));

            closeEntityManager();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private static void createTransactionalEntityManager() {

        // Create a new EntityManager
        em = emf.createEntityManager();

        // Begin transaction
        em.getTransaction().begin();
    }

    private static void closeTransactionalEntityManager() {

        // Commit the transaction
        em.getTransaction().commit();

        // Close this EntityManager
        em.close();
    }

    private static void createEntityManager() {

        // Create a new EntityManager
        em = emf.createEntityManager();
    }

    private static void closeEntityManager() {

        // Close this EntityManager
        em.close();
    }
    public static void checkAvmNodes(File directory) {
        List <AvmNode> list = null;
        try {
            Query q = em.createQuery("select c from AvmNode c");
            list = q.getResultList();
            for (AvmNode entry : list) {
                if (entry.getClassType() != null && "plainfile".equals(entry.getClassType())) {
                    StringBuilder sb = new StringBuilder();
                    sb.append(directory.getAbsolutePath());
                    sb.append(entry.getContentUrl().substring(7));
                    File f = new File(sb.toString());
                    if (! f.exists()) {
                        log.severe(f.getAbsolutePath() + " file doesn't exist");
                    } else {
                        if (f.length() != entry.getLength().longValue()) {
                            log.severe(f.getAbsolutePath() + " size doesn't match");
                        } else {
                            log.info(f.getAbsolutePath());                           
                        }
                    }
                }
            }
        } catch (javax.persistence.NoResultException e) {
//            System.out.println(name + " not found");
        }       
    }

    public static void checkFiles(File directory, boolean recurse, String path) {

        File[] entries = directory.listFiles();

        for (File entry : entries) {

            if (!entry.isDirectory()) {
                StringBuilder sb = new StringBuilder();
                sb.append("%").append(path).append(pathSeparator).append(entry.getName());
                List <AvmNode> list = findAvmNodes(sb.toString());
                if (list.size() == 0) {
                    StringBuilder sbfile = new StringBuilder();
                    sbfile.append(entry.getAbsoluteFile());
                    sbfile.append(" ").append(entry.length());
                    log.severe(sbfile.toString());
                }
            }
            else if (recurse) {
                checkFiles(entry, recurse, path + pathSeparator + entry.getName());
            }
        }
    }

    @SuppressWarnings("unchecked")
    private static List <AvmNode> findAvmNodes(String name) {
        List <AvmNode> list = null;
        try {
            Query q = em.createQuery("select c from AvmNode c where c.contentUrl like :name");
            q.setParameter("name", name);
            list = q.getResultList();
        } catch (javax.persistence.NoResultException e) {
//            System.out.println(name + " not found");
        }
        return list;
    }

}
1 REPLY 1

derek
Star Contributor
Star Contributor
org.alfresco.repo.content.cleanup.ContentStoreCleaner
The store will contain content that is (a) orphaned but not old enough or (b) managed by the regular document management side of things (the content lifecycle).