From 4f6ab6074067e4ca62cdff3df4fb221e7d63505e Mon Sep 17 00:00:00 2001 From: Michael Pollmeier Date: Mon, 11 Nov 2024 14:48:39 +0100 Subject: [PATCH] db: janitor should cleanup builds _older than_ given timestamp Previously janitor would delete all build_data for builds _newer than_ the configured build_data_horizon. Credit goes to @luisbarrueco for finding this. The unit tests only covered the sqlite implementation which is correct, this bug only existed for postgres queries. --- master/buildbot/db/build_data.py | 5 ++--- newsfragments/janitor-timehorizon.bugfix | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 newsfragments/janitor-timehorizon.bugfix diff --git a/master/buildbot/db/build_data.py b/master/buildbot/db/build_data.py index 5ac33a50d9eb..70687a1688a8 100644 --- a/master/buildbot/db/build_data.py +++ b/master/buildbot/db/build_data.py @@ -167,14 +167,13 @@ def thd(conn) -> int: q = q.where( (builds.c.complete_at >= older_than_timestamp) | (builds.c.complete_at == NULL) ) + # n.b.: in sqlite we need to filter on `>= older_than_timestamp` because of the following `NOT IN` clause... q = build_data.delete().where(build_data.c.buildid.notin_(q)) else: q = build_data.delete() q = q.where(builds.c.id == build_data.c.buildid) - q = q.where( - (builds.c.complete_at >= older_than_timestamp) | (builds.c.complete_at == NULL) - ) + q = q.where(builds.c.complete_at <= older_than_timestamp) res = conn.execute(q) conn.commit() res.close() diff --git a/newsfragments/janitor-timehorizon.bugfix b/newsfragments/janitor-timehorizon.bugfix new file mode 100644 index 000000000000..b3e7f21d31d2 --- /dev/null +++ b/newsfragments/janitor-timehorizon.bugfix @@ -0,0 +1 @@ +Fixes the timestamp comparison in janitor: it should cleanup builds 'older than' given timestamp - previously janitor would delete all build_data for builds 'newer than' the configured build data horizon. \ No newline at end of file