feat: add node stale/delete config

closes: #93
This commit is contained in:
Enot (ded) Skelly
2026-07-24 13:09:51 -07:00
parent 3f2506fc8b
commit 99d7eb0bab
17 changed files with 332 additions and 22 deletions
+14
View File
@@ -57,6 +57,20 @@ func (mr *MockQuerierMockRecorder) DeleteOldChannelIATAs(ctx, lastHeard any) *go
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOldChannelIATAs", reflect.TypeOf((*MockQuerier)(nil).DeleteOldChannelIATAs), ctx, lastHeard)
}
// DeleteOldNodes mocks base method.
func (m *MockQuerier) DeleteOldNodes(ctx context.Context, lastSeen pgtype.Timestamptz) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DeleteOldNodes", ctx, lastSeen)
ret0, _ := ret[0].(error)
return ret0
}
// DeleteOldNodes indicates an expected call of DeleteOldNodes.
func (mr *MockQuerierMockRecorder) DeleteOldNodes(ctx, lastSeen any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOldNodes", reflect.TypeOf((*MockQuerier)(nil).DeleteOldNodes), ctx, lastSeen)
}
// DeleteOldPackets mocks base method.
func (m *MockQuerier) DeleteOldPackets(ctx context.Context, lastHeardAt pgtype.Timestamptz) error {
m.ctrl.T.Helper()
+8
View File
@@ -14,6 +14,14 @@ import (
type Querier interface {
// Keeps the channel IATA filter in step with packet retention.
DeleteOldChannelIATAs(ctx context.Context, lastHeard pgtype.Timestamptz) error
// Deletes nodes not seen since the given cutoff. node_iatas and node_neighbors cascade-
// delete via FK. Excludes nodes referenced by observer_owners.owner_node_id -- that FK has
// no ON DELETE action, so deleting one directly would fail the whole statement anyway, and
// an operator manually recorded ownership for that node, so leave it alone even if stale.
// known_routes.node_ids is a plain UUID[] with no FK; a deleted node's id can be left
// dangling in old routes there, but ReconfirmTask already prunes stale/ambiguous routes
// periodically and will clean those up on its own schedule.
DeleteOldNodes(ctx context.Context, lastSeen pgtype.Timestamptz) error
// Deletes packets and their observations older than the given cutoff.
// packet_observations cascade-delete via FK.
DeleteOldPackets(ctx context.Context, lastHeardAt pgtype.Timestamptz) error
+18
View File
@@ -22,6 +22,24 @@ func (q *Queries) DeleteOldChannelIATAs(ctx context.Context, lastHeard pgtype.Ti
return err
}
const deleteOldNodes = `-- name: DeleteOldNodes :exec
DELETE FROM nodes
WHERE last_seen < $1
AND id NOT IN (SELECT owner_node_id FROM observer_owners WHERE owner_node_id IS NOT NULL)
`
// Deletes nodes not seen since the given cutoff. node_iatas and node_neighbors cascade-
// delete via FK. Excludes nodes referenced by observer_owners.owner_node_id -- that FK has
// no ON DELETE action, so deleting one directly would fail the whole statement anyway, and
// an operator manually recorded ownership for that node, so leave it alone even if stale.
// known_routes.node_ids is a plain UUID[] with no FK; a deleted node's id can be left
// dangling in old routes there, but ReconfirmTask already prunes stale/ambiguous routes
// periodically and will clean those up on its own schedule.
func (q *Queries) DeleteOldNodes(ctx context.Context, lastSeen pgtype.Timestamptz) error {
_, err := q.db.Exec(ctx, deleteOldNodes, lastSeen)
return err
}
const deleteOldPackets = `-- name: DeleteOldPackets :exec
DELETE FROM packets WHERE last_heard_at < $1
`