BadgerDB
Main Page
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Friends
Pages
afs
cs.wisc.edu
u
h
a
haiyun
private
cs564-spr17
projects
p2
BufMgr
src
buffer.h
1
8
#pragma once
9
10
#include "file.h"
11
#include "bufHashTbl.h"
12
13
namespace
badgerdb {
14
18
class
BufMgr;
19
23
class
BufDesc
{
24
25
friend
class
BufMgr
;
26
27
private
:
31
File
* file;
32
36
PageId
pageNo;
37
41
FrameId
frameNo;
42
46
int
pinCnt;
47
51
bool
dirty;
52
56
bool
valid;
57
61
bool
refbit;
62
66
void
Clear()
67
{
68
pinCnt = 0;
69
file = NULL;
70
pageNo =
Page::INVALID_NUMBER
;
71
dirty =
false
;
72
refbit =
false
;
73
valid =
false
;
74
};
75
83
void
Set(
File
* filePtr,
PageId
pageNum)
84
{
85
file = filePtr;
86
pageNo = pageNum;
87
pinCnt = 1;
88
dirty =
false
;
89
valid =
true
;
90
refbit =
true
;
91
}
92
93
void
Print()
94
{
95
if
(file)
96
{
97
std::cout <<
"file:"
<< file->
filename
() <<
" "
;
98
std::cout <<
"pageNo:"
<< pageNo <<
" "
;
99
}
100
else
101
std::cout <<
"file:NULL "
;
102
103
std::cout <<
"valid:"
<< valid <<
" "
;
104
std::cout <<
"pinCnt:"
<< pinCnt <<
" "
;
105
std::cout <<
"dirty:"
<< dirty <<
" "
;
106
std::cout <<
"refbit:"
<< refbit <<
"\n"
;
107
}
108
112
BufDesc
()
113
{
114
Clear();
115
}
116
};
117
118
122
struct
BufStats
123
{
127
int
accesses
;
128
132
int
diskreads
;
133
137
int
diskwrites
;
138
142
void
clear
()
143
{
144
accesses
=
diskreads
=
diskwrites
= 0;
145
}
146
150
BufStats
()
151
{
152
clear
();
153
}
154
};
155
156
160
class
BufMgr
161
{
162
private
:
166
FrameId
clockHand;
167
171
std::uint32_t numBufs;
172
176
BufHashTbl
*hashTable;
177
181
BufDesc
*bufDescTable;
182
186
BufStats
bufStats;
187
191
void
advanceClock();
192
199
void
allocBuf(
FrameId
& frame);
200
201
public
:
205
Page
*
bufPool
;
206
210
BufMgr
(std::uint32_t bufs);
211
215
~BufMgr
();
216
226
void
readPage
(
File
* file,
const
PageId
PageNo,
Page
*& page);
227
236
void
unPinPage
(
File
* file,
const
PageId
PageNo,
const
bool
dirty);
237
246
void
allocPage
(
File
* file,
PageId
&PageNo,
Page
*& page);
247
257
void
flushFile
(
const
File
* file);
258
266
void
disposePage
(
File
* file,
const
PageId
PageNo);
267
271
void
printSelf
();
272
276
BufStats
&
getBufStats
()
277
{
278
return
bufStats;
279
}
280
284
void
clearBufStats
()
285
{
286
bufStats.
clear
();
287
}
288
};
289
290
}
badgerdb::File::filename
const std::string & filename() const
Definition:
file.h:179
badgerdb::BufMgr
The central class which manages the buffer pool including frame allocation and deallocation to pages ...
Definition:
buffer.h:160
badgerdb::BufMgr::readPage
void readPage(File *file, const PageId PageNo, Page *&page)
Definition:
buffer.cpp:117
badgerdb::BufStats::accesses
int accesses
Definition:
buffer.h:127
badgerdb::FrameId
std::uint32_t FrameId
Identifier for a frame in buffer pool.
Definition:
types.h:25
badgerdb::BufMgr::clearBufStats
void clearBufStats()
Definition:
buffer.h:284
badgerdb::BufStats::diskwrites
int diskwrites
Definition:
buffer.h:137
badgerdb::File
Class which represents a file in the filesystem containing database pages.
Definition:
file.h:73
badgerdb::BufMgr::unPinPage
void unPinPage(File *file, const PageId PageNo, const bool dirty)
Definition:
buffer.cpp:133
badgerdb::BufStats
Class to maintain statistics of buffer usage.
Definition:
buffer.h:122
badgerdb::PageId
std::uint32_t PageId
Identifier for a page in a file.
Definition:
types.h:15
badgerdb::Page
Class which represents a fixed-size database page containing records.
Definition:
page.h:107
badgerdb::BufDesc
Class for maintaining information about buffer pool frames.
Definition:
buffer.h:23
badgerdb::BufMgr::BufMgr
BufMgr(std::uint32_t bufs)
Definition:
buffer.cpp:19
badgerdb::BufMgr::flushFile
void flushFile(const File *file)
Definition:
buffer.cpp:148
badgerdb::BufMgr::bufPool
Page * bufPool
Definition:
buffer.h:205
badgerdb::BufMgr::printSelf
void printSelf()
Definition:
buffer.cpp:204
badgerdb::BufStats::clear
void clear()
Definition:
buffer.h:142
badgerdb::BufStats::diskreads
int diskreads
Definition:
buffer.h:132
badgerdb::BufMgr::disposePage
void disposePage(File *file, const PageId PageNo)
Definition:
buffer.cpp:191
badgerdb::BufHashTbl
Hash table class to keep track of pages in the buffer pool.
Definition:
bufHashTbl.h:45
badgerdb::BufStats::BufStats
BufStats()
Definition:
buffer.h:150
badgerdb::BufMgr::~BufMgr
~BufMgr()
Definition:
buffer.cpp:38
badgerdb::Page::INVALID_NUMBER
static const PageId INVALID_NUMBER
Definition:
page.h:123
badgerdb::BufMgr::allocPage
void allocPage(File *file, PageId &PageNo, Page *&page)
Definition:
buffer.cpp:177
badgerdb::BufMgr::getBufStats
BufStats & getBufStats()
Definition:
buffer.h:276
Generated on Fri Feb 10 2017 12:39:55 for BadgerDB by
1.8.6