controller

package
v0.0.0-...-50d4516 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Library containing utilities exclusively for the master process

Index

Constants

View Source
const (
	CodeSuccess        int = 0   // Success code
	CodeTraceLimit     int = 77  // The traces are overflown
	CodeOom            int = 137 // When the process exits on OOM
	CodeFatal          int = 14  // When the process could not start
	CodeCantRunCommand int = 15  // When the controller could not run the command
)

List of the possible errors returned by the prover as an exit code. There are other possibilities but the one listed here are the one of interests. Some of these codes are generated by the executor and not the child process itself. These includes, CodeFatal, CodeTooManyRetries and CodeCantRunCommand.

Variables

This section is empty.

Functions

func Execute

func Execute()

Execute the cobra root command

Types

type Executor

type Executor struct {
	Config *config.Config
	// Logger specific to the executor
	Logger *logrus.Entry
}

The executor is responsible for running the commands specified by the jobs

func NewExecutor

func NewExecutor(cfg *config.Config) *Executor

func (*Executor) Run

func (e *Executor) Run(job *Job) (status Status)

Run an execution proof job. Importantly, this code must NOT panic because no matter what happens we want to be able to gracefully shutdown.

type FsWatcher

type FsWatcher struct {
	// Unique ID of the container. Used to identify the owner of a locked file
	LocalID string
	// List of jobs that we are currently matching
	JobToWatch []JobDefinition
	// Suffix to append to the end of a file
	InProgress string
	// Logger specific to the file watcher
	Logger *logrus.Entry
}

FsWatcher is a struct who will watch the filesystem and return files as if it were a message queue.

func NewFsWatcher

func NewFsWatcher(conf *config.Config) *FsWatcher

func (*FsWatcher) GetBest

func (fs *FsWatcher) GetBest() (job *Job)

Returns the list of jobs to perform by priorities. If no

type Job

type Job struct {
	// Configuration parameters relative to the job
	Def *JobDefinition
	// Original name of the file when it was found
	OriginalFile string
	// Name of the locked file. If this value is set, it means that the job
	// was successfully locked.
	LockedFile string
	// Height of the file in the priority queue
	Start int
	End   int

	VersionExecutionTracer string
	VersionStateManager    string
	VersionCompressor      string

	// The hex string of the content hash
	ContentHash string
}

Defines a job to be processed. Jobs are parsed from filenames using regexp.

func NewJob

func NewJob(jdef *JobDefinition, filename string) (j *Job, err error)

Parse a filename into a Job. Returns an error if the file does not corresponds to the specified template of the job type.

func (*Job) DeferToLargeFile

func (j *Job) DeferToLargeFile(status Status) (s string, err error)

Returns the name of the input file modified so that it is retried in large mode. It fails if the job's definition does not provide a suffix to retry in large mode. This is still unexpected because the configuration validation ensures that if there is an exit code amenable to defer the job to a larger machine, then the suffix must be set. If the status code of the prover is zero it will return an error.

func (*Job) DoneFile

func (j *Job) DoneFile(status Status) string

Returns the done file following the jobs status

func (*Job) InProgressPath

func (j *Job) InProgressPath() string

Returns the full path to the inprogress file

func (*Job) ResponseFile

func (j *Job) ResponseFile() (s string, err error)

Returns the name of the output file for the job

func (*Job) Score

func (j *Job) Score() int

Returns the score of a JOB. The score is obtained as 100*job.Stop + P, where P is 1 if the job is an execution job, 2 if the job is a compression job and 3 if the job is an aggregation job. The lower the score the higher will be the priority of the job. The 100 value is chosen to make the score easy to mentally compute.

func (*Job) TmpResponseFile

func (j *Job) TmpResponseFile(c *config.Config) (s string)

Returns the name of the output file for the job

type JobDefinition

type JobDefinition struct {

	// Parameters for the job definition provided by the user
	RequestsRootDir string

	// Name of the job
	Name string

	// The regexp to use to match input files. For instance,
	//
	// 	`^\d+-\d+-etv0.1.2-stv\d.\d.\d-getZkProof.json$`
	//
	// Will tell the controller to accept any version of the state-manager
	// but to only accept execution trace. The regexp should always start "^"
	// and end with "$" otherwise you are going to match in-progress files.
	//
	InputFileRegexp *regexp2.Regexp

	// Template to use to generate the output file. The template should have the
	// form of a go template. For instance,
	//
	// 	`{{.From}}-{{.To}}-pv{{.Version}}-stv{{.Stv}}-etv{{.Etv}}-zkProof.json`
	//
	OutputFileTmpl *template.Template

	// Priority at which this type of job should be processed. The lower the
	// more of a priority.
	//
	// Typically 0 for execution, 1 for compression and 2 for aggregation.
	//
	Priority int

	// The associated compiled regexp, this saves on recompiling the regexps
	// everytime we want to use them. If a field is not needed, it can be left
	// at zero.
	ParamsRegexp struct {
		Start       *regexp2.Regexp
		End         *regexp2.Regexp
		Stv         *regexp2.Regexp
		Etv         *regexp2.Regexp
		Cv          *regexp2.Regexp
		ContentHash *regexp2.Regexp
	}

	// Regexp of the failure code so that we can trim it if we want to retry.
	FailureSuffix *regexp2.Regexp
}

JobDefinition represents a collection of static parameters allowing to define a job.

func AggregatedDefinition

func AggregatedDefinition(conf *config.Config) JobDefinition

Definition of an execution prover job.

func CompressionDefinition

func CompressionDefinition(conf *config.Config) JobDefinition

Definition of an execution prover job.

func ExecutionDefinition

func ExecutionDefinition(conf *config.Config) JobDefinition

Definition of an execution prover job. The function panics on any error since it is called at start up.

type OutputFileRessouce

type OutputFileRessouce struct {
	Job
}

OutputFileRessouce collects all the data needed to fill the output template file.

type Resource

type Resource struct {
	ConfFile string
	// The input and output file paths
	InFile, OutFile string
}

Resource collects all the informations about the job that can be used to fill the input command template. The names of the fields are what defines the API of the command templating.

type Status

type Status struct {
	// The matched return code
	ExitCode int
	// String explaining what when wrong. "success"
	What string
	// Additional errors for context
	Err error
}

Status of a finished job

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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