You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/md/ydb.md
+48-49Lines changed: 48 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,12 +45,48 @@ func main() {
45
45
}
46
46
```
47
47
48
+
## Interactive & Non-Interactive Transactions
49
+
50
+
It is important to say that every request in YDB is executed in a transaction.
51
+
YDB supports two modes of working with transactions, and ent uses both depending on the API you choose.
52
+
53
+
### Non-interactive transactions
54
+
55
+
When you use the standard CRUD builders (`.Create()`, `.Query()`, `.Update()`, `.Delete()`), ent executes them through ydb-go-sdk's retry helpers:
56
+
57
+
-**Write operations** (Create, Update, Delete) go through
58
+
[`retry.DoTx`](https://pkg.go.dev/github.com/ydb-platform/ydb-go-sdk/v3/retry#DoTx) — the SDK
59
+
begins a transaction, executes the operation as a **callback**, commits, and on a transient error
60
+
rolls back and re-executes the callback from scratch.
61
+
-**Read operations** (Query) go through
62
+
[`retry.Do`](https://pkg.go.dev/github.com/ydb-platform/ydb-go-sdk/v3/retry#Do) — the SDK
63
+
obtains a connection, executes the read callback, and retries on transient errors. No explicit
64
+
transaction is created; the read runs with an implicit snapshot.
65
+
66
+
This is the recommended way to work with YDB through ent. Automatic retries and session management
67
+
are handled transparently.
68
+
69
+
### Interactive transactions
70
+
71
+
When you call `Client.BeginTx()`, ent opens a transaction via the standard `database/sql` API and **returns a `Tx` object** to the caller. You then perform operations on it and manually call
72
+
`Commit()` or `Rollback()`. In this model:
73
+
74
+
- There is **no callback** for the SDK to re-execute, so automatic retries are not possible.
75
+
- Session and transaction lifetime are managed by your code.
76
+
77
+
Use interactive transactions only when you need explicit control over commit/rollback boundaries
78
+
that can't be expressed through the standard builders.
79
+
48
80
## Automatic Retry Mechanism
49
81
50
-
YDB requires special handling for transient errors (network issues, temporary unavailability, etc.).
82
+
Since YDB is a distributed database, it requires special handling for transient errors (network issues, temporary unavailability, etc.).
51
83
The ent YDB driver integrates with [ydb-go-sdk's retry package](https://pkg.go.dev/github.com/ydb-platform/ydb-go-sdk/v3/retry)
52
84
to automatically handle these scenarios.
53
85
86
+
:::note
87
+
However, ent does not use automatic retries when you create an interactive transaction using `Client.BeginTx()`. [Read more](ydb.md#no-automatic-retries-when-using-clientbegintx).
88
+
:::
89
+
54
90
### Using WithRetryOptions
55
91
56
92
All CRUD operations support the `WithRetryOptions()` method to configure retry behavior:
@@ -95,61 +131,29 @@ Common retry options from `ydb-go-sdk`:
95
131
|`retry.WithLabel(string)`| Add a label for debugging/tracing |
0 commit comments