Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checksum op #7

Merged
merged 6 commits into from
Nov 4, 2023
Merged

Checksum op #7

merged 6 commits into from
Nov 4, 2023

Conversation

PaulisMatrix
Copy link

No description provided.

disk_store.go Outdated
timestamp := uint32(time.Now().Unix())
h := Header{TimeStamp: timestamp, KeySize: uint32(len(key)), ValueSize: uint32(len(value))}
h := Header{CheckSum: crc32.ChecksumIEEE([]byte(value)), TimeStamp: timestamp, KeySize: uint32(len(key)), ValueSize: uint32(len(value))}
Copy link
Owner

Choose a reason for hiding this comment

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

checksum should be calculated on all the values. What if my KeySize / Key is corrupted?

@avinassh
Copy link
Owner

avinassh commented Nov 4, 2023

@PaulisMatrix this again misses one more thing: what if my timestamp field is corrupted?

the best way would be to calculate checksum using all fields of the record

format.go Outdated
kvBuf := append([]byte(key), []byte(value)...)

buf := append(headerBuf.Bytes()[4:], kvBuf...)
return crc32.ChecksumIEEE(buf)
Copy link
Author

@PaulisMatrix PaulisMatrix Nov 4, 2023

Choose a reason for hiding this comment

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

@avinassh , I have considered all fields only, except the checksum field itself while calculating.

Copy link
Owner

Choose a reason for hiding this comment

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

ahh, I saw only CalculateCheckSum(key, value string), assumed something else. Right, you do use other fields.

but this looks buggy? Because you are calling EncodeHeader, which includes checksum (which could be empty bytes for now)

err := binary.Write(buf, binary.LittleEndian, &h.CheckSum)

I would suggest moving CalculateCheckSum to be part of Record struct and make it idempotent, it should return same value whether header already contains checksum or not

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I just thought of reusing the EncodeHeader and picking up bytes from 4th index(effectively excluding CheckSum field). But I get your point, have made the change!

@avinassh avinassh merged commit 342af29 into avinassh:final Nov 4, 2023
@avinassh
Copy link
Owner

avinassh commented Nov 4, 2023

Thank you! 🎉

Feel free to send a follow up PR which tests for the checkum

@PaulisMatrix PaulisMatrix deleted the checksum-op branch November 4, 2023 14:46
@avinassh
Copy link
Owner

avinassh commented Nov 4, 2023

btw I had this paper in my reading listing related to checksums and data corruption, I haven't read it yet but you might find it interesting - Detecting silent data corruptions in the wild

@avinassh avinassh mentioned this pull request Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants