skaidb 1.4.1 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/docs/pooling.md CHANGED
@@ -44,6 +44,7 @@ Skaidb::Pool.new(
44
44
  )
45
45
 
46
46
  pool.with(affinity: nil) { |conn| … } # the block's value
47
+ pool.transaction(attempts: 3, begin: "BEGIN", affinity: nil) { |conn| … } # the block's value
47
48
  pool.checkout(affinity: nil) -> Skaidb::Connection
48
49
  pool.checkin(conn)
49
50
  pool.members -> Array of Hashes (see "Watching it")
@@ -55,7 +56,14 @@ pool.close
55
56
  (`database`, TLS, `consistency`, `timeout`) apply to every connection, so
56
57
  pooled connections run `USE` and authenticate exactly like single ones. A
57
58
  pooled connection that re-dials after a transport error does so in the
58
- pool's order: usable members first, the one it lost last.
59
+ pool's order: usable members first, the one it lost last. A borrower that
60
+ sends its own `USE` moves that connection only while it holds it: a pool
61
+ with `database:` puts an idle connection back in that database before it
62
+ hands it out again (one extra round trip, only when it was moved; a
63
+ connection that cannot be put back is dropped). A pool without `database:`
64
+ has no database to put it back in, so there a borrower's `USE` stays with
65
+ the connection — send `USE` after every checkout if borrowers use different
66
+ databases.
59
67
  `Connection#endpoint` names the member a connection reached.
60
68
 
61
69
  ## Balancing across members
@@ -161,6 +169,14 @@ the same in every skaidb driver
161
169
  and will fail its first statement with `Skaidb::ConnectionError`; that
162
170
  failure marks it broken, so `checkin` discards it and the next checkout
163
171
  gets a fresh one. Retry the statement in that case if it is safe to.
172
+ - A transaction belongs to one connection. `pool.transaction { |conn| … }`
173
+ checks one out, runs `Connection#transaction` on it (`begin`, the block,
174
+ `COMMIT`, the whole of it again when the `COMMIT` is refused with
175
+ `Skaidb::TransactionConflict`) and checks it in afterwards; separate
176
+ `pool.with` calls may each get a different connection, and statements
177
+ sent that way are not one transaction. A `TransactionConflict` is a
178
+ statement error: it does not count against the member and the connection
179
+ goes back to the idle set.
164
180
  - `close` marks the pool closed, closes the idle connections and stops the
165
181
  background thread; connections checked out at the time are closed when
166
182
  they are returned. `checkout` on a closed pool raises `Skaidb::Error`.
data/docs/streaming.md CHANGED
@@ -94,17 +94,34 @@ Draining is not free and there is no cancel opcode: breaking out of a
94
94
  million-row scan still transfers the rest of it before the connection is
95
95
  usable again. If you only want a few rows, say so in SQL (`LIMIT`).
96
96
 
97
- Two things defeat the drain:
97
+ Three things defeat the drain:
98
98
 
99
99
  - **External iteration** — `e = conn.stream(sql); e.next` — runs the stream
100
100
  inside the Enumerator's Fiber. A Fiber abandoned part-way is collected
101
101
  without running any `ensure`, so nothing drains and the connection stays
102
102
  marked mid-stream: `usable?` is `false` for good and a pool will not hand
103
- it out again. Iterate with a block or `each`.
103
+ it out again. Iterate with a block or `each`. Dropping such an Enumerator
104
+ costs the connection, not the process: its Fiber is collected while it
105
+ owns the connection's lock, and Ruby 3.3 crashes when a lock is freed
106
+ after the Fiber that owns it, so the driver keeps the lock of every
107
+ stream in flight alive until the stream ends — for a stream abandoned
108
+ this way, one small object for the life of the process. Inside
109
+ [`transaction`](api.md#transactions) a stream left that way when the block
110
+ ends costs the session: neither `COMMIT` nor `ROLLBACK` can be sent past
111
+ it, and the transaction must not stay open on a live session, so the
112
+ socket is closed and the stream ended.
104
113
  - **A frame that makes no sense mid-stream**, or a dead socket. The driver
105
114
  no longer knows where the reply ends, so it marks the connection broken
106
- instead of guessing; `usable?` turns `false`, and the next statement
107
- re-dials.
115
+ and closes the socket instead of guessing; `usable?` turns `false`, and
116
+ the next statement re-dials.
117
+ - **A stream cut short while it waits for a frame** — `Timeout.timeout`
118
+ around the stream, an `Interrupt`, `Thread#kill`. Part of that frame may
119
+ already be read, and a drain would hold the exception back until the
120
+ server had sent the rest of the result, so there is none: the connection
121
+ is marked broken, its socket closed, and the exception propagates at
122
+ once. (The same exception arriving while your block runs finds the socket
123
+ at a frame boundary, and the stream is drained as for any other way of
124
+ leaving the block.)
108
125
 
109
126
  There is no read deadline: a peer that is alive but silent blocks the drain,
110
127
  holding the lock. `close` does not take the lock, so another thread can break