Package org.apache.jackrabbit.core.persistence.util

Examples of org.apache.jackrabbit.core.persistence.util.NodePropBundle


     */
    private NodePropBundle getBundleCacheMiss(NodeId id)
            throws ItemStateException {
        long time = System.nanoTime();
        log.debug("Loading bundle {}", id);
        NodePropBundle bundle = loadBundle(id);
        readDuration.addAndGet(System.nanoTime() - time);
        readCounter.incrementAndGet();

        if (bundle != null) {
            bundle.markOld();
            bundles.put(id, bundle, bundle.getSize());
        } else {
            bundles.put(id, MISSING, 16);
        }
        return bundle;
    }
View Full Code Here


    private static final NameFactory nameFactory = NameFactoryImpl.getInstance();

    // Abandoned nodes are nodes that have a link to a parent but that
    // parent does not have a link back to the child
    public void testFixAbandonedNode() throws RepositoryException {
        NodePropBundle bundle1 = new NodePropBundle(new NodeId(0, 0));
        NodePropBundle bundle2 = new NodePropBundle(new NodeId(0, 1));

        // node2 has a reference to node 1 as its parent, but node 1 doesn't have
        // a corresponding child node entry
        bundle2.setParentId(bundle1.getId());

        MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle1, bundle2));
        ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null);

        // run checker with fix = true
        checker.check(null, false, true, null);

        // node1 should now have a child node entry for node2
        bundle1 = pm.loadBundle(bundle1.getId());
        assertEquals(1, bundle1.getChildNodeEntries().size());
        assertEquals(bundle2.getId(), bundle1.getChildNodeEntries().get(0).getId());
    }
View Full Code Here

    /*
     * There was a bug where when there were multiple abandoned nodes by the same parent
     * only one of them was fixed. Hence this separate test case for this scenario.
     */
    public void testFixMultipleAbandonedNodesBySameParent() 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));


        // node2 and node3 have a reference to node1 as its parent, but node1 doesn't have
        // corresponding child node entries
        bundle2.setParentId(bundle1.getId());
        bundle3.setParentId(bundle1.getId());

        MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle1, bundle2, bundle3));
        ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null);

        // run checker with fix = true
        checker.check(null, false, true, null);

        // node1 should now have child node entries for node2 and node3
        bundle1 = pm.loadBundle(bundle1.getId());
        assertEquals(2, bundle1.getChildNodeEntries().size());
        assertEquals(bundle2.getId(), bundle1.getChildNodeEntries().get(0).getId());
        assertEquals(bundle3.getId(), bundle1.getChildNodeEntries().get(1).getId());
    }
View Full Code Here

        assertEquals(bundle3.getId(), bundle1.getChildNodeEntries().get(1).getId());
    }

    // Orphaned nodes are those nodes who's parent does not exist
    public void testAddOrphanedNodeToLostAndFound() throws RepositoryException {
        NodePropBundle lostAndFound = new NodePropBundle(new NodeId(0, 0));
        // lost and found must be of type nt:unstructured
        lostAndFound.setNodeTypeName(NameConstants.NT_UNSTRUCTURED);

        NodePropBundle orphaned = new NodePropBundle(new NodeId(0, 1));
        // set non-existent parent node id
        orphaned.setParentId(new NodeId(1, 0));

        MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(lostAndFound, orphaned));
        ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null);

        // run checker with fix = true
        checker.check(null, false, true, lostAndFound.getId().toString());

        // orphan should have been added to lost+found
        lostAndFound = pm.loadBundle(lostAndFound.getId());
        assertEquals(1, lostAndFound.getChildNodeEntries().size());
        assertEquals(orphaned.getId(), lostAndFound.getChildNodeEntries().get(0).getId());

        orphaned = pm.loadBundle(orphaned.getId());
        assertEquals(lostAndFound.getId(), orphaned.getParentId());
    }
View Full Code Here

    // Disconnected nodes are those nodes for which there are nodes
    // that have the node as its child, but the node itself does not
    // have those nodes as its parent
    public void testFixDisconnectedNode() 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);

        // run checker with fix = true
        checker.check(null, false, true, null);

        bundle1 = pm.loadBundle(bundle1.getId());
        bundle2 = pm.loadBundle(bundle2.getId());
        bundle3 = pm.loadBundle(bundle3.getId());

        // node3 should have been removed as child node entry of node1
        assertEquals(0, bundle1.getChildNodeEntries().size());

        // node3 should still be a child of node2
        assertEquals(1, bundle2.getChildNodeEntries().size());
        assertEquals(bundle2.getId(), bundle3.getParentId());
    }
View Full Code Here

    }

    // make sure we don't fix anything in check mode, we can't be careful enough
    public void testDontFixInCheckMode() throws RepositoryException {
        /** abandoned node, also see {@link #testFixAbandonedNode} */
        NodePropBundle bundle1 = new NodePropBundle(new NodeId(0, 0));
        NodePropBundle bundle2 = new NodePropBundle(new NodeId(0, 1));
        bundle2.setParentId(bundle1.getId());

        /** orphaned node, also see {@link #testAddOrphanedNodeToLostAndFound} */
        NodePropBundle lostAndFound = new NodePropBundle(new NodeId(1, 0));
        lostAndFound.setNodeTypeName(NameConstants.NT_UNSTRUCTURED);
        NodePropBundle orphaned = new NodePropBundle(new NodeId(1, 1));
        orphaned.setParentId(new NodeId(0, 2));

        /** disconnected node, also see {@link #testFixDisconnectedNode} */
        NodePropBundle bundle3 = new NodePropBundle(new NodeId(1, 2));
        NodePropBundle bundle4 = new NodePropBundle(new NodeId(2, 2));
        NodePropBundle bundle5 = new NodePropBundle(new NodeId(0, 3));
        bundle3.addChildNodeEntry(nameFactory.create("", "test"), bundle5.getId());
        bundle4.addChildNodeEntry(nameFactory.create("", "test"), bundle5.getId());
        bundle5.setParentId(bundle4.getId());

        MockPersistenceManager pm = new MockPersistenceManager(Arrays.asList(bundle1, bundle2, bundle3, bundle4, bundle5, lostAndFound, orphaned));
        ConsistencyCheckerImpl checker = new ConsistencyCheckerImpl(pm, null);

        // run checker with fix = false
View Full Code Here

        NodeId lostNFound = null;
        if (fix && lostNFoundId != null) {
            // do we have a "lost+found" node?
            try {
                NodeId tmpid = new NodeId(lostNFoundId);
                NodePropBundle lfBundle = pm.loadBundle(tmpid);
                if (lfBundle == null) {
                    error(lostNFoundId,
                            "specified 'lost+found' node does not exist");
                } else if (!NameConstants.NT_UNSTRUCTURED.equals(lfBundle
                        .getNodeTypeName())) {
                    error(lostNFoundId,
                            "specified 'lost+found' node is not of type nt:unstructured");
                } else {
                    lostNFound = lfBundle.getId();
                }
            } catch (Exception ex) {
                error(lostNFoundId, "finding 'lost+found' folder", ex);
            }
        }

        if (uuids == null) {
            try {
                List<NodeId> allIds = pm.getAllNodeIds(null, NODESATONCE);

                while (!allIds.isEmpty()) {
                    NodeId lastId = null;

                    for (NodeId id : allIds) {
                        lastId = id;
                        try {
                            // parse and check bundle
                            NodePropBundle bundle = pm.loadBundle(id);
                            if (bundle == null) {
                                error(id.toString(), "No bundle found for id '"
                                        + id + "'");
                            } else {
                                checkBundleConsistency(id, bundle, fix, lostNFound, reports);

                                count++;
                                if (count % 1000 == 0 && listener == null) {
                                    log.info(pm + ": checked " + count
                                            + " bundles...");
                                }
                            }
                        } catch (ItemStateException e) {
                            // problem already logged (loadBundle called with
                            // logDetailedErrors=true)
                        }
                    }

                    if (!allIds.isEmpty()) {
                        allIds = pm.getAllNodeIds(lastId, NODESATONCE);
                    }
                }
            } catch (ItemStateException ex) {
                throw new RepositoryException("getting nodeIds", ex);
            }
        } else {
            // check only given uuids, handle recursive flag

            // 1) convert uuid array to modifiable list
            // 2) for each uuid do
            // a) load node bundle
            // b) check bundle, store any bundle-to-be-modified in collection
            // c) if recursive, add child uuids to list of uuids

            List<NodeId> idList = new ArrayList<NodeId>(uuids.length);
            // convert uuid string array to list of UUID objects
            for (int i = 0; i < uuids.length; i++) {
                try {
                    idList.add(new NodeId(uuids[i]));
                } catch (IllegalArgumentException e) {
                    error(uuids[i],
                            "Invalid id for consistency check, skipping: '"
                                    + uuids[i] + "': " + e);
                }
            }

            // iterate over UUIDs (including ones that are newly added inside
            // the loop!)
            for (int i = 0; i < idList.size(); i++) {
                NodeId id = idList.get(i);
                try {
                    // load the node from the database
                    NodePropBundle bundle = pm.loadBundle(id);

                    if (bundle == null) {
                        if (!isVirtualNode(id)) {
                            error(id.toString(), "No bundle found for id '"
                                    + id + "'");
                        }
                    } else {
                        checkBundleConsistency(id, bundle, fix, lostNFound, reports);

                        if (recursive) {
                            for (NodePropBundle.ChildNodeEntry entry : bundle
                                    .getChildNodeEntries()) {
                                idList.add(entry.getId());
                            }
                        }
View Full Code Here

                continue;
            }

            try {
                // analyze child node bundles
                final NodePropBundle childBundle = pm.loadBundle(childNodeId);
                String message = null;
                if (childBundle == null) {
                    // double check whether we still exist and the child entry is still there
                    bundle = pm.loadBundle(id);

                    if (bundle != null) {
                        boolean stillThere = false;
                        for (NodePropBundle.ChildNodeEntry entryRetry : bundle.getChildNodeEntries()) {
                            if (entryRetry.getId().equals(childNodeId)) {
                                stillThere = true;
                                break;
                            }
                        }
                        if (stillThere) {
                            message = "NodeState '" + id
                                    + "' references inexistent child" + " '"
                                    + entry.getName() + "' with id " + "'"
                                    + childNodeId + "'";
                            log.error(message);
                            missingChildren.add(entry);
                        }
                    } else {
                        return;
                    }
                } else {
                    NodeId cp = childBundle.getParentId();
                    if (!id.equals(cp)) {
                        // double check whether the child entry is still there
                        bundle = pm.loadBundle(id);
                        if (bundle != null) {
                            boolean stillThere = false;
                            for (NodePropBundle.ChildNodeEntry entryRetry : bundle.getChildNodeEntries()) {
                                if (entryRetry.getId().equals(childNodeId)) {
                                    stillThere = true;
                                    break;
                                }
                            }
                            if (stillThere) {
                                // indeed we have a disconnected child
                                message = "ChildNode has invalid parent id: '" + cp + "' (instead of '" + id + "')";
                                log.error(message);
                                disconnectedChildren.add(entry);
                            }
                        } else {
                            return;
                        }
                    }
                }
                if (message != null) {
                    addMessage(reports, id, message);
                }
            } catch (ItemStateException e) {
                // problem already logged (loadBundle called with
                // logDetailedErrors=true)
                addMessage(reports, id, e.getMessage());
            }
        }
        // remove child node entry (if fixing is enabled)
        if (fix && (!missingChildren.isEmpty() || !disconnectedChildren.isEmpty())) {
            for (NodePropBundle.ChildNodeEntry entry : missingChildren) {
                bundle.getChildNodeEntries().remove(entry);
            }
            for (NodePropBundle.ChildNodeEntry entry : disconnectedChildren) {
                bundle.getChildNodeEntries().remove(entry);
            }
            fixBundle(bundle);
        }

        // check parent reference
        NodeId parentId = bundle.getParentId();
        try {
            // skip root nodes (that point to itself)
            if (parentId != null && !id.toString().endsWith("babecafebabe")) {
                NodePropBundle parentBundle = pm.loadBundle(parentId);

                if (parentBundle == null) {
                    // double check whether we still exist and the parent is still the same
                    bundle = pm.loadBundle(id);
                    if (bundle != null) {
                        if (parentId.equals(bundle.getParentId())) {
                            String message = "NodeState '" + id
                                    + "' references inexistent parent id '" + parentId
                                    + "'";
                            log.error(message);
                            addMessage(reports, id, message);
                            if (fix && lostNFoundId != null) {
                                // add a child to lost+found
                                NodePropBundle lfBundle = pm.loadBundle(lostNFoundId);
                                lfBundle.markOld();
                                String nodeName = id + "-" + System.currentTimeMillis();
                                lfBundle.addChildNodeEntry(NF.create("", nodeName), id);
                                pm.storeBundle(lfBundle);
                                pm.evictBundle(lostNFoundId);

                                // set lost+found parent
                                bundle.setParentId(lostNFoundId);
View Full Code Here

    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);
View Full Code Here

            }

            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++;
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.persistence.util.NodePropBundle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.