Transactions #
Tx m α is a transaction body of mode m that returns α. Bodies compose with do notation,
raise and catch TypeDBError, and run IO (whose errors become TypeDBError.io).
Tx is an irreducible definition, not an abbreviation, so that Tx .read α and Tx .write α
are different types: a body that writes cannot be passed where a read body is expected. Operations take an
[Allows m need] instance, so a read-mode body cannot call one that needs a write.
Driver.runSync is the transactor: it opens the transaction, runs the body, commits a write or
schema transaction when the body succeeds, and closes the transaction without committing when
the body fails. A retry policy can re-run the whole body when the commit loses a conflict.
What a transaction body runs against.
- driver : Driver
- handle : Native.TxHandle
- database : String
- mode : TxMode
- options : TxOptions
Instances For
A transaction body of mode m returning α: a reader over the transaction's context.
It is irreducible, so Tx .read α and Tx .write α stay different types, while the compiler
still sees a ReaderT over EIO and turns loops over it into plain loops.
Equations
- TypeDB.Tx _m α = ReaderT TypeDB.TxCtx (EIO TypeDB.TypeDBError) α
Instances For
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- TypeDB.Tx.instMonadExceptOfTypeDBError = { throw := @TypeDB.Tx.instMonadExceptOfTypeDBError._aux_1 m, tryCatch := @TypeDB.Tx.instMonadExceptOfTypeDBError._aux_3 m }
Equations
- TypeDB.Tx.instMonadFinally = { tryFinally' := @TypeDB.Tx.instMonadFinally._aux_1 m }
Equations
Equations
- TypeDB.Tx.instMonadLiftIO = { monadLift := fun {α : Type} (x : IO α) => TypeDB.Tx.mk fun (x_1 : TypeDB.TxCtx) => liftM x }
Equations
- TypeDB.Tx.instMonadLiftBaseIO = { monadLift := fun {α : Type} (x : BaseIO α) => TypeDB.Tx.mk fun (x_1 : TypeDB.TxCtx) => liftM x }
Equations
- TypeDB.Tx.instMonadLiftReadWrite = { monadLift := fun {α : Type} => TypeDB.Tx.widen }
Equations
- TypeDB.Tx.instMonadLiftReadSchema = { monadLift := fun {α : Type} => TypeDB.Tx.widen }
Equations
- TypeDB.Tx.instMonadLiftWriteSchema = { monadLift := fun {α : Type} => TypeDB.Tx.widen }
Equations
- TypeDB.Tx.instInhabited = { default := TypeDB.Tx.mk fun (x : TypeDB.TxCtx) => throw (TypeDB.TypeDBError.internal "uninhabited transaction body") }
The transaction's context.
Equations
Instances For
Runs a native call, classifying its error.
Equations
- TypeDB.Tx.native x = liftM (TypeDB.native x)
Instances For
Rolls back the writes made so far without ending the transaction.
Equations
- TypeDB.Tx.rollback = do let __do_lift ← TypeDB.Tx.ctx TypeDB.Tx.native (TypeDB.Native.txRollback __do_lift.handle)
Instances For
Transactions that may implement Tx m operations, for user monad stacks such as
ReaderT Env (Tx .write). Any monad with a MonadLiftT (Tx m) instance qualifies.
Equations
- TypeDB.MonadTypeDB m n = MonadLiftT (TypeDB.Tx m) n
Instances For
Equations
- One or more equations did not get rendered due to their size.
- TypeDB.instReprBackoff.repr TypeDB.Backoff.none prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "TypeDB.Backoff.none")).group prec✝
Instances For
Equations
- TypeDB.instReprBackoff = { reprPrec := TypeDB.instReprBackoff.repr }
Equations
When run re-runs a transaction body.
- never : RetryPolicy
- conflicts
(retries : Nat)
(backoff : Backoff := Backoff.exponential 20)
: RetryPolicy
Re-run on commit conflicts, at most
retriestimes. Other errors are never retried.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- TypeDB.instReprRetryPolicy.repr TypeDB.RetryPolicy.never prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "TypeDB.RetryPolicy.never")).group prec✝
Instances For
Equations
- TypeDB.instReprRetryPolicy = { reprPrec := TypeDB.instReprRetryPolicy.repr }
Equations
Equations
- TypeDB.RetryPolicy.delayMs TypeDB.Backoff.none x✝ = 0
- TypeDB.RetryPolicy.delayMs (TypeDB.Backoff.constant ms) x✝ = ms
- TypeDB.RetryPolicy.delayMs (TypeDB.Backoff.exponential b cap) x✝ = min cap (b * 2 ^ x✝)
Instances For
Opens one transaction, runs body, and commits (write and schema mode) or closes (read
mode). If the body fails, the transaction is closed without committing and the error is
returned.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Runs a transaction on the calling thread, retrying the whole body on commit conflicts if
retry says so.
Equations
- d.runSync db mode body TypeDB.RetryPolicy.never opts = d.runOnce db mode body opts
- d.runSync db mode body (TypeDB.RetryPolicy.conflicts a a_1) opts = TypeDB.Driver.runSync.go d db mode body opts a_1 0 a
Instances For
fuel is the number of retries left.
Equations
- One or more equations did not get rendered due to their size.
- TypeDB.Driver.runSync.go d db mode body opts backoff attempt 0 = d.runOnce db mode body opts