-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer_mgr.c
More file actions
141 lines (115 loc) · 3.77 KB
/
buffer_mgr.c
File metadata and controls
141 lines (115 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
//
//
// Include return codes and methods for logging errors
#include "dberror.h"
// Include bool DT
#include "dt.h"
//include header file
#include "buffer_mgr.h"
// Buffer Manager Interface Pool Handling
/*This function creates the new buffer pool. Within this instance, NumPages are tracked
*using the page replacement strategy. This pool caches pages from pageFileName.
*Initially, this produces an empty Buffer Pool. This does NOT generate a new pageFileName.
*stratData is used to pass info for page replacement in ReplacementStrategy.
*
*/
RC initBufferPool(BM_BufferPool *const bm, const char *const pageFileName,
const int numPages, ReplacementStrategy strategy,
void *stratData) {
return RC_OK;
}
/*This function destroys the Buffer Pool.
*todo Determine if we are to unpin pages if this function is called, or just return an error.
*If pinned pages exist, return an error /or/ Unpin pages if required.
*All dirty pages are written to disk.
*All resources are freed.
*Return RC_OK when process finished.
*
*/
RC shutdownBufferPool(BM_BufferPool *const bm) {
//Check for pinned pages//todo determine directive if pinned pages found.
//if (pinned_pages exist){return error};//todo add new error code
//else{
//call forceFlushPool to write all dirty pages to disk
if (forceFlushPool(bm)!=RC_OK) { //todo check attributes of call
return RC_WRITE_FAILED;//todo add new error code
}else {
//Free all resources
//Return RC_OK when finished.
return RC_OK;
}
//}
//if something else happens, let's return an error:
//return RC_WRITE_FAILED;
}
/*This function causes all dirty pages with a pin count of 0 to be
*written to disk.
*If pin count !=0, it does not change the dirty marker, nor write the page, even if it
*is dirty.
*Iterates through page table, writing dirty pages to disk.
*Set dirty flag to 0.
*Return RC_OK when process finished.
*
*/
RC forceFlushPool(BM_BufferPool *const bm) {
// Iterate through BufferPool, if pinned = 0 and dirty !=0, write page to disk.
//for the length of the BufferPool{
//if (pinned==0 && dirty!=0){
//call writeBlock
//set dirty=0}}
return RC_OK;
}
// Buffer Manager Interface Access Pages
/*This function will mark a single page as dirty.
*Used when page is modified for any reason.
*/
RC markDirty (BM_BufferPool *const bm, BM_PageHandle *const page){
return RC_OK;
}
/*This function is called when the client is finished using a page.
*A client is finished using a page when all modifications are complete,
*and the client can not access any editing of the page in memory.
*NOTE: Because more than one client may have access to the page at a time,
*the fix count could be greater than one. Therefore, this function
* only reduces the fix count by 1.
*/
RC unpinPage (BM_BufferPool *const bm, BM_PageHandle *const page){
//Verify that the fix count is greater than 0.
//Subtract -1 from fix count
return RC_OK;
}
/*This function calls writeBlock to write the given page to disk.
*Sets dirty to 0
*
*/
RC forcePage (BM_BufferPool *const bm, BM_PageHandle *const page){
//call writeBlock to write page to disk.
// set dirty to 0
//On success, return
return RC_OK;
}
/*This function pins the page of page number pageNum.
*
*
*/
RC pinPage (BM_BufferPool *const bm, BM_PageHandle *const page,
const PageNumber pageNum){
return RC_OK;
}
// Statistics Interface
PageNumber *getFrameContents (BM_BufferPool *const bm){
return RC_OK;
}
bool *getDirtyFlags (BM_BufferPool *const bm){
return RC_OK;
}
int *getFixCounts (BM_BufferPool *const bm){
return RC_OK;
}
int getNumReadIO (BM_BufferPool *const bm){
return RC_OK;
}
int getNumWriteIO (BM_BufferPool *const bm){
return RC_OK;
}