打开文档导航
R2D1 / 文档

一致性与恢复

R2D1 不会假装两个 store 构成一个 distributed transaction。DocumentStore 是 content 和 logical existence 的权威来源,IndexStore 是可重建的 materialized projection。

Mutation 顺序

两条 mutation path 都先更新 authoritative document。这样仅通过 authoritative scan 就能恢复。

PUT:    DocumentStore.put    -> IndexStore.upsert
DELETE: DocumentStore.delete -> IndexStore.delete

PartialFailure

第一步成功而第二步失败时,R2D1 抛出 PersistenceException.PartialFailure,其中保留受影响的 DocumentKey 和第二阶段原始 cause。不会自动 rollback、retry 或 compensating write。

例如 authoritative delete 后 index cleanup 失败时,get(id) 会报告文档不存在,但 stale index row 可能让 query 抛出 PersistenceException.InconsistentState。R2D1 不会静默跳过 stale row。

重建 index projection

解决底层 failure 后,在 collection 上调用 rebuildIndex()。它按 bounded page 列出 authoritative document key,读取文档,按 metadata 生成 index entry,只替换 derived rows。

users.rebuildIndex();

非原子操作

rebuildIndex() 对未变化的 collection 可以安全重复执行,但不是 atomic。如果清除 rows 后失败,projection 可能不完整。重建时暂停 collection 写入,解决 failure 后再次运行。

这个 contract 不提供 distributed transaction、background repair、automatic retry、并发 rebuild coordination、lost-update prevention 或 power-loss durability。