/** * AWS S3 implementation of {@link StorageProvider}. * * Wraps `@aws-sdk/client-s3`. Like the Azure provider, this layer is where the * broker's correctness primitives are enforced so the broker/producer/consumer * never touch the AWS SDK directly. It is the second real backend behind the * provider-neutral interface (ADR-0002). * * Two halves: * - **Mechanical methods** (`read`/`rangeRead`/`head`/`putBlockBlob`/ * `copyBlobServerSide`/`listPrefix`/`delete` + the optional DuckDB/presign * hooks) map directly onto S3 commands and are implemented here. * - **Append + lease + the logical-segment read view** (`createAppendBlob`/ * `acquireLease`/`renewLease`/`releaseLease`/`appendBlock` + * `segmentLength`/`rangeReadSegment`/`compactSegment`) are the operations S3 * has no native primitive for. They are delegated to a pluggable * {@link S3AppendLeaseStrategy} selected by the `strategy` option. The EXP-30 * bake-off on real S3 chose `object-per-batch` (Candidate B); it is the * blessed default (ADR-0023). `cas-if-match` (A) and `hybrid-rollup` (D) * remain selectable; `express-append` (C) is a measurement stub. * * Every method is wrapped in an OTEL span with attributes: * storage.provider = "s3" * storage.container = (named `container` for cross-provider parity) * storage.blob = * storage.operation = * — identical attribute keys to the Azure provider so the runbook + Grafana * dashboards work unchanged across backends. */ import { type S3Client } from '@aws-sdk/client-s3'; import { type BlobHead, type BlobInfo, type CopyBlobOptions, type PutBlockBlobOptions, type RangeReadResult, type SegmentCompactionResult, type StagedUploadResult, type StoragePermission, type StorageProvider } from '../types.js'; import { type S3AppendLeaseStrategy, type S3AppendStrategyName } from './strategies/index.js'; export type S3BlobProviderOptions = { /** * The caller's own `S3Client` (built from static creds, * `fromNodeProviderChain()`, an IRSA / IAM-role / web-identity provider, * etc.). The broker never sees the underlying credential — exactly parallel * to `azureBlobProvider({ serviceClient })`. Mirrors the CLAUDE.md * §Credentials contract. */ readonly client: S3Client; readonly bucketName: string; /** * Which append/lease/read-view strategy backs `appendBlock`, the lease * methods, and the logical-segment read view. Defaults to * {@link DEFAULT_S3_APPEND_STRATEGY} (`object-per-batch`, Candidate B) — the * strategy chosen by the EXP-30 bake-off on real S3 and recorded in ADR-0023. * `cas-if-match` (A) and `hybrid-rollup` (D) remain selectable for the reasons * in ADR-0023; `express-append` (C) is a measurement stub that rejects with * `S3StrategyNotImplementedError`. The mechanical methods work regardless. */ readonly strategy?: S3AppendStrategyName; /** * Accepted for signature parity with `azureBlobProvider` — NO-OP on S3 today. * * Azure's ADR-0020 safe-retry exists because the Azure SDK retains in-flight * request bodies for up to 2 minutes per attempt, OOM-ing the heap under * sustained throttle. The AWS SDK v3 standard retry mode does not have that * body-retention pathology, so there is nothing to defang yet. Whether S3 * needs an equivalent tightened-retry policy is exactly what the EXP-12 * (`503 storm` → S3 5xx/throttle) re-run will decide; if it does, this flag * is the gate. Tune retry on your own `S3Client` (`maxAttempts`, * `retryStrategy`) in the meantime. */ readonly applySafeRetryPolicy?: boolean; }; export declare class S3BlobProvider implements StorageProvider { private readonly client; private readonly bucket; private readonly strategy; private readonly tracer; private readonly meter; private readonly durationHistogram; private readonly errorCounter; private readonly shortReadRetriesCounter; constructor(options: S3BlobProviderOptions); createAppendBlob(path: string): Promise; acquireLease(path: string, ttlSeconds: number): Promise; renewLease(path: string, lease: Parameters[1]): Promise; releaseLease(path: string, lease: Parameters[1]): Promise; appendBlock(path: string, bytes: Buffer, options: Parameters[2]): Promise; /** * Logical-segment read view, delegated to the strategy: a single object for * the CAS candidate, stitched part objects for object-per-batch. The broker * consumer reads append segments through these rather than the mechanical * `read`/`head` (which address single objects). */ readSegment(path: string): Promise; segmentLength(path: string): Promise; /** * Ranged logical-segment read — the incremental/tail-follow view. A ranged GET * for the single-object CAS candidate; an assembly of the overlapping part * objects (plus the rollup prefix for `hybrid-rollup`) for the multi-part * candidates. The bake-off's consumer-side cost measurement reads through this. */ rangeReadSegment(path: string, start: number, end: number): Promise; /** * Compaction join — materialise the multi-object segment at `srcPath` as one * archived object at `dstPath`. The seal-time cost the bake-off measures: a * server-side copy for the single-object/hybrid candidates, or a * download-concat of all parts for object-per-batch. Delegated to the strategy. * * **Create-once** (ADR-0025): the compactor relies on a `BlobAlreadyExistsError` * to reconcile a crash between the join and its `segment_archived` index line * (ADR-0013). S3 `CopyObject` has no native destination-conditional, so we guard * with a destination `head` pre-check before delegating — the same mechanism as * {@link copyBlobServerSide}. The TOCTOU window is unreachable: sealing is * serialised through `.index.jsonl` (ADR-0006) and a single compactor runs per * producer (ADR-0013). */ compactSegment(srcPath: string, dstPath: string): Promise; read(path: string): Promise; rangeRead(path: string, start: number, end: number): Promise; head(path: string): Promise; putBlockBlob(path: string, bytes: Buffer, options: PutBlockBlobOptions): Promise; createBlockBlobStaged(path: string, blocks: AsyncIterable): Promise; copyBlobServerSide(srcPath: string, dstPath: string, options: CopyBlobOptions): Promise; listPrefix(prefix: string): AsyncIterable; delete(path: string): Promise; /** * Mint a short-lived presigned URL for `blob`. The S3 analogue of Azure's * SAS-bearing URL — lets DuckDB / curl / a co-located worker read or write the * object using the broker's credential without ever seeing it. * * `permissions` must be an S3-dialect {@link StoragePermission}: `'s3:GetObject'` * presigns a GET, `'s3:PutObject'` presigns a PUT. Passing an Azure SAS code * (`'r'`, `'cw'`, …) throws — the runtime rejection the `StoragePermission` * union documents. */ mintBlobUrl(opts: { readonly blob: string; readonly permissions: StoragePermission; readonly expiresInSeconds: number; }): Promise; /** The `s3:///` URL DuckDB's httpfs/S3 extension addresses. */ buildDuckdbBlobUrl(blob: string): string; /** * Mint credentials for DuckDB's `CREATE SECRET (TYPE S3 ...)`. * * S3's secret needs KEY_ID + SECRET + REGION (+ ENDPOINT for non-AWS) — a * richer shape than the Azure-flavoured `{ blobEndpoint, sasToken }` return * type. We map onto it by resolving the client's static credentials and * packing the S3 parameters as a `;`-delimited body in `sasToken`, with the * resolved endpoint in `blobEndpoint`. The compactor's S3 branch parses this * when the experiment suite re-runs DuckDB-on-S3 (Phase 5); a first-class * typed S3 secret shape on the interface is a Phase-6 follow-up (ADR). */ mintStorageSecret(_opts: { readonly permissions?: StoragePermission; readonly expiresInSeconds: number; }): Promise<{ blobEndpoint: string; sasToken: string; }>; private instrument; private baseAttrs; } /** * Wrap a caller-built `S3Client` into a configured provider against a specific * bucket. The S3 analogue of `azureBlobProvider`. The caller owns the client's * credential + retry config; the broker never sees the credential. */ export declare function s3BlobProvider(opts: S3BlobProviderOptions): S3BlobProvider; //# sourceMappingURL=s3BlobProvider.d.ts.map