Let prune delete old .partial uploads and remote info count them (closes #466)
check / check (push) Waiting to run
check / check (push) Waiting to run
A killed upload leaves a `.partial` object that only remote nuke removed, and that remote info never showed. The storage interface's DeletePartialUploads becomes ListPartialUploads, which returns each such object's key, size and time; Delete removes it. prune deletes those under metadata/ and blobs/ once older than prune_grace_period, and reports kept, deleted and failed counts. remote info counts them on their own line and in --json. remote nuke lists and deletes them like any other object, and now names any it could not delete. Model: opus-5-5
This commit was merged in pull request #474.
This commit is contained in:
1 parent
aaa2219d6b
commit
be362080d3
24 files changed
+625
-230
No files matched your search
@@ -121,9 +121,10 @@ func TestFileStorer_ListSkipsPartialFiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestFileStorer_DeletePartialUploads checks that a leftover temp file is
|
||||
// removed and the object at the real key is kept.
|
||||
func TestFileStorer_DeletePartialUploads(t *testing.T) {
|
||||
// TestFileStorer_ListPartialUploads checks that a leftover temp file is
|
||||
// listed with its size and time, that the object at the real key is not,
|
||||
// and that Delete removes the leftover by the listed key.
|
||||
func TestFileStorer_ListPartialUploads(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
base := t.TempDir()
|
||||
@@ -133,23 +134,46 @@ func TestFileStorer_DeletePartialUploads(t *testing.T) {
|
||||
t.Fatalf("NewFileStorer: %v", err)
|
||||
}
|
||||
|
||||
checkListPartialUploads(t, f, base)
|
||||
}
|
||||
|
||||
// checkListPartialUploads stores an object and writes a leftover temp
|
||||
// file next to it in the directory base that s stores into. It checks
|
||||
// that ListPartialUploads lists only the leftover, with its size and a
|
||||
// time, and that Delete removes it by the listed key and keeps the
|
||||
// object.
|
||||
func checkListPartialUploads(t *testing.T, s storage.Storer, base string) {
|
||||
t.Helper()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
err = f.Put(ctx, testBlobKey, strings.NewReader("blob-bytes"))
|
||||
err := s.Put(ctx, testBlobKey, strings.NewReader("blob-bytes"))
|
||||
if err != nil {
|
||||
t.Fatalf("Put: %v", err)
|
||||
}
|
||||
|
||||
leftover := filepath.Join(base, testBlobKey+"-123456.partial")
|
||||
leftoverKey := testBlobKey + "-123456.partial"
|
||||
leftover := filepath.Join(base, leftoverKey)
|
||||
|
||||
err = os.WriteFile(leftover, []byte("half"), 0o600)
|
||||
if err != nil {
|
||||
t.Fatalf("writing leftover temp file: %v", err)
|
||||
}
|
||||
|
||||
err = f.DeletePartialUploads(ctx, "blobs/")
|
||||
partial, err := s.ListPartialUploads(ctx, "blobs/")
|
||||
if err != nil {
|
||||
t.Fatalf("DeletePartialUploads: %v", err)
|
||||
t.Fatalf("ListPartialUploads: %v", err)
|
||||
}
|
||||
|
||||
if len(partial) != 1 || partial[0].Key != leftoverKey ||
|
||||
partial[0].Size != int64(len("half")) || partial[0].ModTime.IsZero() {
|
||||
t.Fatalf("ListPartialUploads = %+v, want only %s, 4 bytes, "+
|
||||
"with a time", partial, leftoverKey)
|
||||
}
|
||||
|
||||
err = s.Delete(ctx, partial[0].Key)
|
||||
if err != nil {
|
||||
t.Fatalf("Delete: %v", err)
|
||||
}
|
||||
|
||||
_, err = os.Stat(leftover)
|
||||
@@ -157,7 +181,7 @@ func TestFileStorer_DeletePartialUploads(t *testing.T) {
|
||||
t.Errorf("leftover temp file was not removed: %v", err)
|
||||
}
|
||||
|
||||
_, err = f.Stat(ctx, testBlobKey)
|
||||
_, err = s.Stat(ctx, testBlobKey)
|
||||
if err != nil {
|
||||
t.Errorf("Stat of the real key: %v", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user