/** * Commit or abort a given transaction; release all locks associated to the transaction. * * @param tid the ID of the transaction requesting the unlock * @param commit a flag indicating whether we should commit or abort */ public void transactionComplete(TransactionId tid, boolean commit) throws IOException { if (commit) { Set<PageId> dirtiedFlushedPages = transactionsToDirtiedFlushedPages.get(tid); for (PageId pageId : pageIdToPages.keySet()) { Page page = pageIdToPages.get(pageId); if (tid.equals(page.isDirty())) { flushPage(pageId); // use current page contents as the before-image // for the next transaction that modifies this page. page.setBeforeImage(); } else if (dirtiedFlushedPages != null && dirtiedFlushedPages.contains(pageId)) { page.setBeforeImage(); } } } else { for (PageId pageId : pageIdToPages.keySet()) { Page page = pageIdToPages.get(pageId); if (tid.equals(page.isDirty())) { pageIdToPages.put(pageId, page.getBeforeImage()); page.markDirty(false, null); } } } transactionsToDirtiedFlushedPages.remove(tid); lockManager.releasePages(tid); // if commit, flush dirty pages associated with transaction // if !commit, restore dirty pages associated with transaction to // previous // state // release all locks (and other state? don't think there is any) }