Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove job run entries older than 60 days #9346

Merged
merged 1 commit into from May 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,11 +26,11 @@
import com.yahoo.vespa.hosted.controller.persistence.CuratorDb;

import java.net.URI;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -64,6 +64,7 @@
public class JobController {

private static final int historyLength = 256;
private static final Duration maxHistoryAge = Duration.ofDays(60);

private final Controller controller;
private final CuratorDb curator;
Expand Down Expand Up @@ -212,10 +213,13 @@ public void finish(RunId id) {
locked(id.application(), id.type(), runs -> {
runs.put(run.id(), finishedRun);
long last = id.number();
Iterator<RunId> ids = runs.keySet().iterator();
for (RunId old = ids.next(); old.number() <= last - historyLength; old = ids.next()) {
logs.delete(old);
ids.remove();
var oldEntries = runs.entrySet().iterator();
for (var old = oldEntries.next();
old.getKey().number() <= last - historyLength
|| old.getValue().start().isBefore(controller.clock().instant().minus(maxHistoryAge));
old = oldEntries.next()) {
logs.delete(old.getKey());
oldEntries.remove();
}
});
logs.flush(id);
Expand Down