Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add UpdateTupleMetaTs() and UpdateTupleMetaIsDelete() methods #787

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/include/storage/page/table_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ class TablePage {
*/
void UpdateTupleMeta(const TupleMeta &meta, const RID &rid);

/**
* Update timestamp of the meta of a tuple.
*/
void UpdateTupleMetaTs(timestamp_t ts, const RID &rid);

/**
* Update is_deleted of the meta of a tuple.
*/
void UpdateTupleMetaIsDeleted(bool is_deleted, const RID &rid);

/**
* Read a tuple from a table.
*/
Expand Down
14 changes: 14 additions & 0 deletions src/include/storage/table/table_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ class TableHeap {
*/
void UpdateTupleMeta(const TupleMeta &meta, RID rid);

/**
* Update timestamp of the meta of a tuple.
* @param ts new timestamp of meta
* @param rid the rid of the inserted tuple
*/
void UpdateTupleMetaTs(timestamp_t ts, RID rid);

/**
* Update is_deleted of the meta of a tuple.
* @param is_deleted new is_deleted
* @param rid the rid of the inserted tuple
*/
void UpdateTupleMetaIsDelete(bool is_deleted, RID rid);

/**
* Read a tuple from the table.
* @param rid rid of the tuple to read
Expand Down
23 changes: 23 additions & 0 deletions src/storage/page/table_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@ void TablePage::UpdateTupleMeta(const TupleMeta &meta, const RID &rid) {
tuple_info_[tuple_id] = std::make_tuple(offset, size, meta);
}

void TablePage::UpdateTupleMetaTs(timestamp_t ts, const RID &rid) {
auto tuple_id = rid.GetSlotNum();
if (tuple_id >= num_tuples_) {
throw bustub::Exception("Tuple ID out of range");
}
auto &[offset, size, old_meta] = tuple_info_[tuple_id];
TupleMeta new_meta = {ts, old_meta.is_deleted_};
tuple_info_[tuple_id] = std::make_tuple(offset, size, new_meta);
}

void TablePage::UpdateTupleMetaIsDeleted(bool is_deleted, const RID &rid) {
auto tuple_id = rid.GetSlotNum();
if (tuple_id >= num_tuples_) {
throw bustub::Exception("Tuple ID out of range");
}
auto &[offset, size, old_meta] = tuple_info_[tuple_id];
if (!old_meta.is_deleted_ && is_deleted) {
num_deleted_tuples_++;
}
TupleMeta new_meta = {old_meta.ts_, is_deleted};
tuple_info_[tuple_id] = std::make_tuple(offset, size, new_meta);
}

auto TablePage::GetTuple(const RID &rid) const -> std::pair<TupleMeta, Tuple> {
auto tuple_id = rid.GetSlotNum();
if (tuple_id >= num_tuples_) {
Expand Down
12 changes: 12 additions & 0 deletions src/storage/table/table_heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ void TableHeap::UpdateTupleMeta(const TupleMeta &meta, RID rid) {
page->UpdateTupleMeta(meta, rid);
}

void TableHeap::UpdateTupleMetaTs(timestamp_t ts, RID rid) {
auto page_guard = bpm_->WritePage(rid.GetPageId());
auto page = page_guard.AsMut<TablePage>();
page->UpdateTupleMetaTs(ts, rid);
}

void TableHeap::UpdateTupleMetaIsDelete(bool is_deleted, RID rid) {
auto page_guard = bpm_->WritePage(rid.GetPageId());
auto page = page_guard.AsMut<TablePage>();
page->UpdateTupleMetaIsDeleted(is_deleted, rid);
}

auto TableHeap::GetTuple(RID rid) -> std::pair<TupleMeta, Tuple> {
auto page_guard = bpm_->ReadPage(rid.GetPageId());
auto page = page_guard.As<TablePage>();
Expand Down
Loading