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

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


                        // checkBundle will log any problems itself
                        DataInputStream din = new DataInputStream(new ByteArrayInputStream(data));
                        if (binding.checkBundle(din)) {
                            // reset stream for readBundle()
                            din = new DataInputStream(new ByteArrayInputStream(data));
                            NodePropBundle bundle = binding.readBundle(din, id);
                            checkBundleConsistency(id, bundle, fix, modifications);
                        } else {
                            log.error("invalid bundle '" + id + "', see previous BundleBinding error log entry");
                        }
                    } catch (Exception e) {
                        log.error("Error in bundle " + id + ": " + e);
                    }
                    count++;
                    if (count % 1000 == 0) {
                        log.info(name + ": checked " + count + "/" + total + " bundles...");
                    }
                }
            } catch (Exception e) {
                log.error("Error loading bundle", e);
            } finally {
                closeResultSet(rs);
                total = count;
            }
        } 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) {
                    log.error("Invalid uuid 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 = loadBundle(id, true);

                    if (bundle == null) {
                        log.error("No bundle found for uuid '" + id + "'");
                        continue;
                    }

                    checkBundleConsistency(id, bundle, fix, modifications);

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

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

            total = idList.size();
        }

        // repair collected broken bundles
        if (fix && !modifications.isEmpty()) {
            log.info(name + ": Fixing " + modifications.size() + " inconsistent bundle(s)...");
            for (NodePropBundle bundle : modifications) {
                try {
                    log.info(name + ": Fixing bundle '" + bundle.getId() + "'");
                    bundle.markOld(); // use UPDATE instead of INSERT
                    storeBundle(bundle);
                    evictBundle(bundle.getId());
                } catch (ItemStateException e) {
                    log.error(name + ": Error storing fixed bundle: " + e);
                }
            }
        }
View Full Code Here


                    // gets wrapped as proper ItemStateException below
                    throw new Exception("invalid bundle, see previous BundleBinding error log entry");
                }
            }

            NodePropBundle bundle = binding.readBundle(din, id);
            bundle.setSize(bytes.length);
            return bundle;
        } catch (Exception e) {
            String msg = "failed to read bundle: " + id + ": " + e;
            log.error(msg);
            throw new ItemStateException(msg, e);
View Full Code Here

                    // skip the keys that are smaller or equal (see above, maxCount += 10)
                    if (current.compareTo(lowId) <= 0) {
                        continue;
                    }
                }
                NodePropBundle bundle = readBundle(current, rs, getStorageModel() == SM_LONGLONG_KEYS ? 3 : 2);
                NodeInfo nodeInfo = new NodeInfo(bundle);
                result.put(nodeInfo.getId(), nodeInfo);
            }
            return result;
        } catch (SQLException e) {
View Full Code Here

     * {@inheritDoc}
     *
     * Loads the state via the appropriate NodePropBundle.
     */
    public NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException {
        NodePropBundle bundle = getBundle(id);
        if (bundle == null) {
            throw new NoSuchItemStateException(id.toString());
        }
        return bundle.createNodeState(this);
    }
View Full Code Here

     * {@inheritDoc}
     *
     * Loads the state via the appropriate NodePropBundle.
     */
    public PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
        NodePropBundle bundle = getBundle(id.getParentId());
        if (bundle != null) {
            PropertyState state = createNew(id);
            PropertyEntry p = bundle.getPropertyEntry(id.getName());
            if (p != null) {
                state.setMultiValued(p.isMultiValued());
                state.setType(p.getType());
                state.setValues(p.getValues());
                state.setModCount(p.getModCount());
            } else if (id.getName().equals(JCR_UUID)) {
                state.setType(PropertyType.STRING);
                state.setMultiValued(false);
                state.setValues(new InternalValue[] {
                        InternalValue.create(id.getParentId().toString()) });
            } else if (id.getName().equals(JCR_PRIMARYTYPE)) {
                state.setType(PropertyType.NAME);
                state.setMultiValued(false);
                state.setValues(new InternalValue[] {
                        InternalValue.create(bundle.getNodeTypeName()) });
            } else if (id.getName().equals(JCR_MIXINTYPES)) {
                state.setType(PropertyType.NAME);
                state.setMultiValued(true);
                Set<Name> mixins = bundle.getMixinTypeNames();
                state.setValues(InternalValue.create(
                        mixins.toArray(new Name[mixins.size()])));
            } else {
                throw new NoSuchItemStateException(id.toString());
            }
View Full Code Here

     * {@inheritDoc}
     *
     * Loads the state via the appropriate NodePropBundle.
     */
    public boolean exists(PropertyId id) throws ItemStateException {
        NodePropBundle bundle = getBundle(id.getParentId());
        if (bundle != null) {
            Name name = id.getName();
            return bundle.hasProperty(name)
                || JCR_PRIMARYTYPE.equals(name)
                || (JCR_UUID.equals(name) && bundle.isReferenceable())
                || (JCR_MIXINTYPES.equals(name)
                        && !bundle.getMixinTypeNames().isEmpty());
        } else {
            return false;
        }
    }
View Full Code Here

            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, mixinTypes and uuid properties
                if (id.getName().equals(JCR_PRIMARYTYPE)
                    || id.getName().equals(JCR_MIXINTYPES)
                    || 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 pr mixinTypes properties
                if (id.getName().equals(JCR_PRIMARYTYPE)
                    || id.getName().equals(JCR_MIXINTYPES)
                    || 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()) {
View Full Code Here

     * @return the bundle or <code>null</code> if the bundle does not exist
     *
     * @throws ItemStateException if an error occurs.
     */
    private NodePropBundle getBundle(NodeId id) throws ItemStateException {
        NodePropBundle bundle = bundles.get(id);
        readCounter.incrementAndGet();
        if (bundle == MISSING) {
            return null;
        }
        if (bundle != null) {
View Full Code Here

     */
    private NodePropBundle getBundleCacheMiss(NodeId id)
            throws ItemStateException {
        long time = System.nanoTime();
        log.debug("Loading bundle {}", id);
        NodePropBundle bundle = loadBundle(id);
        cacheMissDuration.addAndGet(System.nanoTime() - time);
        cacheMissCounter.incrementAndGet();
        if (bundle != null) {
            bundle.markOld();
            bundles.put(id, bundle, bundle.getSize());
        } else {
            bundles.put(id, MISSING, MISSING_SIZE_ESTIMATE);
        }
        return bundle;
    }
View Full Code Here


    // 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, ClusterException {
        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, null, master.createUpdateChannel("default"));

        // set up cluster event update listener
        final TestUpdateEventListener listener = new TestUpdateEventListener();
        final UpdateEventChannel slaveEventChannel = slave.createUpdateChannel("default");
        slaveEventChannel.setListener(listener);

        checker.check(null, false);

        Set<ReportItem> reportItems = checker.getReport().getItems();
        assertEquals(1, reportItems.size());
        ReportItem reportItem = reportItems.iterator().next();
        assertEquals(ReportItem.Type.ABANDONED, reportItem.getType());
        assertEquals(bundle2.getId().toString(), reportItem.getNodeId());

        checker.repair();

        // 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());

        slave.sync();

        // verify events were correctly broadcast to cluster
        assertNotNull("Cluster node did not receive update event", listener.changes);
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.