This PR enables compaction tasks to verify the integrity of the input data through checksum and digest checks. The mechanism for integrity checking was introduced in previous PRs (#20207, #20720) as a built-in functionality of the input streams. This PR integrates this mechanism with compaction. The change applies to all compaction types and covers both compressed and uncompressed SSTables adhering to the 3.x format. If a compaction task reads only part of an SSTable, then only the per-chunk checksums are verified, not the digest. The PR consists of: * Changes to mx readers to support integrity checking. The kl readers, considered as compatibility-only, were left unchanged. Also, integrity checking on single-partition reversed reads (`data_consume_reversed_partition()`) remains unsupported by mx readers as this is not used in compaction. * Changes to `sstable` and `sstable_set` APIs to allow toggling integrity checks for mx readers. * Activation of integrity checking for all compaction types. * Tests for all compaction types with corrupted SSTables. Integrity checks come at a cost. For uncompressed SSTables, the cost is the loading of the CRC and Digest components from disk, and the calculation of checksums and digest from the actual data. For compressed SSTables, checksums are stored in-place and they are being checked already on all reads, so the only extra cost is the loading and calculation of the digest. The measurements show a ~5% regression in compaction performance for uncompressed SSTables, and a negligible regression for compressed SSTables. Command: `perf-sstable --smp=1 --cpuset=1 --poll-mode --mode=compaction --iterations=1000 --partitions 10000 --sstables=1 --key_size=4096 --num_columns=15 --column_size={32, 1024, 3500, 7000, 14500}` Uncompressed SSTables: ``` +--------------+-----------------------+----------------------+------------+ | SSTable Size | No Integrity (p/sec) | Integrity (p/sec) | Regression | +--------------+-----------------------+----------------------+------------+ | 50 MiB | 65175.59 +- 80.82 | 61814.63 +- 72.88 | 5.16% | | 200 MiB | 41795.10 +- 60.39 | 39686.28 +- 45.05 | 5.05% | | 500 MiB | 21087.41 +- 30.72 | 20092.93 +- 25.05 | 4.72% | | 1 GiB | 12781.64 +- 21.77 | 12233.94 +- 21.71 | 4.29% | | 2 GiB | 6629.99 +- 9.40 | 6377.13 +- 8.28 | 3.81% | +--------------+-----------------------+----------------------+------------+ ``` Compressed SSTables: ``` +--------------+-----------------------+----------------------+------------+ | SSTable Size | No Integrity (p/sec) | Integrity (p/sec) | Regression | +--------------+-----------------------+----------------------+------------+ | 50 MiB | 53975.05 +- 63.18 | 53825.93 +- 62.28 | 0.28% | | 200 MiB | 28687.94 +- 26.58 | 28689.41 +- 26.91 | 0% | | 500 MiB | 13865.35 +- 15.50 | 13790.41 +- 14.88 | 0.54% | | 1 GiB | 7858.10 +- 7.71 | 7829.75 +- 9.66 | 0.36% | | 2 GiB | 4023.11 +- 2.43 | 4010.54 +- 2.55 | 0.31% | +--------------+-----------------------+----------------------+------------+ (p/sec = partitions/sec) ``` Refs #19071. New feature, no backport is needed. Closes scylladb/scylladb#21153 * github.com:scylladb/scylladb: test: Add test for compaction with corrupted SSTables compaction: Enable integrity checks for all compaction types sstables: Add integrity option to factories for sstable_set readers sstables: Add integrity option to sstable::make_reader() sstables: Add integrity option to mx::make_reader() sstables: Load checksums and digests in mx full-scan reader sstables: Add integrity option to data_consume_single_partition() sstables: Disengage integrity_check from sstable class sstables: Allow data sources to disable digest check
Scylla unit tests using C++ and the Boost test framework
The source files in this directory are Scylla unit tests written in C++ using the Boost.Test framework. These unit tests come in three flavors:
-
Some simple tests that check stand-alone C++ functions or classes use Boost's
BOOST_AUTO_TEST_CASE. -
Some tests require Seastar features, and need to be declared with Seastar's extensions to Boost.Test, namely
SEASTAR_TEST_CASE. -
Even more elaborate tests require not just a functioning Seastar environment but also a complete (or partial) Scylla environment. Those tests use the
do_with_cql_env()ordo_with_cql_env_thread()function to set up a mostly-functioning environment behaving like a single-node Scylla, in which the test can run.
While we have many tests of the third flavor, writing new tests of this type should be reserved to white box tests - tests where it is necessary to inspect or control Scylla internals that do not have user-facing APIs such as CQL. In contrast, black-box tests - tests that can be written only using user-facing APIs, should be written in one of newer test frameworks that we offer - such as test/cqlpy or test/alternator (in Python, using the CQL or DynamoDB APIs respectively) or test/cql (using textual CQL commands), or - if more than one Scylla node is needed for a test - using the test/topology* framework.
Running tests
Because these are C++ tests, they need to be compiled before running.
To compile a single test executable row_cache_test, use a command like
ninja build/dev/test/boost/row_cache_test
You can also use ninja dev-test to build all C++ tests, or use
ninja deb-build to build the C++ tests and also the full Scylla executable
(however, note that full Scylla executable isn't needed to run Boost tests).
Replace "dev" by "debug" or "release" in the examples above and below to use the "debug" build mode (which, importantly, compiles the test with ASAN and UBSAN enabling on and helps catch difficult-to-catch use-after-free bugs) or the "release" build mode (optimized for run speed).
To run an entire test file row_cache_test, including all its test
functions, use a command like:
build/dev/test/boost/row_cache_test -- -c1 -m1G
to run a single test function test_reproduce_18045() from the longer test
file, use a command like:
build/dev/test/boost/row_cache_test -t test_reproduce_18045 -- -c1 -m1G
In these command lines, the parameters before the -- are passed to
Boost.Test, while the parameters after the -- are passed to the test code,
and in particular to Seastar. In this example Seastar is asked to run on one
CPU (-c1) and use 1G of memory (-m1G) instead of hogging the entire
machine. The Boost.Test option -t test_reproduce_18045 asks it to run just
this one test function instead of all the test functions in the executable.
Unfortunately, interrupting a running test with control-C while doesn't
work. This is a known bug (#5696). Kill a test with SIGKILL (-9) if you
need to kill it while it's running.
Boost tests can also be run using test.py - which is a script that provides a uniform way to run all tests in scylladb.git - C++ tests, Python tests, etc.
Writing tests
Because of the large build time and build size of each separate test executable, it is recommended to put test functions into relatively large source files. But not too large - to keep compilation time of a single source file (during development) at reasonable levels.
When adding new source files in test/boost, don't forget to list the new source file in configure.py and also in CMakeLists.txt. The former is needed by our CI, but the latter is preferred by some developers.