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

Add optional CRC per log entry. #454

Merged
merged 4 commits into from
Aug 9, 2023
Merged

Add optional CRC per log entry. #454

merged 4 commits into from
Aug 9, 2023

Conversation

yong-li
Copy link
Contributor

@yong-li yong-li commented Aug 7, 2023

Add an option to replicate and verify per-log-entry CRC checksums.

The log entry's checksum is computed when the entry is first created on the leader, and then stored in the log store and replicated over the network. On receive, if the checksum is sent, it is verified.

Comment on lines +106 to +112
uint32_t get_crc32() const {
return crc32_;
}

void set_crc32(uint32_t crc) {
crc32_ = crc;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For backward compatibility (for the previous logs that do not have CRC, and they can be mixed with new logs with CRC), we should have one more field indicating if CRC exists or not, let's say has_crc32_.

Otherwise, we cannot distinguish non-existing CRC and CRC=0. Also we need an API returning that flag:

bool has_crc32() const () { ... }

that will be used in asio layer (replacing crc32 != 0).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Comment on lines 1259 to 1261
if (impl_->get_options().crc_on_payload_) {
ss.put_u32(le->get_crc32());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, we need to ship the existence flag as well.

if (impl_->get_options().crc_on_payload_) {
    ss.put_u8(le->has_crc32() ? 1 : 0);
    ss.put_u32(le->get_crc32());
}

and

LOG_ENTRY_SIZE += 5;

I don't have better idea rather than shipping 5 bytes.

uint64_t log_timestamp = 0)
uint64_t log_timestamp = 0,
uint32_t crc32 = 0,
bool compute_crc = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be false by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to cope with conf logs. There are more than 1 place where conf logs are constructed. Either we need to copy the CRC computation code (or this true flag) everywhere (and I need to make sure I found every place), or we bite the performance overhead and lean towards safety.

@@ -23,8 +23,10 @@ limitations under the License.

#include "basic_types.hxx"
#include "buffer.hxx"
#include "crc32.hxx"
Copy link
Contributor

Choose a reason for hiding this comment

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

Another thing I just found: crc32.hxx is not a public header, but it is included in log_entry.hxx which is the library's public header. Since we don't want to expose our custom CRC implementation, we need a separate log_entry.cxx file in src.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. Will do.

@yong-li yong-li requested a review from greensky00 August 9, 2023 07:18
greensky00
greensky00 previously approved these changes Aug 9, 2023
Copy link
Contributor

@greensky00 greensky00 left a comment

Choose a reason for hiding this comment

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

LGTM, but one missing initialization. Let me add the fix and merge it. Thanks.

* should not be any member running with the old version before supporting
* this flag.
*/
bool crc_on_payload_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Initialization in the constructor is missing.

@greensky00 greensky00 merged commit a4e8ff0 into eBay:master Aug 9, 2023
1 check passed
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