checkpoint

package
v0.0.0-...-ffc4fba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package checkpoint provides state persistence for streaming analysis.

Index

Constants

View Source
const (
	DefaultMaxAge  = 7 * 24 * time.Hour // 7 days.
	DefaultMaxSize = 1 << 30            // 1GB.
)

Default retention values.

View Source
const MetadataVersion = 2

MetadataVersion is the current checkpoint metadata format version. Bumped from 1 to 2 when aggregator spill state was added.

Variables

View Source
var (
	ErrRepoPathMismatch = errors.New("repo path mismatch")
	ErrAnalyzerMismatch = errors.New("analyzer mismatch")
	ErrVersionMismatch  = errors.New("checkpoint version mismatch")
)

Sentinel errors for checkpoint validation.

Functions

func DefaultDir

func DefaultDir() string

DefaultDir returns the default checkpoint directory (~/.codefang/checkpoints).

func RepoHash

func RepoHash(repoPath string) string

RepoHash computes a short hash of the repository path for use as directory name.

Types

type AggregatorSpillEntry

type AggregatorSpillEntry struct {
	// Dir is the directory containing gob-encoded spill files.
	Dir string `json:"dir,omitempty"`

	// Count is the number of spill files in Dir.
	Count int `json:"count,omitempty"`
}

AggregatorSpillEntry records on-disk spill state for a single aggregator.

type Checkpointable

type Checkpointable interface {
	// SaveCheckpoint writes analyzer state to the given directory.
	SaveCheckpoint(dir string) error

	// LoadCheckpoint restores analyzer state from the given directory.
	LoadCheckpoint(dir string) error

	// CheckpointSize returns the estimated size of the checkpoint in bytes.
	CheckpointSize() int64
}

Checkpointable is an optional interface for analyzers that support checkpointing.

type Codec

type Codec = persist.Codec

Codec is an alias for persist.Codec.

type GobCodec

type GobCodec = persist.GobCodec

GobCodec is an alias for persist.GobCodec.

func NewGobCodec

func NewGobCodec() *GobCodec

NewGobCodec creates a gob codec.

type JSONCodec

type JSONCodec = persist.JSONCodec

JSONCodec is an alias for persist.JSONCodec.

func NewJSONCodec

func NewJSONCodec() *JSONCodec

NewJSONCodec creates a JSON codec with pretty-printing.

type Manager

type Manager struct {
	BaseDir  string
	RepoHash string
	MaxAge   time.Duration
	MaxSize  int64
}

Manager coordinates checkpoints across analyzers.

func NewManager

func NewManager(baseDir, repoHash string) *Manager

NewManager creates a new checkpoint manager.

func (*Manager) CheckpointDir

func (m *Manager) CheckpointDir() string

CheckpointDir returns the directory for this repository's checkpoint.

func (*Manager) Clear

func (m *Manager) Clear() error

Clear removes the checkpoint for the current repository.

func (*Manager) Exists

func (m *Manager) Exists() bool

Exists returns true if a valid checkpoint exists.

func (*Manager) Load

func (m *Manager) Load(checkpointables []Checkpointable) (*StreamingState, error)

Load restores state for all checkpointable analyzers.

func (*Manager) LoadMetadata

func (m *Manager) LoadMetadata() (*Metadata, error)

LoadMetadata loads the checkpoint metadata.

func (*Manager) MetadataPath

func (m *Manager) MetadataPath() string

MetadataPath returns the path to the metadata file.

func (*Manager) Save

func (m *Manager) Save(
	checkpointables []Checkpointable,
	state StreamingState,
	repoPath string,
	analyzerNames []string,
) error

Save creates a checkpoint for all checkpointable analyzers.

func (*Manager) Validate

func (m *Manager) Validate(repoPath string, analyzerNames []string) error

Validate checks if the checkpoint is valid for the given parameters.

type Metadata

type Metadata struct {
	Version        int               `json:"version"`
	RepoPath       string            `json:"repo_path"`
	RepoHash       string            `json:"repo_hash"`
	CreatedAt      string            `json:"created_at"`
	Analyzers      []string          `json:"analyzers"`
	StreamingState StreamingState    `json:"streaming_state"`
	Checksums      map[string]string `json:"checksums"`
}

Metadata holds checkpoint metadata for validation and resume.

type Persister

type Persister[T any] = persist.Persister[T]

Persister is an alias for persist.Persister.

func NewPersister

func NewPersister[T any](basename string, codec Codec) *Persister[T]

NewPersister creates a checkpoint persister with the given basename and codec.

type StreamingState

type StreamingState struct {
	TotalCommits     int    `json:"total_commits"`
	ProcessedCommits int    `json:"processed_commits"`
	CurrentChunk     int    `json:"current_chunk"`
	TotalChunks      int    `json:"total_chunks"`
	LastCommitHash   string `json:"last_commit_hash"`
	LastTick         int    `json:"last_tick"`

	// AggregatorSpills records the spill state of each aggregator at checkpoint time.
	// Indexed by analyzer position in the Runner.Analyzers slice.
	// Nil entries mean the analyzer has no aggregator (plumbing, file_history).
	AggregatorSpills []AggregatorSpillEntry `json:"aggregator_spills,omitempty"`
}

StreamingState tracks chunk orchestrator progress.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL