Documentation
¶
Overview ¶
Package planview reads a stored plan back the way the operator reads it.
The SQL an operator applies lives in immutable PtahSchemaPlanChunk objects that a plan manifest binds by index, size and digest. Reading them by hand means reproducing that binding, and the binding is not a format: a chunk boundary falls wherever 512 KiB falls, which may be the middle of a SQL string, of a JSON escape, or of a UTF-8 character. This package resolves which plan a reader asked for, hands the reconstruction to the operator's own store, and returns bytes that have already been checked against everything the plan says about itself.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrSchemaNotFound = errors.New("no such schema") ErrNoPlan = errors.New("no such plan") ErrUnsupported = errors.New("unsupported plan format") )
Errors a caller distinguishes. Absence is not an empty plan: a reader who asked for SQL that is not there is told so, with a status to match.
var Formats = []Format{Text, SQL, JSON}
Formats are the accepted values, in the order the help lists them.
Functions ¶
Types ¶
type Selection ¶
type Selection string
Selection is which stored plan a reader asked for.
They are two different questions and neither answers the other: the current plan is what the operator would run next, and the applied plan is what the last confirmed apply ran. A reader asking for one is never given the other, and neither is "the newest plan object in the namespace".
type View ¶
type View struct {
Namespace string
Schema string
Selection Selection
PlanName string
PlanUID types.UID
Fingerprint string
ContentDigest string
Dialect string
Destructive bool
// PrivilegeChanges are the kinds of authority the plan object records. They
// are what the manager decided on: any of them made the plan wait for an
// approval under apply: Always.
PrivilegeChanges []string
// UnrecordedPrivilegeChanges are kinds this plugin reads in the SQL and the
// plan object does not record. The manager that published the plan did not
// hold the plan for them, so they are shown apart from the recorded ones
// rather than as a reason the plan waited. They appear only where the
// plugin and the manager are different builds.
UnrecordedPrivilegeChanges []string
StatementCount int
CreatedAt metav1.Time
// CompletedAt is when the apply this plan belongs to finished. It is set
// for an applied plan and empty for a current one, which has not run.
CompletedAt *metav1.Time
Document []byte
Plan dataplane.PlanFile
}
View is one verified plan.
Document holds the bytes the store reconstructed and checked against the plan's content digest. They are the plan as it was published, and printing them is how a reader gets a document that still matches that digest.
func Load ¶
func Load( ctx context.Context, reader client.Reader, namespace, name string, selection Selection, ) (View, error)
Load resolves the selected plan, reconstructs it and verifies it.
Nothing reaches the caller before every check has held. A plan whose last chunk is corrupt produces an error and no document, rather than an error after half the SQL has already been handed over.