Documentation
¶
Overview ¶
Package archive moves cold rows out of the live database into zstd compressed NDJSON bundles in a local directory, and can list, browse, restore and verify them.
Index ¶
- Constants
- Variables
- type Bundle
- type Kind
- type Manager
- func (m *Manager) Browse(id, table string, offset, limit int) (Rows, error)
- func (m *Manager) Create(ctx context.Context, kind Kind, cutoff time.Time) (Bundle, error)
- func (m *Manager) Delete(id string) error
- func (m *Manager) Get(id string) (Bundle, error)
- func (m *Manager) HotRows(ctx context.Context) map[string]int
- func (m *Manager) List() ([]Bundle, error)
- func (m *Manager) Path(id string) (string, error)
- func (m *Manager) Prune(keepDays int) (int, error)
- func (m *Manager) Restore(ctx context.Context, id string) (RestoreResult, error)
- func (m *Manager) Run(ctx context.Context, p store.ArchiveSettings) (RunResult, error)
- func (m *Manager) Verify(ctx context.Context, id string) (Bundle, error)
- type RestoreResult
- type Rows
- type RunResult
Constants ¶
const DirName = "archives"
DirName is the bundle directory's name under the data dir.
Variables ¶
var ( // ErrInvalidID means the id does not match the bundle name pattern. ErrInvalidID = errors.New("invalid archive id") // ErrNotFound means no bundle with that id exists. ErrNotFound = errors.New("archive not found") // ErrNothingToArchive means no row is old enough to leave the live tables. ErrNothingToArchive = errors.New("nothing to archive") // ErrChecksum means a bundle no longer matches its recorded checksum. ErrChecksum = errors.New("archive checksum mismatch") )
var Kinds = []Kind{KindAudit, KindDeploys, KindPipelines}
Kinds lists every archivable kind.
Functions ¶
This section is empty.
Types ¶
type Bundle ¶
type Bundle struct {
ID string `json:"id"`
Kind Kind `json:"kind"`
CreatedAt time.Time `json:"created_at"`
Cutoff time.Time `json:"cutoff"`
Rows map[string]int `json:"rows"`
TotalRows int `json:"total_rows"`
SizeBytes int64 `json:"size_bytes"`
SHA256 string `json:"sha256"`
VerifiedAt *time.Time `json:"verified_at,omitempty"`
VerifiedOK *bool `json:"verified_ok,omitempty"`
RestoredAt *time.Time `json:"restored_at,omitempty"`
}
Bundle describes one archive bundle.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager creates, lists, restores and prunes bundles in one directory.
func (*Manager) Browse ¶
Browse returns up to limit rows of table starting at offset, without touching the live database.
func (*Manager) Create ¶
Create archives every cold row of kind older than cutoff into one bundle and removes those rows from the live tables once the bundle has been re-read and matches. It returns ErrNothingToArchive when no row qualifies.
func (*Manager) Restore ¶
Restore puts a bundle's rows back into the live tables. Rows already present are left alone; pipeline runs whose pipeline was deleted are skipped.
type RestoreResult ¶
type RestoreResult struct {
Restored map[string]int `json:"restored"`
Existing int `json:"already_present"`
Skipped int `json:"skipped_missing_parent"`
}
RestoreResult reports how many rows came back per table.