feat(#116): setBatch() helper with mutation-budget enforcement - #117
Merged
Merged
Conversation
- Transaction::setBatch(iterable $pairs): queues [key, value] pairs (string|KeyConvertible keys) into the current transaction; total key+value bytes validated against the 10 MB per-transaction mutation budget BEFORE any mutation is queued, throwing BatchTooLargeException (public readonly batchSize/maxBatchSize) at the call site - Database::setBatch(iterable $pairs, bool $split = false): single transaction via transact() (retries included), or split: true mode grouping entries under MutationBudget::SPLIT_TARGET_BYTES (8 MB) with per-group retried transactions (per-key atomicity, no cross-key snapshot consistency — documented) - Shared @internal MutationBudget accounting (pure byte math, reusable by the upcoming chunked-values layer from #115) - Generator-backed iterables consumed lazily - Unit tests (MutationBudgetTest) + integration tests (SetBatchTest); docs/batch-writes.md + CHANGELOG entry
This was referenced Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the batch write helpers from #116:
Transaction::setBatch(iterable $pairs)— queues[key, value]pairs (stringorKeyConvertiblekeys) into the current transaction. The total key+value byte size is validated against FoundationDB's 10,000,000 B per-transaction mutation budget before any mutation is queued; an oversized batch throws the newBatchTooLargeException(public readonlybatchSize/maxBatchSize) at the call site instead of an opaque server-side error duringcommit(). Nothing is written.Database::setBatch(iterable $pairs, bool $split = false)— single-transaction mode viatransact()(retries included), orsplit: truemode that groups entries underMutationBudget::SPLIT_TARGET_BYTES(8,000,000 B) and commits each group in its own retried transaction. Per-key atomicity guaranteed; no cross-key snapshot consistency and no all-or-nothing commit — documented in the PHPDoc anddocs/batch-writes.md(deliberately not symmetric with the chunked-values meta-swap from [Feature] Chunked values: setValueChunked() / getValueChunked() #115).MutationBudget(@internal) — pure byte-accounting shared infrastructure, deliberately ignorant of the chunked key-space; the chunked layer ([Feature] Chunked values: setValueChunked() / getValueChunked() #115) will reuse it but not the\x00key-space codec.iterableinput is consumed lazily (no double materialization).Semantics
setBatch()calls do not conflict with each other (last commit wins); read-modify-write conflict detection comes from reads in the same transaction.Transaction::setBatchalways throws above budget (splitting inside a caller-owned transaction makes no sense);splitexists only onDatabase::setBatch.Closes #116
Testing
composer lint— PHPCS + Rector + PHPStan level 9: cleancomposer test:unit— 602 tests OK (incl. newMutationBudgetTest)composer test:integration— 292 tests OK (incl. newSetBatchTest: round-trip at value-limit boundaries, oversized batch rejected before any mutation and DB stays usable, split mode across multiple transactions, generator input, empty batch no-op, read-modify-write conflict/retry)Docs & changelog
docs/batch-writes.md(new)CHANGELOG.md—[Unreleased] / Addedentry referencing [[Feature] setBatch() helper — multi-key writes with transaction budget enforcement #116]