checksum

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package checksum compares the shadow table with its source and mints the proofs the cutover demands of that comparison (CO-1, CO-2, CO-3). A Verifier reads every key at or below the copier's landed watermark in chunks, cutting each chunk and digesting both tables inside one read-only REPEATABLE READ transaction per chunk so the cut and the two digests describe one snapshot and the cut is bounded like the reads (LK-2), with every column cast to the type the shadow declares so a schema change that converts a column compares as the shadow holds it (D7). Each transaction runs under the table's lock session and refuses relations that are no longer the ones the proofs describe. Verify reports what differed; Check runs the same pass under a DivergencePolicy the caller states for every pass — abort on a difference; repair, which recopies every differing chunk from the source with the copier's own statement in one transaction and reads each again, assuming nothing else writes the shadow and the source rows it recopies hold still until the rereads; or recopy, the same recopy with no reread, for a source written while the pass runs whose later writes a stream opened before the pass carries — a recopy that collides with a shadow row because the source moved a unique value from a chunk the comparison read equal into a differing chunk is rolled back, and the pass compares again and recopies what that comparison finds, a bounded number of times. CheckLive is the pass for a source written while the catch-up applies the stream to the shadow: a chunk that differs in the sweep is read again once the catch-up has confirmed past the position it was read at, and the two reads are judged together — equal or the shadow at the earlier source state is settled, movement on either side is another reread up to a stated bound, stillness on both sides is the divergence; its repair holds the catch-up's flushes off the shadow through the catch-up's own gate while it recopies, with SHARE MODE against any other writer, and settles each repaired chunk the same way. Only a pass that found no difference and repaired nothing mints a CleanWatermark, and a VerifiedShadow when its watermark is complete; the proofs' constructors are private to this package.

Index

Constants

View Source
const (
	// DefaultSettleAttempts is how many fresh rereads a live pass gives a
	// chunk whose rows keep changing before it reports the chunk unsettled.
	DefaultSettleAttempts = 3
	// DefaultSettleWait is the longest a live pass waits for the catch-up
	// to confirm past the position a chunk was read at.
	DefaultSettleWait = 30 * time.Second
	// DefaultSettlePoll is how often a live pass asks the catch-up for its
	// confirmed position while it waits.
	DefaultSettlePoll = 100 * time.Millisecond
)

Default bounds of a live pass's settling.

View Source
const DefaultRecopyAttempts = 5

DefaultRecopyAttempts is the number of times a recopy pass compares and recopies before it stops on a recopy that keeps colliding, when Options leaves RecopyAttempts zero.

Variables

View Source
var (
	// ErrInvariantViolation marks a fail-closed refusal; the wrapped message
	// names the invariant.
	ErrInvariantViolation = dbconn.ErrInvariantViolation
	// ErrInvalidOptions reports verifier options that cannot bound a pass: a
	// timeout below PostgreSQL's one-millisecond resolution, which the server
	// would read as no timeout at all.
	ErrInvalidOptions = errors.New("invalid verifier options")
	// ErrNothingLanded reports a pass asked to verify up to the zero
	// watermark, below which no key has been copied: there is nothing to
	// compare, and a pass that compared nothing must not read as clean.
	ErrNothingLanded = errors.New("nothing has landed to verify")
	// ErrPassRunning reports a pass started on a verifier whose previous
	// pass has not returned. A verifier runs one pass at a time: the
	// counters it reports and its registration with the tracker belong to
	// the pass in progress, and a second pass would reset the one and end
	// the other.
	ErrPassRunning = errors.New("a verification pass is already running")
)
View Source
var ErrNoDivergencePolicy = errors.New("no divergence policy")

ErrNoDivergencePolicy reports a pass asked to run without saying what a difference means.

View Source
var ErrVerificationUnresolved = errors.New("live verification could not settle a chunk")

ErrVerificationUnresolved is the sentinel an UnresolvedError unwraps to: a live pass could not decide whether a differing chunk is a divergence or a chunk the stream has not yet settled.

Functions

This section is empty.

Types

type CleanWatermark

type CleanWatermark struct {
	// contains filtered or unexported fields
}

CleanWatermark proves every chunk through its watermark was clean on a fresh read and that the pass repaired nothing. Its zero value is forgeable; consumers must reject it when Watermark().Valid() is false. Only a pass (Check or CheckLive) that found no difference and repaired nothing mints one (CO-2).

func (CleanWatermark) Watermark

func (w CleanWatermark) Watermark() copier.Watermark

Watermark returns the clean copied-through watermark.

type ConfirmedSource added in v0.4.0

type ConfirmedSource interface {
	Confirmed() decode.LSN
}

ConfirmedSource answers how far the catch-up has applied the stream: the position it last confirmed to the server, below which every change to a landed key is committed in the shadow. The applier's Catchup is one. An implementation of its own must answer from memory without blocking — a live pass reads it from its own goroutine once every LiveOptions.Poll while it waits — must never answer lower than it already has, and must follow the walsender's own position, not only the transactions it delivers: the pass waits for the position of a marker it wrote, which no transaction carries, and a source that advances only on applied transactions never reaches it on a quiet table.

type Digest added in v0.4.0

type Digest struct {
	// Rows is the number of rows whose key lies in the chunk.
	Rows int64
	// Hash is the hex SHA-256 of the concatenation, in key order, of the
	// per-row SHA-256 of the row's copy columns rendered as a record. It is
	// the SHA-256 of the empty input for an empty range.
	Hash string
}

Digest is one side's summary of a chunk: how many rows the range holds and an order-sensitive hash of every one of them.

type DivergenceError added in v0.4.0

type DivergenceError struct {
	// Report is the pass that found the differences.
	Report Report
}

DivergenceError is a pass that found differences under DivergenceAbort. It carries the report so the caller can say which chunks differed; the shadow is as the pass found it.

func (*DivergenceError) Error added in v0.4.0

func (e *DivergenceError) Error() string

type DivergencePolicy added in v0.4.0

type DivergencePolicy string

DivergencePolicy says what a pass does with a chunk whose source and shadow differ. It is a setting the caller states for every pass, never a default and never inferred from what happens to be wired up (CO-3): in the steady state a divergence is a defect and aborts; only a pass that expects differences — reconciliation after a lost replication slot — recopies them. The zero value names no policy and is refused.

const (
	// DivergenceAbort ends the pass at its report: nothing is written, and
	// the caller refuses to cut over.
	DivergenceAbort DivergencePolicy = "abort"
	// DivergenceRepair recopies every differing chunk from the source and
	// reads it again, refusing a chunk that still differs; it is for a
	// source that holds still through the pass. The pass mints no proof.
	DivergenceRepair DivergencePolicy = "repair"
	// DivergenceRecopy recopies every differing chunk from the source and
	// reads none of them again; it is for a source that is written while
	// the pass runs, when a stream opened before the pass carries every
	// write that lands after a recopy, so a fresh read now would refuse a
	// chunk the stream is about to settle. The pass mints no proof.
	DivergenceRecopy DivergencePolicy = "recopy"
)

func ParseDivergencePolicy added in v0.4.0

func ParseDivergencePolicy(value string) (DivergencePolicy, error)

ParseDivergencePolicy returns the policy a configuration value or flag names, or ErrNoDivergencePolicy when it names neither, so a caller can refuse a setting when it loads it rather than at its first pass. Only DivergenceAbort and DivergenceRepair can be named this way: a setting is for the steady state, where a divergence is a defect and a pass that heals one without reading it back would hide the defect. DivergenceRecopy is selected by the reconcile mode alone, never by a setting.

type FlushGate added in v0.4.0

type FlushGate interface {
	Pause(ctx context.Context) (resume func(), err error)
}

FlushGate holds the catch-up's flushes off the shadow for as long as a live repair recopies it. The applier's Catchup is one. Pause returns once no flush is in flight, with none starting until resume is called, or with ctx's cause once ctx ends first; the catch-up goes on reading and confirming the stream under the hold, so what the source writes meanwhile is buffered and flushed after the resume. An implementation of its own must make the same promise: nothing the stream carries writes the shadow between Pause's return and the resume. The caller calls resume exactly once on every path after Pause returns a nil error, including when its own work fails, so an implementation need not tolerate a second call or a missing one.

type LiveOptions added in v0.4.0

type LiveOptions struct {
	// Confirmed is the catch-up applying the stream to the shadow.
	Confirmed ConfirmedSource
	// Flushes holds that catch-up's flushes off the shadow while a repair
	// recopies it. A pass under DivergenceRepair requires it; a pass under
	// DivergenceAbort recopies nothing and leaves it unused. The applier's
	// Catchup serves as both Confirmed and Flushes.
	Flushes FlushGate
	// Attempts is how many fresh rereads a chunk that keeps changing gets
	// before the pass reports it unsettled.
	Attempts int
	// SettleWait bounds each wait for the catch-up to confirm past the
	// position a chunk was read at. It is spent in sleeps of Poll, so it
	// must be at least one Poll long.
	SettleWait time.Duration
	// Poll is the interval between reads of the catch-up's confirmed
	// position during a wait.
	Poll time.Duration
	// Sleep waits between polls; nil waits on the wall clock. Tests inject
	// one to drive the settling without real time passing.
	Sleep func(ctx context.Context, d time.Duration) error
}

LiveOptions bounds how a live pass settles a chunk that differed while the source is written and the catch-up applies the stream. Zero values take the defaults; Confirmed has none and is required, and so is Flushes under DivergenceRepair. Attempts and SettleWait bound each chunk, not the pass: a pass over many differing chunks can spend them on every one, so a caller with a deadline of its own passes it on the context.

type Mismatch added in v0.4.0

type Mismatch struct {
	// Chunk is the closed key range the two digests cover.
	Chunk copier.Chunk
	// Source is the source table's digest of the chunk.
	Source Digest
	// Shadow is the shadow table's digest of the chunk.
	Shadow Digest
}

Mismatch is one chunk whose source and shadow digests differ: the range, and what each side reported for it. It says that the two sides differed within one snapshot, not why; the divergence policy that acts on it is the caller's.

type Options added in v0.4.0

type Options struct {
	// LockTimeout bounds every lock wait inside a chunk transaction.
	LockTimeout time.Duration
	// StatementTimeout bounds every statement inside a chunk transaction.
	StatementTimeout time.Duration
	// Chunker sizes the chunks a pass compares. They are cut independently
	// of the chunks the copier copied; only the key range matters.
	Chunker copier.ChunkerOptions
	// Clock times each chunk for the chunker's chunk-time sizing feedback
	// (docs/copy-and-swap-design.md#d12--throttle-by-chunk-time-and-slot-lag).
	Clock progress.Clock
	// Tracker, when set, is told the pass's work for the lifetime of Verify
	// or Check: the verifier is its progress.WorkSource from before the
	// first chunk until just before the call returns, through the repair
	// phase as well. The caller owns the tracker's steps; the verifier only
	// fills the current step's counters.
	Tracker *progress.Tracker
	// RecopyAttempts is the number of times a pass under DivergenceRecopy
	// compares and recopies before it stops on a recopy that keeps
	// colliding with a unique value the source moves between chunks. Zero
	// takes DefaultRecopyAttempts; one recopies once and never compares
	// again.
	RecopyAttempts int
}

Options bounds a verification pass. Zero values take the defaults: the dbconn session timeouts for every chunk transaction, the copier's ChunkerOptions defaults, and the wall clock.

type Outcome added in v0.4.0

type Outcome struct {
	// Report is the comparison the pass acted on: the one before the
	// repair, or under DivergenceRecopy the last one made, which is the
	// comparison the committed recopy — or the recopy that stopped the
	// pass — was cut from. It is the zero Report when no comparison ran.
	Report Report
	// Repairs lists the chunks the pass recopied and committed under
	// DivergenceRepair or DivergenceRecopy, in ascending key order, whether
	// or not every one then read equal. It is empty under DivergenceAbort
	// and for a clean pass.
	Repairs []Repair
	// Collisions is the number of recopies under DivergenceRecopy the
	// server refused because a shadow row still held one of their values
	// under a unique index or an exclusion constraint, each followed by
	// another comparison and recopy or by the pass stopping. It is zero
	// under every other policy.
	Collisions int
	// contains filtered or unexported fields
}

Outcome is one pass run under a divergence policy: what it compared and found, what it repaired, and — only when it found nothing and repaired nothing — the proofs the cutover and the checkpoint demand. A pass that repaired a chunk has read that chunk clean afterwards, but it mints no proof: the proof comes from the next pass, which reads every chunk fresh (CO-2). Check returns an Outcome with its error too, so what a failed pass compared and wrote to the shadow is never lost.

func (Outcome) Clean added in v0.4.0

func (o Outcome) Clean() bool

Clean reports whether the pass read every compared chunk equal and so minted the clean watermark. A pass that found a difference, repaired anything, or was refused is not clean, whatever its Report says.

func (Outcome) CleanWatermark added in v0.4.0

func (o Outcome) CleanWatermark() (CleanWatermark, bool)

CleanWatermark returns the proof that every chunk through the pass's watermark was read clean, and whether the pass minted one.

func (Outcome) VerifiedShadow added in v0.4.0

func (o Outcome) VerifiedShadow() (VerifiedShadow, bool)

VerifiedShadow returns the proof that the whole shadow equals its source, and whether the pass minted one: a clean pass through the complete watermark does; a clean pass through a partial watermark proves only its prefix and does not.

type Repair added in v0.4.0

type Repair struct {
	// Mismatch is the difference the pass found before the repair.
	Mismatch Mismatch
	// Removed is the number of shadow rows the repair deleted from the chunk.
	Removed int64
	// Inserted is the number of source rows the repair copied back.
	Inserted int64
}

Repair is one chunk a pass recopied under DivergenceRepair or DivergenceRecopy: the difference it found, and what the recopy removed and put back. The recopy has committed; whether the chunk then read equal is the pass's result, not the Repair's — under DivergenceRepair a chunk that did not is named by a RepairError alongside the Repairs that committed with it, and under DivergenceRecopy no chunk is read again.

type RepairError added in v0.4.0

type RepairError struct {
	// Repair is the recopy that did not take.
	Repair Repair
	// After is the chunk as the fresh read found it.
	After Mismatch
}

RepairError is a chunk that still differed when read again after its repair. A recopy that does not converge means something other than the copier writes the shadow, or the source changed between the recopy and the read, which a repair pass assumes does not happen; either way the pass cannot vouch for the chunk, and repairing it again would not say why. The recopy has committed, with every other chunk's: the Outcome returned alongside lists them.

func (*RepairError) Error added in v0.4.0

func (e *RepairError) Error() string

type Report added in v0.4.0

type Report struct {
	// Through is the watermark the pass verified up to: every chunk at or
	// below it was read.
	Through copier.Watermark
	// Chunks is the number of chunks the pass compared.
	Chunks int
	// Rows is the number of source rows the pass hashed.
	Rows int64
	// Mismatches lists the chunks whose digests differed, in ascending key
	// order. It is empty for a clean pass. Under a live pass these are the
	// confirmed divergences: chunks that still differed once the stream had
	// delivered everything the sweep saw.
	Mismatches []Mismatch
	// Settled is the number of chunks a live pass found differing in its
	// sweep and then read clean, or read with the shadow at exactly the
	// state the sweep saw on the source, once the catch-up had confirmed
	// past the sweep's read. A quiesced pass settles nothing.
	Settled int
	// Unsettled is the number of chunks a live pass found differing in its
	// sweep and could settle neither way within its bounds: the catch-up
	// did not confirm past the read in time, or the chunk changed on every
	// reread. They are not in Mismatches, since nothing was confirmed about
	// them, and a report that counts any is not clean. A quiesced pass
	// leaves nothing unsettled.
	Unsettled int
}

Report is the outcome of one verification pass over the keys at or below a watermark: how much it read and every chunk that differed. A pass that finds no mismatch is clean, and only a clean pass can back a proof; the report itself proves nothing and is not one.

func (Report) Clean added in v0.4.0

func (r Report) Clean() bool

Clean reports whether every compared chunk matched or settled, with none left unsettled.

type UnresolvedCause added in v0.4.0

type UnresolvedCause string

UnresolvedCause says why a live pass gave up on a chunk.

const (
	// CauseLagging is a catch-up that did not confirm past the position the
	// chunk's digests were read at within LiveOptions.SettleWait.
	CauseLagging UnresolvedCause = "lagging"
	// CauseHot is a chunk whose source or shadow changed on every one of
	// LiveOptions.Attempts rereads, so no two reads could be compared.
	CauseHot UnresolvedCause = "hot"
)

type UnresolvedError added in v0.4.0

type UnresolvedError struct {
	// Chunk is the closed key range the pass could not settle.
	Chunk copier.Chunk
	// Cause says whether the catch-up fell behind or the chunk kept moving.
	Cause UnresolvedCause
	// Rereads is the number of fresh-snapshot rereads the pass made of the
	// chunk before it gave up.
	Rereads int
	// Source and Shadow are the two digests of the pass's last read.
	Source Digest
	Shadow Digest
	// Captured is the position of the marker the last read wrote to the
	// WAL; every change the read saw committed before it, and the pass was
	// waiting for the catch-up to confirm past it.
	Captured decode.LSN
	// Confirmed is the catch-up's confirmed position when the pass gave up.
	Confirmed decode.LSN
}

UnresolvedError is a chunk a live pass could neither read clean nor confirm divergent. It is not a finding about the data: the shadow is as the pass found it, and the caller decides whether to run the pass again or wait for the source to quiet down. It unwraps to ErrVerificationUnresolved.

func (*UnresolvedError) Error added in v0.4.0

func (e *UnresolvedError) Error() string

Error says what the pass could not decide and what to do about it: a lagging catch-up wants the pass run again once it has caught up, and a hot chunk wants a quieter source.

func (*UnresolvedError) Unwrap added in v0.4.0

func (e *UnresolvedError) Unwrap() error

Unwrap makes every UnresolvedError match ErrVerificationUnresolved.

type VerifiedShadow

type VerifiedShadow struct {
	// contains filtered or unexported fields
}

VerifiedShadow proves a full checksum pass found source and shadow equal. Its zero value is forgeable; consumers must reject a proof whose Table is empty. Only a pass that compared every key, found no difference, and repaired nothing mints one (CO-1, CO-2): Check, over a quiesced source, and CheckLive, over a source the stream is carrying to the shadow. The proof says which (Live), because the two do not mean the same thing to the swap: a quiesced proof is the shadow equal to the source as it stands, and a live proof is the shadow equal to the source as of the position the pass settled against, with every change since in the stream, which the swap must drain under its lock before it renames. It names the two relations by OID as well as by name: the shadow's name is derived from the source's, so a shadow rebuilt after this proof was minted wears the same name while holding none of the rows the pass compared.

func (VerifiedShadow) Live added in v0.4.0

func (v VerifiedShadow) Live() bool

Live reports whether the pass that minted the proof ran while the stream was applying the source's changes to the shadow. A live proof holds only up to the position the pass settled against; the swap that acts on it must drain the stream's remaining changes under its lock before it renames, and the cutover refuses a live proof with no drain.

func (VerifiedShadow) Schema

func (v VerifiedShadow) Schema() string

Schema returns the verified source schema.

func (VerifiedShadow) Shadow

func (v VerifiedShadow) Shadow() string

Shadow returns the verified shadow table.

func (VerifiedShadow) ShadowOID added in v0.4.0

func (v VerifiedShadow) ShadowOID() uint32

ShadowOID returns pg_class.oid of the shadow relation the pass compared.

func (VerifiedShadow) SourceOID added in v0.4.0

func (v VerifiedShadow) SourceOID() uint32

SourceOID returns pg_class.oid of the source relation the pass compared.

func (VerifiedShadow) Table

func (v VerifiedShadow) Table() string

Table returns the verified source table.

func (VerifiedShadow) VerifiedAt

func (v VerifiedShadow) VerifiedAt() time.Time

VerifiedAt returns the verification time.

func (VerifiedShadow) Watermark

func (v VerifiedShadow) Watermark() copier.Watermark

Watermark returns the copied-through watermark at verification.

type Verifier added in v0.4.0

type Verifier struct {
	// contains filtered or unexported fields
}

Verifier compares a proven source table with its built shadow, chunk by chunk, and reports every chunk whose rows differ. Each chunk is read in its own short read-only transaction whose one snapshot covers both tables, so a chunk's two digests describe the same instant and no pass holds a snapshot open for longer than one chunk. It runs only under the table's lock session. The only state a Verifier keeps between passes is the counters of the pass in progress, which the next pass resets, so the same one runs a pass after every repair, one pass at a time; a pass started while another runs is refused with ErrPassRunning.

func NewVerifier added in v0.4.0

func NewVerifier(target preflight.CopySwapTarget, shadow copier.Shadow, lock *dbconn.TableLockSession, opts Options) (*Verifier, error)

NewVerifier prepares verification of target against shadow. It refuses a proof, shadow, or lock session that does not describe this table, and options that cannot bound a pass. The shadow is checked as the copier checks it: the verifier reads both relations the copier wrote between and must refuse everything the copier would have.

func (*Verifier) Check added in v0.4.0

func (v *Verifier) Check(ctx context.Context, pool *pgxpool.Pool, through copier.Watermark, policy DivergencePolicy) (Outcome, error)

Check runs one verification pass through the copier's landed watermark and acts on what it finds as policy says. A clean pass mints a CleanWatermark, and a VerifiedShadow when the watermark is complete. Under DivergenceAbort a difference is returned as a *DivergenceError carrying the report, with the shadow untouched. Under DivergenceRepair every differing chunk is recopied from the source in one transaction and then read again in a fresh snapshot; a chunk still different after its repair is returned as a *RepairError, with the Outcome listing every repair that committed. A pass whose repairs all took returns a nil error and no proof. Under DivergenceRecopy every differing chunk is recopied the same way and none is read again: the pass returns the committed repairs, a nil error, and no proof. The policy is stated for every pass; there is no default (CO-3).

A repair pass assumes nothing else writes the shadow and no source row in a differing chunk changes between the pass and its rereads; a write that lands inside it makes the repaired chunk read different again, and the pass refuses it as a RepairError rather than repair it twice. A recopy pass is the reconciliation after slot loss: the source is written while it runs, and every write committed after the new slot's consistent point replays when the stream reopens, so a recopied chunk a write lands in afterwards converges under the applier as any copied chunk does, and a fresh read now would refuse what the stream is about to settle. One write the recopy cannot absorb is a unique value the source moved from a row in a chunk the comparison read equal to a row in a differing chunk after the comparison read the equal one: the recopy's insert collides with the shadow row still holding the value. The pass then compares again — the equal chunk now differs too — and recopies what it finds, up to Options.RecopyAttempts times, counting each collision in the Outcome; a recopy that collides on the last attempt ends the pass with the server's error.

While it runs, through the repair phase as well, the verifier is the tracker's work source (Options.Tracker). A Check that overlaps a pass still running on this verifier is refused with ErrPassRunning.

func (*Verifier) CheckLive added in v0.4.0

func (v *Verifier) CheckLive(ctx context.Context, pool *pgxpool.Pool, through copier.Watermark, policy DivergencePolicy, live LiveOptions) (Outcome, error)

CheckLive runs one verification pass through the copier's landed watermark while the source is written and the catch-up applies the stream to the shadow, and acts on what it finds as policy says. The sweep is the same as Check's: every chunk cut and digested on both sides in one snapshot. A chunk that differs in the sweep is not yet a finding, since the shadow may simply not have received the source's latest writes: the pass writes a marker to the WAL in the chunk's transaction, waits for the catch-up to confirm past it, reads the chunk again in a fresh snapshot, and judges the two reads together (settle). A chunk whose two sides then agree, or whose shadow has reached exactly what the sweep saw on the source, is settled and counts as clean; a chunk that kept changing is reread up to LiveOptions.Attempts times and then left unsettled; a chunk that held still on both sides across a confirmed position and still differs is a divergence. The sweep's premise is that the stream is the shadow's only writer, so the shadow either lags the source or has caught up to it, and nothing else moves it.

Every differing chunk is settled before the pass decides anything, so one chunk that will not settle does not hide a divergence in another; the Report counts the unsettled chunks and lists the confirmed divergences. A clean pass — every chunk equal or settled — mints the proofs as Check does, marked as a live pass's. A pass with unsettled chunks and no divergence returns the first unsettled chunk as an *UnresolvedError: not a finding about the data, the shadow is as the pass found it, and the caller runs the pass again. Under DivergenceAbort a divergence is returned as a *DivergenceError with the shadow untouched, whether or not other chunks were unsettled. Under DivergenceRepair every divergent chunk is recopied from the source in one transaction, with the catch-up's flushes held off the shadow through LiveOptions.Flushes for as long as it runs and SHARE MODE on the shadow against any other writer; the pass resumes the flushes, waits for the catch-up to confirm past the recopy, and settles the chunk again; a chunk divergent after its repair is a *RepairError, and a pass whose repairs all took but which left other chunks unsettled returns the first of them as an *UnresolvedError with the repairs committed and listed in the Outcome. A pass with repairs mints no proof (CO-2). DivergenceRecopy is refused: it is the reconcile mode's policy for a pass that reads nothing again, and a live pass settles every chunk it recopies.

While it runs the verifier is the tracker's work source: the sweep's differing chunks count as chunks_mismatched, and every settling reread as chunks_reread. A CheckLive that overlaps a pass still running on this verifier is refused with ErrPassRunning.

func (*Verifier) Verify added in v0.4.0

func (v *Verifier) Verify(ctx context.Context, pool *pgxpool.Pool, through copier.Watermark) (Report, error)

Verify runs one pass over every key at or below through — the copier's landed watermark, below which every chunk has committed — and reports what it found. Keys above the watermark are not compared: they are in chunks the copier has not finished, and a difference there is expected, not a finding. The pass reads the shadow's column types once, then cuts and digests each chunk in one guarded transaction of its own, so the cut and both digests read one snapshot and the cut's lock wait is bounded like the reads. It stops at the first error; a report with mismatches is not an error, and the caller's divergence policy decides what to do with it. Every transaction runs under the lock session's Bind context, so losing the table lock cancels the read in flight and Verify reports the loss. While it runs the verifier is the tracker's work source (Options.Tracker). A Verify that overlaps a pass still running on this verifier is refused with ErrPassRunning.

func (*Verifier) Work added in v0.4.0

func (v *Verifier) Work(context.Context) (progress.Work, error)

Work reports the pass's counters for the progress tracker: it is the progress.WorkSource the verifier registers for the lifetime of Verify or Check. Every counter is read from memory — the pass knows what it has digested and recopied — so a poll never waits on the database, and the counters reset to zero when a pass starts.

  • chunks_compared is the number of chunks the comparison has digested on both sides; a digest counts when its transaction commits. Under DivergenceRecopy a recopy that collided is followed by another comparison, whose chunks count here too, so the figure can pass the number of chunks through the watermark.
  • rows_hashed is the number of source rows those digests covered.
  • chunks_mismatched is the number of chunks the comparison found differing.
  • chunks_repaired is the number of chunks whose recopy has committed. Every differing chunk is recopied in one transaction, so it moves from zero to chunks_mismatched at that commit.
  • chunks_reread is the number of chunks digested again in a fresh snapshot after the comparison: under Check the repaired chunks reread after the recopy, so it climbs towards chunks_repaired and the repair phase's remaining work is chunks_repaired − chunks_reread; under CheckLive every settling reread of a differing or repaired chunk, so it can pass chunks_mismatched while the pass waits on a chunk that keeps changing.

The counters are the pass's, not the step's: once the pass returns the tracker no longer asks the verifier, and the pass's final figures are the Report or Outcome it returned.

Jump to

Keyboard shortcuts

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