Commit 070d5e6
committed
refactor(raft): address PR #746 round-1 review
- gemini medium (snapshot_spool.go:75): Switch the cap check from
`int64(len(p))+s.size > s.maxSize` to
`int64(len(p)) > s.maxSize-s.size`. With the new env override an
operator can set maxSize near math.MaxInt64; the previous form
would overflow there and silently let the write through.
Subtraction stays in [0, maxSize] and rejects the same payloads
correctly. Mathematically equivalent for all sane configurations,
no caller-visible semantic change.
- gemini medium (snapshot_spool.go:90): Replace `io.ReadAll(s.file)`
with `make([]byte, s.size)` + `io.ReadFull`. Write only increments
s.size on successful os.File.Write returns, so it is the truth-of-
record for what's on disk. Pre-allocating skips ~30 reallocs and
intermediate copies that ReadAll would do via power-of-two
doublings on a 1.35 GiB receive.
- codex P1 (snapshot_spool.go:28): "Keep snapshot cap within
in-memory apply limit" — a 16 GiB receive cap admits payloads
larger than the in-memory materialization can survive on a
memory-constrained node. Acknowledged: this PR alone is the
on-disk-cap fix; the in-memory hazard is closed by stacked PR
#747, which routes receive into the existing token-format
streaming path so Snapshot.Data is a 17-byte token (not the
payload) and apply reads from disk via io.Reader. #747 keeps
the receive cap aligned with disk space (where 16 GiB is
realistic) rather than RAM (where it is not). See PR #747 for
the streaming-receive change and self-review.
No semantic changes here: Write's reject/accept set is unchanged;
Bytes() returns the same content via a faster path. Tests still
green:
go test -race -count=1 -short ./internal/raftengine/etcd
-- 11.6s, all green.1 parent 2bcd177 commit 070d5e6
1 file changed
Lines changed: 16 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
76 | 81 | | |
77 | 82 | | |
78 | 83 | | |
| |||
86 | 91 | | |
87 | 92 | | |
88 | 93 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
93 | 102 | | |
94 | 103 | | |
95 | | - | |
| 104 | + | |
96 | 105 | | |
97 | 106 | | |
98 | 107 | | |
| |||
0 commit comments