Search in sources :

Example 1 with InconsistentVersioningState

use of org.apache.jackrabbit.core.version.InconsistentVersioningState in project jackrabbit by apache.

the class RepositoryChecker method checkVersionHistory.

private void checkVersionHistory(NodeState node) {
    String message = null;
    NodeId nid = node.getNodeId();
    boolean isVersioned = node.hasPropertyName(JCR_VERSIONHISTORY);
    NodeId vhid = null;
    try {
        String type = isVersioned ? "in-use" : "candidate";
        log.debug("Checking " + type + " version history of node {}", nid);
        String intro = "Removing references to an inconsistent " + type + " version history of node " + nid;
        message = intro + " (getting the VersionInfo)";
        VersionHistoryInfo vhi = versionManager.getVersionHistoryInfoForNode(node);
        if (vhi != null) {
            // get the version history's node ID as early as possible
            // so we can attempt a fixup even when the next call fails
            vhid = vhi.getVersionHistoryId();
        }
        message = intro + " (getting the InternalVersionHistory)";
        InternalVersionHistory vh = null;
        try {
            vh = versionManager.getVersionHistoryOfNode(nid);
        } catch (ItemNotFoundException ex) {
            // it's ok if we get here if the node didn't claim to be versioned
            if (isVersioned) {
                throw ex;
            }
        }
        if (vh == null) {
            if (isVersioned) {
                message = intro + "getVersionHistoryOfNode returned null";
                throw new InconsistentVersioningState(message);
            }
        } else {
            vhid = vh.getId();
            // additional checks, see JCR-3101
            message = intro + " (getting the version names failed)";
            Name[] versionNames = vh.getVersionNames();
            boolean seenRoot = false;
            for (Name versionName : versionNames) {
                seenRoot |= JCR_ROOTVERSION.equals(versionName);
                log.debug("Checking version history of node {}, version {}", nid, versionName);
                message = intro + " (getting version " + versionName + "  failed)";
                InternalVersion v = vh.getVersion(versionName);
                message = intro + "(frozen node of root version " + v.getId() + " missing)";
                if (null == v.getFrozenNode()) {
                    throw new InconsistentVersioningState(message);
                }
            }
            if (!seenRoot) {
                message = intro + " (root version is missing)";
                throw new InconsistentVersioningState(message);
            }
        }
    } catch (InconsistentVersioningState e) {
        log.info(message, e);
        NodeId nvhid = e.getVersionHistoryNodeId();
        if (nvhid != null) {
            if (vhid != null && !nvhid.equals(vhid)) {
                log.error("vhrid returned with InconsistentVersioningState does not match the id we already had: " + vhid + " vs " + nvhid);
            }
            vhid = nvhid;
        }
        removeVersionHistoryReferences(node, vhid);
    } catch (Exception e) {
        log.info(message, e);
        removeVersionHistoryReferences(node, vhid);
    }
}
Also used : VersionHistoryInfo(org.apache.jackrabbit.core.version.VersionHistoryInfo) InconsistentVersioningState(org.apache.jackrabbit.core.version.InconsistentVersioningState) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalVersionHistory(org.apache.jackrabbit.core.version.InternalVersionHistory) RepositoryException(javax.jcr.RepositoryException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ItemNotFoundException(javax.jcr.ItemNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException) Name(org.apache.jackrabbit.spi.Name) InternalVersion(org.apache.jackrabbit.core.version.InternalVersion)

Aggregations

ItemNotFoundException (javax.jcr.ItemNotFoundException)1 RepositoryException (javax.jcr.RepositoryException)1 NodeId (org.apache.jackrabbit.core.id.NodeId)1 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)1 InconsistentVersioningState (org.apache.jackrabbit.core.version.InconsistentVersioningState)1 InternalVersion (org.apache.jackrabbit.core.version.InternalVersion)1 InternalVersionHistory (org.apache.jackrabbit.core.version.InternalVersionHistory)1 VersionHistoryInfo (org.apache.jackrabbit.core.version.VersionHistoryInfo)1 Name (org.apache.jackrabbit.spi.Name)1