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

Method rollback

src/java/simpledb/storage/LogFile.java:458–497  ·  view source on GitHub ↗

Rollback the specified transaction, setting the state of any of pages it updated to their pre-updated state. To preserve transaction semantics, this should not be called on transactions that have already committed (though this may not be enforced by this method.)

(TransactionId tid)

Source from the content-addressed store, hash-verified

456 @param tid The transaction to rollback
457 */
458 public void rollback(TransactionId tid)
459 throws NoSuchElementException, IOException {
460 synchronized (Database.getBufferPool()) {
461 synchronized(this) {
462 // some code goes here
463 preAppend();
464 long tidId = tid.getId();
465 Long begin = tidToFirstLogRecord.get(tidId);
466 raf.seek(begin);
467 while(true){
468 try{
469 int type = raf.readInt();
470 Long curTid = raf.readLong();
471 if(curTid!=tidId){
472 //如果不是当前的tid,就直接跳过
473 if(type==3){
474 //update record 还要跳过页数据
475 readPageData(raf);
476 readPageData(raf);
477 }
478 }else{
479 if(type==3){
480 //只需要恢复到最初的状态就行
481 Page before = readPageData(raf);
482 Page after = readPageData(raf);
483 DbFile databaseFile = Database.getCatalog().getDatabaseFile(before.getId().getTableId());
484 databaseFile.writePage(before);
485 Database.getBufferPool().discardPage(after.getId());
486 raf.seek(raf.getFilePointer()+8);
487 break;
488 }
489 }
490 raf.seek(raf.getFilePointer()+8);
491 }catch (EOFException e){
492 break;
493 }
494 }
495 }
496 }
497 }
498
499 /** Shutdown the logging system, writing out whatever state
500 is necessary so that start up can happen quickly (without

Callers 1

logAbortMethod · 0.95

Calls 10

getBufferPoolMethod · 0.95
preAppendMethod · 0.95
getIdMethod · 0.95
readPageDataMethod · 0.95
getCatalogMethod · 0.95
writePageMethod · 0.95
getMethod · 0.80
discardPageMethod · 0.80
getTableIdMethod · 0.65
getDatabaseFileMethod · 0.45

Tested by

no test coverage detected