Documentation
¶
Index ¶
- func ObjectPath(bucketID, objectID string) string
- func PartPath(uploadID string, partNumber int) string
- type Store
- func (s *Store) AssembleParts(bucketID, objectID string, partLocations []string) (checksum string, size int64, locationRef string, err error)
- func (s *Store) BucketObjectsDir(bucketID string) string
- func (s *Store) CleanTmp() (int, error)
- func (s *Store) Cleanup(locationRef string)
- func (s *Store) CleanupUploadParts(uploadID string) error
- func (s *Store) DataDir() string
- func (s *Store) DeleteObject(locationRef string) error
- func (s *Store) EnsureBucketDir(bucketID string) error
- func (s *Store) ListBucketFiles(bucketID string) ([]string, error)
- func (s *Store) ObjectExists(obj *meta.Object) bool
- func (s *Store) Quarantine(locationRef string) error
- func (s *Store) ReadObject(locationRef string) (*os.File, error)
- func (s *Store) RemoveBucketDir(bucketID string) error
- func (s *Store) SafePath(locationRef string) (string, error)
- func (s *Store) SetFsyncErrorHook(fn func(err error))
- func (s *Store) VerifyChecksum(locationRef, expected string) (bool, string, error)
- func (s *Store) VerifyChecksumRateLimited(locationRef, expected string, limiter *rate.Limiter) (bool, string, error)
- func (s *Store) WriteObject(bucketID, objectID string, body io.Reader) (checksum string, size int64, locationRef string, err error)
- func (s *Store) WritePart(uploadID string, partNumber int, body io.Reader) (checksum string, size int64, locationRef string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ObjectPath ¶
ObjectPath returns the relative location_ref for a given bucket and object ID. Uses two-level hash directory: <bucket-id>/objects/<id[0:2]>/<id[2:4]>/<id>
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages physical object files on the filesystem.
func (*Store) AssembleParts ¶
func (s *Store) AssembleParts(bucketID, objectID string, partLocations []string) (checksum string, size int64, locationRef string, err error)
AssembleParts concatenates parts into a final object file. Returns the SHA-256 checksum, total size, and location ref of the assembled object.
func (*Store) BucketObjectsDir ¶
BucketObjectsDir returns the absolute path to a bucket's objects directory. Callers that only need to walk a bucket's directory tree should use this instead of constructing paths manually.
func (*Store) CleanTmp ¶
CleanTmp removes all files in the tmp directory. Best-effort: an error on one entry is logged and the remaining entries are still attempted. Returns the count of files actually removed and the first error observed (if any).
func (*Store) Cleanup ¶
Cleanup safely removes the file at locationRef, logging but not propagating errors. It is intended for best-effort cleanup when a subsequent operation (e.g. metadata commit) fails after a successful write.
func (*Store) CleanupUploadParts ¶
CleanupUploadParts removes all part files for an upload.
func (*Store) DeleteObject ¶
DeleteObject removes the physical file at locationRef.
func (*Store) EnsureBucketDir ¶
EnsureBucketDir creates the objects directory for a bucket and fsyncs the parent to ensure the directory entry is durable.
func (*Store) ListBucketFiles ¶
ListBucketFiles walks the bucket's objects directory and returns all object file paths (relative).
func (*Store) ObjectExists ¶
ObjectExists checks if a physical object file exists at the location ref within this store.
func (*Store) Quarantine ¶
Quarantine moves a file from its location to the quarantine directory.
func (*Store) ReadObject ¶
ReadObject opens the file at locationRef for reading. Caller must close it.
func (*Store) RemoveBucketDir ¶
RemoveBucketDir removes the bucket's directory tree. Only call after confirming no objects remain.
func (*Store) SafePath ¶
SafePath validates locationRef and returns the absolute path. Use this whenever locationRef originates from untrusted or externally-stored input.
func (*Store) SetFsyncErrorHook ¶
SetFsyncErrorHook registers a callback invoked after any fsync failure in the store. Safe to call with nil to clear. Callers typically wire this to a metrics counter.
func (*Store) VerifyChecksum ¶
VerifyChecksum reads the file at locationRef and returns whether its SHA-256 matches expected. Uses a 1 MiB buffered reader to reduce syscall overhead on large objects.
func (*Store) VerifyChecksumRateLimited ¶
func (s *Store) VerifyChecksumRateLimited(locationRef, expected string, limiter *rate.Limiter) (bool, string, error)
VerifyChecksumRateLimited behaves like VerifyChecksum but throttles read bandwidth via limiter. If limiter is nil the read is unbounded. The limiter's burst size must be >= the chunk size (1 MiB); callers that construct the limiter should size the burst accordingly.
func (*Store) WriteObject ¶
func (s *Store) WriteObject(bucketID, objectID string, body io.Reader) (checksum string, size int64, locationRef string, err error)
WriteObject streams body to a temp file, computes SHA-256, then atomically moves it to its final location. Returns checksum, size, and locationRef.
The sequence ensures durability:
- Write to temp file (.writing suffix so GC can identify in-flight writes)
- fsync temp file
- Rename directly to final path
- fsync parent directory