Documentation
¶
Overview ¶
Package sqlx holds the transaction helpers the rag packages share: running a transaction again, whole, when it loses against a concurrent writer.
The package does not know which SQLite driver the caller uses, so the test for "this error means the writer lost a race" is a parameter. Callers that own a precise classifier (Pando's internal/db.IsRetryable understands the multiwriter engine's error types) pass it in; everyone else gets DefaultRetryable, which matches the error text every SQLite driver produces.
Index ¶
- Constants
- func DefaultRetryable(err error) bool
- func RetryLoop(ctx context.Context, retryable Retryable, fn func() error) error
- func RunTx(ctx context.Context, conn TxBeginner, retryable Retryable, ...) error
- func RunTxOpts(ctx context.Context, conn TxBeginner, opts *sql.TxOptions, retryable Retryable, ...) error
- type Retryable
- type TxBeginner
Constants ¶
const RetryBudget = 30 * time.Second
RetryBudget bounds how long one operation keeps retrying a lost commit before the error is returned to the caller.
Variables ¶
This section is empty.
Functions ¶
func DefaultRetryable ¶
DefaultRetryable recognises SQLITE_BUSY, SQLITE_LOCKED (including the extended BUSY_SNAPSHOT code) and "database is locked" by their error text, which every Go SQLite driver includes in its messages.
func RetryLoop ¶
RetryLoop runs fn until it succeeds, fails with an error retryable does not accept, the context ends or RetryBudget is spent. The backoff starts in the microseconds: a lost commit retried against a fresh snapshot usually wins at once. A nil retryable means DefaultRetryable.
func RunTx ¶
RunTx runs fn inside a transaction and commits it. When the commit (or any statement) loses against a concurrent writer, the transaction is rolled back and fn runs again, whole, on a fresh snapshot.
fn may therefore run more than once: it must only act through tx and must not have effects outside the transaction (send events, mutate shared state) before RunTx returns. Compute expensive inputs such as embeddings before calling RunTx.