BadgerDB
Main Page
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Friends
Pages
afs
cs.wisc.edu
u
h
a
haiyun
private
cs564-spr17
projects
p3
Btree
src
buffer.h
1
8
#pragma once
9
10
#include "file.h"
11
#include "bufHashTbl.h"
12
#include <iostream>
13
14
namespace
badgerdb {
15
19
class
BufMgr;
20
24
class
BufDesc
{
25
26
friend
class
BufMgr
;
27
28
private
:
32
File
* file;
33
37
PageId
pageNo;
38
42
FrameId
frameNo;
43
47
int
pinCnt;
48
52
bool
dirty;
53
57
bool
valid;
58
62
bool
refbit;
63
67
void
Clear()
68
{
69
pinCnt = 0;
70
file = NULL;
71
pageNo =
Page::INVALID_NUMBER
;
72
dirty =
false
;
73
refbit =
false
;
74
valid =
false
;
75
};
76
84
void
Set(
File
* filePtr,
PageId
pageNum)
85
{
86
file = filePtr;
87
pageNo = pageNum;
88
pinCnt = 1;
89
dirty =
false
;
90
valid =
true
;
91
refbit =
true
;
92
}
93
94
void
Print()
95
{
96
if
(file != NULL)
97
{
98
std::cout <<
"file:"
<< file->
filename
() <<
" "
;
99
std::cout <<
"pageNo:"
<< pageNo <<
" "
;
100
}
101
else
102
std::cout <<
"file:NULL "
;
103
104
std::cout <<
"valid:"
<< valid <<
" "
;
105
std::cout <<
"pinCnt:"
<< pinCnt <<
" "
;
106
std::cout <<
"dirty:"
<< dirty <<
" "
;
107
std::cout <<
"refbit:"
<< refbit <<
"\n"
;
108
}
109
113
BufDesc
()
114
{
115
Clear();
116
}
117
};
118
119
123
struct
BufStats
124
{
128
int
accesses
;
129
133
int
diskreads
;
134
138
int
diskwrites
;
139
143
void
clear
()
144
{
145
accesses
=
diskreads
=
diskwrites
= 0;
146
}
147
151
BufStats
()
152
{
153
clear
();
154
}
155
};
156
157
161
class
BufMgr
162
{
163
private
:
167
FrameId
clockHand;
168
172
std::uint32_t numBufs;
173
177
BufHashTbl
*hashTable;
178
182
BufDesc
*bufDescTable;
183
187
BufStats
bufStats;
188
195
void
allocBuf(
FrameId
& frame);
196
200
void
advanceClock()
201
{
202
clockHand = (clockHand + 1) % numBufs;
203
}
204
205
206
public
:
210
Page
*
bufPool
;
211
215
BufMgr
(std::uint32_t bufs);
216
220
~BufMgr
();
221
231
void
readPage
(
File
* file,
const
PageId
PageNo,
Page
*& page);
232
241
void
unPinPage
(
File
* file,
const
PageId
PageNo,
const
bool
dirty);
242
251
void
allocPage
(
File
* file,
PageId
&PageNo,
Page
*& page);
252
262
void
flushFile
(
const
File
* file);
263
271
void
disposePage
(
File
* file,
const
PageId
PageNo);
272
276
void
printSelf
();
277
281
BufStats
&
getBufStats
()
282
{
283
return
bufStats;
284
}
285
289
void
clearBufStats
()
290
{
291
bufStats.
clear
();
292
}
293
};
294
295
}
badgerdb::File::filename
const std::string & filename() const
Definition:
file.h:158
badgerdb::BufMgr
The central class which manages the buffer pool including frame allocation and deallocation to pages ...
Definition:
buffer.h:161
badgerdb::BufMgr::readPage
void readPage(File *file, const PageId PageNo, Page *&page)
Definition:
buffer.cpp:120
badgerdb::BufStats::accesses
int accesses
Definition:
buffer.h:128
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:289
badgerdb::BufStats::diskwrites
int diskwrites
Definition:
buffer.h:138
badgerdb::File
Class which represents a file in the filesystem containing database pages.
Definition:
file.h:75
badgerdb::BufMgr::unPinPage
void unPinPage(File *file, const PageId PageNo, const bool dirty)
Definition:
buffer.cpp:154
badgerdb::BufStats
Class to maintain statistics of buffer usage.
Definition:
buffer.h:123
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:108
badgerdb::BufDesc
Class for maintaining information about buffer pool frames.
Definition:
buffer.h:24
badgerdb::BufMgr::BufMgr
BufMgr(std::uint32_t bufs)
Definition:
buffer.cpp:23
badgerdb::BufMgr::flushFile
void flushFile(const File *file)
Definition:
buffer.cpp:171
badgerdb::BufMgr::bufPool
Page * bufPool
Definition:
buffer.h:210
badgerdb::BufMgr::printSelf
void printSelf()
Definition:
buffer.cpp:232
badgerdb::BufStats::clear
void clear()
Definition:
buffer.h:143
badgerdb::BufStats::diskreads
int diskreads
Definition:
buffer.h:133
badgerdb::BufMgr::disposePage
void disposePage(File *file, const PageId PageNo)
Definition:
buffer.cpp:196
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:151
badgerdb::BufMgr::~BufMgr
~BufMgr()
Definition:
buffer.cpp:42
badgerdb::Page::INVALID_NUMBER
static const PageId INVALID_NUMBER
Definition:
page.h:124
badgerdb::BufMgr::allocPage
void allocPage(File *file, PageId &PageNo, Page *&page)
Definition:
buffer.cpp:213
badgerdb::BufMgr::getBufStats
BufStats & getBufStats()
Definition:
buffer.h:281
Generated on Mon Feb 20 2017 08:22:53 for BadgerDB by
1.8.6