use of com.metabroadcast.common.queue.MessagingException in project atlas-deer by atlasapi.
the class AbstractEquivalentContentStore method updateEquivalences.
@Override
public final void updateEquivalences(EquivalenceGraphUpdate update) throws WriteException {
metricRegistry.meter(updateEquivalences + METER_CALLED).mark();
Set<Id> ids = idsOf(update);
ImmutableSet<Id> staleContentIds = ImmutableSet.of();
try {
lock.lock(ids);
ImmutableSetMultimap.Builder<EquivalenceGraph, Content> graphsAndContentBuilder = ImmutableSetMultimap.builder();
Function<Id, Optional<Content>> toContent = Functions.forMap(resolveIds(ids));
for (EquivalenceGraph graph : update.getAllGraphs()) {
Iterable<Optional<Content>> content = Collections2.transform(graph.getEquivalenceSet(), toContent);
graphsAndContentBuilder.putAll(graph, Optional.presentInstances(content));
}
ImmutableSetMultimap<EquivalenceGraph, Content> graphsAndContent = graphsAndContentBuilder.build();
// This has to run before we process the update so we can still resolve the set(s)
// that are going to be deleted
staleContentIds = getStaleContent(update.getDeleted(), graphsAndContent);
update(graphsAndContent, update);
sendEquivalentContentGraphChangedMessage(update);
} catch (MessagingException | InterruptedException e) {
metricRegistry.meter(updateEquivalences + METER_FAILURE).mark();
throw new WriteException("Updating " + ids, e);
} finally {
lock.unlock(ids);
}
// We are updating stale content after we have already released our held IDs because
// the ID(s) of the deleted graph(s) on which we hold a lock could be among the stale
// content IDs and the lock is not reentrant
updateStaleContent(staleContentIds);
}
Aggregations