// updatedTriplesCache will be null when recovering from a crashed commit
boolean validCache = updatedTriplesCache != null && updatedTriplesCache.isValid();
for (TripleIndex index : indexes) {
BTree btree = index.getBTree();
RecordIterator iter;
if (validCache) {
// Use the cached set of updated triples
iter = updatedTriplesCache.getRecords();
}
else {
// Cache is invalid; too much updates(?). Iterate over all triples
iter = btree.iterateAll();
}
try {
byte[] data;
while ((data = iter.next()) != null) {
byte flags = data[FLAG_IDX];
boolean wasAdded = (flags & ADDED_FLAG) != 0;
boolean wasRemoved = (flags & REMOVED_FLAG) != 0;
boolean wasToggled = (flags & TOGGLE_EXPLICIT_FLAG) != 0;
if (wasRemoved) {
btree.remove(data);
}
else if (wasAdded || wasToggled) {
if (wasToggled) {
data[FLAG_IDX] ^= EXPLICIT_FLAG;
}
if (wasAdded) {
data[FLAG_IDX] ^= ADDED_FLAG;
}
if (validCache) {
// We're iterating the cache
btree.insert(data);
}
else {
// We're iterating the BTree itself
iter.set(data);
}