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;
}
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);
}
}
}
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();
}
Aggregations