문서 탐색 열기
R2D1 / 문서

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을 검증합니다. 네 인자 형식은 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를 이미 소유한다면 두 번째 constructor를 사용하세요. 이 경우 R2DocumentStore를 닫아도 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을 가립니다.