feat: persistent volumes with TTL for container/worktree storage (archie-core-j7v)
Add [containers].volume_ttl (default 72h). Persistent-storage repos get a per-repo bare Git cache (--reference-if-able --dissociate) so task worktrees clone fast without repeated full network clones, while staying fully independent of the cache's lifecycle — cache expiry can never corrupt an active or parked task's worktree. Docker repo volumes are labeled as Archie-owned and swept non-forced (a volume still attached to a running container survives and retries next cycle); the repo cache directory is swept by mtime. Both cleanups run at daemon startup and each poll cycle. Filed archie-core-756 (repo-wide golangci-lint baseline) and archie-core-340 (intermittent JetStream TempDir teardown flake) as separate follow-ups rather than scope-creeping them into this change.
This commit is contained in:
1 parent
827c108401
commit
e4368f70af
15 files changed
+562
-29
No files matched your search
@@ -76,6 +76,7 @@ func (d *Daemon) emit(e events.Event) {
|
||||
|
||||
// Startup runs crash recovery and access verification once.
|
||||
func (d *Daemon) Startup(ctx context.Context) error {
|
||||
d.cleanupExpiredStorage(ctx)
|
||||
n, err := d.Store.RecoverStale(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -112,6 +113,7 @@ func (d *Daemon) Run(ctx context.Context) error {
|
||||
// reconcile open PRs, act on human replies to waiting tasks, then
|
||||
// process queued tasks concurrently up to containers.max_concurrency.
|
||||
func (d *Daemon) Cycle(ctx context.Context) {
|
||||
d.cleanupExpiredStorage(ctx)
|
||||
d.poll(ctx)
|
||||
d.reconcilePRs(ctx)
|
||||
d.checkWaiting(ctx)
|
||||
@@ -122,6 +124,31 @@ func (d *Daemon) Cycle(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Daemon) cleanupExpiredStorage(ctx context.Context) {
|
||||
ttl := d.Cfg.Containers.VolumeTTL.Std()
|
||||
if ttl <= 0 {
|
||||
return
|
||||
}
|
||||
if d.Storage != nil {
|
||||
n, err := d.Storage.CleanupExpired(ctx, ttl)
|
||||
if err != nil {
|
||||
d.Log.Warn("persistent volume cleanup failed", "err", err)
|
||||
}
|
||||
if n > 0 {
|
||||
d.Log.Info("expired persistent volumes removed", "count", n)
|
||||
}
|
||||
}
|
||||
if d.Trees != nil {
|
||||
n, err := d.Trees.CleanupExpiredCaches(ttl)
|
||||
if err != nil {
|
||||
d.Log.Warn("repo cache cleanup failed", "err", err)
|
||||
}
|
||||
if n > 0 {
|
||||
d.Log.Info("expired repo caches removed", "count", n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// drainSQLite claims queued tasks from SQLite and dispatches them concurrently.
|
||||
func (d *Daemon) drainSQLite(ctx context.Context) {
|
||||
dispatcher := newTaskDispatcher(d.Cfg.Containers.MaxConcurrency, d.allowConcurrentFor)
|
||||
@@ -634,7 +661,16 @@ func (d *Daemon) process(ctx context.Context, task *store.Task) {
|
||||
// Clone the worktree before Docker mount setup. The container
|
||||
// binds /data/worktree to workDir on the host — the directory
|
||||
// must exist before Acquire is called.
|
||||
_, branch, err := d.Trees.Prepare(ctx, task.Owner, task.Repo, repo.Base, task.IssueNumber, task.Title, task.Body, task.Labels)
|
||||
var branch string
|
||||
var err error
|
||||
if repo.PersistentStorage && d.Cfg.Containers.VolumeTTL.Std() > 0 {
|
||||
_, branch, err = d.Trees.PreparePersistent(
|
||||
ctx, task.Owner, task.Repo, repo.Base, task.IssueNumber,
|
||||
task.Title, task.Body, task.Labels, d.Cfg.Containers.VolumeTTL.Std(),
|
||||
)
|
||||
} else {
|
||||
_, branch, err = d.Trees.Prepare(ctx, task.Owner, task.Repo, repo.Base, task.IssueNumber, task.Title, task.Body, task.Labels)
|
||||
}
|
||||
if err != nil {
|
||||
d.Log.Error("worktree prepare failed", "err", err)
|
||||
_ = d.Store.Transition(ctx, task.ID, store.StatusRunning, store.StatusParked, "worktree prepare failed: "+err.Error())
|
||||
|
||||
@@ -18,10 +18,45 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/forge"
|
||||
arnats "github.com/samcharles93/archie-core/internal/nats"
|
||||
"github.com/samcharles93/archie-core/internal/storage"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
"github.com/samcharles93/archie-core/internal/taskrun"
|
||||
)
|
||||
|
||||
type cleanupStorage struct {
|
||||
ttl time.Duration
|
||||
}
|
||||
|
||||
func (s *cleanupStorage) Setup(context.Context, storage.TaskRef) ([]storage.Mount, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *cleanupStorage) Teardown(context.Context, storage.TaskRef) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *cleanupStorage) CleanupExpired(_ context.Context, ttl time.Duration) (int, error) {
|
||||
s.ttl = ttl
|
||||
return 2, nil
|
||||
}
|
||||
|
||||
func TestCleanupExpiredStorageUsesConfiguredTTL(t *testing.T) {
|
||||
backend := &cleanupStorage{}
|
||||
d := &Daemon{
|
||||
Cfg: config.Config{
|
||||
Containers: config.ContainerConfig{VolumeTTL: config.Duration(6 * time.Hour)},
|
||||
},
|
||||
Storage: backend,
|
||||
Log: slog.New(slog.DiscardHandler),
|
||||
}
|
||||
|
||||
d.cleanupExpiredStorage(context.Background())
|
||||
|
||||
if backend.ttl != 6*time.Hour {
|
||||
t.Fatalf("CleanupExpired ttl = %s, want 6h", backend.ttl)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskDispatcherEnforcesMaxConcurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in new issue
Block a user