Documentation ¶
Overview ¶
Package hooks implements pre- and post snapshot hooks.
Plan is a generic executor for ExpectStepReports before and after an activity specified in a callback. It provides a reporting facility that can be polled while the plan is executing to gather progress information.
This package also provides all supported hook type implementations and abstractions around them.
Use For Other Kinds Of ExpectStepReports ¶
This package REQUIRES REFACTORING before it can be used for other activities than snapshots, e.g. pre- and post-replication:
The Hook interface requires a hook to provide a Filesystems() filter, which doesn't make sense for all kinds of activities.
The hook implementations should move out of this package. However, there is a lot of tight coupling which to untangle isn't worth it ATM.
How This Package Is Used By Package Snapper ¶
Deserialize a config.List using ListFromConfig(). Then it MUST filter the list to only contain hooks for a particular filesystem using hooksList.CopyFilteredForFilesystem(fs).
Then create a CallbackHook using NewCallbackHookForFilesystem().
Pass all of the above to NewPlan() which provides a Report() and Run() method:
Plan.Run(ctx context.Context,dryRun bool) executes the plan and take a context as argument that should contain a logger added using hooks.WithLogger()). The value of dryRun is passed through to the hooks' Run() method. Command hooks make it available in the environment variable ZREPL_DRYRUN.
Plan.Report() can be called while Plan.Run() is executing to give an overview of plan execution progress (future use in "zrepl status").
Index ¶
- Constants
- func NewLogWriter(mtx *sync.Mutex, logger Logger, level logger.Level, field string) *logWriter
- type CallbackHook
- type CallbackHookReport
- type CommandHook
- type CommandHookReport
- type Edge
- type Env
- type Filter
- type Hook
- type HookEnvVar
- type HookJobCallback
- type HookReport
- type List
- type Logger
- type MyLockTablesReport
- type MySQLLockTables
- type PgChkptHook
- type PgChkptHookReport
- type Phase
- type Plan
- type PlanReport
- type Step
- type StepStatus
Constants ¶
const ( PhaseSnapshot = Phase("snapshot") PhaseTesting = Phase("testing") )
const ( Pre = Edge(1 << iota) Callback Post )
const MAX_HOOK_LOG_SIZE_DEFAULT int = 1 << 20
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CallbackHook ¶
type CallbackHook struct {
// contains filtered or unexported fields
}
func NewCallbackHook ¶
func NewCallbackHook(displayString string, cb HookJobCallback, filter Filter) *CallbackHook
func NewCallbackHookForFilesystem ¶
func NewCallbackHookForFilesystem(displayString string, fs *zfs.DatasetPath, cb HookJobCallback) *CallbackHook
func (*CallbackHook) ErrIsFatal ¶
func (h *CallbackHook) ErrIsFatal() bool
func (*CallbackHook) Filesystems ¶
func (h *CallbackHook) Filesystems() Filter
func (*CallbackHook) Run ¶
func (h *CallbackHook) Run(ctx context.Context, edge Edge, phase Phase, dryRun bool, extra Env, state map[interface{}]interface{}) HookReport
func (*CallbackHook) String ¶
func (h *CallbackHook) String() string
type CallbackHookReport ¶
func (*CallbackHookReport) Error ¶
func (r *CallbackHookReport) Error() string
func (*CallbackHookReport) HadError ¶
func (r *CallbackHookReport) HadError() bool
func (*CallbackHookReport) String ¶
func (r *CallbackHookReport) String() string
type CommandHook ¶
type CommandHook struct {
// contains filtered or unexported fields
}
func NewCommandHook ¶
func NewCommandHook(in *config.HookCommand) (r *CommandHook, err error)
func (*CommandHook) ErrIsFatal ¶
func (h *CommandHook) ErrIsFatal() bool
func (*CommandHook) Filesystems ¶
func (h *CommandHook) Filesystems() Filter
func (*CommandHook) Run ¶
func (h *CommandHook) Run(ctx context.Context, edge Edge, phase Phase, dryRun bool, extra Env, state map[interface{}]interface{}) HookReport
func (*CommandHook) String ¶
func (h *CommandHook) String() string
type CommandHookReport ¶
type CommandHookReport struct { Command string Args []string // currently always empty Env Env Err error CapturedStdoutStderrCombined []byte }
func (*CommandHookReport) Error ¶
func (r *CommandHookReport) Error() string
func (*CommandHookReport) HadError ¶
func (r *CommandHookReport) HadError() bool
func (*CommandHookReport) String ¶
func (r *CommandHookReport) String() string
type Env ¶
type Env map[HookEnvVar]string
type Filter ¶
type Filter zfs.DatasetFilter
Re-export type here so that every file in package hooks doesn't have to import github.com/zrepl/zrepl/zfs
type Hook ¶
type Hook interface { Filesystems() Filter // If true and the Pre edge invocation of Run fails, Post edge will not run and other Pre edges will not run. ErrIsFatal() bool // Run is invoked by HookPlan for a Pre edge. // If HookReport.HadError() == false, the Post edge will be invoked, too. Run(ctx context.Context, edge Edge, phase Phase, dryRun bool, extra Env, state map[interface{}]interface{}) HookReport String() string }
type HookEnvVar ¶
type HookEnvVar string
const ( EnvType HookEnvVar = "ZREPL_HOOKTYPE" EnvDryRun HookEnvVar = "ZREPL_DRYRUN" EnvFS HookEnvVar = "ZREPL_FS" EnvSnapshot HookEnvVar = "ZREPL_SNAPNAME" EnvTimeout HookEnvVar = "ZREPL_TIMEOUT" )
type HookJobCallback ¶
type HookReport ¶
type List ¶
type List []Hook
func (List) CopyFilteredForFilesystem ¶
func (l List) CopyFilteredForFilesystem(fs *zfs.DatasetPath) (ret List, err error)
type MyLockTablesReport ¶
func (*MyLockTablesReport) Error ¶
func (r *MyLockTablesReport) Error() string
func (*MyLockTablesReport) HadError ¶
func (r *MyLockTablesReport) HadError() bool
func (*MyLockTablesReport) String ¶
func (r *MyLockTablesReport) String() string
type MySQLLockTables ¶
type MySQLLockTables struct {
// contains filtered or unexported fields
}
https://dev.mysql.com/doc/mysql-backup-excerpt/5.7/en/backup-methods.html
Making Backups Using a File System Snapshot:
If you are using a Veritas file system, you can make a backup like this: From a client program, execute FLUSH TABLES WITH READ LOCK. From another shell, execute mount vxfs snapshot. From the first client, execute UNLOCK TABLES. Copy files from the snapshot. Unmount the snapshot. Similar snapshot capabilities may be available in other file systems, such as LVM or ZFS.
func MyLockTablesFromConfig ¶
func MyLockTablesFromConfig(in *config.HookMySQLLockTables) (*MySQLLockTables, error)
func (*MySQLLockTables) ErrIsFatal ¶
func (h *MySQLLockTables) ErrIsFatal() bool
func (*MySQLLockTables) Filesystems ¶
func (h *MySQLLockTables) Filesystems() Filter
func (*MySQLLockTables) Run ¶
func (h *MySQLLockTables) Run(ctx context.Context, edge Edge, phase Phase, dryRun bool, extra Env, state map[interface{}]interface{}) HookReport
func (*MySQLLockTables) String ¶
func (h *MySQLLockTables) String() string
type PgChkptHook ¶
type PgChkptHook struct {
// contains filtered or unexported fields
}
func PgChkptHookFromConfig ¶
func PgChkptHookFromConfig(in *config.HookPostgresCheckpoint) (*PgChkptHook, error)
func (*PgChkptHook) ErrIsFatal ¶
func (h *PgChkptHook) ErrIsFatal() bool
func (*PgChkptHook) Filesystems ¶
func (h *PgChkptHook) Filesystems() Filter
func (*PgChkptHook) Run ¶
func (h *PgChkptHook) Run(ctx context.Context, edge Edge, phase Phase, dryRun bool, extra Env, state map[interface{}]interface{}) HookReport
func (*PgChkptHook) String ¶
func (h *PgChkptHook) String() string
type PgChkptHookReport ¶
type PgChkptHookReport struct{ Err error }
func (*PgChkptHookReport) Error ¶
func (r *PgChkptHookReport) Error() string
func (*PgChkptHookReport) HadError ¶
func (r *PgChkptHookReport) HadError() bool
func (*PgChkptHookReport) String ¶
func (r *PgChkptHookReport) String() string
type Plan ¶
type Plan struct {
// contains filtered or unexported fields
}
func (*Plan) Report ¶
func (p *Plan) Report() PlanReport
type PlanReport ¶
type PlanReport []Step
func (PlanReport) HadError ¶
func (r PlanReport) HadError() bool
func (PlanReport) HadFatalError ¶
func (r PlanReport) HadFatalError() bool
func (PlanReport) String ¶
func (r PlanReport) String() string
type Step ¶
type Step struct { Hook Hook Edge Edge Status StepStatus Begin, End time.Time // Report may be nil // FIXME cannot serialize this for client status, but contains interesting info (like what error happened) Report HookReport // contains filtered or unexported fields }
type StepStatus ¶
type StepStatus int
const ( StepPending StepStatus = 1 << iota StepExec StepOk StepErr StepSkippedDueToFatalErr StepSkippedDueToPreErr )
func StepStatusString ¶
func StepStatusString(s string) (StepStatus, error)
StepStatusString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func StepStatusValues ¶
func StepStatusValues() []StepStatus
StepStatusValues returns all values of the enum
func (StepStatus) IsAStepStatus ¶
func (i StepStatus) IsAStepStatus() bool
IsAStepStatus returns "true" if the value is listed in the enum definition. "false" otherwise
func (StepStatus) String ¶
func (i StepStatus) String() string