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

Enhance Data Integrity with Binlog Event Checksum Verification #458

Conversation

why-arong
Copy link
Contributor

@why-arong why-arong commented Aug 28, 2023

Overview

This PR add supports for verifying event checksums when the binlog_checksum option is enabled in MySQL/MariaDB(5.7, 8.0). It enhances data integrity and security by validating each event in the binary log.

Changes

Key updates in this PR include:

  • Introduction of the _verify_event method in the BinlogEvent class. When both the binlog_checksum option of MySQL/MariaDB and the verify_checksum option of BinLogStreamReader are active, this function:
    • Reads data, omitting the final CRC32 4 bytes.
    • Applies the zlib CRC32 algorithm on the data, then contrasts the outcome with the last 4 CRC32 bytes.
    • Restores the packet's state to its original condition post-execution.

The reason this method is effective lies in the shared use of the CRC32 algorithm by both MySQL and this method.

Test Code

To ensure the accuracy of the _verify_event method, test code has been designed to handle two main scenarios: valid events and corrupted events. The respective tests can be accessed in this source code file.

Benefits

  • Enhances data integrity by verifying event checksums.
  • Improves system reliability and reduces the risk of data loss.

Comment

Slave already has these features. When slave_sql_verify_checksum is enabled, the replication SQL thread uses checksums read from relay logs to verify data. I believe that incorporating these functionalities into our project would be highly advantageous.

@julien-duponchelle julien-duponchelle merged commit 460a702 into julien-duponchelle:main Sep 1, 2023
4 checks passed
@julien-duponchelle
Copy link
Owner

That's great !

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