use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.
the class ConsistencyCheckerImplTest method testDoubleCheckDisonnectedNode.
public void testDoubleCheckDisonnectedNode() throws RepositoryException {
NodePropBundle bundle1 = new NodePropBundle(new NodeId(0, 0));
NodePropBundle bundle2 = new NodePropBundle(new NodeId(0, 1));
NodePropBundle bundle3 = new NodePropBundle(new NodeId(1, 0));
// node1 has child node3
bundle1.addChildNodeEntry(nameFactory.create("", "test"), bundle3.getId());
// node2 also has child node3
bundle2.addChildNodeEntry(nameFactory.create("", "test"), bundle3.getId());
// node3 has node2 as parent
bundle3.setParentId(bundle2.getId());
MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle1, bundle2, bundle3));
ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null, null, null);
checker.check(null, false);
Set<ReportItem> reportItems = checker.getReport().getItems();
assertEquals(1, reportItems.size());
ReportItem reportItem = reportItems.iterator().next();
assertEquals(ReportItem.Type.DISCONNECTED, reportItem.getType());
assertEquals(bundle1.getId().toString(), reportItem.getNodeId());
checker.doubleCheckErrors();
assertFalse("Double check removed valid error", checker.getReport().getItems().isEmpty());
// fix the error
bundle1.getChildNodeEntries().remove(0);
checker.doubleCheckErrors();
assertTrue("Double check didn't remove invalid error", checker.getReport().getItems().isEmpty());
}
use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.
the class ConsistencyCheckerImpl method internalCheckConsistency.
private int internalCheckConsistency(String[] uuids, boolean recursive) throws RepositoryException {
int count = 0;
if (uuids == null) {
// check all nodes
try {
Map<NodeId, NodeInfo> batch = pm.getAllNodeInfos(null, NODESATONCE);
Map<NodeId, NodeInfo> allInfos = batch;
NodeId lastId = null;
while (!batch.isEmpty()) {
for (Map.Entry<NodeId, NodeInfo> entry : batch.entrySet()) {
lastId = entry.getKey();
count++;
if (count % 1000 == 0) {
log.info(pm + ": loaded " + count + " infos...");
}
}
batch = pm.getAllNodeInfos(lastId, NODESATONCE);
allInfos.putAll(batch);
}
if (lastId == null) {
log.info("No nodes exists, skipping");
} else if (pm.exists(lastId)) {
for (Map.Entry<NodeId, NodeInfo> entry : allInfos.entrySet()) {
checkBundleConsistency(entry.getKey(), entry.getValue(), allInfos);
}
} else {
log.info("Failed to read all nodes, starting over");
internalCheckConsistency(uuids, recursive);
}
} catch (ItemStateException e) {
throw new RepositoryException("Error loading nodes", e);
} finally {
NodeInfo.clearPool();
}
} else {
// check only given uuids, handle recursive flag
List<NodeId> idList = new ArrayList<NodeId>(uuids.length);
for (final String uuid : uuids) {
try {
idList.add(new NodeId(uuid));
} catch (IllegalArgumentException e) {
error(uuid, "Invalid id for consistency check, skipping: '" + uuid + "': " + e);
}
}
for (int i = 0; i < idList.size(); i++) {
NodeId id = idList.get(i);
try {
final NodePropBundle bundle = pm.loadBundle(id);
if (bundle == null) {
if (!isVirtualNode(id)) {
error(id.toString(), "No bundle found for id '" + id + "'");
}
} else {
checkBundleConsistency(id, new NodeInfo(bundle), Collections.<NodeId, NodeInfo>emptyMap());
if (recursive) {
for (NodePropBundle.ChildNodeEntry entry : bundle.getChildNodeEntries()) {
idList.add(entry.getId());
}
}
count++;
if (count % 1000 == 0 && listener == null) {
log.info(pm + ": checked " + count + "/" + idList.size() + " bundles...");
}
}
} catch (ItemStateException ignored) {
// problem already logged
}
}
}
log.info(pm + ": checked " + count + " bundles.");
return count;
}
use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.
the class ConsistencyCheckerImpl method checkLostNFound.
private void checkLostNFound() {
if (lostNFoundId != null) {
// do we have a "lost+found" node?
try {
NodePropBundle lfBundle = pm.loadBundle(lostNFoundId);
if (lfBundle == null) {
error(lostNFoundId.toString(), "Specified 'lost+found' node does not exist");
lostNFoundId = null;
} else if (!NameConstants.NT_UNSTRUCTURED.equals(lfBundle.getNodeTypeName())) {
error(lostNFoundId.toString(), "Specified 'lost+found' node is not of type nt:unstructured");
lostNFoundId = null;
}
} catch (Exception ex) {
error(lostNFoundId.toString(), "finding 'lost+found' folder", ex);
lostNFoundId = null;
}
} else {
info(null, "No 'lost+found' node specified: orphans cannot be fixed");
}
}
use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.
the class AbstractBundlePersistenceManager method storeInternal.
/**
* Stores the given changelog and updates the bundle cache.
*
* @param changeLog the changelog to store
* @throws ItemStateException on failure
*/
private void storeInternal(ChangeLog changeLog) throws ItemStateException {
// delete bundles
HashSet<ItemId> deleted = new HashSet<ItemId>();
for (ItemState state : changeLog.deletedStates()) {
if (state.isNode()) {
NodePropBundle bundle = getBundle((NodeId) state.getId());
if (bundle == null) {
throw new NoSuchItemStateException(state.getId().toString());
}
deleteBundle(bundle);
deleted.add(state.getId());
}
}
// gather added node states
HashMap<ItemId, NodePropBundle> modified = new HashMap<ItemId, NodePropBundle>();
for (ItemState state : changeLog.addedStates()) {
if (state.isNode()) {
NodePropBundle bundle = new NodePropBundle((NodeState) state);
modified.put(state.getId(), bundle);
}
}
// gather modified node states
for (ItemState state : changeLog.modifiedStates()) {
if (state.isNode()) {
NodeId nodeId = (NodeId) state.getId();
NodePropBundle bundle = modified.get(nodeId);
if (bundle == null) {
bundle = getBundle(nodeId);
if (bundle == null) {
throw new NoSuchItemStateException(nodeId.toString());
}
modified.put(nodeId, bundle);
}
bundle.update((NodeState) state);
} else {
PropertyId id = (PropertyId) state.getId();
// skip redundant primaryType and uuid properties
if (id.getName().equals(JCR_PRIMARYTYPE) || id.getName().equals(JCR_UUID)) {
continue;
}
NodeId nodeId = id.getParentId();
NodePropBundle bundle = modified.get(nodeId);
if (bundle == null) {
bundle = getBundle(nodeId);
if (bundle == null) {
throw new NoSuchItemStateException(nodeId.toString());
}
modified.put(nodeId, bundle);
}
bundle.addProperty((PropertyState) state, getBlobStore());
}
}
// add removed properties
for (ItemState state : changeLog.deletedStates()) {
if (state.isNode()) {
// check consistency
NodeId parentId = state.getParentId();
if (!modified.containsKey(parentId) && !deleted.contains(parentId)) {
log.warn("Deleted node state's parent is not modified or deleted: " + parentId + "/" + state.getId());
}
} else {
PropertyId id = (PropertyId) state.getId();
NodeId nodeId = id.getParentId();
if (!deleted.contains(nodeId)) {
NodePropBundle bundle = modified.get(nodeId);
if (bundle == null) {
// should actually not happen
log.warn("deleted property state's parent not modified!");
bundle = getBundle(nodeId);
if (bundle == null) {
throw new NoSuchItemStateException(nodeId.toString());
}
modified.put(nodeId, bundle);
}
bundle.removeProperty(id.getName(), getBlobStore());
}
}
}
// add added properties
for (ItemState state : changeLog.addedStates()) {
if (!state.isNode()) {
PropertyId id = (PropertyId) state.getId();
// skip primaryType and uuid properties
if (id.getName().equals(JCR_PRIMARYTYPE) || id.getName().equals(JCR_UUID)) {
continue;
}
NodeId nodeId = id.getParentId();
NodePropBundle bundle = modified.get(nodeId);
if (bundle == null) {
// should actually not happen
log.warn("added property state's parent not modified!");
bundle = getBundle(nodeId);
if (bundle == null) {
throw new NoSuchItemStateException(nodeId.toString());
}
modified.put(nodeId, bundle);
}
bundle.addProperty((PropertyState) state, getBlobStore());
}
}
// now store all modified bundles
long updateSize = 0;
for (NodePropBundle bundle : modified.values()) {
putBundle(bundle);
updateSize += bundle.getSize();
}
changeLog.setUpdateSize(updateSize);
// store the refs
for (NodeReferences refs : changeLog.modifiedRefs()) {
if (refs.hasReferences()) {
store(refs);
} else {
destroy(refs);
}
}
}
use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.
the class AbstractBundlePersistenceManager method init.
// -------------------------------------------------< PersistenceManager >---
/**
* {@inheritDoc}
*
* Initializes the internal structures of this abstract persistence manager.
*/
public void init(PMContext context) throws Exception {
this.context = context;
// init bundle cache
bundles = new ConcurrentCache<NodeId, NodePropBundle>(context.getHomeDir().getName() + "BundleCache");
bundles.setMaxMemorySize(bundleCacheSize);
bundles.setAccessListener(this);
// statistics
RepositoryStatisticsImpl stats = context.getRepositoryStatistics();
readCounter = stats.getCounter(RepositoryStatistics.Type.BUNDLE_READ_COUNTER);
writeCounter = stats.getCounter(RepositoryStatistics.Type.BUNDLE_WRITE_COUNTER);
writeDuration = stats.getCounter(RepositoryStatistics.Type.BUNDLE_WRITE_DURATION);
cacheAccessCounter = stats.getCounter(RepositoryStatistics.Type.BUNDLE_CACHE_ACCESS_COUNTER);
cacheSizeCounter = stats.getCounter(RepositoryStatistics.Type.BUNDLE_CACHE_SIZE_COUNTER);
cacheMissCounter = stats.getCounter(RepositoryStatistics.Type.BUNDLE_CACHE_MISS_COUNTER);
cacheMissDuration = stats.getCounter(RepositoryStatistics.Type.BUNDLE_CACHE_MISS_DURATION);
}
Aggregations