Search in sources :

Example 1 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit-oak by apache.

the class BundleLoader method loadBundle.

NodePropBundle loadBundle(NodeId id) throws ItemStateException {
    if (loadBundle != null) {
        try {
            return checkNotNull((NodePropBundle) loadBundle.invoke(pm, id), "Could not load NodePropBundle for id [%s]", id);
        } catch (InvocationTargetException e) {
            if (e.getCause() instanceof ItemStateException) {
                throw (ItemStateException) e.getCause();
            }
        // fall through
        } catch (IllegalArgumentException e) {
        // fall through
        } catch (IllegalAccessException e) {
        // fall through
        }
    }
    NodeState state = pm.load(id);
    checkNotNull(state, "Could not load NodeState for id [%s]", id);
    NodePropBundle bundle = new NodePropBundle(state);
    for (Name name : state.getPropertyNames()) {
        if (NameConstants.JCR_UUID.equals(name)) {
            bundle.setReferenceable(true);
        } else if (!NameConstants.JCR_PRIMARYTYPE.equals(name) && !NameConstants.JCR_MIXINTYPES.equals(name)) {
            bundle.addProperty(new PropertyEntry(pm.load(new PropertyId(id, name))));
        }
    }
    return bundle;
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) InvocationTargetException(java.lang.reflect.InvocationTargetException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 2 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle 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 3 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class BundleDbPersistenceManager method getAllNodeInfos.

/**
 * {@inheritDoc}
 */
@Override
public synchronized Map<NodeId, NodeInfo> getAllNodeInfos(NodeId bigger, int maxCount) throws ItemStateException {
    ResultSet rs = null;
    try {
        String sql = bundleSelectAllBundlesSQL;
        NodeId lowId = null;
        Object[] keys = new Object[0];
        if (bigger != null) {
            sql = bundleSelectAllBundlesFromSQL;
            lowId = bigger;
            keys = getKey(bigger);
        }
        if (getStorageModel() == SM_LONGLONG_KEYS && maxCount > 0) {
            // get some more rows, in case the first row is smaller
            // only required for SM_LONGLONG_KEYS
            // probability is very low to get get the wrong first key, < 1 : 2^64
            // see also bundleSelectAllIdsFrom SQL statement
            maxCount += 10;
        }
        rs = conHelper.exec(sql, keys, false, maxCount);
        Map<NodeId, NodeInfo> result = new LinkedHashMap<NodeId, NodeInfo>(maxCount);
        while ((maxCount == 0 || result.size() < maxCount) && rs.next()) {
            NodeId current;
            if (getStorageModel() == SM_BINARY_KEYS) {
                current = new NodeId(rs.getBytes(1));
            } else {
                long high = rs.getLong(1);
                long low = rs.getLong(2);
                current = new NodeId(high, low);
            }
            if (getStorageModel() == SM_LONGLONG_KEYS && lowId != null) {
                // 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) {
        String msg = "getAllNodeIds failed.";
        log.error(msg, e);
        throw new ItemStateException(msg, e);
    } finally {
        DbUtility.close(rs);
    }
}
Also used : SQLException(java.sql.SQLException) NodeInfo(org.apache.jackrabbit.core.persistence.util.NodeInfo) ResultSet(java.sql.ResultSet) NodeId(org.apache.jackrabbit.core.id.NodeId) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) LinkedHashMap(java.util.LinkedHashMap) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 4 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class AbstractBundlePersistenceManager method getBundleCacheMiss.

/**
 * Called when the bundle is not present in the cache, so we'll need to load
 * it from the PM impl.
 *
 * This also updates the cache.
 *
 * @param id
 * @return
 * @throws ItemStateException
 */
private NodePropBundle getBundleCacheMiss(NodeId id) throws ItemStateException {
    long time = System.nanoTime();
    NodePropBundle bundle = loadBundle(id);
    time = System.nanoTime() - time;
    cacheMissDuration.addAndGet(time);
    final long timeMs = time / 1000000;
    log.debug("Loaded bundle {} in {}ms", id, timeMs);
    cacheMissCounter.incrementAndGet();
    if (bundle != null) {
        bundle.markOld();
        bundles.put(id, bundle, bundle.getSize());
    } else {
        bundles.put(id, MISSING, MISSING_SIZE_ESTIMATE);
    }
    return bundle;
}
Also used : NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle)

Example 5 with NodePropBundle

use of org.apache.jackrabbit.core.persistence.util.NodePropBundle in project jackrabbit by apache.

the class AbstractBundlePersistenceManager method getBundle.

/**
 * Gets the bundle for the given node id. Read/write synchronization
 * happens higher up at the SISM level, so we don't need to worry about
 * conflicts here.
 *
 * @param id the id of the bundle to retrieve.
 * @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) {
        return bundle;
    }
    // cache miss
    return getBundleCacheMiss(id);
}
Also used : NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle)

Aggregations

NodePropBundle (org.apache.jackrabbit.core.persistence.util.NodePropBundle)19 NodeId (org.apache.jackrabbit.core.id.NodeId)14 ConsistencyCheckerImpl (org.apache.jackrabbit.core.persistence.bundle.ConsistencyCheckerImpl)9 ReportItem (org.apache.jackrabbit.core.persistence.check.ReportItem)8 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)5 UpdateEventChannel (org.apache.jackrabbit.core.cluster.UpdateEventChannel)4 RepositoryException (javax.jcr.RepositoryException)3 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ClusterException (org.apache.jackrabbit.core.cluster.ClusterException)2 PropertyId (org.apache.jackrabbit.core.id.PropertyId)2 NodeInfo (org.apache.jackrabbit.core.persistence.util.NodeInfo)2 PropertyEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry)2 Name (org.apache.jackrabbit.spi.Name)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1