資源簡介
http://blog.csdn.net/freagle112/article/details/17525249
為了了解數據庫buffer管理器的工作原理,對數據庫底層結構有進一步的了解,編寫一個data storage manager和buffer manager。該試驗涉及儲存和緩沖管理器。緩沖技術,散列技術,文件儲存結構,磁盤空間和緩沖模塊的接口功能。

代碼片段和文件信息
#include?“BMgr.h“
#include?
BMgr::BMgr()
{
????for(int?i?=?0;i?????{
????????ftop[i]?=?-1;
????????ptof[i]?=?NULL;
????}
????head?=?NULL;
????tail?=?NULL;
}
int?BMgr::SelectVictim()
{
int?vframe?=?0page_id?=?0frame_id?=?0;
BCB?*bcb?=?NULL;
bool?found?=?false;
LRU?*temp?=?tail;
if(temp?==?NULL)
{
return?0;
}
for(int?i?=?0;?i? {
if(ftop[i]?==?-1)
{
return?i;
}
}
vframe?=?temp->frame_id;
page_id?=?ftop[vframe];
frame_id?=?Hash(page_id);
bcb?=?ptof[frame_id];
while(found?!=?true)
{
if(bcb?==?NULL)
{
break;
}
????????while(bcb->frame_id?!=?vframe)
????????{
??????????bcb?=?bcb->next;
????????}
????????if(bcb->count?==?0?&&?bcb->latch?==?0)
????????{
????????????found?=?true;
????????}
????????else
????????{
????????????temp?=?temp->prior;
????????????if(temp?==?NULL)
????????????{
????????????????break;
????????????}
????????????vframe?=?temp->frame_id;
????????????page_id?=?ftop[vframe];
????????????frame_id?=?Hash(page_id);
????????????bcb?=?ptof[frame_id];
????????}
}
page_id?=?ftop[vframe];
frame_id?=?Hash(page_id);
bcb?=?ptof[frame_id];
if(bcb?!=?NULL)
{
if(bcb->next?!=?NULL)
{
while(bcb?!=?NULL?&&?bcb->page_id?!=?page_id)
{
bcb?=?bcb->next;
}
if(bcb?!=?NULL?&&?bcb->dirty?==?1)
{
ds.WritePage(page_idbuf[vframe]);
}
if(bcb?!=?NULL)
{
RemoveLRUEle(vframe);
RemoveBCB(bcbpage_id);
}
}
}
return?vframe;
}
int?BMgr::Hash(int?page_id)
{
????return?page_id?%?DEFBUFSIZE;
}
void?BMgr::LRUProcess(BCB?*bcb)
{
????double?time?=?-1.0;
????LRU?*p?=?NULL;
????LRU?*temp?=?NULL;
????if?(head?==?NULL)
????{
????????head?=?new?LRU();
????????head->frame_id?=?bcb->frame_id;
????????if?(bcb->last_time?!=?-1.0)
????????{
????????????head->b2dtime?=?bcb->last_time?-?bcb->first_time;
????????}
????????tail?=?head;
????}
????else
????{
p?=?head;
if(bcb->last_time?!=?-1.0)
{
time?=?bcb->last_time?-?bcb->first_time;
}
if(time?==?-1.0)
{
while(p->next?!=?NULL)
{
if?(p->next->b2dtime?==?-1.0)
????????????????{
????????????????????temp?=?new?LRU();
????????????????????temp->frame_id?=?bcb->frame_id;
????????????????????temp->b2dtime?=?time;
????????????????????temp->next?=?p->next;
????????????????????temp->prior?=?p;
????????????????????p->next->prior?=?temp;
????????????????????p->next?=?temp;
????????????????????break;
????????????????}
p?=?p->next;
}
if(p->next?==?NULL)
{
p->next?=?new?LRU();
p->next->prior?=?p;
p?=?p->next;
p->frame_id?=?bcb->frame_id;
p->next?=?NULL;
p->b2dtime?=?time;
tail?=?p;
}
}
????????else
{
while(p->next?!=?NULL)
{
if(time?<=?p->next->b2dtime)
????????????????{
????????????????????temp?=?new?LRU();
????????????????????temp->b2dtime?=?time;
????????????????????temp->frame_id?=?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-12-24?10:38??db_01\
?????文件????????6148??2013-12-24?10:38??db_01\.DS_Store
?????目錄???????????0??2013-12-24?10:38??__MACOSX\
?????目錄???????????0??2013-12-24?10:38??__MACOSX\db_01\
?????文件?????????120??2013-12-24?10:38??__MACOSX\db_01\._.DS_Store
?????目錄???????????0??2013-11-23?23:14??db_01\bin\
?????目錄???????????0??2013-11-23?23:14??db_01\bin\Debug\
?????文件?????1054096??2013-11-23?23:42??db_01\bin\Debug\db_01.exe
?????目錄???????????0??2013-12-24?10:38??__MACOSX\db_01\bin\
?????目錄???????????0??2013-12-24?10:38??__MACOSX\db_01\bin\Debug\
?????文件?????????223??2013-11-23?23:42??__MACOSX\db_01\bin\Debug\._db_01.exe
?????文件?????????223??2013-11-23?23:14??__MACOSX\db_01\bin\._Debug
?????文件?????????223??2013-11-23?23:14??__MACOSX\db_01\._bin
?????文件????????7094??2013-11-23?23:11??db_01\BMgr.cpp
?????文件?????????223??2013-11-23?23:11??__MACOSX\db_01\._BMgr.cpp
?????文件?????????749??2013-11-23?23:25??db_01\BMgr.h
?????文件?????????223??2013-11-23?23:25??__MACOSX\db_01\._BMgr.h
?????文件????????4169??2013-11-23?22:48??db_01\d.cpp
?????文件?????????223??2013-11-23?22:48??__MACOSX\db_01\._d.cpp
?????文件?????3690270??2013-11-23?23:19??db_01\data-5w-50w-zipf.txt
?????文件?????????223??2013-11-23?23:19??__MACOSX\db_01\._data-5w-50w-zipf.txt
?????文件????????1315??2013-11-23?23:09??db_01\db_01.cbp
?????文件?????????223??2013-11-23?23:09??__MACOSX\db_01\._db_01.cbp
?????文件?????????800??2013-11-23?23:42??db_01\db_01.depend
?????文件?????????223??2013-11-23?23:42??__MACOSX\db_01\._db_01.depend
?????文件?????????278??2013-11-23?22:11??db_01\def.cpp
?????文件?????????223??2013-11-23?22:11??__MACOSX\db_01\._def.cpp
?????文件?????????616??2013-11-23?23:42??db_01\def.h
?????文件?????????223??2013-11-23?23:42??__MACOSX\db_01\._def.h
?????文件????????1132??2013-11-23?23:30??db_01\DSMgr.cpp
?????文件?????????223??2013-11-23?23:30??__MACOSX\db_01\._DSMgr.cpp
............此處省略21個文件信息
- 上一篇:藍牙藍牙基礎知識ppt
- 下一篇:Linux服務器性能調整
評論
共有 條評論