Skip to content

Commit be552e3

Browse files
frristclaude
andcommitted
refactor(blockstore): drop unused Spool methods (PutBlock, Has, Remove)
PutBlock had no callers and *Spool was never consumed as a BlockWriter (the only implementer of that interface is bucketop.Tx); Has and Remove had no callers either. Remove all three and the now-unsatisfiable BlockWriter compile-time assertion, leaving Spool at Path/WriteBlob/ OpenBlob/GetBlock. GetBlock stays because Layered holds the spool as a BlockReader. Has/Remove are the spool's eviction primitives and will return with the spool eviction policy (#26), shaped to what that driver needs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 223b557 commit be552e3

1 file changed

Lines changed: 6 additions & 47 deletions

File tree

blockstore/spool.go

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import (
2121
// floor and the read cache — a just-written or hot blob is served straight from
2222
// disk, skipping the network read tier.
2323
//
24-
// Spool is deliberately pure file I/O: it is a blockstore.BlockReader +
25-
// BlockWriter and nothing more. The lifecycle of a blob (the upload_intents
26-
// state machine, eviction policy) is owned by the caller that has the registry
27-
// handle — blockstore cannot import registry without a cycle (registry imports
24+
// Spool is deliberately pure file I/O: a blockstore.BlockReader plus the
25+
// streaming BlobReader/BlobWriter, and nothing more. The lifecycle of a blob
26+
// (the upload_intents state machine, eviction policy) is owned by the caller
27+
// that has the registry handle — blockstore cannot import registry without a
28+
// cycle (registry imports
2829
// blockstore for the segment-metadata types).
2930
type Spool struct {
3031
dir string
@@ -48,32 +49,6 @@ func (s *Spool) Path(digest mh.Multihash) string {
4849
return filepath.Join(s.dir, hex.EncodeToString(digest))
4950
}
5051

51-
// PutBlock writes a raw block to the spool, keyed by its multihash. Writing is
52-
// atomic (write to a temp file, then rename) so a crash mid-write never leaves a
53-
// partial blob readable under its digest.
54-
func (s *Spool) PutBlock(_ context.Context, blk block.Block) error {
55-
final := s.Path(blk.Cid().Hash())
56-
tmp, err := os.CreateTemp(s.dir, ".tmp-*")
57-
if err != nil {
58-
return fmt.Errorf("blockstore: spool tempfile: %w", err)
59-
}
60-
tmpName := tmp.Name()
61-
if _, err := tmp.Write(blk.RawData()); err != nil {
62-
_ = tmp.Close()
63-
_ = os.Remove(tmpName)
64-
return fmt.Errorf("blockstore: spool write: %w", err)
65-
}
66-
if err := tmp.Close(); err != nil {
67-
_ = os.Remove(tmpName)
68-
return fmt.Errorf("blockstore: spool close: %w", err)
69-
}
70-
if err := os.Rename(tmpName, final); err != nil {
71-
_ = os.Remove(tmpName)
72-
return fmt.Errorf("blockstore: spool rename: %w", err)
73-
}
74-
return nil
75-
}
76-
7752
// WriteBlob streams r to the spool, computing its sha256 digest as it writes so
7853
// the blob is never held whole in memory (object-body blobs run up to
7954
// max_blob_size = 256 MiB; buffering them would put that × concurrency in RAM).
@@ -143,26 +118,10 @@ func (s *Spool) GetBlock(_ context.Context, c cid.Cid) (block.Block, error) {
143118
return block.NewBlockWithCid(data, c)
144119
}
145120

146-
// Has reports whether a blob with the given digest is on disk.
147-
func (s *Spool) Has(digest mh.Multihash) bool {
148-
_, err := os.Stat(s.Path(digest))
149-
return err == nil
150-
}
151-
152-
// Remove deletes a spooled blob (eviction / cleanup). Absent files are not an
153-
// error.
154-
func (s *Spool) Remove(digest mh.Multihash) error {
155-
if err := os.Remove(s.Path(digest)); err != nil && !errors.Is(err, os.ErrNotExist) {
156-
return fmt.Errorf("blockstore: spool remove: %w", err)
157-
}
158-
return nil
159-
}
160-
161-
// Compile-time assertions: Spool is a read+write block tier, and the streaming
121+
// Compile-time assertions: Spool is a raw-block read tier and the streaming
162122
// blob tier for object bodies.
163123
var (
164124
_ BlockReader = (*Spool)(nil)
165-
_ BlockWriter = (*Spool)(nil)
166125
_ BlobReader = (*Spool)(nil)
167126
_ BlobWriter = (*Spool)(nil)
168127
)

0 commit comments

Comments
 (0)