Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
hx235 committed Dec 20, 2024
1 parent 20cfacf commit de8df0e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
21 changes: 15 additions & 6 deletions db/db_wal_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1850,12 +1850,14 @@ TEST_F(DBWALTest, TrackAndVerifyWALsRecycleWAL) {
ASSERT_OK(Put("key_ignore", "wal_to_recycle"));
ASSERT_OK(Put("key_ignore1", "wal_to_recycle"));
ASSERT_OK(Put("key_ignore2", "wal_to_recycle"));
ASSERT_OK(Flush());
FlushOptions fo;
fo.wait = true;
ASSERT_OK(dbfull()->Flush(fo));

ASSERT_OK(Put("key_ignore", "wal_to_recycle"));
ASSERT_OK(Put("key_ignore1", "wal_to_recycle"));
ASSERT_OK(Put("key_ignore2", "wal_to_recycle"));
ASSERT_OK(Flush());
ASSERT_OK(dbfull()->Flush(fo));

// Stop background flush to avoid deleting any WAL
env_->SetBackgroundThreads(1, Env::HIGH);
Expand Down Expand Up @@ -1909,6 +1911,7 @@ TEST_P(DBWALTrackAndVerifyWALsWithParamsTest, Basic) {
options.avoid_flush_during_shutdown = true;
options.track_and_verify_wals = true;
options.wal_recovery_mode = GetParam();
// options.wal_compression = CompressionType::kZSTD;

DestroyAndReopen(options);

Expand Down Expand Up @@ -1940,6 +1943,12 @@ TEST_P(DBWALTrackAndVerifyWALsWithParamsTest, Basic) {
options.wal_recovery_mode ==
WALRecoveryMode::kTolerateCorruptedTailRecords) {
ASSERT_TRUE(s.IsCorruption());
// Debug
if (!(s.ToString().find(
"Mismatched last sequence number recorded in the WAL") !=
std::string::npos)) {
std::cout << s.ToString() << std::endl;
}
ASSERT_TRUE(s.ToString().find(
"Mismatched last sequence number recorded in the WAL") !=
std::string::npos);
Expand Down Expand Up @@ -2006,7 +2015,7 @@ TEST_P(DBWALTestWithParams, kTolerateCorruptedTailRecords) {

// Fill data for testing
Options options = CurrentOptions();
options.track_and_verify_wals = std::get<4>(GetParam());
options.track_and_verify_wals = false && std::get<4>(GetParam());
const size_t row_count = RecoveryTestHelper::FillData(this, &options);
// test checksum failure or parsing
RecoveryTestHelper::CorruptWAL(this, options, corrupt_offset * .3,
Expand All @@ -2030,7 +2039,7 @@ TEST_P(DBWALTestWithParams, kTolerateCorruptedTailRecords) {
TEST_P(DBWALTestWithParams, kAbsoluteConsistency) {
// Verify clean slate behavior
Options options = CurrentOptions();
options.track_and_verify_wals = std::get<4>(GetParam());
options.track_and_verify_wals = false && std::get<4>(GetParam());
const size_t row_count = RecoveryTestHelper::FillData(this, &options);
options.create_if_missing = false;
ASSERT_OK(TryReopen(options));
Expand Down Expand Up @@ -2281,7 +2290,7 @@ TEST_P(DBWALTestWithParams, kPointInTimeRecovery) {

// Fill data for testing
Options options = CurrentOptions();
options.track_and_verify_wals = std::get<4>(GetParam());
options.track_and_verify_wals = false && std::get<4>(GetParam());
options.wal_compression = compression_type;
const size_t row_count = RecoveryTestHelper::FillData(this, &options);

Expand Down Expand Up @@ -2339,7 +2348,7 @@ TEST_P(DBWALTestWithParams, kSkipAnyCorruptedRecords) {

// Fill data for testing
Options options = CurrentOptions();
options.track_and_verify_wals = std::get<4>(GetParam());
options.track_and_verify_wals = false && std::get<4>(GetParam());
options.wal_compression = compression_type;
const size_t row_count = RecoveryTestHelper::FillData(this, &options);

Expand Down
7 changes: 5 additions & 2 deletions db/log_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ enum RecordType : uint8_t {
kUserDefinedTimestampSizeType = 10,
kRecyclableUserDefinedTimestampSizeType = 11,

kPredecessorWALInfoType = 12,
kRecyclePredecessorWALInfoType = 13,

// For WAL verification
kPredecessorWALInfoType = 129,
kRecyclePredecessorWALInfoType = 130,
// kPredecessorWALInfoType = 129,
// kRecyclePredecessorWALInfoType = 130,
};
// Unknown type of value with the 8-th bit set will be ignored
constexpr uint8_t kRecordTypeSafeIgnoreMask = 1 << 7;
Expand Down
16 changes: 15 additions & 1 deletion db/log_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "db/log_reader.h"

#include <cstdio>
#include <iostream>

#include "file/sequence_file_reader.h"
#include "port/lang.h"
Expand Down Expand Up @@ -579,7 +580,14 @@ uint8_t Reader::ReadPhysicalRecord(Slice* result, size_t* drop_size,
continue;
}
}

if (track_and_verify_wals_) {
std::cout << " " << std::endl;
std::cout << "Normal: " << std::endl;
std::cout << "Type: " << std::to_string(type) << std::endl;
std::cout << "header_size: " << header_size << std::endl;
std::cout << "length: " << length << std::endl;
std::cout << "buffer_.size(): " << buffer_.size() << std::endl;
}
if (header_size + length > buffer_.size()) {
assert(buffer_.size() >= static_cast<size_t>(header_size));
*drop_size = buffer_.size();
Expand All @@ -588,6 +596,12 @@ uint8_t Reader::ReadPhysicalRecord(Slice* result, size_t* drop_size,
// `header_size + length` bytes of payload, report a corruption. The
// higher layers can decide how to handle it based on the recovery mode,
// whether this occurred at EOF, whether this is the final WAL, etc.
std::cout << " " << std::endl;
std::cout << "kBadRecordLen: " << std::endl;
std::cout << "Type: " << std::to_string(type) << std::endl;
std::cout << "header_size: " << header_size << std::endl;
std::cout << "length: " << length << std::endl;
std::cout << "buffer_.size(): " << buffer_.size() << std::endl;
return kBadRecordLen;
}

Expand Down
12 changes: 12 additions & 0 deletions db/log_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "db/log_writer.h"

#include <cstdint>
#include <iostream>

#include "file/writable_file_writer.h"
#include "rocksdb/env.h"
Expand Down Expand Up @@ -395,6 +396,17 @@ IOStatus Writer::MaybeSwitchToNewBlock(const WriteOptions& write_options,
}

block_offset_ = 0;
std::cout << " " << std::endl;
std::cout << "Switching to a new block" << std::endl;
} else {
std::cout << " " << std::endl;
std::cout << "Did not switch to a new block" << std::endl;
std::cout << "leftover: " << leftover << std::endl;
std::cout << "header_size_: " << header_size_ << std::endl;
std::cout << "content_to_write.size(): " << content_to_write.size()
<< std::endl;
std::cout << "(int)content_to_write.size(): "
<< (int)content_to_write.size() << std::endl;
}
return s;
}
Expand Down

0 comments on commit de8df0e

Please sign in to comment.