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 cb229c3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
19 changes: 13 additions & 6 deletions db/db_wal_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1850,12 +1850,12 @@ 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());
ASSERT_OK(dbfull()->TEST_WaitForBackgroundWork());

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()->TEST_WaitForBackgroundWork());

// Stop background flush to avoid deleting any WAL
env_->SetBackgroundThreads(1, Env::HIGH);
Expand Down Expand Up @@ -1909,6 +1909,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 +1941,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 +2013,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 +2037,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 +2288,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 +2346,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
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 cb229c3

Please sign in to comment.