Closed SaintNerevar closed 2 years ago
OLD:
int StaticBuffer::setDirtyBit(int blockNum) {
// Check if blockNum is valid (non zero and less than number of disk blocks)
// and return E_OUTOFBOUND if not valid.
// find the buffer number corresponding to the block using getBufferNum().
// set the dirty flag of that buffer in metaInfo to true
// return SUCCESS
}
POSSIBLE NEW CHANGE:
int StaticBuffer::setDirtyBit(int blockNum) {
// Check if blockNum is valid (non zero and less than number of disk blocks)
// and return E_OUTOFBOUND if not valid.
// find the buffer number corresponding to the block using getBufferNum().
// if it returns FAILURE, then Block is not loaded to any buffer. Hence return FAILURE (or a new ERROR?).
// set the dirty flag of that buffer in metaInfo to true
// return SUCCESS
}
Note:
@jessiyajoy please verify
Do setDirtyBit function has to be public? is it being called anywhere else, other than its friend classes.
@jessiyajoy please verify
Return E_BLOCKNOTINBUFFER(new constant to be added)
int StaticBuffer::setDirtyBit(int blockNum) {
//find the buffer index corresponding to the block using the getBufferNum().
int ret = getBufferNum(blockNum);
// if Buffer is valid, bufferNum != E_BLOCKNOTINBUFFER
if (ret != E_BLOCKNOTINBUFFER) {
int bufferNum = ret;
// set the dirty bit of that buffer in the metaInfo to true.
metainfo[bufferNum].dirty = true;
} else {
// E_OUTOFBOUND - blockNum is invalid
// E_BLOCKNOTINBUFFER - block with blockNum is not present in Buffer
return ret;
}
// return SUCCESS
return SUCCESS;
}
The algorithm doesn't state what happens if the call to StaticBuffer::getBufferNum fails i.e the block in question isn't in the buffer. If this scenario never happens due to design, the docs should make it clear.