From a74621af996e542e3d54c629aec818b8246c9d45 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 18 Jun 2024 14:02:32 -0400 Subject: [PATCH] 21703: Delete unused entries in uuid_locks during trash sweep. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- services/api/app/controllers/sys_controller.rb | 3 +++ services/api/test/functional/sys_controller_test.rb | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/services/api/app/controllers/sys_controller.rb b/services/api/app/controllers/sys_controller.rb index bfffa908da..d1222da323 100644 --- a/services/api/app/controllers/sys_controller.rb +++ b/services/api/app/controllers/sys_controller.rb @@ -39,6 +39,9 @@ class SysController < ApplicationController # Sweep expired tokens ActiveRecord::Base.connection.execute("DELETE from api_client_authorizations where expires_at <= statement_timestamp()") + + # Sweep unused uuid_locks entries + ActiveRecord::Base.connection.execute("DELETE FROM uuid_locks WHERE uuid IN (SELECT uuid FROM uuid_locks FOR UPDATE SKIP LOCKED)") end head :no_content end diff --git a/services/api/test/functional/sys_controller_test.rb b/services/api/test/functional/sys_controller_test.rb index 2f02d58e3f..4446925e83 100644 --- a/services/api/test/functional/sys_controller_test.rb +++ b/services/api/test/functional/sys_controller_test.rb @@ -141,4 +141,10 @@ class SysControllerTest < ActionController::TestCase assert_equal cr_nr_was-1, ContainerRequest.all.length end + test "trash_sweep - delete unused uuid_locks" do + uuid = "zzzzz-zzzzz-deleteuuidlocks" + ActiveRecord::Base.connection.exec_query("INSERT INTO uuid_locks (uuid) VALUES ($1)", "", [uuid]) + post :trash_sweep + assert_equal [[uuid]], ActiveRecord::Base.connection.exec_query("SELECT uuid FROM uuid_locks", "", []).rows + end end -- 2.30.2