Пример #1
0
void BufferManager::pageOut(int index) {
	// If page is dirty, write it to disk
	if (dirtied[index] == 1) {
		char buffer[4096] = {};
		char* pageBytes = (char*) &pages[index];
		for (int i = 0; i < 4096; i++) { buffer[i] = pageBytes[i]; }
		int blockOffset = getBlockOffset(pageNums[index]);
		fm->write(dbName, blockOffset, 8, buffer);
	}

	// Evict page
	pages[index] = Page();

	// Reset page status
	pageNums[index] = 0;
	dirtied[index] = 0;
	pinned[index] = 0;
}
Пример #2
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;
			}
		}
	}
}