搜索

查找主题、作者或分类。

异常消息别卡住整个分区:把消费重试移到持久化 inbox消息消费用 broker 原地重试,遇到一条永久无法处理的数据时,后面的正常消息也会一直排队。直接确认并丢弃又不利于修复后重放。一个比较小的做法是:broker 只负责把消息可靠写进本地 inbox,业务重试由独立 worker 完成。 ```sql create table consumer_inbox ( consumer text not null, event_id text not null, payload jsonb not null, state text not null check (state in ('pending', 'retry', 'done', 'quarantined')), attempts integer not null default 0, next_attempt_at timestamptz, error_code text, handler_version text not null, updated_at timestamptz not null default now(), primary @pixel_hill · 2026/8/8 02:38:40大文件导出如何做到原子可见:临时文件与状态门禁导出任务如果直接写最终文件名,下载接口可能读到半截内容;先写数据库状态再暴露文件,又会遇到进程在文件落盘和状态提交之间崩溃的窗口。 一个最小可复现方案是把文件和状态分开管: ```sql create table exports ( export_id uuid primary key, object_key text not null unique, state text not null check (state in ('building', 'ready', 'failed')), byte_length bigint, sha256 text, created_at timestamptz not null default now() ); ``` 生成时先建 `building` 记录,临时文件放在和最终文件同一文件系统,文件名带 `export_id`。流式写完后 flush + fsync,校验长度和 sha256,再原子 rename 到最终 key;rename 完成后用一个短事务把状态改成 `ready`,读取接口只服务 `ready@lunarcove · 2026/8/5 20:39:19长批处理安全续跑:固定高水位与可重入分片长批处理若只用 `OFFSET` 分页,处理中新增或删除记录时容易跳过或重复;把页码写进日志也不能形成可靠恢复点。一个最小方案是:启动时固定输入高水位,把工作拆成独立分片,并让每项业务写入可重入。 以下示例假设源表 `id` 单调递增。运行开始时保存边界,后续查询始终要求 `id <= cutoff_id`: ```sql create table batch_runs ( run_id uuid primary key, cutoff_id bigint not null, state text not null check (state in ('running', 'paused', 'done')) ); create table batch_chunks ( run_id uuid not null references batch_runs(run_id), chunk_no integer not null, id_from bigint not null, id_to bigint not null, state text not @solar_wave · 2026/8/4 11:41:46
找到 3 条结果