Avoid pointless calls to ThreadLocalRandom during CRC probability calculations
Patch by Jeff Jirsa; Reviewed by Jason Brown for CASSANDRA-14094 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b885e9c0 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b885e9c0 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b885e9c0 Branch: refs/heads/trunk Commit: b885e9c0547709152b5a118af30508bf287d3844 Parents: 090f418 Author: Jeff Jirsa <jji...@apple.com> Authored: Mon Dec 4 16:32:30 2017 -0800 Committer: Jeff Jirsa <jji...@apple.com> Committed: Wed Dec 6 21:55:47 2017 -0800 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/io/compress/CompressedRandomAccessReader.java | 6 ++++-- .../cassandra/streaming/compress/CompressedInputStream.java | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/b885e9c0/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 9638886..b275397 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.16 + * Optimize CRC check chance probability calculations (CASSANDRA-14094) * Fix cleanup on keyspace with no replicas (CASSANDRA-13526) * Fix updating base table rows with TTL not removing materialized view entries (CASSANDRA-14071) * Reduce garbage created by DynamicSnitch (CASSANDRA-14091) http://git-wip-us.apache.org/repos/asf/cassandra/blob/b885e9c0/src/java/org/apache/cassandra/io/compress/CompressedRandomAccessReader.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/io/compress/CompressedRandomAccessReader.java b/src/java/org/apache/cassandra/io/compress/CompressedRandomAccessReader.java index 0624e89..9658316 100644 --- a/src/java/org/apache/cassandra/io/compress/CompressedRandomAccessReader.java +++ b/src/java/org/apache/cassandra/io/compress/CompressedRandomAccessReader.java @@ -129,7 +129,8 @@ public class CompressedRandomAccessReader extends RandomAccessReader buffer.flip(); } - if (getCrcCheckChance() > ThreadLocalRandom.current().nextDouble()) + if (getCrcCheckChance() >= 1d || + getCrcCheckChance() > ThreadLocalRandom.current().nextDouble()) { compressed.rewind(); metadata.checksumType.update( checksum, (compressed)); @@ -191,7 +192,8 @@ public class CompressedRandomAccessReader extends RandomAccessReader buffer.flip(); } - if (getCrcCheckChance() > ThreadLocalRandom.current().nextDouble()) + if (getCrcCheckChance() >= 1d || + getCrcCheckChance() > ThreadLocalRandom.current().nextDouble()) { compressedChunk.position(chunkOffset).limit(chunkOffset + chunk.length); http://git-wip-us.apache.org/repos/asf/cassandra/blob/b885e9c0/src/java/org/apache/cassandra/streaming/compress/CompressedInputStream.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/streaming/compress/CompressedInputStream.java b/src/java/org/apache/cassandra/streaming/compress/CompressedInputStream.java index 6577980..e3d698e 100644 --- a/src/java/org/apache/cassandra/streaming/compress/CompressedInputStream.java +++ b/src/java/org/apache/cassandra/streaming/compress/CompressedInputStream.java @@ -136,7 +136,8 @@ public class CompressedInputStream extends InputStream totalCompressedBytesRead += compressed.length; // validate crc randomly - if (this.crcCheckChanceSupplier.get() > ThreadLocalRandom.current().nextDouble()) + if (this.crcCheckChanceSupplier.get() >= 1d || + this.crcCheckChanceSupplier.get() > ThreadLocalRandom.current().nextDouble()) { checksum.update(compressed, 0, compressed.length - checksumBytes.length); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org