Documentation
¶
Overview ¶
Package config declares the settings of the data transfer commands and resolves them from flags, plan.yaml, BYDBCTL_* environment variables and defaults.
Every setting is one struct field whose tags say where it comes from:
flag:"node-rate-limit" the command-line flag (required); "-" declares a plan-only
setting: no flag, no variable, Sources labels it by plan path
short:"o" an optional one-letter shorthand
plan:"export.nodeRateLimit" the dotted plan.yaml path; absent = not in plan.yaml
env:"NODE_RATE_LIMIT" the variable BYDBCTL_NODE_RATE_LIMIT; absent = no variable
default:"0" the default, in the same grammar as the flag
usage:"..." the flag help text
parse:"rate-bytes" the grammar: size, rate-bytes, rate-rows, parallelism,
count, selector, format, compress, conflict-policy,
conflict-rules (plan-only) or duplication-policy; string,
bool, []string and
time.Duration fields need none
Bind registers the flags and Resolve fills the struct with typed values, an explicit flag first, then plan.yaml, then the environment, then the default.
Index ¶
- Constants
- Variables
- func Bind(fs *pflag.FlagSet, opts ...any)
- func CheckCheckpoint(sources Sources, checkpointSetting *string, dir, fileName string) error
- func CheckSchemaOnly(sources Sources, schemaOnly, includeSchema *bool) error
- func ClampParallelism(requested, sourceNodes int) (effective int, clamped bool)
- func Defaults(opts any)
- func FormatParallelism(n int) string
- func LoadPlan(path string) (map[string]any, error)
- func ParseCompress(raw string) (transferv1.Compress, error)
- func ParseConflictPolicy(raw string) (string, error)
- func ParseCount(raw string) (int, error)
- func ParseFormat(raw string) (transferv1.Format, error)
- func ParseParallelism(raw string) (int, error)
- func ParseRate(raw string, kind RateKind) (float64, error)
- func ParseSize(raw string) (uint64, error)
- func SameDir(a, b string) bool
- func ValidateConflictMatch(match string) error
- type ConflictRule
- type Connection
- type DuplicationPolicy
- type Export
- type Import
- type RateKind
- type SelectorConfig
- type Sources
Constants ¶
const ( // ConflictPolicyError rejects the import on a schema conflict. ConflictPolicyError = "error" // ConflictPolicyIgnore keeps the target schema and imports the data anyway. ConflictPolicyIgnore = "ignore" // ConflictPolicyOverwrite replaces the target schema with the artifact's. ConflictPolicyOverwrite = "overwrite" )
Schema conflict policies of an import.
const ( MinWriteBatchSize = 1 MaxWriteBatchSize = 10000 MinWriteBatchBytes = 64 << 10 MaxWriteBatchBytes = 64 << 20 // MinPartChunkSize and MaxPartChunkSize bound --part-chunk-size; the maximum is the wire // limit of ImportPartsRequest.Chunk, which the liaison enforces. MinPartChunkSize = 64 << 10 MaxPartChunkSize = nativefmt.MaxChunkSize )
Bounds of the import batch settings; a value outside them is refused, never clamped.
const EnvPrefix = "BYDBCTL_"
EnvPrefix is prepended to every env tag.
const PlanFlag = "plan"
PlanFlag is the flag naming the plan.yaml every data command reads its settings from.
Variables ¶
var ConflictMatchKinds = []string{"group", "stream", "measure", "trace", "property", "indexRule", "indexRuleBinding", "topNAggregation"}
ConflictMatchKinds are the schema kinds a conflict rule can match.
Functions ¶
func Bind ¶
Bind registers --plan and one flag per field of every option struct in opts (pointers to structs). The flags hold the raw text; Resolve parses it. The usage text names the plan.yaml key and the variable.
func CheckCheckpoint ¶
CheckCheckpoint refuses a checkpoint setting (the --checkpoint field) that names a directory, or dir (the artifact or output directory) itself, rather than a progress file; fileName is the progress file the message suggests below it. Export and import share it.
func CheckSchemaOnly ¶
CheckSchemaOnly refuses --schema-only together with --include-schema=false, given as the two fields, since a schema-only transfer needs the schema. Export and import share it.
func ClampParallelism ¶
ClampParallelism bounds the requested value by the number of source nodes and reports whether clamping happened so the caller can print the effective value.
func Defaults ¶
func Defaults(opts any)
Defaults fills the option struct opts points to with the defaults its fields declare.
func FormatParallelism ¶
FormatParallelism is the inverse of ParseParallelism: math.MaxInt is "max".
func LoadPlan ¶
LoadPlan reads plan.yaml into its leaf values keyed by dotted path; "" yields no values. Every key must be declared by a plan tag of an option struct of this package, so a typo never silently falls back to a default. Numbers keep their text (json.Number).
func ParseCompress ¶
func ParseCompress(raw string) (transferv1.Compress, error)
ParseCompress parses a file compression name: none or gzip, in any case.
func ParseConflictPolicy ¶
ParseConflictPolicy accepts exactly error, ignore or overwrite.
func ParseCount ¶
ParseCount parses a plain decimal integer >= 1.
func ParseFormat ¶
func ParseFormat(raw string) (transferv1.Format, error)
ParseFormat parses an artifact format name: csv or native, in any case.
func ParseParallelism ¶
ParseParallelism maps "max" to math.MaxInt and a decimal integer >= 1 to itself.
func ParseRate ¶
ParseRate parses `<quantity>[/<period>]` and normalizes it to units per second: "0" is no limit, a bare number is per second, and the period is s, min or h. A negative value, an unknown period (including the ambiguous "m"), a byte unit on a row rate and a non-zero rate below 1 per second are rejected.
func ParseSize ¶
ParseSize parses a non-negative size: bare bytes or a B/KB/.../PiB unit (pkg/convert). A non-zero size below one byte is rejected: it would round to 0, which means no limit.
func ValidateConflictMatch ¶
ValidateConflictMatch checks `<kind>/<group>[/<name>]`: the kind is one of ConflictMatchKinds (case-sensitive), every segment is non-empty, and the group kind only takes the two-segment form. Wildcards are not supported.
Types ¶
type ConflictRule ¶
ConflictRule overrides the schema conflict policy of the resources its Match names: `<kind>/<group>` (every resource of that kind in the group, or the group itself for the group kind) or `<kind>/<group>/<name>`.
type Connection ¶
type Connection struct {
Cert string `flag:"cert" plan:"connection.nodesTLS.cert" env:"CERT" usage:"Certificate for tls"`
// LoggingLevel and LoggingEnv configure the client's own logger.
LoggingLevel string `flag:"logging-level" env:"LOGGING_LEVEL" default:"info" usage:"log level"`
LoggingEnv string `flag:"logging-env" env:"LOGGING_ENV" default:"prod" usage:"log environment: prod|dev"`
Nodes []string `` /* 136-byte string literal not displayed */
EnableTLS bool `flag:"enable-tls" plan:"connection.nodesTLS.enable" env:"ENABLE_TLS" usage:"Used to enable tls"`
Insecure bool `flag:"insecure" plan:"connection.nodesTLS.insecure" env:"INSECURE" usage:"Used to skip server's cert"`
}
Connection is how a data command reaches the liaisons and logs.
type DuplicationPolicy ¶
type DuplicationPolicy string
DuplicationPolicy is what a resumed import does with a stream or trace payload that may have landed already and that count reconciliation cannot decide. Measure and property payloads are always pushed again: a second copy converges to the first.
const ( // DuplicationBlock pushes nothing, lists the payloads and halts (exit 7). DuplicationBlock DuplicationPolicy = "block" // DuplicationWarn pushes the payload again with a warning naming what it may duplicate. DuplicationWarn DuplicationPolicy = "warn" // DuplicationPush pushes the payload again silently. DuplicationPush DuplicationPolicy = "push" // DuplicationSkip leaves the payload out and forces --verify on. DuplicationSkip DuplicationPolicy = "skip" )
The resume duplication policies of an import.
func ParseDuplicationPolicy ¶
func ParseDuplicationPolicy(raw string) (DuplicationPolicy, error)
ParseDuplicationPolicy accepts block, warn, push or skip.
type Export ¶
type Export struct {
Output string `` /* 162-byte string literal not displayed */
Checkpoint string `` /* 249-byte string literal not displayed */
OutputFormat string `flag:"output-format" short:"o" env:"OUTPUT_FORMAT" default:"table" usage:"dry-run rendering: table|yaml|json"`
Selectors []*transferv1.Selector `` /* 142-byte string literal not displayed */
MaxFileSize uint64 `` /* 226-byte string literal not displayed */
NodeRateLimit float64 `` /* 176-byte string literal not displayed */
NodeRowRateLimit float64 `` /* 192-byte string literal not displayed */
LiaisonRateLimit float64 `` /* 192-byte string literal not displayed */
NodeIdleTimeout time.Duration `` /* 167-byte string literal not displayed */
SendRetryTimeout time.Duration `` /* 253-byte string literal not displayed */
// Parallelism is math.MaxInt for "max".
Parallelism int `` /* 171-byte string literal not displayed */
Format transferv1.Format `flag:"format" plan:"export.format" env:"FORMAT" default:"csv" parse:"format" usage:"artifact format: csv|native"`
Compress transferv1.Compress `` /* 166-byte string literal not displayed */
CSVAnnotations bool `` /* 128-byte string literal not displayed */
IncludeSchema bool `` /* 185-byte string literal not displayed */
SchemaOnly bool `` /* 136-byte string literal not displayed */
Preempt bool `flag:"preempt" env:"PREEMPT" usage:"take over any export session the cluster already holds"`
Resume bool `` /* 216-byte string literal not displayed */
DryRun bool `` /* 127-byte string literal not displayed */
StrictCoverage bool `` /* 127-byte string literal not displayed */
}
Export is every setting of `data export`. The liaison rate limit is plan.yaml connection.rateLimit: it is a property of the liaisons, shared by export and import.
type Import ¶
type Import struct {
Input string `flag:"input" plan:"import.input" env:"IMPORT_INPUT" usage:"artifact directory written by data export"`
Checkpoint string `` /* 419-byte string literal not displayed */
OutputFormat string `flag:"output-format" short:"o" env:"OUTPUT_FORMAT" default:"table" usage:"rendering of the import plan: table|yaml|json"`
OnSchemaConflict string `` /* 272-byte string literal not displayed */
// DuplicationPolicy decides, at resume, what happens to a payload that may have landed
// already and cannot be reconciled.
DuplicationPolicy DuplicationPolicy `` /* 433-byte string literal not displayed */
ConflictRules []ConflictRule `flag:"-" plan:"import.schemaConflictPolicy.rules" parse:"conflict-rules"`
WriteBatchBytes uint64 `` /* 169-byte string literal not displayed */
WriteRateLimit float64 `` /* 216-byte string literal not displayed */
LiaisonRateLimit float64 `` /* 203-byte string literal not displayed */
NodeRateLimit float64 `` /* 260-byte string literal not displayed */
NodeRowRateLimit float64 `` /* 272-byte string literal not displayed */
PartRateLimit float64 `` /* 212-byte string literal not displayed */
PartChunkSize uint64 `` /* 181-byte string literal not displayed */
SendRetryTimeout time.Duration `` /* 288-byte string literal not displayed */
VerifyTimeout time.Duration `` /* 154-byte string literal not displayed */
// Parallelism is math.MaxInt for "max".
Parallelism int `` /* 197-byte string literal not displayed */
WriteBatchSize int `` /* 154-byte string literal not displayed */
DryRun bool `` /* 300-byte string literal not displayed */
Resume bool `` /* 216-byte string literal not displayed */
Restart bool `` /* 249-byte string literal not displayed */
IncludeSchema bool `` /* 178-byte string literal not displayed */
SchemaOnly bool `flag:"schema-only" plan:"import.schemaOnly" env:"IMPORT_SCHEMA_ONLY" usage:"write the schema only, without data"`
Force bool `flag:"force" usage:"confirm an overwrite schema conflict policy"`
ForceTTL bool `flag:"force-ttl" usage:"import units whose data the target TTL has already expired"`
StrictCoverage bool `` /* 317-byte string literal not displayed */
AllSources bool `flag:"all-sources" usage:"import every source of a unit instead of the minimal covering set"`
AbortOnPlanChange bool `flag:"abort-on-plan-change" usage:"exit 5 when the plan re-checked after writing the schema differs from the first one"`
Verify bool `` /* 170-byte string literal not displayed */
}
Import is every setting of `data import`. The liaison rate limit is plan.yaml connection.rateLimit, as for an export.
func (*Import) EffectiveVerify ¶
EffectiveVerify reports whether the import verifies the written rows: --verify is on and data is written (neither --schema-only nor --dry-run).
func (*Import) HasDuplicationSkip ¶
HasDuplicationSkip tells whether the policy is skip: a resume may then leave payloads out, which a verify checks.
func (*Import) HasOverwrite ¶
HasOverwrite reports whether the default schema conflict policy or any rule is overwrite.
func (*Import) Validate ¶
Validate checks the resolved import settings against each other before anything is contacted, naming the source of each offending setting. Every error is a usage error (exit 1):
- --write-batch-bytes outside [MinWriteBatchBytes, MaxWriteBatchBytes] (the dry run uses it for its batch warnings);
- --part-chunk-size outside [MinPartChunkSize, MaxPartChunkSize];
- --write-batch-size outside [MinWriteBatchSize, MaxWriteBatchSize] (not checked under --dry-run);
- --schema-only with --include-schema=false;
- --verify-timeout given explicitly (flag or plan.yaml) with --schema-only (not checked under --dry-run, which ignores it); with --verify=false it is accepted, because a skip duplication policy, or a payload an earlier run skipped and the progress file records, forces the verification on;
- --verify-timeout not positive while data is written (neither --schema-only nor --dry-run), whether verification is on or can be forced on;
- --force while neither the default policy nor any plan.yaml rule is overwrite;
- --restart with the --resume flag, unless --dry-run or --schema-only, which ignore --resume; a resume from BYDBCTL_IMPORT_RESUME yields to --restart instead, and is turned off;
type SelectorConfig ¶
SelectorConfig is one plan.yaml selectors[] entry: a catalog name and optional group names.
func ParseSelector ¶
func ParseSelector(raw string) (SelectorConfig, error)
ParseSelector parses the syntax of one selector "catalog=<name>[,groups=<g1>;<g2>]"; ToProto validates the catalog and group names like a plan.yaml selector. Group names containing any of ",;=" cannot be expressed in this syntax and must be given in the plan file.
func (*SelectorConfig) ToProto ¶
func (s *SelectorConfig) ToProto() (*transferv1.Selector, error)
ToProto converts the config selector to the wire selector, rejecting an unknown catalog and empty or duplicate group names.
type Sources ¶
type Sources struct {
// contains filtered or unexported fields
}
Sources records where each setting Resolve filled came from: "--<flag>", "plan.yaml <path>" or "BYDBCTL_<NAME>", nothing for a setting left at its default. A setting is named by a pointer to its field in the option struct Resolve filled, such as sources.FromFlag(&opts.Verify), so that settings of different structs sharing a flag name are told apart. A pointer to anything else is a programming error and panics.
func Resolve ¶
func Resolve(fs *pflag.FlagSet, lookupEnv func(string) (string, bool), opts ...any) (Sources, error)
Resolve fills every option struct in opts (pointers to structs bound with Bind on fs) with typed values. Each setting comes from its explicit flag, else the plan.yaml --plan names (when set), else the BYDBCTL_* variable lookupEnv finds (an empty value counts as unset), else the default. plan.yaml is strict: a key no option struct of this package declares is rejected. Errors name the source of the bad value.
func (Sources) Explicit ¶
Explicit reports whether the setting was given as a flag or in plan.yaml, rather than by the environment or the default.
func (Sources) FromEnv ¶
FromEnv reports whether the setting came from its BYDBCTL_* environment variable.