Search in sources :

Example 1 with IterablePersistenceManager

use of org.apache.jackrabbit.core.persistence.IterablePersistenceManager in project jackrabbit by apache.

the class RepositoryImpl method createDataStoreGarbageCollector.

/**
 * Creates a data store garbage collector for this repository.
 * <p>
 * Note that you should use the {@link RepositoryManager} interface
 * to access this functionality. This RepositoryImpl method may be
 * removed in future Jackrabbit versions.
 */
public GarbageCollector createDataStoreGarbageCollector() throws RepositoryException {
    ArrayList<PersistenceManager> pmList = new ArrayList<PersistenceManager>();
    InternalVersionManagerImpl vm = context.getInternalVersionManager();
    PersistenceManager pm = vm.getPersistenceManager();
    pmList.add(pm);
    String[] wspNames = getWorkspaceNames();
    SessionImpl[] sessions = new SessionImpl[wspNames.length];
    for (int i = 0; i < wspNames.length; i++) {
        String wspName = wspNames[i];
        WorkspaceInfo wspInfo = getWorkspaceInfo(wspName);
        // this will initialize the workspace if required
        SessionImpl systemSession = SystemSession.create(context, wspInfo.getConfig());
        // mark the workspace as 'active' so it does not get disposed by
        // the workspace-janitor until the garbage collector is done
        wspInfo.setActive(true);
        // the workspace could be disposed, so re-initialize if required
        // afterwards it will not be disposed because it was marked active
        wspInfo.initialize();
        sessions[i] = systemSession;
        pm = wspInfo.getPersistenceManager();
        pmList.add(pm);
    }
    IterablePersistenceManager[] ipmList = new IterablePersistenceManager[pmList.size()];
    for (int i = 0; i < pmList.size(); i++) {
        pm = pmList.get(i);
        if (!(pm instanceof IterablePersistenceManager)) {
            ipmList = null;
            break;
        }
        ipmList[i] = (IterablePersistenceManager) pm;
    }
    GarbageCollector gc = new GarbageCollector(context, context.getDataStore(), ipmList, sessions);
    synchronized (this) {
        if (context.isGcRunning()) {
            throw new RepositoryException("Cannot create GC. GC already running");
        }
        context.setGcRunning(true);
    }
    return gc;
}
Also used : PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) InternalVersionManagerImpl(org.apache.jackrabbit.core.version.InternalVersionManagerImpl) IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) GarbageCollector(org.apache.jackrabbit.core.gc.GarbageCollector)

Example 2 with IterablePersistenceManager

use of org.apache.jackrabbit.core.persistence.IterablePersistenceManager in project jackrabbit by apache.

the class GarbageCollector method scanPersistenceManagersByNodeIds.

private void scanPersistenceManagersByNodeIds() throws RepositoryException, ItemStateException {
    int pmCount = 0;
    for (IterablePersistenceManager pm : pmList) {
        pmCount++;
        List<NodeId> allNodeIds = pm.getAllNodeIds(null, 0);
        int overAllCount = allNodeIds.size();
        if (overAllCount > minSplitSize) {
            final int splits = getConcurrentThreadSize();
            ExecutorService executorService = Executors.newFixedThreadPool(splits);
            try {
                Set<Future<Void>> futures = new HashSet<Future<Void>>();
                List<List<NodeId>> lists = splitIntoParts(allNodeIds, splits);
                LOG.debug(splits + " concurrent Threads will be started. Split Size: " + lists.get(0).size() + " Total Size: " + overAllCount);
                for (int i = 0; i < splits; i++) {
                    List<NodeId> subList = lists.get(i);
                    futures.add(executorService.submit(new ScanNodeIdListTask(i + 1, subList, pm, pmCount)));
                }
                for (Future<Void> future : futures) {
                    future.get();
                }
            } catch (Exception e) {
                throw new RepositoryException(e);
            } finally {
                executorService.shutdown();
            }
        } else {
            scanNodeIdList(0, allNodeIds, pm, pmCount);
        }
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) NodeId(org.apache.jackrabbit.core.id.NodeId) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 3 with IterablePersistenceManager

use of org.apache.jackrabbit.core.persistence.IterablePersistenceManager in project jackrabbit by apache.

the class GarbageCollector method scanPersistenceManagersByNodeInfos.

private void scanPersistenceManagersByNodeInfos() throws RepositoryException, ItemStateException {
    int pmCount = 0;
    for (IterablePersistenceManager pm : pmList) {
        pmCount++;
        int count = 0;
        Map<NodeId, NodeInfo> batch = pm.getAllNodeInfos(null, NODESATONCE);
        while (!batch.isEmpty()) {
            NodeId lastId = null;
            for (NodeInfo info : batch.values()) {
                count++;
                if (count % 1000 == 0) {
                    LOG.debug(pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes...");
                }
                lastId = info.getId();
                if (callback != null) {
                    callback.beforeScanning(null);
                }
                if (info.hasBlobsInDataStore()) {
                    try {
                        NodeState state = pm.load(info.getId());
                        Set<Name> propertyNames = state.getPropertyNames();
                        for (Name name : propertyNames) {
                            PropertyId pid = new PropertyId(info.getId(), name);
                            PropertyState ps = pm.load(pid);
                            if (ps.getType() == PropertyType.BINARY) {
                                for (InternalValue v : ps.getValues()) {
                                    // getLength will update the last modified date
                                    // if the persistence manager scan is running
                                    v.getLength();
                                }
                            }
                        }
                    } catch (NoSuchItemStateException ignored) {
                    // the node may have been deleted in the meantime
                    }
                }
            }
            batch = pm.getAllNodeInfos(lastId, NODESATONCE);
        }
    }
    NodeInfo.clearPool();
}
Also used : IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeInfo(org.apache.jackrabbit.core.persistence.util.NodeInfo) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Aggregations

IterablePersistenceManager (org.apache.jackrabbit.core.persistence.IterablePersistenceManager)3 ArrayList (java.util.ArrayList)2 RepositoryException (javax.jcr.RepositoryException)2 NodeId (org.apache.jackrabbit.core.id.NodeId)2 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)2 HashSet (java.util.HashSet)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 GarbageCollector (org.apache.jackrabbit.core.gc.GarbageCollector)1 PropertyId (org.apache.jackrabbit.core.id.PropertyId)1 PersistenceManager (org.apache.jackrabbit.core.persistence.PersistenceManager)1 NodeInfo (org.apache.jackrabbit.core.persistence.util.NodeInfo)1 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)1 NodeState (org.apache.jackrabbit.core.state.NodeState)1 PropertyState (org.apache.jackrabbit.core.state.PropertyState)1 InternalValue (org.apache.jackrabbit.core.value.InternalValue)1