整合性と復旧
R2D1 は2つの store を1つの distributed transaction であるかのように扱いません。DocumentStore は content と logical existence の権威ソースで、IndexStore は再構築可能な materialized projection です。
Mutation の順序
2つの mutation path はどちらも authoritative document を先に更新します。これにより authoritative scan だけで復旧できます。
PUT: DocumentStore.put -> IndexStore.upsert
DELETE: DocumentStore.delete -> IndexStore.deletePartialFailure
最初の操作が成功し、2つ目が失敗すると PersistenceException.PartialFailure が発生します。影響を受けた DocumentKey と2段目の元の cause を保持します。自動 rollback、retry、compensating write はありません。
authoritative delete 後の index cleanup に失敗した場合、get(id) は document absent と報告しますが、stale index row により query が PersistenceException.InconsistentState になることがあります。stale row を黙って無視しません。
Index projection の再構築
基盤の failure を解決した後、collection で rebuildIndex() を呼びます。authoritative document key を bounded page で列挙し、各 document を読み、metadata から index entry を作り、derived rows だけを置き換えます。
users.rebuildIndex();非アトミックな操作
rebuildIndex() は変更されていない collection なら再実行できますが atomic ではありません。rows を clear した後に失敗すると projection が不完全になります。collection への書き込みを止め、failure を解決してから再実行してください。
この contract は distributed transaction、background repair、automatic retry、concurrent rebuild coordination、lost-update prevention、power-loss durability を提供しません。
