Skip to content

CASSANDRA-21694: Validate CRC before zero-copy streaming sstables - #5182

Open
nivykani wants to merge 1 commit into
apache:trunkfrom
nivykani:crc
Open

nivykani wants to merge 1 commit into
apache:trunkfrom
nivykani:crc

Conversation

@nivykani

Copy link
Copy Markdown

This patch adds CRC validation on the receiving side, after an entire sstable is received via zero-copy streaming. This detects SSTables that were already corrupt on the sender's disk and prevents them from being accepted, which stops the corruption from spreading.

Since it's possible for the digest component not to be streamed, this check is disabled by default in the config via entire_sstable_stream_digest_validation_enabled, and fails open (if no digest is present, the streaming succeeds).

Validation costs one sequential read of the data file per received SSTable, and any mismatch makes the streaming session fail and increments a metric for entireSSTableDigestMismatches.

The Cassandra Jira

/**
* When receiving a zero-copy stream, validate Digest.crc32 before the sstable is made visible.
*/
public volatile boolean entire_sstable_stream_digest_validation_enabled = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In 4.0, 4.1, and 5.0, I could see leaving this false by default to preserve behavior on minor upgrade. In 6.0+ I think we want it to be true by default, with an accompanying note in the NEWS.txt "Upgrading" section for 6.0.

WDYT?

try
{
new DataIntegrityMetadata.FileDigestValidator(descriptor.fileFor(Components.DATA),
descriptor.fileFor(Components.DIGEST)).validate();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

validate() throws a NumberFormatException if the digest is malformed. Do we want that to count against countEntireSSTableDigestMismatch() or just flow through?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, it makes more sense to count it toward countEntireSSTableDigestMismatch since it technically still is one. But I notice the other place that validates digests (SortedTableVerifier.verifyDigest()) doesn't catch a NumberFormatException, only IOException. The more reliable fix seems to be throwing an IOException, not a NumberFormatException, so it's correctly caught and handled in both sites. Updated with this change!

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