wisc_db
buffer.h
1 
9 #pragma once
10 
11 #include "include/file.h"
12 #include "bufferHashTable.h"
13 
14 namespace wiscdb {
15 
19 class BufferManager;
20 
25 class Frame {
26 
27  friend class BufferManager;
28 
29  private:
33  File* file;
34 
38  PageId pageNo;
39 
43  FrameId frameNo;
44 
48  int pinCnt;
49 
53  bool dirty;
54 
58  bool valid;
59 
63  bool refbit;
64 
68  void reset();
69 
78  void load(File* filePtr, PageId pageNum);
79 
80  void print();
81 
85  Frame();
86 };
87 
88 
93 {
97  int accesses;
98 
103 
108 
112  void clear()
113  {
114  accesses = diskreads = diskwrites = 0;
115  }
116 
121  {
122  clear();
123  }
124 };
125 
126 
132 {
133  private:
138  FrameId clockHand;
139 
143  std::uint32_t numFrames;
144 
148  BufferHashTable *hashTable;
149 
154  Frame *frameTable;
155 
159  BufferStats bufferStats;
160 
164  void advanceClock();
165 
175  void allocateFrame(FrameId & frame);
176 
177  public:
183 
187  BufferManager(std::uint32_t bufs);
188 
192  ~BufferManager();
193 
206  void readPage(File* file, const PageId PageNo, Page*& page);
207 
217  void unPinPage(File* file, const PageId PageNo, const bool dirty);
218 
229  void allocatePage(File* file, PageId &PageNo, Page*& page);
230 
243  void flushFile(const File* file);
244 
253  void disposePage(File* file, const PageId PageNo);
254 
258  void printSelf();
259 
264  {
265  return bufferStats;
266  }
267 
272  {
273  bufferStats.clear();
274  }
275 };
276 
277 }
Class which represents a fixed-size database page containing records.
Definition: page.h:110
Definition: buffer.h:14
Maintains information about one buffer pool frame. One frame corresponds to one page on disk...
Definition: buffer.h:25
BufferStats & getBufferStats()
Definition: buffer.h:263
Class to maintain statistics of buffer usage.
Definition: buffer.h:92
std::uint32_t PageId
Identifier for a page in a file.
Definition: types.h:15
std::uint32_t FrameId
Identifier for a frame in buffer pool.
Definition: types.h:25
Represents a file in the filesystem containing pages.
Definition: file.h:71
The central class which manages the buffer pool including frame allocation and deallocation to pages ...
Definition: buffer.h:131
void clearBufferStats()
Definition: buffer.h:271