aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--komfydb/komfydb.cc4
-rw-r--r--komfydb/storage/heap_page.cc27
-rw-r--r--komfydb/storage/heap_page.h9
3 files changed, 21 insertions, 19 deletions
diff --git a/komfydb/komfydb.cc b/komfydb/komfydb.cc
index cb734a9..033734c 100644
--- a/komfydb/komfydb.cc
+++ b/komfydb/komfydb.cc
@@ -36,8 +36,8 @@ int main(int argc, char* argv[]) {
file->ReadPage(storage::PageId(table_id, 0)).value();
storage::HeapPage* hp = static_cast<storage::HeapPage*>(page.get());
- for (auto& tuple : hp->GetTuples()) {
- LOG(INFO) << static_cast<std::string>(tuple);
+ for (auto& record : hp->GetRecords()) {
+ LOG(INFO) << static_cast<std::string>(record);
}
}
}
diff --git a/komfydb/storage/heap_page.cc b/komfydb/storage/heap_page.cc
index 1d5decc..f2b3f12 100644
--- a/komfydb/storage/heap_page.cc
+++ b/komfydb/storage/heap_page.cc
@@ -49,32 +49,32 @@ void DumpInt(Field* field, std::vector<uint8_t>& result) {
namespace komfydb::storage {
absl::StatusOr<std::unique_ptr<HeapPage>> HeapPage::Create(
- PageId id, TupleDesc* td, std::vector<uint8_t>& data) {
+ PageId pid, TupleDesc* td, std::vector<uint8_t>& data) {
int n_slots = (CONFIG_PAGE_SIZE * 8) / (td->GetSize() * 8 + 1);
int header_len = (n_slots + 7) / 8;
int n_fields = td->Length();
int data_idx = header_len;
std::vector<uint8_t> header;
- std::vector<Tuple> tuples;
+ std::vector<Record> records;
header.insert(header.end(), data.begin(), data.begin() + header_len);
for (int i = 0; i < n_slots; i++) {
- Tuple tuple(td);
+ Record record(td, pid, i);
for (int j = 0; j < n_fields; j++) {
ASSIGN_OR_RETURN(Type field_type, td->GetFieldType(j));
if (field_type.GetValue() == Type::INT) {
- RETURN_IF_ERROR(tuple.SetField(j, ParseInt(data, data_idx)));
+ RETURN_IF_ERROR(record.SetField(j, ParseInt(data, data_idx)));
} else if (field_type.GetValue() == Type::STRING) {
- RETURN_IF_ERROR(tuple.SetField(j, ParseString(data, data_idx)));
+ RETURN_IF_ERROR(record.SetField(j, ParseString(data, data_idx)));
}
}
- tuples.push_back(std::move(tuple));
+ records.push_back(std::move(record));
}
return std::unique_ptr<HeapPage>(
- new HeapPage(id, td, header, std::move(tuples), n_slots));
+ new HeapPage(pid, td, header, std::move(records), n_slots));
}
PageId HeapPage::GetId() {
@@ -93,19 +93,20 @@ absl::StatusOr<std::vector<uint8_t>> HeapPage::GetPageData() {
// return old_data;
std::vector<uint8_t> result = header;
- int n_tuples = tuples.size();
int tuple_len = td->Length();
+ int record_idx = 0;
- for (int i = 0; i < n_tuples; i++) {
+ for (int i = 0; i < num_slots; i++) {
ASSIGN_OR_RETURN(bool tuple_present, TuplePresent(header, i));
if (!tuple_present) {
result.insert(result.end(), td->GetSize(), '\0');
continue;
}
- Tuple& tuple = tuples[i];
+ Record& record = records[record_idx];
+ record_idx++;
for (int j = 0; j < tuple_len; j++) {
ASSIGN_OR_RETURN(Type field_type, td->GetFieldType(j));
- ASSIGN_OR_RETURN(Field * field, tuple.GetField(j));
+ ASSIGN_OR_RETURN(Field * field, record.GetField(j));
if (field_type.GetValue() == Type::STRING)
DumpString(field, result);
@@ -129,8 +130,8 @@ absl::Status HeapPage::SetBeforeImage() {
return absl::OkStatus();
}
-std::vector<Tuple>& HeapPage::GetTuples() {
- return tuples;
+std::vector<Record>& HeapPage::GetRecords() {
+ return records;
}
}; // namespace komfydb::storage
diff --git a/komfydb/storage/heap_page.h b/komfydb/storage/heap_page.h
index d3d5307..1b6dd20 100644
--- a/komfydb/storage/heap_page.h
+++ b/komfydb/storage/heap_page.h
@@ -11,6 +11,7 @@
#include "komfydb/common/tuple_desc.h"
#include "komfydb/storage/page.h"
#include "komfydb/storage/page_id.h"
+#include "komfydb/storage/record.h"
#include "komfydb/transaction/transaction_id.h"
namespace {
@@ -30,18 +31,18 @@ class HeapPage : public Page {
PageId pid;
TupleDesc* td;
std::vector<uint8_t> header;
- std::vector<Tuple> tuples;
+ std::vector<Record> records;
int num_slots; // TODO I don't like this name ; do we even need this?
std::vector<uint8_t> old_data;
// Take a look on absl::MutexLock to see how to acquire it
absl::Mutex old_data_lock;
HeapPage(PageId pid, TupleDesc* td, std::vector<uint8_t> header,
- std::vector<Tuple> tuples, int num_slots)
+ std::vector<Record> records, int num_slots)
: pid(pid),
td(td),
header(header),
- tuples(std::move(tuples)),
+ records(std::move(records)),
num_slots(num_slots) {}
public:
@@ -63,7 +64,7 @@ class HeapPage : public Page {
absl::StatusOr<std::vector<uint8_t>> GetPageData() override;
- std::vector<Tuple>& GetTuples();
+ std::vector<Record>& GetRecords();
};
}; // namespace komfydb::storage