1 / 34

Transaction Manager

Software is like entropy. It is difficult to grasp, weighs nothing, and obeys the Second Law of Thermodynamics; i.e., it always increases. Norman Augstine. Transaction Manager. Mon. Tue. Wed. Thur. Fri. 9:00. Overview. TP mons. Log+RM. Files &Buffers. B-tree. 11:00. Faults.

alma-savage
Download Presentation

Transaction Manager

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Software is like entropy. It is difficult to grasp, weighs nothing, and obeys the Second Law of Thermodynamics; i.e., it always increases. Norman Augstine Transaction Manager Mon Tue Wed Thur Fri 9:00 Overview TP mons Log+RM Files &Buffers B-tree 11:00 Faults Lock Theory TM COM+ Access Paths 1:30 Tolerance Lock Techniq CICS & Inet Corba Groupware 3:30 T Models Queues Adv TM Replication Benchmark 7:00 Party Workflow Cyberbrick Party Gray& Reuter: Transaction Mgr

  2. When Everything Works Normally, no resorce manager fails, and the system is up.The TM receives the following calls: • Begin_Work(), • Save_Work(), • Prepare_Work(), • Commit_Work(), • Rollback_Work(), • Read_ Context(). Gray& Reuter: Transaction Mgr

  3. Other “Normal” Calls Normally, no resorce manager fails, and the system is up.The TM receives the following calls: • Leave_Transaction(), • Resume_Transaction(), • Status_Transaction(), • Identify(), • Join_Work(). Gray& Reuter: Transaction Mgr

  4. The TM And Context • With each type of savepoint, the TM can record context information for the transaction. • Context is provided by a resource manager and can be reestablished when the transaction returns to that savepoint. • For the TM, context is only a string of bytes. • The “meaning” of context is only understood by the subsystem that created it. The context established by a database system is different from the one provided by a transactional GUI. Gray& Reuter: Transaction Mgr

  5. Transaction Identifiers TRIDs must be created at high rates at each node in a distributed system. TRIDs must be unique in time and space. This is the structure of a TRID: typedef struct {TIMESTAMP BirhtdayOf TM; RMID IDofTM; long LocalSqncNo; char FutureUse[2]; } TRID; Gray& Reuter: Transaction Mgr

  6. The TM´s Data Structures Gray& Reuter: Transaction Mgr

  7. What the TM Knows About RMs typedef struct { RMCB * NextRMCB; char RMName[BIG]; RMID IDofRM; Boolean RMisUP; LSN OldestLogRecForREDO; LSN CheckpointLSN; } RMCB; Gray& Reuter: Transaction Mgr

  8. What the TM Knows About Transactions typedef struct { TransCB * NextTranCBt; TRID TRIDofTran; tran_status StatusOfTran; long NextSaveptNo; long CurrentSaveptNo; LSN LSNofCurrentSavept; LSN MostRecentLSNofTran; LSN FirstLSNofTran; to be continued ... Gray& Reuter: Transaction Mgr

  9. . . . Knows About Transactions RMTranCB * RMsAttachedToTran; SECB * SessionsAttachedToTran; pointer LocksHeldByTran; pointer LockTranWaitsFor; long TimeoutForLockWaits; TransCB * ForDeadlockDetector; } TransCB; Gray& Reuter: Transaction Mgr

  10. Some Simple Addressing Functions TRID MyTrid(void); Returns transaction identifier of caller’s process. TransCB MyTrans(void); Returns a copy of caller’s transaction CB. TransCB * MyTransP(void); Returns pointer to caller’s transaction CB. Gray& Reuter: Transaction Mgr

  11. Implementation of MyTrid TRID MyTrid(void) /*return curr. TRID of calling process*/ { TransCB * mytranp = MyTransP(); /*pointer to caller’s TA CB */ if ( mytranp != NULL ) return mytranp->trid; /*return his trid if he has one*/ else return NULLTrid;} /*no trid if caller has no control blk*/ Gray& Reuter: Transaction Mgr

  12. Savepoints There are seven basic types of savepoints: • Begin • Save • Prepare • Rollback • Commit • Abort • Complete Gray& Reuter: Transaction Mgr

  13. The TM Savepoint Log Record typedef struct { SAVE_PT_TYPE RecordType; long SaveptNum; tran_status Status; Boolean SoftOrPersistent; long NumRMs; RMTransCB RM[NumRMs]; long NumSess; SECB Session[NumSess]; context ContextData; } TM_savepoint; Gray& Reuter: Transaction Mgr

  14. Implementation of Begin_Work TRID Begin_Work(context * it, Boolean soft) {TransCB * trans; /*the transaction’s descriptor */ TRID him; /*the newTRID */ TM_savepoint save; /*the savept record */ if (MyTrid() != NULLTrid) return(NULLTrid); him = TM_anchor.next_trid; /*give nextTRID */ TM_anchor.next_trid.sequence++; (MyProcessP())->trid = him; trans = malloc(sizeof(TransCB)); trans->next = TM_anchor.tran_list; TM_anchor.tran_list = trans; trans->trid = him Gray& Reuter: Transaction Mgr

  15. Implementation of Begin_Work trans->status = ACTIVE; trans->save_pt = 1; trans->next_save_pt = 2; trans->RM_list = trans->lock_list = trans->ses_list = NULL; save.record_type = begin; save.save_pt_num= 1; save.soft = soft; save.num_RM = save.sessions = 0; copy(save.it, it, it.length); trans->save_pt_lsn = log_insert( save, sizeof(save)); if (!soft) log_flush(trans->max_lsn,FALSE); return(him); }; Gray& Reuter: Transaction Mgr

  16. Implementation of Commit_Work Boolean Commit_Work(context * it, Boolean lazy) { TransCB * trans = MyTransP(); TM_savepoint save; long save_num Boolean vote; RMTransCB * rm; SECB * session; if (MyTrid() == NULLTrid) return(0); for each rm in trans->RM_list {rm->prepared =rmid.Prepare(&rm->save_pt_lsn)) if (!rm->prepared) { Abort_Work(); return FALSE;};} Gray& Reuter: Transaction Mgr

  17. Implementation of Commit_Work for each outgoing session in trans->ses_list {vote = TM.Prepare(void); if (! vote or timeout) { Abort_Work(); return FALSE;};}; trans->status = PREPARED; save_num = trans->save_pt ++; save.record_type = commit; save.soft = FALSE; save.save_pt_num = save_num; copy(save, trans->RM_list); copy(save, trans->ses_list); copy(save.it, it); Gray& Reuter: Transaction Mgr

  18. Implementation of Commit_Work trans->save_pt_lsn = log_insert( save, sizeof(save)); log_flush(trans->max_lsn, lazy); trans->status = COMMITTING; for each rm in trans->RM_list { if ( rmid.Commit( )) { deallocate rmid from transaction;}; else {rm_commit(&rm);};}; for each outgoing session in trans->ses_list { TM.Commit(); if (! timeout) { free session; } else {session_failure(&session);};}; Gray& Reuter: Transaction Mgr

  19. Implementation of Commit_Work if ( trans->RM_list == NULL && trans->ses_list == NULL) { trans->status = COMMITTED; save.record_type = commit_complete; log_insert( save, sizeof(header)+sizeof(record_type)); dequeue and free trans structure;} (MyProcessP())->trid = NULLTrid; return TRUE; }; Gray& Reuter: Transaction Mgr

  20. Data Flow at Commit Outgoing Sessions From Application or Remote Transaction Remote Manager Transaction Managers and Servers Savepoint Local Rollback Transaction Prepare Manager Commit / Abort Joined Resource Managers Gray& Reuter: Transaction Mgr

  21. Handling a Session Failure void session_failure(SECB * session) { TransCB * trans = MyTransP(); Boolean timeout = TRUE; TM_savepoint save; RMID TM= session->him; while( timeout) { TM.Commit( );}; free session; if ( trans->RM_list == NULL && trans->ses_list == NULL) { trans->status = COMMITTED; save.record_type = commit_complete; log_insert( save, sizeof(save)); dequeue and free trans structure;}; exit(); }; Gray& Reuter: Transaction Mgr

  22. Distributed Commit participant root Communications Manager Ø1 TM.Prepare() Ø1 Ø1 Local TM Ø2 callbacks Ø2 Ø2 TM. Commit() participant participant Ø1 Ø1 Ø1 Ø2 Ø2 Ø2 participant participant Gray& Reuter: Transaction Mgr

  23. Coordinator Failure void coordinator_failure(SECB * session) tran_status outcome = prepared; RMID TM= session->him; while( outcome not in {committing, aborting}) { outcome=TM.Status_Transaction(MyTrid());}; switch (outcome) { aborting: Abort(); break; committing:Commit( ); break; } exit(); }; Gray& Reuter: Transaction Mgr

  24. Savepoint Logic In the TM´s savepoint record, the LSNs of the participating resource managers are recored, so they can be reestablished later on. Gray& Reuter: Transaction Mgr

  25. Savepoint Implementation int Save_Work(context * it, Boolean soft) {TransCB * trans = MyTransP(); TM_savepoint save; long save_num; RMTransCB * rm; SECB * session; Boolean vote; if (MyTrid() == NULLTrid) return(0); save_num = trans->next_save_pt + +; for each rm in trans->RM_list if( ! vote = rmid.Savepoint(&rm->save_pt_lsn ))) { Abort_Work(); return 0;}; Gray& Reuter: Transaction Mgr

  26. Savepoint Implementation for each session in trans->ses_list { vote = TM.Savepoint(save_num); if (timeout || ! vote ) { Abort_Work(); return 0;};}; trans->save_pt = trans->next_save_pt++; save.record_type = save; save.save_pt_num = save_num; save.soft = soft; copy(save, trans->RM_list); copy(save, trans->ses_list); copy(save.it, it); trans->save_pt_lsn = log_insert( save, sizeof(save)); if (!soft) log_flush(trans->max_lsn, soft); return save_num; }; Gray& Reuter: Transaction Mgr

  27. The UNDO of Savepoints void UNDO(LSN lsn) {TransCB * trans = MyTransP(); TM_savepoint save; TRID him =MyTrid(); RMID rmid; RMTransCB * rm; SECB * session; log_record_header header; Boolean vote=TRUE; log_read(lsn,&header,save,sizeof(save)); trans->save_pt = save.save_pt_num; Gray& Reuter: Transaction Mgr

  28. The UNDO of Savepoints for each rm in trans->RM_list { if ( rm is in save ) rm->save_pt_lsn = save.RM.save_pt_lsn; else rm->save_pt_lsn = NULLlsn;. vote= vote || rmid.UNDO_Savepoint(rm->save_pt_lsn);} for each session in trans->ses_list vote = vote || TM.UNDO_Savepoint(trans->save_pt); if ( vote ) { trans->max_lsn = header.tran_prev_lsn; trans->save_pt_lsn = log_insert(save,sizeof(save));} return;}; Gray& Reuter: Transaction Mgr

  29. Rollback Log Records Compensation log records Rollback UnDo Begin UnDo UnDo UnDo Save Do Do Do Do Do Do Do Do Do Gray& Reuter: Transaction Mgr

  30. System Restart Gray& Reuter: Transaction Mgr

  31. Transaction States at Restart Gray& Reuter: Transaction Mgr

  32. Resource Manager at Restart Gray& Reuter: Transaction Mgr

  33. Using Two Checkpoints For Restart One scan for ALL RMs Gray& Reuter: Transaction Mgr

  34. Why Restart Works Gray& Reuter: Transaction Mgr

More Related