void BufferManager::pageIn(int index, int pageNum) { // Read page data from disk into buffer char buffer[4096] = {}; int blockOffset = getBlockOffset(pageNum); fm->read(dbName, blockOffset, 8, buffer); // Create page pages[index] = Page(buffer); // Set page status pageNums[index] = pageNum; dirtied[index] = 0; pinned[index] = 0; }
void LogManager::forceLSNRecord(int index) { for (int pageNum = 0; pageNum < 4; pageNum++) { char page[4096] = {}; fm->read(logName, pageNum * 8, 8, page); for (int i = 0; i < 73; i++) { char bytes[56] = {}; int start = i * 56; for (int j = 0; j < 56; j++) { bytes[j] = page[start + j]; } LogRecord rec = LogRecord(bytes); if (rec.LSN == 0) { char* recordBytes = (char*) &log[index]; for (int k = 0; k < 56; k++) { page[start + k] = recordBytes[k]; } fm->write(logName, pageNum * 8, 8, page); return; } } } }
void LogManager::start(char* inLogName) { logName = inLogName; char page[4096] = {}; for (int pageNum = 0; pageNum < 4; pageNum++) { fm->read(logName, pageNum * 8, 8, page); for (int i = 0; i < 73; i++) { char bytes[56] = {}; int start = i * 56; for (int j = 0; j < 56; j++) { bytes[j] = page[start + j]; } LogRecord rec = LogRecord(bytes); if (rec.LSN == 0) { return; } else if (rec.LSN != 0) { log[tail] = rec; tail++; } } } }