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) {