agent-substrate / agent-substrate/substrate

Move PostgreSQL expired-lease cleanup off the lock acquisition path

未關閉
#1,040 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
area/api-machinery kind/cleanup
主要語言
Go
星號
1.8k
分支
316
平均合併
2 天 43 分鐘
30 天內合併 PR
287

描述

## Problem

In #1023 `atepg.AcquireLock` currently runs `DELETE FROM leases WHERE expires_at <= clock_timestamp()` before every lease acquisition. The `expires_at` index keeps this bounded, but it still adds an extra database write and round trip to every lock acquisition, including when there are no expired leases.

The acquisition query already reclaims an expired lease for the requested key through `INSERT ... ON CONFLICT ... DO UPDATE ... WHERE leases.expires_at <= clock_timestamp()`, so global cleanup is not required for lock correctness. It only prevents expired rows for inactive keys from accumulating.

## Proposed follow-up

Move global expired-lease cleanup off the acquisition path, for example to a periodic background task with a bounded interval and/or batch size. In a multi-replica deployment, ensure cleanup work is not needlessly duplicated or that concurrent cleaners remain cheap and safe.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。