Skip to content

Commit

Permalink
Run clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
ray6080 committed Apr 7, 2024
1 parent 1f4a573 commit 3ca5ce7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 37 deletions.
4 changes: 3 additions & 1 deletion src/include/common/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ TO ku_dynamic_cast(FROM old) {
KU_ASSERT(newVal != nullptr);
}
return newVal;
} catch (std::bad_cast& e) { KU_ASSERT(false); }
} catch (std::bad_cast& e) {
KU_ASSERT(false);
}
#else
return reinterpret_cast<TO>(old);
#endif
Expand Down
12 changes: 6 additions & 6 deletions src/include/storage/wal/wal_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ struct PageUpdateOrInsertRecord final : public WALRecord {
bool isInsert;

PageUpdateOrInsertRecord() = default;
PageUpdateOrInsertRecord(
DBFileID dbFileID, uint64_t pageIdxInOriginalFile, uint64_t pageIdxInWAL, bool isInsert)
PageUpdateOrInsertRecord(DBFileID dbFileID, uint64_t pageIdxInOriginalFile,
uint64_t pageIdxInWAL, bool isInsert)
: WALRecord{WALRecordType::PAGE_UPDATE_OR_INSERT_RECORD}, dbFileID{dbFileID},
pageIdxInOriginalFile{pageIdxInOriginalFile}, pageIdxInWAL{pageIdxInWAL}, isInsert{
isInsert} {}
pageIdxInOriginalFile{pageIdxInOriginalFile}, pageIdxInWAL{pageIdxInWAL},
isInsert{isInsert} {}
void serialize(common::Serializer& serializer) const override;
static std::unique_ptr<PageUpdateOrInsertRecord> deserialize(
common::Deserializer& deserializer);
Expand Down Expand Up @@ -142,8 +142,8 @@ struct RdfGraphRecord final : public WALRecord {
std::unique_ptr<CreateTableRecord> literalTripleTableRecord)
: WALRecord{WALRecordType::CREATE_RDF_GRAPH_RECORD}, tableID{tableID},
resourceTableRecord{std::move(resourceTableRecord)},
literalTableRecord{std::move(literalTableRecord)}, resourceTripleTableRecord{std::move(
resourceTripleTableRecord)},
literalTableRecord{std::move(literalTableRecord)},
resourceTripleTableRecord{std::move(resourceTripleTableRecord)},
literalTripleTableRecord{std::move(literalTripleTableRecord)} {}

void serialize(common::Serializer& serializer) const override;
Expand Down
24 changes: 12 additions & 12 deletions src/storage/storage_structure/db_file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ WALPageIdxAndFrame createWALVersionIfNecessaryAndPinPage(page_idx_t originalPage
try {
if (fileHandle.hasWALPageVersionNoWALPageIdxLock(originalPageIdx)) {
pageIdxInWAL = fileHandle.getWALPageIdxNoWALPageIdxLock(originalPageIdx);
walFrame = bufferManager.pin(
wal.getShadowingFH(), pageIdxInWAL, BufferManager::PageReadPolicy::READ_PAGE);
walFrame = bufferManager.pin(wal.getShadowingFH(), pageIdxInWAL,
BufferManager::PageReadPolicy::READ_PAGE);
} else {
pageIdxInWAL =
wal.logPageUpdateRecord(dbFileID, originalPageIdx /* pageIdxInOriginalFile */);
walFrame = bufferManager.pin(
wal.getShadowingFH(), pageIdxInWAL, BufferManager::PageReadPolicy::DONT_READ_PAGE);
walFrame = bufferManager.pin(wal.getShadowingFH(), pageIdxInWAL,
BufferManager::PageReadPolicy::DONT_READ_PAGE);
if (!insertingNewPage) {
bufferManager.optimisticRead(fileHandle, originalPageIdx,
[&](uint8_t* frame) -> void {
memcpy(walFrame, frame, BufferPoolConstants::PAGE_4KB_SIZE);
});
}
fileHandle.setWALPageIdxNoLock(
originalPageIdx /* pageIdxInOriginalFile */, pageIdxInWAL);
fileHandle.setWALPageIdxNoLock(originalPageIdx /* pageIdxInOriginalFile */,
pageIdxInWAL);
wal.getShadowingFH().setLockedPageDirty(pageIdxInWAL);
}
} catch (Exception& e) {
Expand Down Expand Up @@ -79,17 +79,17 @@ std::pair<BMFileHandle*, page_idx_t> DBFileUtils::getFileHandleAndPhysicalPageId
!fileHandle.hasWALPageVersionNoWALPageIdxLock(physicalPageIdx)) {
return std::make_pair(&fileHandle, physicalPageIdx);
} else {
return std::make_pair(
&wal.getShadowingFH(), fileHandle.getWALPageIdxNoWALPageIdxLock(physicalPageIdx));
return std::make_pair(&wal.getShadowingFH(),
fileHandle.getWALPageIdxNoWALPageIdxLock(physicalPageIdx));
}
}

common::page_idx_t DBFileUtils::insertNewPage(BMFileHandle& fileHandle, DBFileID dbFileID,
BufferManager& bufferManager, WAL& wal, const std::function<void(uint8_t*)>& insertOp) {
auto newOriginalPage = fileHandle.addNewPage();
auto newWALPage = wal.logPageInsertRecord(dbFileID, newOriginalPage);
auto walFrame = bufferManager.pin(
wal.getShadowingFH(), newWALPage, BufferManager::PageReadPolicy::DONT_READ_PAGE);
auto walFrame = bufferManager.pin(wal.getShadowingFH(), newWALPage,
BufferManager::PageReadPolicy::DONT_READ_PAGE);
fileHandle.addWALPageIdxGroupIfNecessary(newOriginalPage);
fileHandle.setWALPageIdx(newOriginalPage, newWALPage);
insertOp(walFrame);
Expand All @@ -115,8 +115,8 @@ void DBFileUtils::updatePage(BMFileHandle& fileHandle, DBFileID dbFileID,
void DBFileUtils::readWALVersionOfPage(BMFileHandle& fileHandle, page_idx_t originalPageIdx,
BufferManager& bufferManager, WAL& wal, const std::function<void(uint8_t*)>& readOp) {
page_idx_t pageIdxInWAL = fileHandle.getWALPageIdxNoWALPageIdxLock(originalPageIdx);
auto frame = bufferManager.pin(
wal.getShadowingFH(), pageIdxInWAL, BufferManager::PageReadPolicy::READ_PAGE);
auto frame = bufferManager.pin(wal.getShadowingFH(), pageIdxInWAL,
BufferManager::PageReadPolicy::READ_PAGE);
readOp(frame);
unpinPageIdxInWALAndReleaseOriginalPageLock(pageIdxInWAL, originalPageIdx, fileHandle,
bufferManager, wal);
Expand Down
8 changes: 4 additions & 4 deletions src/storage/wal/wal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ WAL::~WAL() {
page_idx_t WAL::logPageUpdateRecord(DBFileID dbFileID, page_idx_t pageIdxInOriginalFile) {
lock_t lck{mtx};
auto pageIdxInWAL = shadowingFH->addNewPage();
PageUpdateOrInsertRecord walRecord(
dbFileID, pageIdxInOriginalFile, pageIdxInWAL, false /*isInsert*/);
PageUpdateOrInsertRecord walRecord(dbFileID, pageIdxInOriginalFile, pageIdxInWAL,
false /*isInsert*/);
addNewWALRecordNoLock(walRecord);
return pageIdxInWAL;
}

page_idx_t WAL::logPageInsertRecord(DBFileID dbFileID, page_idx_t pageIdxInOriginalFile) {
lock_t lck{mtx};
auto pageIdxInWAL = shadowingFH->addNewPage();
PageUpdateOrInsertRecord walRecord(
dbFileID, pageIdxInOriginalFile, pageIdxInWAL, true /*isInsert*/);
PageUpdateOrInsertRecord walRecord(dbFileID, pageIdxInOriginalFile, pageIdxInWAL,
true /*isInsert*/);
addNewWALRecordNoLock(walRecord);
return pageIdxInWAL;
}
Expand Down
27 changes: 13 additions & 14 deletions src/storage/wal_replayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,29 +151,28 @@ void WALReplayer::replayTableStatisticsRecord(const WALRecord& walRecord) {
if (isCheckpoint) {
switch (tableStatisticsRecord.tableType) {
case TableType::NODE: {
auto walFilePath = StorageUtils::getNodesStatisticsAndDeletedIDsFilePath(
vfs, wal->getDirectory(), common::FileVersionType::WAL_VERSION);
auto originalFilePath = StorageUtils::getNodesStatisticsAndDeletedIDsFilePath(
vfs, wal->getDirectory(), common::FileVersionType::ORIGINAL);
auto walFilePath = StorageUtils::getNodesStatisticsAndDeletedIDsFilePath(vfs,
wal->getDirectory(), common::FileVersionType::WAL_VERSION);
auto originalFilePath = StorageUtils::getNodesStatisticsAndDeletedIDsFilePath(vfs,
wal->getDirectory(), common::FileVersionType::ORIGINAL);
vfs->overwriteFile(walFilePath, originalFilePath);
if (!isRecovering) {
storageManager->getNodesStatisticsAndDeletedIDs()->checkpointInMemoryIfNecessary();
}
} break;
case TableType::REL: {
auto walFilePath = StorageUtils::getRelsStatisticsFilePath(
vfs, wal->getDirectory(), common::FileVersionType::WAL_VERSION);
auto originalFilePath = StorageUtils::getRelsStatisticsFilePath(
vfs, wal->getDirectory(), common::FileVersionType::ORIGINAL);
auto walFilePath = StorageUtils::getRelsStatisticsFilePath(vfs, wal->getDirectory(),
common::FileVersionType::WAL_VERSION);
auto originalFilePath = StorageUtils::getRelsStatisticsFilePath(vfs,
wal->getDirectory(), common::FileVersionType::ORIGINAL);
vfs->overwriteFile(walFilePath, originalFilePath);
if (!isRecovering) {
storageManager->getRelsStatistics()->checkpointInMemoryIfNecessary();
}
} break;
default: {
KU_UNREACHABLE;
}
break;
default: {
KU_UNREACHABLE;
}
}
} else {
switch (tableStatisticsRecord.tableType) {
Expand Down Expand Up @@ -368,8 +367,8 @@ void WALReplayer::checkpointOrRollbackVersionedFileHandleAndBufferManager(
// Update the page in buffer manager if it is in a frame. Note that we assume
// that the pageBuffer currently contains the contents of the WALVersion, so the
// caller needs to make sure that this assumption holds.
bufferManager->updateFrameIfPageIsInFrameWithoutLock(
*fileHandle, pageBuffer.get(), pageInsertOrUpdateRecord.pageIdxInOriginalFile);
bufferManager->updateFrameIfPageIsInFrameWithoutLock(*fileHandle, pageBuffer.get(),
pageInsertOrUpdateRecord.pageIdxInOriginalFile);
} else {
truncateFileIfInsertion(fileHandle, pageInsertOrUpdateRecord);
}
Expand Down

0 comments on commit 3ca5ce7

Please sign in to comment.