-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db): batch cleanup expired rows from postgres (#10407)
* feat(db): batch cleanup expired rows from postgres ### Summary The PR #10405 changed cleanup to only happen on nodes that have Admin API listeners. This PR makes deletion to happen in maximum of 50.000 row batches. Inspired from #10331 and #10389. * change to batch delete on every table * update changelog * add test for ttl cleanup --------- Co-authored-by: windmgc <windmgc@gmail.com>
- Loading branch information
Showing
3 changed files
with
92 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
local helpers = require "spec.helpers" | ||
|
||
for _, strategy in helpers.each_strategy() do | ||
local postgres_only = strategy == "postgres" and describe or pending | ||
postgres_only("postgres ttl cleanup logic", function() | ||
describe("ttl cleanup timer #postgres", function() | ||
local bp, db, consumer1 | ||
lazy_setup(function() | ||
bp, db = helpers.get_db_utils("postgres", { | ||
"routes", | ||
"services", | ||
"plugins", | ||
"consumers", | ||
"keyauth_credentials" | ||
}) | ||
|
||
consumer1 = bp.consumers:insert { | ||
username = "conumer1" | ||
} | ||
|
||
assert(helpers.start_kong({ | ||
database = strategy, | ||
})) | ||
end) | ||
|
||
lazy_teardown(function() | ||
helpers.stop_kong() | ||
db:truncate() | ||
end) | ||
|
||
it("init_worker should run ttl cleanup in background timer", function () | ||
helpers.clean_logfile() | ||
local names_of_table_with_ttl = db.connector._get_topologically_sorted_table_names(db.strategies) | ||
assert.truthy(#names_of_table_with_ttl > 0) | ||
for _, name in ipairs(names_of_table_with_ttl) do | ||
assert.errlog().has.line([[cleaning up expired rows from table ']] .. name .. [[' took \d+\.\d+ seconds]], false, 120) | ||
end | ||
|
||
local _ = bp.keyauth_credentials:insert({ | ||
key = "secret1", | ||
consumer = { id = consumer1.id }, | ||
}, {ttl = 3}) | ||
helpers.clean_logfile() | ||
|
||
helpers.wait_until(function() | ||
return assert.errlog().has.line([[cleaning up expired rows from table ']] .. "keyauth_credentials" .. [[' took \d+\.\d+ seconds]], false, 120) | ||
end, 120) | ||
|
||
local ok, err = db.connector:query("SELECT * FROM keyauth_credentials") | ||
assert.is_nil(err) | ||
assert.same(0, #ok) | ||
end) | ||
end) | ||
end) | ||
end |
fa90a68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bazel Build
Docker image available
kong/kong:fa90a685b5a7ac03774460a92f856293184d704d
Artifacts available https://github.com/Kong/kong/actions/runs/4322374032