From 3a75219e5d2e1067a127d550eda7892941ec3284 Mon Sep 17 00:00:00 2001 From: Changyu Bi Date: Wed, 31 Aug 2022 17:47:07 -0700 Subject: [PATCH] Validate option `memtable_protection_bytes_per_key` (#10621) Summary: sanity check value for option `memtable_protection_bytes_per_key` in `ColumnFamilyData::ValidateOptions()`. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10621 Test Plan: `make check`, added unit test in ColumnFamilyTest. Reviewed By: ajkr Differential Revision: D39180133 Pulled By: cbi42 fbshipit-source-id: 009e0da3ccb332d1c9e14d20193304610bd4eb8a --- db/column_family.cc | 8 ++++++++ db/column_family_test.cc | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/db/column_family.cc b/db/column_family.cc index 95cb7cee4..ebeb574fa 100644 --- a/db/column_family.cc +++ b/db/column_family.cc @@ -1415,6 +1415,14 @@ Status ColumnFamilyData::ValidateOptions( "FIFO compaction only supported with max_open_files = -1."); } + std::vector supported{0, 1, 2, 4, 8}; + if (std::find(supported.begin(), supported.end(), + cf_options.memtable_protection_bytes_per_key) == + supported.end()) { + return Status::NotSupported( + "Memtable per key-value checksum protection only supports 0, 1, 2, 4 " + "or 8 bytes per key."); + } return s; } diff --git a/db/column_family_test.cc b/db/column_family_test.cc index 07d28f155..aa8f73f63 100644 --- a/db/column_family_test.cc +++ b/db/column_family_test.cc @@ -3433,6 +3433,27 @@ TEST(ColumnFamilyTest, ValidateBlobGCForceThreshold) { .IsInvalidArgument()); } +TEST(ColumnFamilyTest, ValidateMemtableKVChecksumOption) { + DBOptions db_options; + + ColumnFamilyOptions cf_options; + ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options)); + + cf_options.memtable_protection_bytes_per_key = 5; + ASSERT_TRUE(ColumnFamilyData::ValidateOptions(db_options, cf_options) + .IsNotSupported()); + + cf_options.memtable_protection_bytes_per_key = 1; + ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options)); + + cf_options.memtable_protection_bytes_per_key = 16; + ASSERT_TRUE(ColumnFamilyData::ValidateOptions(db_options, cf_options) + .IsNotSupported()); + + cf_options.memtable_protection_bytes_per_key = 0; + ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options)); +} + } // namespace ROCKSDB_NAMESPACE int main(int argc, char** argv) {