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;
}
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);
}
}
}
}
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);
}
}
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;
}
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);
}
Aggregations