本文整理汇总了C++中Frame::GetPageID方法的典型用法代码示例。如果您正苦于以下问题:C++ Frame::GetPageID方法的具体用法?C++ Frame::GetPageID怎么用?C++ Frame::GetPageID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Frame
的用法示例。
在下文中一共展示了Frame::GetPageID方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindFrame
//--------------------------------------------------------------------
// BufMgr::FindFrame
//
// Input : pid - a page id
// Output : None
// Purpose : Look for the page in the buffer pool, return the frame
// number if found.
// PreCond : None
// PostCond : None
// Return : the frame number if found. INVALID_FRAME otherwise.
//--------------------------------------------------------------------
int BufMgr::FindFrame( PageID pid )
{
Frame* currFrame;
for (int iter = 0; iter < numFrames; iter++) {
currFrame = &frames[iter];
if (currFrame->GetPageID() == pid) {
return iter;
}
}
return INVALID_FRAME;
}
示例2: UnpinPage
//--------------------------------------------------------------------
// BufMgr::UnpinPage
//
// Input : pid - page id of a particular page
// dirty - indicate whether the page with page id = pid
// is dirty or not. (Optional, default to false)
// Output : None
// Purpose : Unpin the page with page id = pid in the buffer. Mark
// the page dirty if dirty is true.
// Condition: The page is already in the buffer and is pinned.
// PostCond : The page is unpinned and the number of pin on the
// page decrease by one.
// Return : OK if operation is successful. FAIL otherwise.
//--------------------------------------------------------------------
Status BufMgr::UnpinPage(PageID pid, bool dirty)
{
//std::cout << "Unin PageID " << pid << std::endl;
////std::cout << "Unpinning page " << pid << " Dirty?: " << dirty << std::endl;
int frameIndex = FindFrame(pid);
if (frameIndex == INVALID_FRAME) return FAIL;
Frame* targetFrame = &frames[frameIndex];
if (targetFrame->NotPinned()) return FAIL;
if (dirty) targetFrame->DirtyIt();
targetFrame->Unpin();
if (targetFrame->NotPinned()) replacer->AddFrame(targetFrame->GetPageID());
return OK;
}
示例3: FlushPage
//--------------------------------------------------------------------
// BufMgr::FlushPage
//
// Input : pid - page id of a particular page
// Output : None
// Purpose : Flush the page with the given pid to disk.
// Condition: The page with page id = pid must be in the buffer,
// and is not pinned. pid cannot be INVALID_PAGE.
// PostCond : The page with page id = pid is written to disk if it's dirty.
// The frame where the page resides is empty.
// Return : OK if operation is successful. FAIL otherwise.
//--------------------------------------------------------------------
Status BufMgr::FlushPage(PageID pid)
{
//std::cout << "Flush Page" << pid << std::endl;
////std::cout << "Flush Page " << pid << std::endl;
int frameIndex = FindFrame(pid);
if (frameIndex == INVALID_FRAME) return FAIL;
Frame* targetFrame = &frames[frameIndex];
if(!targetFrame->IsValid() || !targetFrame->NotPinned()) return FAIL;
if (targetFrame->IsDirty()){
if (targetFrame->Write() != OK) return FAIL;
numDirtyPageWrites++;
}
replacer->RemoveFrame(targetFrame->GetPageID());
targetFrame->EmptyIt();
//std::cout << "Flush OK " << std::endl;
return OK;
}
示例4: FlushAllPages
Status BufMgr::FlushAllPages()
{
//std::cout << "Flush all " << std::endl;
bool failedOnce = false;
Frame* currFrame;
for (int iter = 0; iter < numFrames; iter++) {
currFrame = &frames[iter];
if (currFrame->IsValid()) {
// Check that the frame is not pinned
if (!currFrame->NotPinned()){
failedOnce = true;
}
if (currFrame->IsDirty()){
if (currFrame->Write() != OK) failedOnce = true;
numDirtyPageWrites++;
}
replacer->RemoveFrame(currFrame->GetPageID());
currFrame->EmptyIt();
}
}
return (failedOnce) ? FAIL : OK;
}
示例5: PinPage
//--------------------------------------------------------------------
// BufMgr::PinPage
//
// Input : pid - page id of a particular page
// isEmpty - (optional, default to false) if true indicate
// that the page to be pinned is an empty page.
// Output : page - a pointer to a page in the buffer pool. (NULL
// if fail)
// Purpose : Pin the page with page id = pid to the buffer.
// Read the page from disk unless isEmpty is true or unless
// the page is already in the buffer.
// Condition: Either the page is already in the buffer, or there is at
// least one frame available in the buffer pool for the
// page.
// PostCond : The page with page id = pid resides in the buffer and
// is pinned. The number of pin on the page increase by
// one.
// Return : OK if operation is successful. FAIL otherwise.
//--------------------------------------------------------------------
Status BufMgr::PinPage(PageID pid, Page*& page, bool isEmpty)
{
if(pid == INVALID_PAGE) return FAIL;
totalCall++;
// Check if the page is in the buffer pool
bool inPool = false;
Frame* currFrame;
for (int iter = 0; iter < numFrames; iter++) {
currFrame = &frames[iter];
if (currFrame->GetPageID() == pid){
inPool = true;
totalHit++;
break;
}
}
if (inPool){
// Increase its pin count and set output page pointer
currFrame->Pin();
page = currFrame->GetPage();
}
else {
// Find the first free frame if there is one
bool foundEmptyFrame = false;
for (int iter = 0; iter < numFrames; iter++) {
currFrame = &frames[iter];
if (!currFrame->IsValid()){
foundEmptyFrame = true;
break;
}
}
if (!foundEmptyFrame) {
// Find a page to evict based on our replacement policy
int replacedPageID = replacer->PickVictim();
// Get a pointer to the frame we will flush
for (int iter = 0; iter < numFrames; iter++) {
currFrame = &frames[iter];
if (currFrame->GetPageID() == replacedPageID){
break;
}
}
if(FlushPage(replacedPageID) != OK) {
page = NULL;
return FAIL;
}
}
currFrame->SetPageID(pid);
currFrame->Pin();
// If the page is not empty, read it in from disk
if (!isEmpty && currFrame->Read(pid) != OK) {
page = NULL;
return FAIL;
}
page = currFrame->GetPage();
}
// Now that the frame is pinned we need to remove it from the ones that can be evicted
replacer->RemoveFrame(currFrame->GetPageID());
////std::cout << "pinned page: " << currFrame->GetPageID() <<std::endl;
return OK;
}