Compare commits

...

2 Commits

Author SHA1 Message Date
Owen Smallwood
3d182d36e7 Merge branch 'main' into unified-storage-sql-garbage-collection 2026-01-12 11:20:00 -06:00
Owen Smallwood
5beeec8560 WIP - adding garbage collection to sql backend 2026-01-12 11:19:55 -06:00
3 changed files with 36 additions and 0 deletions

View File

@@ -242,6 +242,23 @@ func (b *backend) initPruner(ctx context.Context) error {
return nil
}
func (b *backend) initGarbageCollection(ctx context.Context) error {
// TODO
/*
# Garbage collect every minute?
gr = getGroupResources()
for each gr in grs:
rows = garbageCollect(gr)
log rows deleted
sleep 1s
*/
return nil
}
func (b *backend) IsHealthy(ctx context.Context, _ *resourcepb.HealthCheckRequest) (*resourcepb.HealthCheckResponse, error) {
// ctxLogger := s.log.FromContext(log.WithContextualAttributes(ctx, []any{"method", "isHealthy"}))

View File

@@ -0,0 +1,13 @@
DELETE FROM {{ .Ident "resource_history" }} h
WHERE h.{{ .Ident "group" }} = {{ .Arg .Group }}
AND h.{{ .Ident "resource" }} = {{ .Arg .Resource }}
AND h.{{ .Ident "action" }} = 3
AND h.{{ .Ident "resource_version" }} < {{ .Arg .CutoffTimestamp }}
AND NOT EXISTS (
SELECT 1 FROM {{ .Ident "resource" }} r
WHERE r.{{ .Ident "namespace" }} = h.{{ .Ident "namespace" }}
AND r.{{ .Ident "group" }} = h.{{ .Ident "group" }}
AND r.{{ .Ident "resource" }} = h.{{ .Ident "resource" }}
AND r.{{ .Ident "name" }} = h.{{ .Ident "name" }}
)
LIMIT {{ .Arg .BatchSize }};

View File

@@ -220,5 +220,11 @@ func initResourceTables(mg *migrator.Migrator) string {
mg.AddMigration("Change key_path collation of resource_history in postgres", migrator.NewRawSQLMigration("").Postgres(`ALTER TABLE resource_history ALTER COLUMN key_path TYPE VARCHAR(2048) COLLATE "C";`))
mg.AddMigration("Change key_path collation of resource_events in postgres", migrator.NewRawSQLMigration("").Postgres(`ALTER TABLE resource_events ALTER COLUMN key_path TYPE VARCHAR(2048) COLLATE "C";`))
mg.AddMigration("Add index to resource_history for garbage collection", migrator.NewAddIndexMigration(resource_history_table, &migrator.Index{
Cols: []string{"group", "resource", "action", "resource_version", "name"},
Type: migrator.IndexType,
Name: "IDX_resource_history_resource_action_version_name",
}))
return marker
}