Skip to content

Commit

Permalink
fix: fix typo error and add test for not cover function in asyncwrite…
Browse files Browse the repository at this point in the history
…buffer
  • Loading branch information
SYaoJun committed Aug 5, 2024
1 parent 9100425 commit b48ded5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/buffer-manager/BufferManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BufferManager::BufferManager(leanstore::LeanStore* store) : mStore(store) {
const uint64_t totalMemSize = bfSize * (mNumBfs + mNumSaftyBfs);

// Init buffer pool with zero-initialized buffer frames. Use mmap with flags
// MAP_PRIVATE and MAP_ANONYMOUS, no underlying file desciptor to allocate
// MAP_PRIVATE and MAP_ANONYMOUS, no underlying file descriptor to allocate
// totalmemSize buffer pool with zero-initialized contents.
void* underlyingBuf =
mmap(NULL, totalMemSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
Expand Down Expand Up @@ -128,9 +128,9 @@ Result<void> BufferManager::CheckpointAllBufferFrames() {
Log::Info("CheckpointAllBufferFrames, mNumBfs={}", mNumBfs);
SCOPED_DEFER({
auto stoppedAt = std::chrono::steady_clock::now();
auto elaspedNs =
auto elapsedNs =
std::chrono::duration_cast<std::chrono::nanoseconds>(stoppedAt - startAt).count();
Log::Info("CheckpointAllBufferFrames finished, timeElasped={:.6f}s", elaspedNs / 1000000000.0);
Log::Info("CheckpointAllBufferFrames finished, timeElapsed={:.6f}s", elapsedNs / 1000000000.0);
});

LS_DEBUG_EXECUTE(mStore, "skip_CheckpointAllBufferFrames", {
Expand Down Expand Up @@ -306,7 +306,7 @@ BufferFrame* BufferManager::ResolveSwipMayJump(HybridGuard& nodeGuard, Swip& swi
WorkerCounters::MyCounters().dt_page_reads[bf.mPage.mBTreeId]++;
}

// 4. Intialize the buffer frame header
// 4. Initialize the buffer frame header
LS_DCHECK(!bf.mHeader.mIsBeingWrittenBack);
bf.mHeader.mFlushedGsn = bf.mPage.mGSN;
bf.mHeader.mState = State::kLoaded;
Expand Down Expand Up @@ -350,7 +350,7 @@ BufferFrame* BufferManager::ResolveSwipMayJump(HybridGuard& nodeGuard, Swip& swi
ioFrame.mNumReaders++; // incremented while holding partition lock
inflightIOGuard->unlock();

// wait untile the reading is finished
// wait until the reading is finished
JumpScoped<std::unique_lock<std::mutex>> ioFrameGuard(ioFrame.mMutex);
ioFrameGuard->unlock(); // no need to hold the mutex anymore
if (ioFrame.mNumReaders.fetch_add(-1) == 1) {
Expand Down
10 changes: 5 additions & 5 deletions src/buffer-manager/PageEvictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void PageEvictor::PickBufferFramesToCool(Partition& targetPartition) {
PPCounters::MyCounters().touched_bfs_counter++;
}

// Iterate all the child pages to check wherher all the children are
// Iterate all the child pages to check whether all the children are
// evicted, otherwise pick the fist met unevicted child as the next
// cool page candidate.
bool allChildrenEvicted(true);
Expand Down Expand Up @@ -202,7 +202,7 @@ void PageEvictor::PickBufferFramesToCool(Partition& targetPartition) {
JUMPMU_CATCH() {
LS_DLOG("Cool candidate discarded, optimistic latch failed, "
"someone has modified the buffer frame during cool "
"validateion, pageId={}",
"validation, pageId={}",
coolCandidate->mHeader.mPageId);
}
}
Expand Down Expand Up @@ -261,8 +261,8 @@ void PageEvictor::PrepareAsyncWriteBuffer(Partition& targetPartition) {
}

// Async write dirty pages back. They should keep in memory and stay in
// cooling stage until all the contents are writtern back to the
// underluing disk.
// cooling stage until all the contents are written back to the
// underlying disk.
if (mAsyncWriteBuffer.IsFull()) {
LS_DLOG("Async write buffer is full, bufferSize={}",
mAsyncWriteBuffer.GetPendingRequests());
Expand All @@ -286,7 +286,7 @@ void PageEvictor::PrepareAsyncWriteBuffer(Partition& targetPartition) {
}
JUMPMU_CATCH() {
LS_DLOG("COOLed buffer frame discarded, optimistic latch failed, "
"someone has modified the buffer frame during cool validateion, "
"someone has modified the buffer frame during cool validation, "
"pageId={}",
cooledBf->mHeader.mPageId);
}
Expand Down
10 changes: 8 additions & 2 deletions tests/buffer-manager/AsyncWriteBufferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AsyncWriteBufferTest : public ::testing::Test {
BufferFrameHolder(size_t pageSize, PID pageId)
: mBuffer(512 + pageSize),
mBf(new(mBuffer.Get()) BufferFrame()) {
mBf->mHeader.mPageId = pageId;
mBf->Init(pageId);
}
};

Expand Down Expand Up @@ -107,6 +107,12 @@ TEST_F(AsyncWriteBufferTest, Basic) {
EXPECT_EQ(doneRequests, testMaxBatchSize);
EXPECT_EQ(testWriteBuffer.GetPendingRequests(), 0);

// check the flushed content
testWriteBuffer.IterateFlushedBfs([](BufferFrame& flushedBf, uint64_t flushedGsn){
EXPECT_FALSE(flushedBf.IsDirty());
EXPECT_EQ(flushedGsn, 0);
}, testMaxBatchSize);

// read the file content
for (int i = 0; i < testMaxBatchSize; i++) {
BufferFrameHolder bfHolder(testPageSize, i);
Expand All @@ -118,4 +124,4 @@ TEST_F(AsyncWriteBufferTest, Basic) {
}
}

} // namespace leanstore::storage::test
} // namespace leanstore::storage::test

0 comments on commit b48ded5

Please sign in to comment.