Skip to content

Commit

Permalink
Debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang committed Mar 14, 2022
1 parent 37ff827 commit 60820e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dbms/src/Storages/Page/V3/LogFile/LogReader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Common/Checksum.h>
#include <Common/Exception.h>
#include <Common/FailPoint.h>
#include <Common/RedactHelpers.h>
#include <Encryption/ReadBufferFromFileProvider.h>
#include <IO/ReadBufferFromMemory.h>
#include <IO/ReadHelpers.h>
Expand Down Expand Up @@ -306,6 +307,7 @@ LogReader::deserializeHeader(LogReader::RecyclableHeader * hdr, size_t * drop_si
readIntBinary(hdr->checksum, *file);
readIntBinary(hdr->length, *file);
readChar(hdr->type, *file);
LOG_FMT_DEBUG(&Poco::Logger::get("fff"), "Read crc: {:0X} length: {} type: {}", hdr->checksum, hdr->length, static_cast<int>(hdr->type));
size_t header_size = Format::HEADER_SIZE;
if (hdr->type >= Format::RecyclableFullType && hdr->type <= Format::RecyclableLastType)
{
Expand Down Expand Up @@ -393,6 +395,14 @@ UInt8 LogReader::readPhysicalRecord(std::string_view * result, size_t * drop_siz
hdr.length + header_size - Format::CHECKSUM_START_OFFSET);
if (Format::ChecksumType actual_checksum = digest.checksum(); actual_checksum != hdr.checksum)
{
LOG_FMT_DEBUG(
&Poco::Logger::get("fff"),
"checksum for pos:{}, size:{}, cks:{:0X}, exp_cks:{:0X}, c:{}",
buffer.data() - header_pos,
hdr.length + header_size - Format::CHECKSUM_START_OFFSET,
actual_checksum,
hdr.checksum,
Redact::keyToHexString(header_pos + Format::CHECKSUM_START_OFFSET, hdr.length + header_size - Format::CHECKSUM_START_OFFSET));
// Drop the rest of the buffer since "length" itself may have
// been corrupted and if we trust it, we could find some
// fragment of a real log record that just happens to look
Expand Down
8 changes: 8 additions & 0 deletions dbms/src/Storages/Page/V3/LogFile/LogWriter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <Common/Checksum.h>
#include <Common/Exception.h>
#include <Common/RedactHelpers.h>
#include <IO/ReadBuffer.h>
#include <IO/WriteBufferFromFile.h>
#include <IO/WriteHelpers.h>
Expand Down Expand Up @@ -181,6 +182,13 @@ void LogWriter::emitPhysicalRecord(Format::RecordType type, ReadBuffer & payload
writeString(header_buff.buffer().begin(), header_buff.count(), write_buffer);
writeString(payload.position(), length, write_buffer);

LOG_FMT_DEBUG(
&Poco::Logger::get("fff"),
"CRC: {:08X} header: {} payload: {}",
checksum,
Redact::keyToHexString(header_buff.buffer().begin(), header_buff.count()),
Redact::keyToHexString(payload.position(), length));

block_offset += header_size + length;
}
} // namespace DB::PS::V3

0 comments on commit 60820e5

Please sign in to comment.