Skip to content

S3 lock: scale strategy for very large datasets (>5K objects) #387

Closed

Description

@neuromechanist

Tracking the large-dataset concern code-reviewer raised on #386.

Current state (post-#385)

`applyObjectLockBatch` streams via S3 ListObjectsV2 continuation tokens with `batchSize=25`. Per CLI invocation: ~35 subrequests. Each batch = one CLI round-trip.

Live dataset sizes

Dataset Objects Batches @ 25 CLI rounds (no retries)
nm000103 (HBN-EEG NC) 3,523 141 ~3-5 min wall clock
nm000104 (emg2qwerty) 2,272 91 ~2-3 min
nm000107 (wrist) 365 15 ~30s
nm000130 702 28 ~1 min
nm000131 24 1 ~1s

For current datasets the streamed approach is acceptable. For datasets > ~5,000 objects it becomes pathological — at 50K objects it would take ~30+ min of foreground CLI execution, fragile to network blips on every batch.

Options for scale ceiling

  1. Bucket-level Default Object Lock Configuration — one PutBucketObjectLockConfiguration call locks all future objects automatically. Doesn't help backfill existing keys, but combined with the streaming approach for the historical tail, future uploads need zero per-object locking.

  2. S3 Batch Operations — AWS-native batch job that applies retention to a manifest of objects out-of-band. One `CreateJob` call, then poll. Scales to billions of objects. Adds operational complexity (manifest generation, job status polling).

  3. KV-cached key list — list once at start, persist to Cloudflare KV / D1, iterate. Reduces LIST cost on retry but doesn't help wall-clock time.

  4. Adaptive ceiling in code — at the start of `applyObjectLockBatch`, look up the dataset's known object count (cached on the dataset row from `getDatasetS3Stats`). If above threshold (e.g. 5K), refuse with a clear error advising the admin to use S3 Batch Operations directly via AWS CLI.

Recommendation

Defer until a real dataset exceeds ~5K objects or the wall-clock cost on nm000103-class datasets becomes a blocker. When triggered, implement option (1) to handle future uploads + option (2) for the existing tail.

For now: ensure the current implementation degrades visibly (the 426 upgrade-required path on old CLIs already covers one silent-failure shape; the rest of #386's review fixes cover the others).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions