R2 DocumentStore
R2DocumentStore は Cloudflare R2 を authoritative DocumentStore として使う実装です。完全な document bytes は R2 に保存され、indexed query の projection は選択した IndexStore に保存されます。
依存関係と生成
R2 adapter は dev.nexcraft:r2d1 に含まれます。設定 constructor は HTTPS origin、credential、bucket、region を検証します。4引数形式は signing region に auto を使います。
implementation("dev.nexcraft:r2d1:<version>")R2Config
以下の値は placeholder です。access key と secret は source control の外にある secret configuration から渡してください。
R2Config config =
new R2Config(
URI.create("https://<account-id>.r2.cloudflarestorage.com"),
accessKeyId,
secretAccessKey,
bucketName);
R2DocumentStore documents = new R2DocumentStore(config);非同期 client の所有権
new R2DocumentStore(R2Config) は asynchronous client を作成して所有します。store を閉じると client も閉じます。
アプリケーションが S3AsyncClient を所有している場合は2つ目の constructor を使います。この場合、store を閉じても caller-owned client は閉じません。
adapter は R2D1 executor、scheduler、virtual thread、retry policy、timeout policy を追加しません。
操作と失敗
R2 write の後の index update に失敗すると、collection facade は PersistenceException.PartialFailure を報告します。
- put は encoded collection/document key に serialized bytes を書きます。
- get は missing object を DocumentNotFoundException にします。
- delete は object がすでにない場合も idempotent です。
- list は bounded S3-compatible pagination と adapter-owned opaque cursor を使います。
Endpoint と credential
endpoint は path、query、fragment、user information のない HTTPS origin でなければなりません。R2Config.toString() は endpoint、bucket、access key、secret を隠します。
