use raft.TCPTransport#35
Merged
Merged
Conversation
3 tasks
bootjp
added a commit
that referenced
this pull request
Jun 3, 2026
…ers (#912) ## Summary - S3 (`encodeBucket`) and DDB (`encodeTable`) now check that the on-disk subdirectory matches `EncodeSegment([]byte(name))` from `_bucket.json` / `_schema.json` before emitting any records. - Closes task #35 (the M4 + M5 follow-up the original session-summary tracked). ## Background The reverse encoders use two identifiers for the same logical entity: - On-disk subdir: `s3/<bucketDir>/`, `dynamodb/<tableDir>/` — decoder spells as `EncodeSegment([]byte(name))`. - Embedded name in `_bucket.json` / `_schema.json` — encoder uses for MVCC keys (`s3keys.BucketMetaKey(pub.Name)`, base64'd `tableName`). Until now, both sides were trusted independently. A tampered or hand-rebuilt dump that renamed the directory without touching the JSON (or vice versa) would silently emit records keyed by the JSON name while pulling object / item bytes from a mismatched filesystem path — a name/dir consistency violation that splits a single restore artifact across two identities. ## Fix After the existing empty-name guard, both encoders verify `EncodeSegment([]byte(name)) == <dir>`. Mismatch fails closed with the existing per-adapter sentinel (`ErrS3EncodeInvalidBucket` / `ErrDDBEncodeInvalidSchema`), and the error message names both the JSON value and the encoded form so the operator can correct the dump. ## Caller audit (CLAUDE.md semantic-change rule) - `encodeBucket` (S3): success path gains one new fail-closed check; sole production caller is `S3RecordEncoder.Encode`. - `encodeTable` (DDB): success path gains one new fail-closed check; sole production caller is `DynamoDBEncoder.Encode`. - Both checks reuse existing per-adapter sentinels, so `runAdapterEncoders`' `errors.Mark(ErrEncodeAdapterData)` wrap still routes failures through the CLI's exit-2 classification — no new sentinel needed in `classifyEncodeError`. ## Self-review of code changes (5 lenses) 1. **Data loss** — Stricter validation; no commit/apply path touched. No data-loss surface. 2. **Concurrency / distributed failures** — Encoder is single-process / single-goroutine on the input tree. No new concurrency surface. 3. **Performance** — One extra `EncodeSegment` call and string compare per bucket / per table. Negligible. 4. **Data consistency** — This IS the data-consistency improvement. The check enforces the round-trip invariant `<dir> == EncodeSegment(name)` for every published record. 5. **Test coverage** — Two new tests (one per adapter) pin the rejection. Existing positive tests use `EncodeSegment` for the dir spelling, so they remain green; existing rejection tests trip earlier guards, also green. ## Test plan - [x] `go test -race ./internal/backup/... ./cmd/elastickv-snapshot-encode/...` - [x] `golangci-lint --config=.golangci.yaml run` - [ ] Bot review cycle (claude / codex / CodeRabbit)
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.
No description provided.