Search in sources :

Example 1 with ClusterException

use of org.apache.jackrabbit.core.cluster.ClusterException in project jackrabbit by apache.

the class ConsistencyCheckerImpl method repair.

/**
 * Repair any errors found during a {@link #check}. Should be run after a {#check} and
 * (if needed) {@link #doubleCheckErrors}.
 *
 * @throws RepositoryException
 */
public void repair() throws RepositoryException {
    checkLostNFound();
    bundles = new HashMap<NodeId, NodePropBundle>();
    if (hasRepairableErrors()) {
        boolean successful = false;
        final CheckerUpdate update = new CheckerUpdate();
        try {
            eventChannel.updateCreated(update);
            for (ConsistencyCheckerError error : errors) {
                if (error.isRepairable()) {
                    try {
                        error.repair(update.getChanges());
                        info(null, "Repairing " + error);
                    } catch (ItemStateException e) {
                        error(null, "Failed to repair error: " + error, e);
                    }
                }
            }
            final ChangeLog changes = update.getChanges();
            if (changes.hasUpdates()) {
                eventChannel.updatePrepared(update);
                for (NodePropBundle bundle : bundles.values()) {
                    storeBundle(bundle);
                }
                update.setAttribute(ATTRIBUTE_UPDATE_SIZE, changes.getUpdateSize());
                successful = true;
            }
        } catch (ClusterException e) {
            throw new RepositoryException("Cannot create update", e);
        } finally {
            if (successful) {
                eventChannel.updateCommitted(update, "checker@");
            } else {
                eventChannel.updateCancelled(update);
            }
        }
    }
}
Also used : ClusterException(org.apache.jackrabbit.core.cluster.ClusterException) NodeId(org.apache.jackrabbit.core.id.NodeId) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) RepositoryException(javax.jcr.RepositoryException) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 2 with ClusterException

use of org.apache.jackrabbit.core.cluster.ClusterException in project jackrabbit by apache.

the class ConsistencyCheck method doubleCheckErrors.

public void doubleCheckErrors() {
    if (!errors.isEmpty()) {
        log.info("Double checking errors");
        final ClusterNode clusterNode = handler.getContext().getClusterNode();
        if (clusterNode != null) {
            try {
                clusterNode.sync();
            } catch (ClusterException e) {
                log.error("Could not sync cluster node for double checking errors");
            }
        }
        final Iterator<ConsistencyCheckError> iterator = errors.iterator();
        while (iterator.hasNext()) {
            try {
                final ConsistencyCheckError error = iterator.next();
                if (!error.doubleCheck(handler, stateMgr)) {
                    log.info("False positive: " + error.toString());
                    iterator.remove();
                }
            } catch (RepositoryException e) {
                log.error("Failed to double check consistency error", e);
            } catch (IOException e) {
                log.error("Failed to double check consistency error", e);
            }
        }
    }
}
Also used : ClusterNode(org.apache.jackrabbit.core.cluster.ClusterNode) ClusterException(org.apache.jackrabbit.core.cluster.ClusterException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)2 ClusterException (org.apache.jackrabbit.core.cluster.ClusterException)2 IOException (java.io.IOException)1 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)1 NodeId (org.apache.jackrabbit.core.id.NodeId)1 NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)1 ChangeLog (org.apache.jackrabbit.core.state.ChangeLog)1 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)1