Skip to content

Commit

Permalink
Print record header info in page data parser
Browse files Browse the repository at this point in the history
  • Loading branch information
hnjylwb committed Mar 12, 2024
1 parent fadd2aa commit a32bee6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/table/record_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cassert>
#include <cstring>
#include <sstream>

namespace huadb {

Expand Down Expand Up @@ -33,4 +34,15 @@ db_size_t RecordHeader::DeserializeFrom(const char *data) {
return offset;
}

std::string RecordHeader::ToString() const {
std::ostringstream oss;
oss << "Header[";
oss << "deleted: " << deleted_;
oss << ", xmin: " << xmin_;
oss << ", xmax: " << xmax_;
oss << ", cid: " << cid_;
oss << "]";
return oss.str();
}

} // namespace huadb
4 changes: 4 additions & 0 deletions src/table/record_header.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <string>

#include "common/constants.h"

namespace huadb {
Expand All @@ -13,6 +15,8 @@ class RecordHeader {
db_size_t SerializeTo(char *data) const;
db_size_t DeserializeFrom(const char *data);

std::string ToString() const;

private:
// LAB 1: 记录是否删除
bool deleted_ = false;
Expand Down
12 changes: 11 additions & 1 deletion src/table/table_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,19 @@ std::string TablePage::ToString() const {
oss << " next_page_id: " << *next_page_id_ << std::endl;
oss << " lower: " << *lower_ << std::endl;
oss << " upper: " << *upper_ << std::endl;
if (*lower_ > *upper_) {
oss << "***Error: lower > upper***" << std::endl;
}
oss << " slots: " << std::endl;
for (size_t i = 0; i < GetRecordCount(); i++) {
oss << " " << i << ": offset " << slots_[i].offset_ << ", size " << slots_[i].size_ << std::endl;
oss << " " << i << ": offset " << slots_[i].offset_ << ", size " << slots_[i].size_ << " ";
if (slots_[i].size_ <= RECORD_HEADER_SIZE) {
oss << "***Error: record size smaller than header size***" << std::endl;
} else {
RecordHeader header;
header.DeserializeFrom(page_data_ + slots_[i].offset_);
oss << header.ToString() << std::endl;
}
}
oss << "]\n";
return oss.str();
Expand Down
1 change: 1 addition & 0 deletions test/lab1/10-insert.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ select score, info from test_insert;
5.5 eeeee
6.6 ffffff

# 新建页面
query
insert into test_insert values(7, 7.7, 'ggggggg'), (8, 8.8, 'hhhhhhhh'), (9, 9.9, 'iiiiiiiii'), (10, 10.1, 'jjjjjjjjjj'), (11, 11.1, 'kkkkkkkkkkk');
----
Expand Down

0 comments on commit a32bee6

Please sign in to comment.