summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorChangyu Bi <changyubi@fb.com>2022-06-15 13:43:58 -0700
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>2022-06-15 13:43:58 -0700
commit9882652b0e2db21974aaa682ef7664c7ebe2f84e (patch)
tree7bba5d2e6424593c87f3875a30a02afa78b4fa84 /tools
parent2e5a323dbd4dbfad5b1e3d45d489e6dca37f4257 (diff)
Verify write batch checksum before WAL (#10114)
Summary: Context: WriteBatch can have key-value checksums when it was created `with protection_bytes_per_key > 0`. This PR added checksum verification for write batches before they are written to WAL. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10114 Test Plan: - Added new unit tests to db_kv_checksum_test.cc: `make check -j32` - benchmark on performance regression: `./db_bench --benchmarks=fillrandom[-X20] -db=/dev/shm/test_rocksdb -write_batch_protection_bytes_per_key=8` - Pre-PR: ` fillrandom [AVG 20 runs] : 198875 (± 3006) ops/sec; 22.0 (± 0.3) MB/sec ` - Post-PR: ` fillrandom [AVG 20 runs] : 196487 (± 2279) ops/sec; 21.7 (± 0.3) MB/sec ` Mean regressed about 1% (198875 -> 196487 ops/sec). Reviewed By: ajkr Differential Revision: D36917464 Pulled By: cbi42 fbshipit-source-id: 29beb74edf65f04b1a890b4f650d873dc7ed790d
Diffstat (limited to 'tools')
-rw-r--r--tools/db_bench_tool.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc
index a163d8667..46d8a9af1 100644
--- a/tools/db_bench_tool.cc
+++ b/tools/db_bench_tool.cc
@@ -1656,6 +1656,10 @@ static const bool FLAGS_table_cache_numshardbits_dummy __attribute__((__unused__
RegisterFlagValidator(&FLAGS_table_cache_numshardbits,
&ValidateTableCacheNumshardbits);
+DEFINE_uint32(write_batch_protection_bytes_per_key, 0,
+ "Size of per-key-value checksum in each write batch. Currently "
+ "only value 0 and 8 are supported.");
+
namespace ROCKSDB_NAMESPACE {
namespace {
static Status CreateMemTableRepFactory(
@@ -4910,7 +4914,8 @@ class Benchmark {
RandomGenerator gen;
WriteBatch batch(/*reserved_bytes=*/0, /*max_bytes=*/0,
- /*protection_bytes_per_key=*/0, user_timestamp_size_);
+ FLAGS_write_batch_protection_bytes_per_key,
+ user_timestamp_size_);
Status s;
int64_t bytes = 0;
@@ -6699,7 +6704,8 @@ class Benchmark {
void DoDelete(ThreadState* thread, bool seq) {
WriteBatch batch(/*reserved_bytes=*/0, /*max_bytes=*/0,
- /*protection_bytes_per_key=*/0, user_timestamp_size_);
+ FLAGS_write_batch_protection_bytes_per_key,
+ user_timestamp_size_);
Duration duration(seq ? 0 : FLAGS_duration, deletes_);
int64_t i = 0;
std::unique_ptr<const char[]> key_guard;
@@ -6899,7 +6905,8 @@ class Benchmark {
std::string keys[3];
WriteBatch batch(/*reserved_bytes=*/0, /*max_bytes=*/0,
- /*protection_bytes_per_key=*/0, user_timestamp_size_);
+ FLAGS_write_batch_protection_bytes_per_key,
+ user_timestamp_size_);
Status s;
for (int i = 0; i < 3; i++) {
keys[i] = key.ToString() + suffixes[i];
@@ -6931,7 +6938,7 @@ class Benchmark {
std::string suffixes[3] = {"1", "2", "0"};
std::string keys[3];
- WriteBatch batch(0, 0, /*protection_bytes_per_key=*/0,
+ WriteBatch batch(0, 0, FLAGS_write_batch_protection_bytes_per_key,
user_timestamp_size_);
Status s;
for (int i = 0; i < 3; i++) {