From cb229c3b6ee83a2d6ee41b202974b18d727783cf Mon Sep 17 00:00:00 2001 From: Hui Xiao Date: Thu, 19 Dec 2024 21:18:53 -0800 Subject: [PATCH] debug --- db/db_wal_test.cc | 19 +++++++++++++------ db/log_reader.cc | 16 +++++++++++++++- db/log_writer.cc | 12 ++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/db/db_wal_test.cc b/db/db_wal_test.cc index 102f671ba63c..67b7f5d9b71b 100644 --- a/db/db_wal_test.cc +++ b/db/db_wal_test.cc @@ -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); @@ -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); @@ -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); @@ -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, @@ -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)); @@ -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); @@ -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); diff --git a/db/log_reader.cc b/db/log_reader.cc index 177e9be31226..c05fac8eaa8e 100644 --- a/db/log_reader.cc +++ b/db/log_reader.cc @@ -10,6 +10,7 @@ #include "db/log_reader.h" #include +#include #include "file/sequence_file_reader.h" #include "port/lang.h" @@ -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(header_size)); *drop_size = buffer_.size(); @@ -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; } diff --git a/db/log_writer.cc b/db/log_writer.cc index ae4cb821184a..365553371cf4 100644 --- a/db/log_writer.cc +++ b/db/log_writer.cc @@ -10,6 +10,7 @@ #include "db/log_writer.h" #include +#include #include "file/writable_file_writer.h" #include "rocksdb/env.h" @@ -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; }