busy
Classifying and retrying SQLite failures on the cache.
The pod, its flow child processes and the API threads all write one SQLite file, so a write can find itself behind another writer. SQLite reports several unrelated faults as the same exception type, and only one of them is worth retrying: a busy file clears by itself, a full disk does not. Splitting them out lets a caller retry the first and report the rest.
Module
Functions
classify_operational_error
def classify_operational_error(error: BaseException) ‑> str:Return which of the known causes error names, or "other".
Only the message is read, never the SQL or the bound parameters, so the result is safe to report to telemetry: a site's paths and values never reach it.
Arguments
error: The exception a cache write raised.
Returns
One of "locked", "disk_full", "io_error", "readonly",
"corrupt", "too_many_variables" or "other".
is_lock_contention
def is_lock_contention(error: BaseException) ‑> bool:Return whether error is another writer holding the file.
Arguments
error: The exception a cache write raised.
Returns Whether the failure is lock contention, and so may clear by itself.
retry_on_lock_contention
def retry_on_lock_contention( operation: Callable[[], _T], *, what: str, attempts: int = 8, initial_delay_seconds: float = 1.0, max_delay_seconds: float = 30.0,) ‑> ~_T:Run operation, retrying while another writer holds the file.
The delay starts at initial_delay_seconds and doubles up to max_delay_seconds between tries, so the default budget is about two minutes: long enough for a large write in another process to finish, short enough that a genuinely stuck holder still fails the caller.
Nothing is retried unless the failure classifies as lock contention, so a full disk or a corrupt file fails on the first try.
Arguments
operation: The write to run. Must be safe to run again after it raised, which a failed write transaction is: nothing was committed.what: What the write does, for the log line.attempts: How many times to run operation, including the first.initial_delay_seconds: The delay after the first failure.max_delay_seconds: The largest delay between tries.
Returns Whatever operation returned.
Raises
sqlalchemy.exc.OperationalError: The last failure, once the attempts are spent or when it was not lock contention.
Global variables
CLASSIFIED_LOCKED : Final[str]- Another writer held the file for longer than the busy timeout allowed.