diff --git a/db/version_edit.h b/db/version_edit.h index 808be58bd..229531792 100644 --- a/db/version_edit.h +++ b/db/version_edit.h @@ -229,6 +229,10 @@ class VersionEdit { uint64_t log_number() { return log_number_; } + bool has_next_file_number() const { return has_next_file_number_; } + + uint64_t next_file_number() const { return next_file_number_; } + // Add the specified file at the specified number. // REQUIRES: This version has not been saved (see VersionSet::SaveTo) // REQUIRES: "smallest" and "largest" are smallest and largest keys in file diff --git a/db/version_edit_test.cc b/db/version_edit_test.cc index 0668de7aa..64d1fd77b 100644 --- a/db/version_edit_test.cc +++ b/db/version_edit_test.cc @@ -8,6 +8,7 @@ // found in the LICENSE file. See the AUTHORS file for names of contributors. #include "db/version_edit.h" +#include "util/coding.h" #include "util/sync_point.h" #include "util/testharness.h" @@ -197,6 +198,47 @@ TEST_F(VersionEditTest, AtomicGroupTest) { TestEncodeDecode(edit); } +TEST_F(VersionEditTest, IgnorableField) { + VersionEdit ve; + std::string encoded; + + // Size of ignorable field is too large + PutVarint32Varint64(&encoded, 2 /* kLogNumber */, 66); + // This is a customized ignorable tag + PutVarint32Varint64(&encoded, + 0x2710 /* A field with kTagSafeIgnoreMask set */, + 5 /* fieldlength 5 */); + encoded += "abc"; // Only fills 3 bytes, + ASSERT_NOK(ve.DecodeFrom(encoded)); + + encoded.clear(); + // Error when seeing unidentified tag that is not ignorable + PutVarint32Varint64(&encoded, 2 /* kLogNumber */, 66); + // This is a customized ignorable tag + PutVarint32Varint64(&encoded, 666 /* A field with kTagSafeIgnoreMask unset */, + 3 /* fieldlength 3 */); + encoded += "abc"; // Fill 3 bytes + PutVarint32Varint64(&encoded, 3 /* next file number */, 88); + ASSERT_NOK(ve.DecodeFrom(encoded)); + + // Safely ignore an identified but safely ignorable entry + encoded.clear(); + PutVarint32Varint64(&encoded, 2 /* kLogNumber */, 66); + // This is a customized ignorable tag + PutVarint32Varint64(&encoded, + 0x2710 /* A field with kTagSafeIgnoreMask set */, + 3 /* fieldlength 3 */); + encoded += "abc"; // Fill 3 bytes + PutVarint32Varint64(&encoded, 3 /* kNextFileNumber */, 88); + + ASSERT_OK(ve.DecodeFrom(encoded)); + + ASSERT_TRUE(ve.has_log_number()); + ASSERT_TRUE(ve.has_next_file_number()); + ASSERT_EQ(66, ve.log_number()); + ASSERT_EQ(88, ve.next_file_number()); +} + } // namespace rocksdb int main(int argc, char** argv) {