Documentation
¶
Overview ¶
Package filecheck compares the database's file references with the file store, records the differences, and deletes files nothing has referenced for 30 days.
Index ¶
- Constants
- func ParseRetention(raw string) (time.Duration, error)
- type Checker
- type Discrepancy
- type Job
- type Kind
- type Objects
- type Report
- type Store
- func (s *Store) Forget(ctx context.Context, key string, kind Kind) error
- func (s *Store) List(ctx context.Context) ([]Discrepancy, error)
- func (s *Store) Record(ctx context.Context, now time.Time, found []Discrepancy) error
- func (s *Store) References(ctx context.Context) (map[string][]string, error)
- func (s *Store) Texts(ctx context.Context) ([]string, error)
- func (s *Store) WithLock(ctx context.Context, f func(context.Context) error) (bool, error)
Constants ¶
const MaxRetention = 30 * 24 * time.Hour
MaxRetention is the longest a file may go unreferenced before it is deleted, and the default (FILE_RETENTION can make it shorter, e.g. on dev).
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker runs file checks.
func NewChecker ¶
NewChecker deletes files after MaxRetention unless WithRetention says otherwise.
type Discrepancy ¶
type Discrepancy struct {
Key string `db:"key"`
Kind Kind `db:"kind"`
// Detail names the rows that point at a missing file, e.g. "players 12".
Detail string `db:"detail"`
FirstSeen time.Time `db:"first_seen"`
LastSeen time.Time `db:"last_seen"`
}
Discrepancy is one recorded difference.
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
Job runs the file check, with deletion, once a day (see NewJob). Every server instance runs a Job; the Postgres lock means only one of them checks at a time.
func NewJob ¶
NewJob checks once a day, or as often as the retention period when that is shorter, so files are deleted close to when they fall due.
type Objects ¶
type Objects interface {
List(ctx context.Context) ([]string, error)
Delete(ctx context.Context, key string) error
}
Objects is the file store (satisfied by *storage.Store).
type Report ¶
type Report struct {
Objects int
References int
// Retention is how long a file may go unreferenced before it is deleted.
Retention time.Duration
// Differences are all recorded differences after the check, oldest first.
Differences []Discrepancy
// Deleted are files removed for being unreferenced for 30 days.
Deleted []string
// DeletionSkipped explains why nothing was deleted, when deletion was asked
// for but held back.
DeletionSkipped string
}
Report is what one check found and did.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads file references from the database and keeps the file_discrepancies table (migration 005).
func (*Store) List ¶
func (s *Store) List(ctx context.Context) ([]Discrepancy, error)
List returns every recorded difference, oldest first.
func (*Store) Record ¶
Record saves what a check found at now: new differences are added, ones seen before keep their first_seen, and ones no longer found are removed.
func (*Store) References ¶
References maps each storage key a row points at to the rows pointing at it ("players 12"). It reads every table in the schema with a file_name column, found from the database itself, so a table the code doesn't know about (or one added later) can't have its files deleted by mistake.