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

Remove unnecessary calls to WAL::flushAllPages and clear the dirty flag when flushing pages #3427

Merged
merged 1 commit into from
May 1, 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
5 changes: 1 addition & 4 deletions src/include/processor/operator/persistent/batch_insert.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ struct BatchInsertSharedState {
}
inline common::row_idx_t getNumRows() { return numRows.load(); }
// NOLINTNEXTLINE(readability-make-member-function-const): Semantically non-const.
inline void logBatchInsertWALRecord() {
wal->logCopyTableRecord(table->getTableID());
wal->flushAllPages();
}
inline void logBatchInsertWALRecord() { wal->logCopyTableRecord(table->getTableID()); }
inline void updateNumTuplesForTable() { table->updateNumTuplesByValue(getNumRows()); }
};

Expand Down
3 changes: 3 additions & 0 deletions src/include/storage/buffer_manager/bm_file_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class PageState {
KU_ASSERT(getState(stateAndVersion.load()) == LOCKED);
stateAndVersion &= ~DIRTY_MASK;
}
// Meant to be used when flushing in a single thread.
// Should not be used if other threads are modifying the page state
inline void clearDirtyWithoutLock() { stateAndVersion &= ~DIRTY_MASK; }
inline bool isDirty() const { return stateAndVersion & DIRTY_MASK; }
uint64_t getStateAndVersion() const { return stateAndVersion.load(); }

Expand Down
2 changes: 1 addition & 1 deletion src/main/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ void Database::commit(Transaction* transaction, bool skipCheckpointForTestingRec
// Note: committing and stopping new transactions can be done in any order. This
// order allows us to throw exceptions if we have to wait a lot to stop.
transactionManager->commitButKeepActiveWriteTransaction(transaction);
wal->flushAllPages();
if (skipCheckpointForTestingRecovery) {
wal->flushAllPages();
transactionManager->allowReceivingNewTransactions();
return;
}
Expand Down
2 changes: 0 additions & 2 deletions src/processor/operator/persistent/node_batch_insert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ void NodeBatchInsert::finalize(ExecutionContext* context) {
if (nodeSharedState->globalIndexBuilder) {
nodeSharedState->globalIndexBuilder->finalize(context);
}
// Batch Insert wal record needs to be logged after PrimaryKeyIndex::prepareCommit
// so that the wal pages get flushed before the index is re-initialized.
sharedState->logBatchInsertWALRecord();
auto outputMsg = stringFormat("{} tuples have been copied to the {} table.",
sharedState->getNumRows(), info->tableEntry->getName());
Expand Down
1 change: 1 addition & 0 deletions src/storage/buffer_manager/buffer_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ void BufferManager::flushIfDirtyWithoutLock(BMFileHandle& fileHandle, page_idx_t
if (pageState->isDirty()) {
fileHandle.getFileInfo()->writeFile(getFrame(fileHandle, pageIdx), fileHandle.getPageSize(),
pageIdx * fileHandle.getPageSize());
pageState->clearDirtyWithoutLock();
}
}

Expand Down
Loading