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

Fix updating the diskArray nextPipPageIdx when multiple new PIPs are added #3329

Merged
merged 1 commit into from
Apr 21, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/include/storage/storage_structure/disk_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct DiskArrayHeader {
};

struct PIP {
PIP() : nextPipPageIdx{DBFileUtils::NULL_PAGE_IDX} {}
PIP() : nextPipPageIdx{DBFileUtils::NULL_PAGE_IDX}, pageIdxs{} {}

common::page_idx_t nextPipPageIdx;
common::page_idx_t pageIdxs[NUM_PAGE_IDXS_PER_PIP];
Expand Down
15 changes: 10 additions & 5 deletions src/storage/storage_structure/disk_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,25 @@ void BaseDiskArrayInternal::setNextPIPPageIDxOfPIPNoLock(DiskArrayHeader* update
if (!pipUpdates.updatedLastPIP.has_value()) {
pipUpdates.updatedLastPIP = std::make_optional(pips[pipIdxOfPreviousPIP]);
}
pipUpdates.updatedLastPIP->pipContents.nextPipPageIdx = nextPIPPageIdx;
if (pipIdxOfPreviousPIP == pips.size() - 1) {
pipUpdates.updatedLastPIP->pipContents.nextPipPageIdx = nextPIPPageIdx;
} else {
KU_ASSERT(pipIdxOfPreviousPIP >= pips.size() &&
pipUpdates.newPIPs.size() > pipIdxOfPreviousPIP - pips.size());
pipUpdates.newPIPs[pipIdxOfPreviousPIP - pips.size()].pipContents.nextPipPageIdx =
nextPIPPageIdx;
}
}
}

page_idx_t BaseDiskArrayInternal::getAPPageIdxNoLock(page_idx_t apIdx, TransactionType trxType) {
auto pipIdxAndOffset = StorageUtils::getQuotientRemainder(apIdx, NUM_PAGE_IDXS_PER_PIP);
uint64_t pipIdx = pipIdxAndOffset.first;
uint64_t offsetInPIP = pipIdxAndOffset.second;
auto [pipIdx, offsetInPIP] = StorageUtils::getQuotientRemainder(apIdx, NUM_PAGE_IDXS_PER_PIP);
if ((trxType == TransactionType::READ_ONLY) || !hasPIPUpdatesNoLock(pipIdx)) {
return pips[pipIdx].pipContents.pageIdxs[offsetInPIP];
} else if (pipIdx == pips.size() - 1 && pipUpdates.updatedLastPIP) {
return pipUpdates.updatedLastPIP->pipContents.pageIdxs[offsetInPIP];
} else {
KU_ASSERT(pipIdx >= pips.size());
KU_ASSERT(pipIdx >= pips.size() && pipIdx - pips.size() < pipUpdates.newPIPs.size());
return pipUpdates.newPIPs[pipIdx - pips.size()].pipContents.pageIdxs[offsetInPIP];
}
}
Expand Down
Loading