Skip to content

Commit

Permalink
type
Browse files Browse the repository at this point in the history
  • Loading branch information
hx235 committed Dec 17, 2024
1 parent 09c989f commit dc07c04
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
7 changes: 5 additions & 2 deletions db/log_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace ROCKSDB_NAMESPACE {
namespace log {

enum RecordType {
enum RecordType : int {
// Zero is reserved for preallocated files
kZeroType = 0,
kFullType = 1,
Expand All @@ -39,8 +39,11 @@ enum RecordType {
// User-defined timestamp sizes
kUserDefinedTimestampSizeType = 10,
kRecyclableUserDefinedTimestampSizeType = 11,

// Reserve kRecordTypeSafeIgnoreMask = 32
};
constexpr int kMaxRecordType = kRecyclableUserDefinedTimestampSizeType;
const int kRecordTypeSafeIgnoreMask = 1 << 5;
constexpr int kMaxRecordType = kRecordTypeSafeIgnoreMask + 5;

constexpr unsigned int kBlockSize = 32768;

Expand Down
24 changes: 14 additions & 10 deletions db/log_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,13 @@ bool Reader::ReadRecord(Slice* record, std::string* scratch,
break;

default: {
std::string reason =
"unknown record type " + std::to_string(record_type);
ReportCorruption(
(fragment.size() + (in_fragmented_record ? scratch->size() : 0)),
reason.c_str());
if (record_type <= kRecordTypeSafeIgnoreMask) {
std::string reason =
"unknown record type " + std::to_string(record_type);
ReportCorruption(
(fragment.size() + (in_fragmented_record ? scratch->size() : 0)),
reason.c_str());
}
in_fragmented_record = false;
scratch->clear();
break;
Expand Down Expand Up @@ -781,11 +783,13 @@ bool FragmentBufferedReader::ReadRecord(Slice* record, std::string* scratch,
break;

default: {
std::string reason =
"unknown record type " + std::to_string(fragment_type_or_err);
ReportCorruption(
fragment.size() + (in_fragmented_record_ ? fragments_.size() : 0),
reason.c_str());
if (fragment_type_or_err <= kRecordTypeSafeIgnoreMask) {
std::string reason =
"unknown record type " + std::to_string(fragment_type_or_err);
ReportCorruption(
fragment.size() + (in_fragmented_record_ ? fragments_.size() : 0),
reason.c_str());
}
in_fragmented_record_ = false;
fragments_.clear();
break;
Expand Down
6 changes: 3 additions & 3 deletions db/log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,14 @@ TEST_P(LogTest, ReadError) {
ASSERT_EQ("OK", MatchError("read error"));
}

TEST_P(LogTest, BadRecordType) {
TEST_P(LogTest, ForwardCompatibleType) {
Write("foo");
// Type is stored in header[6]
IncrementByte(6, 100);
FixChecksum(0, 3, false);
ASSERT_EQ("EOF", Read());
ASSERT_EQ(3U, DroppedBytes());
ASSERT_EQ("OK", MatchError("unknown record type"));
ASSERT_EQ(0U, DroppedBytes());
ASSERT_EQ("", ReportMessage());
}

TEST_P(LogTest, TruncatedTrailingRecordIsIgnored) {
Expand Down

0 comments on commit dc07c04

Please sign in to comment.