// 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 uuidList = new ArrayList(uuids.length);
// convert uuid string array to list of UUID objects
for (int i = 0; i < uuids.length; i++) {
try {
uuidList.add(new UUID(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 < uuidList.size(); i++) {
final UUID uuid = (UUID) uuidList.get(i);
try {
// load the node from the database
NodeId id = new NodeId(uuid);
NodePropBundle bundle = loadBundle(id, true);
if (bundle == null) {
log.error("No bundle found for uuid '" + uuid + "'");
continue;
}
checkBundleConsistency(id, bundle, fix, modifications);
if (recursive) {
Iterator iter = bundle.getChildNodeEntries().iterator();
while (iter.hasNext()) {
NodePropBundle.ChildNodeEntry entry = (NodePropBundle.ChildNodeEntry) iter.next();
uuidList.add(entry.getId().getUUID());
}
}
count++;
if (count % 1000 == 0) {
log.info(name + ": checked " + count + "/" + uuidList.size() + " bundles...");
}
} catch (ItemStateException e) {
// problem already logged (loadBundle called with logDetailedErrors=true)
}
}
total = uuidList.size();
}
// repair collected broken bundles
if (fix && !modifications.isEmpty()) {
log.info(name + ": Fixing " + modifications.size() + " inconsistent bundle(s)...");
Iterator iterator = modifications.iterator();
while (iterator.hasNext()) {
NodePropBundle bundle = (NodePropBundle) iterator.next();
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);
}
}
}