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)
| 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 |
no test coverage detected