Repository navigation
Commit 082a127
[PLTFRM-1887] Route SELECT FOR UPDATE queries to writable servers (#192)
* Route SELECT FOR UPDATE queries to writable servers
* Avoid false positives in locking read detection
* Feedback
* Simplify locking read detection
Detect FOR UPDATE, FOR SHARE and LOCK IN SHARE MODE with a single
tail-anchored regex. Allowing anything but a quote after the clause
rules out string literals while still matching OF/NOWAIT/SKIP LOCKED/WAIT
modifiers, semicolons and trailing comments, which the previous version
missed and routed to a replica.
The quick-n-dirty match is first as it's the more popular case.
* Make locking read detection linear
The check rescanned to the next quote for every "FOR UPDATE" in the
query, so a SELECT with a long string value repeating those words took
seconds to classify. Search only the text after the last quote instead.
The rule is unchanged, and a regex error now counts as a write.
Still on purpose: the words in a comment count as a write, and a lock
clause followed by a quote is missed. Both are described in the code.
---------
Co-authored-by: Iliya Polihronov <vnsavage@gmail.com>1 parent 6fd480d commit 082a127
1 file changed
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
344 | 343 | | |
345 | | - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
346 | 368 | | |
347 | 369 | | |
348 | 370 | | |
| |||
0 commit comments