Skip to content

Commit

Permalink
Add retry limit to datasets update labels - Fixes #342
Browse files Browse the repository at this point in the history
  • Loading branch information
johnaohara committed May 24, 2023
1 parent 5af37e3 commit d9bb171
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -169,6 +170,9 @@ RelativeDifferenceChangeDetectionModel.NAME, new RelativeDifferenceChangeDetecti
@ConfigProperty(name = "horreum.internal.url")
String internalUrl;

@ConfigProperty(name = "horreum.alerting.updateLabel.retries", defaultValue = "5")
Integer labelCalcRetries;

@Inject
TransactionManager tm;

Expand All @@ -181,6 +185,7 @@ RelativeDifferenceChangeDetectionModel.NAME, new RelativeDifferenceChangeDetecti
@Inject
TimeService timeService;

static ConcurrentHashMap<Integer, AtomicInteger> retryCounterSet = new ConcurrentHashMap<>();

// entries can be removed from timer thread while normally this is updated from one of blocking threads
private final ConcurrentMap<Integer, Recalculation> recalcProgress = new ConcurrentHashMap<>();
Expand All @@ -201,13 +206,23 @@ public void onLabelsUpdated(DataSetDAO.LabelsUpdatedEvent event) {
DataSetDAO dataset = DataSetDAO.findById(event.datasetId);
if (dataset == null) {
// The run is not committed yet?
vertx.setTimer(1000, timerId -> messageBus.executeForTest(event.datasetId,
() -> Util.withTx(tm, () -> {
onLabelsUpdated(event);
return null;
})
));
return;
// Retry `horreum.alerting.updateLabel.retries` times before logging a warning
retryCounterSet.putIfAbsent(event.datasetId, new AtomicInteger(0));
int retryCounter = retryCounterSet.get(event.datasetId).getAndIncrement();
if ( retryCounter < labelCalcRetries ) {
log.infof("Retrying labels update for dataset %d, attempt %d/%d", event.datasetId, retryCounter, this.labelCalcRetries);
vertx.setTimer(1000, timerId -> messageBus.executeForTest(event.datasetId, () -> Util.withTx(tm, () -> {
onLabelsUpdated(event);
return null;
})
));
return;
} else {
//we have retried `horreum.alerting.updateLabel.retries` number of times, log a warning and stop retrying
log.warnf("Unsuccessfully retried updating labels %d times for dataset %d. Stopping", this.labelCalcRetries, event.datasetId);
retryCounterSet.remove(event.datasetId);
return;
}
}
if (event.isRecalculation) {
sendNotifications = false;
Expand Down

0 comments on commit d9bb171

Please sign in to comment.