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

[WIP] Skip the checksum for diskless replication #1181

Conversation

Shivshankar-Reddy
Copy link
Contributor

fixes: #1129
Below is the background information from #1129 by @madolson

When we are not writing to disk (either on the primary or replica) there isn't a lot of sense in doing CRC64 checksumming during fullsync. We do checking summing at the TCP layer already. At AWS we've seen it can take up to 15% overhead for not much of a benefit. We should look into a mechanism so that a replica can indicate that it will load something directly into memory, since today we only indicate we support the EOF marker. The replica might still choose to save the RDB file to disk unless repl-diskless-load is enabled. With this mechanism in place, we should be able to skip the checksum for replication, while still using it for RDB.

Here is my understanding and proposal as a fix for the issue. Please correct me if my understanding is wrong or missing something!

image

  • Added 'replication-diskless-load' to sendCommand replica details in syncWithPrimary and FullSyncWithPrimary.
  • Added rdbFlag to skip checksum based on 'replica-diskless-load' configuaration from the replica.

@Shivshankar-Reddy Shivshankar-Reddy changed the title Skip the checksum for diskless replication [WIP] Skip the checksum for diskless replication Oct 17, 2024
@hpatro hpatro requested a review from ranshid October 22, 2024 17:24
Copy link
Collaborator

@hpatro hpatro left a comment

Choose a reason for hiding this comment

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

Do we avoid any kind of memory corruption by performing a checksum match? If CRC64 is expensive, we could look at other alternatives.

Copy link
Member

@ranshid ranshid left a comment

Choose a reason for hiding this comment

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

@Shivshankar-Reddy Sorry had some urgent issues and holidays so was unable to look at it yet.
Overall I like this added ability!

General question I have: I noticed that you only disabled CRC calculation on the primary side? Basically both primary and replica are performing the CRC calculation. When the replica is completely aware that the data is sent and loaded diskless it can just skip CRC check even when the primary did calculate and report it (for example a replica syncing with an older version primary). the replica can probably know that the Primary is streaming via socket by the fact that it send the EOF marker.

startSaving(RDBFLAGS_REPLICATION);
getRandomHexChars(eofmark, RDB_EOF_MARK_SIZE);
if (error) *error = 0;
if (rioWrite(rdb, "$EOF:", 5) == 0) goto werr;
if (rioWrite(rdb, eofmark, RDB_EOF_MARK_SIZE) == 0) goto werr;
if (rioWrite(rdb, "\r\n", 2) == 0) goto werr;
if (server.repl_diskless_sync && req & REPLICA_REQ_CHKSUM_SKIP)
skip_cksum_repl |= RDBFLAGS_CKSUM_SKIP;
if (rdbSaveRio(req, rdb, error, skip_cksum_repl, rsi) == C_ERR) goto werr;
Copy link
Member

Choose a reason for hiding this comment

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

we should probably keep only one rdbSaveRio :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for noticing this. I am aware of this and removed in my local branch, this has had happened because I had merge conflict in the branch so created this by copying the code from original branch. it was missed during the copy paste

long rdb_diskless_load = 0;
if (getRangeLongFromObjectOrReply(c, c->argv[j + 1], 0, 1, &rdb_diskless_load, NULL) != C_OK) return;
if (rdb_diskless_load == 1)
c->replica_req |= REPLICA_REQ_CHKSUM_SKIP;
Copy link
Member

@ranshid ranshid Oct 27, 2024

Choose a reason for hiding this comment

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

I think at this point the skip CRC is more "capability" than "requirement" on the replica side. So I would suggest adding a replconf capa indication instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially my plan also was to add in capabilities, However the capabilies were not passed many function as requirements being passed. Since requirements are so flexible in the available functions I added in the requirements. But I agree with you this should be part of the capa. PR is still in-progress I will try to make this in Capabilities instead of requirements. Thank you!

@Shivshankar-Reddy
Copy link
Contributor Author

Thank you for the review and the input!

General question I have: I noticed that you only disabled CRC calculation on the primary side? Basically both primary and replica are performing the CRC calculation. When the replica is completely aware that the data is sent and loaded diskless it can just skip CRC check even when the primary did calculate and report it (for example a replica syncing with an older version primary). the replica can probably know that the Primary is streaming via socket by the fact that it send the EOF marker.

In my initial testing, found that replica was able to deteremine CRC is enabled/disabled so I thought it would be enough to disable at primary end. and I think you have the valid point to consider replica side aswell. I will look into this and will update the diff soon, thanks again!

@ranshid
Copy link
Member

ranshid commented Jan 14, 2025

@Shivshankar-Reddy thank you so much for taking the time to handle this. I think that since it was in conflict with #1479 (which is almost completed) we will close this one.

@ranshid ranshid closed this Jan 14, 2025
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.

Skip CRC64 checksumming when doing diskless replication
3 participants