Commit 71ecc12
committed
backup: #904 v14 - fan out Redis encoder across all db_<N> directories
## Codex P1 v13: hardcoded db_0 silently dropped non-default Redis DBs
The Redis adapter runner in adapterRunners was hardcoded to
NewRedisEncoder(root, 0). RedisEncoder is scoped to a single
redis/db_<n>/ subdirectory; any Phase 1 multi-DB dump that included
redis/db_3/, redis/db_5/, etc. would silently drop those DBs from
the produced .fsm — a header-only encode for those keys, exactly
the silent-data-loss pattern the encoder is supposed to fail closed
against. With --self-test on, the same valid multi-DB dump would be
rejected at the diff stage (the decoded scratch tree would not match
the input's db_3 content).
Phase 0a/0b inputs only emit redis/db_0/, so this is a latent bug
that fires the moment Phase 1's multi-DB dumper lands; codex flagged
it as P1.
## Fix: enumerate redis/db_<N> directories and fan out per DB
Two new helpers in encode_snapshot.go:
- enumerateRedisDBs(inRoot) returns the sorted dbIndex values for
which <inRoot>/redis/db_<N>/ exists as a directory. A missing
redis/ returns nil (no-op, matching the per-DB encoder's
missing-subdir convention). Non-canonical entries (non-numeric
suffix, negative, leading-zero like "db_01", wrong prefix,
regular files at the redis/ level) are silently skipped — they
cannot be produced by the canonical decoder. A symlinked or
regular-file redis/ path is rejected with ErrRedisEncodeNotDir
(mirrors the per-DB encoder's symlink refusal).
- encodeAllRedisDBs(b, inRoot) invokes NewRedisEncoder per
enumerated index in ascending order, wrapping per-DB errors with
"redis encoder db_%d" for traceability.
The redis adapter runner now uses encodeAllRedisDBs as its function
value directly (gocritic unlambda).
## Pinned by
- TestEnumerateRedisDBsMissingDir: missing redis/ returns nil indices.
- TestEnumerateRedisDBsMixedEntries: only canonical db_<N> dirs
kept; non-numeric, negative, leading-zero, empty-suffix, wrong-
prefix, and regular-file entries are skipped; result sorted
ascending (asserted via direct index comparison).
- TestEnumerateRedisDBsRedisIsRegularFile: regular file at redis/
path triggers ErrRedisEncodeNotDir.
- TestEncodeSnapshotRedisMultiDB: a fixture under redis/db_3/ ONLY
(no db_0) produces strictly more bytes than an empty-redis baseline
through EncodeSnapshot. Pre-fix, the hardcoded db_0 path would
have produced an identical header-only .fsm for both inputs.
## Caller audit per CLAUDE.md semantic-change rule
- adapterRunners.redis: closure replaced with encodeAllRedisDBs
function value (gocritic unlambda). Error contract:
- errors.Is(err, ErrEncodeAdapterData) — still true (errors.Mark
in runAdapterEncoders is unchanged).
- errors.Is(err, ErrRedisEncodeNotDir) etc. — still true
(errors.Mark + errors.Wrap preserve the inner chain).
- Error prefix changed from "redis encoder: ..." to
"redis encoder db_%d: ..." (or "redis encoder enumerate: ..."
for the enumeration step). More specific, not less.
- NewRedisEncoder direct callers (encode_redis_test.go,
encode_redis_coll_test.go, encode_redis_hardlink_unix_test.go):
unaffected — they call NewRedisEncoder directly, never through
the adapter runner.
- enumerateRedisDBs / parseRedisDBDir / checkRedisRoot / encodeAllRedisDBs
are new package-private functions; no external callers exist yet.
## Lint compliance
Two cyclop refactor splits required:
- enumerateRedisDBs (initially 12 branches) split into
checkRedisRoot + parseRedisDBDir helpers. Each is ≤6 branches.
- TestEnumerateRedisDBs (initially 14 branches via t.Run) split
into three top-level tests. Each is ≤4 branches.
Tests + lint green.1 parent 48b0b0e commit 71ecc12
2 files changed
Lines changed: 220 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
359 | 459 | | |
360 | 460 | | |
361 | 461 | | |
| |||
366 | 466 | | |
367 | 467 | | |
368 | 468 | | |
369 | | - | |
370 | | - | |
371 | | - | |
| 469 | + | |
372 | 470 | | |
373 | 471 | | |
374 | 472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
391 | 510 | | |
392 | 511 | | |
393 | 512 | | |
| |||
0 commit comments