Skip to content

Conversation

@bootjp
Copy link
Owner

@bootjp bootjp commented Aug 29, 2025

Summary

  • add ErrInvalidChecksum for detecting corrupt snapshot data
  • write CRC32 checksums to memory and RB tree store snapshots and verify during restore
  • test snapshot checksum handling for both store implementations

Testing

  • go test ./...

https://chatgpt.com/codex/tasks/task_e_68b1f3ef3e388324973d28a4bed306ea

assert.NoError(t, err)

st2 := NewMemoryStore()
err = st2.Restore(bytes.NewReader(buf.(*bytes.Buffer).Bytes()))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
right hand must be only type assertion (forcetypeassert)


buf, err := st.Snapshot()
assert.NoError(t, err)
data := buf.(*bytes.Buffer).Bytes()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
right hand must be only type assertion (forcetypeassert)

assert.NoError(t, err)

st2 := NewRbMemoryStore()
err = st2.Restore(bytes.NewReader(buf.(*bytes.Buffer).Bytes()))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
right hand must be only type assertion (forcetypeassert)

if err != nil {
return errors.WithStack(err)
}
if len(data) < 4 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Magic number: 4, in detected (mnd)

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines +225 to +238
func (s *memoryStore) Restore(r io.Reader) error {
s.mtx.Lock()
defer s.mtx.Unlock()

s.m = make(map[uint64][]byte)
err := gob.NewDecoder(buf).Decode(&s.m)
data, err := io.ReadAll(r)
if err != nil {
return errors.WithStack(err)
}
if len(data) < 4 {
return errors.WithStack(ErrInvalidChecksum)
}
payload := data[:len(data)-4]
expected := binary.LittleEndian.Uint32(data[len(data)-4:])
if crc32.ChecksumIEEE(payload) != expected {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve ability to restore pre-checksum snapshots

The new Restore path now unconditionally expects the last 4 bytes of the snapshot to be a CRC32 checksum. Snapshots that were produced by previous releases contain only gob data, so upgrading a node with existing snapshot files will cause Restore to immediately return ErrInvalidChecksum and leave the store empty. This breaks backward compatibility and can prevent data recovery after deploys. Consider detecting the old format (e.g., fall back to gob decoding when the checksum validation fails or when the payload cannot decode) so that pre-existing snapshots still load. The same concern applies to rbMemoryStore.Restore.

Useful? React with 👍 / 👎.

if err != nil {
return errors.WithStack(err)
}
if len(data) < 4 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Magic number: 4, in detected (mnd)

@bootjp bootjp enabled auto-merge September 14, 2025 17:27
@bootjp bootjp merged commit 323d8e8 into main Sep 14, 2025
7 checks passed
@bootjp bootjp deleted the codex/fix-issue-with-elastickv-functionality branch September 14, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants