The rule: 2xx = I did it, 4xx = you did it, 5xx = we did it. Never wrap errors in 200 — clients can't retry unseen errors. 502 = bad reply, 504 = no reply.
2xx 是我搞定了,4xx 是你搞错了,5xx 是我们搞砸了。别把错误包进 200——看不见的错没法重试。502 坏响应,504 没回音。
HTTP status codes have personalities. 200 OK smiles "all good" — while hiding an error inside. 500 is the server crying for help. 502 is the gateway taking the blame. 418? A teapot.
HTTP 状态码也有性格。200 笑说"一切正常",却藏着报错。500 在求救,502 在背锅。418?是个茶壶。
防不住的也要兜底:捕获 1213 死锁错误,指数退避重试(最多 3 次);把长事务拆小、缩短持锁时间,死锁自然变少。
For the rest, catch error 1213 and retry with exponential backoff (max 3 tries); keep transactions short so locks are held briefly — deadlocks fade away.
死锁不是随机事件:两个事务按不同顺序抢同一组锁,互相等对方先放手。
Deadlock isn't random: two transactions lock the same rows in different order, each waiting for the other.
#MySQL#Backend
根因几乎总是加锁顺序不一致:A 先锁行 1 再锁行 2,B 反过来。修复:全代码按同一顺序加锁;批量更新先按主键排序。
The root cause is almost always inconsistent lock order: A locks row 1 then 2, B the reverse. Fix: lock in one fixed order everywhere; sort batch updates by PK.
周四夜,先给周六清晨留个念想。
日出、空街道,一周从脚步声开始。
跑完,城市刚醒,早餐摊刚开张。
慢慢跑,慢慢醒。
Thursday night, saving a thought for Saturday morning.
Sunrise, empty streets — the week starts with footsteps.
Run slow, wake up slow.
#MorningRun
The fix isn't "trust AI less". It's: pin the library version in your prompt, check the real docs, and run one test before you believe it. Confidence is not correctness.
解法不是「少信 AI」,而是:提示词里写死库版本、查真文档、信之前先跑一个测试。自信不是正确。
AI wrote it so confidently. The method doesn't exist. Not deprecated — never existed. Docs link: 404.
AI 写得自信满满,方法根本不存在。文档链接 404,幻觉 API 是新版「在我电脑上能跑」。
#AI#DevLife
最后分清「大」和「漏」:缓存大不一定是泄漏。对两次 dump 做 histogram 对比,实例数一直在涨的类才是真凶。
Finally, big is not leaking: a large cache isn't a leak. Compare histograms of two dumps — the class whose instance count keeps growing is the real culprit.
堆转储是 OOM 的案发现场:jmap -dump:live,file=heap.hprof <pid>,live 只抓存活对象;文件和堆一样大,先看磁盘。
A heap dump is the OOM crime scene: jmap -dump:live,file=heap.hprof <pid> — live keeps only live objects. The file is as big as the heap, check disk.
#JVM#Java
再看 Leak Suspects 报告:MAT 直接算出嫌疑对象占堆的百分比、引用链和可能原因。超过 30% 的单一对象,先查它。
Then read the Leak Suspects report: MAT gives the suspect's share of the heap, the reference chain, and a likely cause. One object over 30%? Check it first.
周三的夜,留一盏灯给明早的豆浆摊。
蒸汽升起来的时候,城市才刚醒。
一碗热豆浆,两个刚出笼的包子,
再冷的天,也能从胃里暖起来。
Wednesday night. The soy milk stall will be steaming before the city wakes.
A bowl of hot soy milk, two fresh buns — winter starts warm.
Ctrl+S stopped being a save long ago. It's a ritual — muscle memory from the era when one crash ate your afternoon. The keystroke never saved you. git commit did.
Ctrl+S 早就不是保存,是仪式——是那个崩溃一次丢一下午的年代留下的肌肉记忆。真正救你的从来不是按键,是 git commit。
删也别直接 DEL:同步释放内存,100MB 的 key 能卡几百毫秒。改用 UNLINK 异步删,设好 TTL 与写入上限,定期巡检告警。
Don't DEL either: it frees memory synchronously — a 100MB key can stall hundreds of ms. Use UNLINK, set TTLs and write limits, alert on bigkeys regularly.
Redis 大 Key 治理:一个 100MB 的 key 能拖垮单线程 Redis。
问题不在"大",而在每次读写、删除都变慢操作,全实例一起排队。
One 100MB key can stall single-threaded Redis. Not the size — every op on it turns slow, and the whole instance queues up.
#Redis#Backend
怎么拆?大 hash 按 id 取模拆 64 个小 hash,大 list 按时间分片,热点 key 加随机后缀打散。单 key 压到 KB 级,操作回毫秒内。
How to split? Hash by id % 64 into small hashes, shard big lists by time, suffix hot keys to spread load. Keys drop to KBs, ops back to ms.