Commit 9c25afd
fix(sessions): use read-only transactions for get/list operations
DatabaseSessionService.get_session() and list_sessions() are pure-read
operations but currently open regular read-write transactions via
_rollback_on_exception_session(). On Cloud Spanner this causes
RetryAborted errors when a concurrent write commits during the read,
because Spanner's OCC layer sees the read-write transaction as
conflicting.
Add _readonly_session() context manager that:
- Marks the connection as read-only (postgresql_readonly=True) which
also benefits Cloud Spanner's sqlalchemy-spanner dialect
- Never commits, avoiding unnecessary write-path overhead
- Still rolls back on exception to release the connection cleanly
Switch get_session() and list_sessions() to use _readonly_session().
Write operations (create_session, delete_session, append_event) continue
to use _rollback_on_exception_session() with explicit commits.
Fixes #4771
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent f8270c8 commit 9c25afd
1 file changed
+22
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
216 | 236 | | |
217 | 237 | | |
218 | 238 | | |
| |||
403 | 423 | | |
404 | 424 | | |
405 | 425 | | |
406 | | - | |
| 426 | + | |
407 | 427 | | |
408 | 428 | | |
409 | 429 | | |
| |||
458 | 478 | | |
459 | 479 | | |
460 | 480 | | |
461 | | - | |
| 481 | + | |
462 | 482 | | |
463 | 483 | | |
464 | 484 | | |
| |||
0 commit comments