aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2019-03-11 09:34:51 +0100
committerMartin Polden <mpolden@mpolden.no>2019-03-11 09:42:31 +0100
commitc6f9d0931d5dccf636927085e9ec0a35b40a75cd (patch)
treefa4106209af91b53becc68c54c8f99d218422b1a
parent2b7cd4abc2e41da915901445a2c2adaec4cadf14 (diff)
Prevent log from growing unbounded within expiry
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLog.java8
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLogger.java4
2 files changed, 10 insertions, 2 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLog.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLog.java
index 3190ce7d332..c467a4a0acd 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLog.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLog.java
@@ -44,7 +44,13 @@ public class AuditLog {
return new AuditLog(entries);
}
- /** Returns all entries in this. Entries are sorted descending by their timestamp */
+ /** Returns the first n entries in this. Since entries are sorted descendingly, this will be the n newest entries */
+ public AuditLog first(int n) {
+ if (entries.size() < n) return this;
+ return new AuditLog(entries.subList(0, n));
+ }
+
+ /** Returns all entries in this. Entries are sorted descendingly by their timestamp */
public List<Entry> entries() {
return entries;
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLogger.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLogger.java
index fcf33a92f79..7d8bbb17361 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLogger.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLogger.java
@@ -25,6 +25,7 @@ public class AuditLogger {
/** The TTL of log entries. Entries older than this will be removed when the log is updated */
private static final Duration entryTtl = Duration.ofDays(14);
+ private static final int maxEntries = 2000;
private final CuratorDb db;
private final Clock clock;
@@ -71,7 +72,8 @@ public class AuditLogger {
try (Lock lock = db.lockAuditLog()) {
AuditLog auditLog = db.readAuditLog()
.pruneBefore(now.minus(entryTtl))
- .with(entry);
+ .with(entry)
+ .first(maxEntries);
db.writeAuditLog(auditLog);
}