MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / getEmptyPage

Method getEmptyPage

src/java/simpledb/index/BTreeFile.java:1175–1192  ·  view source on GitHub ↗

Method to encapsulate the process of creating a new page. It reuses old pages if possible, and creates a new page if none are available. It wipes the page on disk and in the cache and returns a clean copy locked with read-write permission @param tid - the transaction id @param dirtypages - the li

(TransactionId tid, Map<PageId, Page> dirtypages, int pgcateg)

Source from the content-addressed store, hash-verified

1173 * @throws TransactionAbortedException
1174 */
1175 private Page getEmptyPage(TransactionId tid, Map<PageId, Page> dirtypages, int pgcateg)
1176 throws DbException, IOException, TransactionAbortedException {
1177 // create the new page
1178 int emptyPageNo = getEmptyPageNo(tid, dirtypages);
1179 BTreePageId newPageId = new BTreePageId(tableid, emptyPageNo, pgcateg);
1180
1181 // write empty page to disk
1182 RandomAccessFile rf = new RandomAccessFile(f, "rw");
1183 rf.seek(BTreeRootPtrPage.getPageSize() + (long) (emptyPageNo - 1) * BufferPool.getPageSize());
1184 rf.write(BTreePage.createEmptyPageData());
1185 rf.close();
1186
1187 // make sure the page is not in the buffer pool or in the local cache
1188 Database.getBufferPool().discardPage(newPageId);
1189 dirtypages.remove(newPageId);
1190
1191 return getPage(tid, dirtypages, newPageId, Permissions.READ_WRITE);
1192 }
1193
1194 /**
1195 * Mark a page in this BTreeFile as empty. Find the corresponding header page

Callers 4

splitLeafPageMethod · 0.95
splitInternalPageMethod · 0.95
setEmptyPageMethod · 0.95

Calls 9

getEmptyPageNoMethod · 0.95
getPageSizeMethod · 0.95
getPageSizeMethod · 0.95
createEmptyPageDataMethod · 0.95
getBufferPoolMethod · 0.95
getPageMethod · 0.95
discardPageMethod · 0.80
closeMethod · 0.65
removeMethod · 0.45

Tested by

no test coverage detected