Documentation
¶
Overview ¶
Package exporter is the client-side orchestration of data export: the connection preflight against the liaisons, the dry-run Plan and its report, the export session library (create, list, heartbeat, release), and RunExport, which writes the schema, drives one Export stream per data node, dealt round robin over the liaisons, verifies and persists every file and seals manifest.json. The settings are resolved by pkg/transfer/config. It talks to the liaison only and never depends on any banyand/ storage package.
Index ¶
- Constants
- func CheckFormat(opts *config.Export) error
- func CheckOutputDir(dir, progressPath string) error
- func CheckResume(sources config.Sources, opts *config.Export) error
- func DryRunResume(env Env, opts config.Export) (bool, error)
- func HeartbeatOnce(ctx context.Context, conn *grpc.ClientConn, sessionID string, ...) error
- func ListSessions(ctx context.Context, conn *grpc.ClientConn) ([]*transferv1.SessionsResponse, error)
- func ProgressPath(opts config.Export) string
- func Render(w io.Writer, format string, rep *Report) error
- func RunExport(ctx context.Context, env Env, opts config.Export) error
- func SelectedGroups(groups []*commonv1.Group, selectors []*transferv1.Selector) []*commonv1.Group
- func StageNames(g *commonv1.Group) []string
- func StageWarnings(groups []*commonv1.Group, result *cluster.PlanResult) []string
- func StartHeartbeat(ctx context.Context, conn *grpc.ClientConn, sessionID string, ...) (stop func(), lost <-chan error)
- func ValidateSelectors(groups []*commonv1.Group, selectors []*transferv1.Selector) error
- type Classification
- type DoneUnitView
- type Env
- type MultiSource
- type Occupant
- type ProgressView
- type ReleaseResult
- type Report
- type RequiredNodes
- type ResumedProgress
- type Row
- type Session
- type SessionOptions
- type Source
Constants ¶
const ( // HeartbeatInterval is fixed. A heartbeat keeps the lease fresh (the data // node sweeps a session only once it expired) and records when the holder was last seen, // which is what an operator refused by that session judges from before preempting it; // the data node itself takes no liveness decision. HeartbeatInterval = 5 * time.Minute )
const ( // ProgressFileName is the progress file of an export below its output directory, unless // --checkpoint names another path. ProgressFileName = ".export-progress.json" )
Variables ¶
This section is empty.
Functions ¶
func CheckFormat ¶
CheckFormat checks the settings a format takes: a native artifact is never compressed, so an unspecified compression becomes none and gzip is refused, and its volume limit must leave room for a container. Any format but csv and native is refused.
func CheckOutputDir ¶
CheckOutputDir accepts an output directory that does not exist or is empty, or one that holds the progress file at progressPath (ProgressPath): that export is resumed. The lock file of the progress file does not count. It also accepts what an export killed before its first progress write leaves when the progress file belongs in the directory (leftover), which the export removes (cleanLeftover) once it holds the lock. Anything else is refused, naming what the directory holds: a fresh export must not mix with leftovers. A progress file in a subdirectory of the output directory is refused: that subdirectory would end up in the artifact.
func CheckResume ¶
CheckResume checks the output directory and the progress file of an export before anything is contacted; every failure is a usage error (exit 1). A --checkpoint that names a directory, or the output directory itself, is refused. For a dry run, which writes nothing and previews a resume only, it drops the output directory and the progress file the environment sets: they are defaults of real exports. A progress file from the environment is kept for an output directory given as a flag or in plan.yaml, as where that export records its progress. An output directory or a progress file given so is refused unless the progress file it names exists to preview.
func DryRunResume ¶
DryRunResume is `data export --dry-run` over the output directory of an interrupted export: it runs the checks a resume makes without the cluster (the bindings, the files of the finished units, the schema they were exported with), prints the resume summary to env.Log and the plan of what is left to env.Out, and reports whether a progress file was there. It does not take the lock, so it reads an export that is running too, and it writes and deletes nothing. The export session is not contacted, which a NOTE says.
func HeartbeatOnce ¶
func HeartbeatOnce(ctx context.Context, conn *grpc.ClientConn, sessionID string, holders RequiredNodes) error
HeartbeatOnce sends one ACTION_HEARTBEAT and fails if any of holders did not take it: a node that was unreachable or no longer holds the session answers an error frame, which is a coverage gap; a node outside holders, which never held the session or has no unit left to export, answers one too and is ignored. holders go to the liaison as required_nodes, so the lease of a node outside them expiring is such an error frame too, while an expired session on a holder fails the call itself with FAILED_PRECONDITION. With no holder no node needs the session any more and nothing is sent.
func ListSessions ¶
func ListSessions(ctx context.Context, conn *grpc.ClientConn) ([]*transferv1.SessionsResponse, error)
ListSessions collects the ACTION_LIST frames, one per data node.
func ProgressPath ¶
ProgressPath is the progress file of an export: --checkpoint, or ProgressFileName below the output directory; "" when neither is given.
func RunExport ¶
RunExport performs a real export: schema, session, one Export stream per node, manifest, release. Schema, Plan and Sessions go through the primary liaison, the node streams are spread over every liaison. Once the session exists any failure keeps it and tells the operator how to release it; the error is an exitcode.ExitError (exit 3 unless the cause carries its own code). The progress file (ProgressPath) records the session, its plan and every finished unit until the manifest is written; an output directory that holds one is resumed instead.
func SelectedGroups ¶
SelectedGroups returns the groups the selectors cover, in the given order: all groups for no selector, every group of the catalog for a selector without groups.
func StageNames ¶
StageNames returns the lifecycle stage names a group declares, plus the default tier.
func StageWarnings ¶
func StageWarnings(groups []*commonv1.Group, result *cluster.PlanResult) []string
StageWarnings reports every (node, group, stage) a Plan frame carries whose stage the group schema does not declare: the node holds data the current lifecycle config does not describe, which the operator should know before exporting.
func StartHeartbeat ¶
func StartHeartbeat(ctx context.Context, conn *grpc.ClientConn, sessionID string, holders func() RequiredNodes, interval time.Duration, l *logger.Logger, warn io.Writer, ) (stop func(), lost <-chan error)
StartHeartbeat sends ACTION_HEARTBEAT for the session every interval until stop is called (0 means HeartbeatInterval). holders, asked before every tick, names the data nodes that must still hold the session, see HeartbeatOnce. A transport failure or an error frame of a holder is a WARN line on warn, not fatal: the lease outlives several missed heartbeats, so the next tick retries. FAILED_PRECONDITION means the session expired or its lease is unreadable on a holder; it is sent on lost once and the heartbeat stops.
func ValidateSelectors ¶
func ValidateSelectors(groups []*commonv1.Group, selectors []*transferv1.Selector) error
ValidateSelectors checks that every group a selector names exists in the schema and belongs to the selected catalog, so a typo fails before anything is planned.
Types ¶
type Classification ¶
type Classification struct {
Occupants []Occupant
// Split is true when more than one session id exists or a session is held by only
// some of the answering nodes: a half-won create that must be released in full.
Split bool
}
Classification is the merged view of the listed sessions. Nobody decides liveness: the client renders each occupant with its last heartbeat so the operator can judge whether to preempt it.
func ClassifySessions ¶
func ClassifySessions(frames []*transferv1.SessionsResponse) Classification
ClassifySessions merges per-node list frames into occupants, one per session id, and flags a split. The copy with the newest heartbeat represents the session: a heartbeat that reached only some nodes must not make it look older than it is.
func (Classification) String ¶
func (c Classification) String() string
String renders the occupants for error and warning text.
type DoneUnitView ¶
DoneUnitView is one finished unit of one node and the files it wrote, relative to the output directory, in the order they came.
type Env ¶
type Env struct {
// Log receives the information, warnings and hints and Out the progress and the final
// summary, both stdout; Err receives what explains a failure before its error (stderr), Log
// when nil.
Log io.Writer
Out io.Writer
Err io.Writer
// Terminal is nil when Out is not a terminal. Otherwise it returns the terminal's width and
// height (0 when unknown), and the progress redraws one live line per exporting node.
Terminal func() (width, height int)
// Confirm asks the operator a yes/no question and reports a yes; nil when stdin is not a
// terminal or none of stdout and stderr is one to ask on (stderr only when stdout is
// redirected, with the lines Log and Out got so far shown there first), and then a cluster
// held by another session refuses the export, and a progress file to resume needs --resume.
Confirm func(ctx context.Context, question string) bool
Cluster *cluster.Info
Liaisons *cluster.Liaisons
// Groups is the full group list from cluster.FetchGroups; RunExport picks the selected ones.
Groups []*commonv1.Group
}
Env is what RunExport works with besides the settings: where it prints, what the preflight learned and the liaison connections.
type MultiSource ¶
MultiSource is a (catalog, group, stage, segment, shard) key held by more than one node. Property groups are left out: their rows are documents, not time-bounded units an importer chooses between. Index-mode segment-level units are left out too: they have no shard id, so the plan cannot tell replicas of one segment from different shards' slices of it.
type Occupant ¶
type Occupant struct {
Lease *transferv1.SessionLease
Nodes []string
}
Occupant is one listed session with the nodes that hold it.
type ProgressView ¶
type ProgressView struct {
// SessionID is the export session the progress file records, "" before it has one.
SessionID string
// Plan is the plan of the plan side file, none before it is written.
Plan []*transferv1.UnitFrame
// Done is every finished unit of every node.
Done []DoneUnitView
}
ProgressView is a read-only view of an export progress file and its plan side file as a resume reads them, without checking them against an invocation: for tests and checks.
func ReadProgress ¶
func ReadProgress(path string) (*ProgressView, error)
ReadProgress reads the export progress file at path and its plan side file, checked against the digest the progress file records. A missing progress file is an error that wraps os.ErrNotExist.
type ReleaseResult ¶
type ReleaseResult struct {
// Released are the nodes that held the session and deleted it.
Released []string
// NotHeld are the nodes that did not hold the session; nothing was deleted there.
NotHeld []string
// Failed are the error frames, one per node that could not release; an unexpected outcome becomes one.
Failed []*transferv1.SessionsResponse
}
ReleaseResult sorts the data nodes by their answer to a release.
func ReleaseSession ¶
func ReleaseSession(ctx context.Context, conn *grpc.ClientConn, sessionID string) (*ReleaseResult, error)
ReleaseSession asks every data node to drop the session snapshot and sorts their answers.
type Report ¶
type Report struct {
// Resumed, set by the dry run of an interrupted export, names its progress file and how many
// of its units are done: Rows then list only the units left.
Resumed *ResumedProgress `json:"resumed,omitempty"`
Rows []Row `json:"rows"`
MultiSource []MultiSource `json:"multiSource"`
// DataNodes are the nodes the liaison fanned out to: the answered and the unreachable
// ones, which may differ from the preflight's registry snapshot.
DataNodes []string `json:"dataNodes"`
AnsweredNodes []string `json:"answeredNodes"`
// MissingNodes are the nodes the liaison reported unreachable or not holding the
// session; their data would not be exported.
MissingNodes []string `json:"missingNodes"`
UnreachableNodes []string `json:"unreachableNodes"`
Standalone bool `json:"standalone"`
}
Report is the dry-run summary rendered by Render.
func BuildReport ¶
func BuildReport(info *cluster.Info, result *cluster.PlanResult) *Report
BuildReport folds Plan frames into the table, the multi-source list and the NODES gap. Every list is non-nil so the json and yaml renderings print [] rather than null.
func (*Report) LargestNodeCompressedBytes ¶
LargestNodeCompressedBytes is the largest per-node compressed subtotal and its node: each data node pins its own session snapshot, so that node needs the most space.
type RequiredNodes ¶
type RequiredNodes struct {
// contains filtered or unexported fields
}
RequiredNodes names the data nodes that must hold an export session: every data node of the cluster (AllNodes), or the given ones (OnlyNodes), which may be none.
func OnlyNodes ¶
func OnlyNodes(nodes []string) RequiredNodes
OnlyNodes requires the given data nodes; with none, no node needs the session.
type ResumedProgress ¶
type ResumedProgress struct {
Path string `json:"path"`
Done int `json:"done"`
Total int `json:"total"`
}
ResumedProgress is the progress file a dry run previews the resume of.
type Row ¶
type Row struct {
Node string `json:"node"`
Catalog string `json:"catalog"`
Group string `json:"group"`
Stage string `json:"stage"`
Segments int `json:"segments"`
Shards int `json:"shards"`
Parts int `json:"parts"`
EstRows uint64 `json:"estRows"`
CompressedBytes uint64 `json:"compressedBytes"`
UncompressedBytes uint64 `json:"uncompressedBytes"`
MinTimestamp int64 `json:"minTimestamp"`
MaxTimestamp int64 `json:"maxTimestamp"`
}
Row is one (node, catalog, group) line of the dry-run table.
type Session ¶
Session is a created export session as seen by the client.
func CreateSession ¶
func CreateSession(ctx context.Context, conn *grpc.ClientConn, selectors []*transferv1.Selector, opts SessionOptions) (*Session, *cluster.PlanResult, error)
CreateSession runs Plan(create{preempt}) and collects the snapshot inventory. A data node holding any other session refuses with ALREADY_EXISTS unless opts.Preempt is set; the refusal is rendered with the occupants the nodes list and exits 2. The liaison rolls a failed create back itself, so a failure leaves no session behind. Transient failures are retried with jitter; a failure after the session id was announced exits 3 because snapshots may have been taken in between.
type SessionOptions ¶
type SessionOptions struct {
// OnCreated is called with the session id as soon as the liaison announces it, before
// the inventory arrives, so the caller can print it right away.
OnCreated func(id string)
// Confirm, when set and Preempt is not, is asked whether to take over the sessions that
// refused the create, given their rendered list; on yes the create is made once more
// with Preempt, on no the refusal only says how to take them over or release them.
Confirm func(occupants string) bool
// Preempt removes every session the data nodes hold and creates ours.
Preempt bool
}
SessionOptions configure CreateSession.