Hacker Newsnew | past | comments | ask | show | jobs | submit | ucarion's commentslogin

Do folks have any thoughts on ways of avoiding deadlocking access patterns? In a codebase where folks are sort of adding ad-hoc endpoints left and right, it's hard to avoid the case of two endpoints that more or less want to do:

    tx1: update a
    tx2: update b
    tx1: update b
    tx2: update a
Is there a "discipline" or practice that works well? Like, can you realistically, in a real-world messy business codebase, impose an "ordering" on your tables to avoid dining philosophers?


Recalling from my previous studies here: I think you can use Serializable Isolation Level, the strictest level - this will cause one of the two to fail (that is; fail only when the two txns affected rows that would logically conflict). And then you build the expectation of such possible transaction failures into the code and treat retries as a first-class expectation. Does this get to what you're trying to solve at all?


It does get at what I'm talking about. But I've seen retrying in this situation lead to worsening the situation, because your basic problem is two hot paths conflicting with each other and now you're conflicting even more.


(Matt from Hatchet - Hi Ulysse :wave:)

I, at least, don't know of a perfect fix here. Re: the original comment - Postgres will also error on deadlocks after it detects them without setting your isolation level to Serializable, but I agree with you that often retrying doesn't help, and could even cause cascading / snowballing failures if you have a backlog of retries piling up because of deadlocks.

I don't know if there's a good solution, really. We've fixed deadlocks incrementally over time as we've found them, which has worked pretty well, but of course that means also needing to deal with the "finding" part, which has generally come in the form of lots of `deadlock detected` log lines and errors (and retries accompanying those).

One thing that might be worth auditing is why there are two different bits of application code that are updating the same rows in two different tables in different orders. I know it's a contrived example, but it seems like it could be a code smell to me. Maybe this is the kind of thing that arises when two different subteams are working on the same database and are largely siloed.

Alexander will likely have more thoughts here as well, just my two cents!


If you have different endpoints contending over the same rows, I would create “backend batching”. I would force endpoints to call a stored procedure. The stored procedure would append only to a “queue” table. Multiple workers would read from the queue and update the real tables in batches then update the queue with success and error codes. The batches are partitioned by the PK to minimize lock contention.


When I've dealt with this I've generally made sure the transactions are updating rows in a consistent order. You can do that by sorting the rows before you update them


> I do not agree that slice() should operate on extended grapheme clusters. Don’t lump the grapheme cluster/scalar value split in with the sins of UTF-16 and its unreliable code point/code unit split.

Maybe a simpler argument against this idea is that the definition of an extended grapheme cluster changes between versions of Unicode. The relevant standard is on its 47th revision (not all of which change extended grapheme clusters, but many do): https://www.unicode.org/reports/tr29/


In old-school chess AIs, zugzwang is also of interest because it can break null-move pruning[0], which is a way to prune the search tree. "Null move" just means "skip your turn", and the assumption that skipping your turn is always worse than the optimal move. But in zugzwang positions, that assumption is wrong, so you have to avoid doing null-move pruning.

Stockfish's heuristic for "risk of zugzwang" is basically "only kings and pawns left over", alongside logic for "is null-move pruning even useful right now" [1]:

    // Step 9. Null move search with verification search
    if (cutNode && ss->staticEval >= beta - 16 * depth - 53 * improving + 378 && !excludedMove
        && pos.non_pawn_material(us) && ss->ply >= nmpMinPly && !is_loss(beta))
    {

[0]: https://en.wikipedia.org/wiki/Null-move_heuristic

[1]: https://github.com/official-stockfish/Stockfish/blob/1a882ef...


Leads me to discover: https://www.twitch.tv/chat_loadtest_01 ... neat!


Theres a lot of weird channels on twitch, I run into ones with "ingest" in their name quite often.


I've almost never needed any of these, but there's all sorts of weird redirections you can do in GNU Bash: https://www.gnu.org/software/bash/manual/bash.html#Redirecti...


agentic ai tends to use it ALL the time.


It is news to me that manipulating ASCII art is something AI can do well! I remember this being something LLMs were all particularly horrible at. But I just checked and it seems to work at least with Opus 4.5.

claude(1) with Opus 4.5 seems to be able to take the examples in that article, and handle things like "collapse the sidebar" or "show me what it looks like with an open modal" or "swap the order of the second and third rows". I remember not long ago you'd get back UI mojibake if you asked for this.

Goes to show you really can't rest on your laurels for longer than 3 months with these tools.


Eddie Izzard was joking in 1998 about the "The" and the prohibited names for The City (https://youtu.be/QRB_GhLXCds?si=R4kYkodzvYDxe33H&t=276), so it's probably been like this for many decades thence!


For those unfamiliar: https://news.ycombinator.com/item?id=26998308 ... It's basically a bunch of posts that 'dang and 'tomhow (others too? idk) think are underrated, so it tends to be potent hacker-catnip stuff.


For others, I'm sure parent knows: OKLCH is largely a bugfix for CILEAB. Both try to make a color space where even steps feel evenly spaced to a human. But CIELAB had procedural flaws in its creation.

See slide 19: https://www.w3.org/Graphics/Color/Workshop/slides/talk/lille... -- if you ask CIELAB to make "pure blue" (RGB 0 0 100%) become grayscale, the intermediate colors become purple to the human eye. The entire point of a perceptual color space is that that doesn't happen. OKLCH fixes that.

BTW, credit to Björn Ottosson, who basically side-projected a color space into the web standards and more: https://bottosson.github.io/posts/oklab/ ... folks like him are why we sometimes have nice things!


Kind of moot anyway; 100x zoom is equivalent to a 2400mm lens (with no stabilization assist). If you can hand-aim that on target, you're an elite marksman.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: