Presentation is loading. Please wait.

Presentation is loading. Please wait.

Gray& Reuter: Transaction Mgr 11: 1 Transaction Manager Software is like entropy. It is difficult to grasp, weighs nothing, and obeys the Second Law of.

Similar presentations


Presentation on theme: "Gray& Reuter: Transaction Mgr 11: 1 Transaction Manager Software is like entropy. It is difficult to grasp, weighs nothing, and obeys the Second Law of."— Presentation transcript:

1 Gray& Reuter: Transaction Mgr 11: 1 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 9:00 11:00 1:30 3:30 7:00 Overview Faults Tolerance T Models Party TP mons Lock Theory Lock Techniq Queues Workflow Log+RM TM CICS & Inet Adv TM Cyberbrick Files &Buffers COM+ Corba Replication Party B-tree Access Paths Groupware Benchmark MonTueWedThurFri

2 Gray& Reuter: Transaction Mgr 11: 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().

3 Gray& Reuter: Transaction Mgr 11: 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().

4 Gray& Reuter: Transaction Mgr 11: 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.

5 Gray& Reuter: Transaction Mgr 11: 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 {TIMESTAMPBirhtdayOf TM; RMIDIDofTM; long LocalSqncNo; char FutureUse[2]; } TRID;

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

7 Gray& Reuter: Transaction Mgr 11: 7 What the TM Knows About RMs typedef struct {RMCB *NextRMCB; charRMName[BIG]; RMIDIDofRM; BooleanRMisUP; LSNOldestLogRecForREDO; LSNCheckpointLSN; } RMCB;

8 Gray& Reuter: Transaction Mgr 11: 8 What the TM Knows About Transactions typedef struct {TransCB * NextTranCBt; TRIDTRIDofTran; tran_statusStatusOfTran; longNextSaveptNo; longCurrentSaveptNo; LSNLSNofCurrentSavept; LSNMostRecentLSNofTran; LSNFirstLSNofTran; to be continued...

9 Gray& Reuter: Transaction Mgr 11: 9 RMTranCB * RMsAttachedToTran; SECB *SessionsAttachedToTran; pointerLocksHeldByTran; pointerLockTranWaitsFor; longTimeoutForLockWaits; TransCB *ForDeadlockDetector; } TransCB;... Knows About Transactions

10 Gray& Reuter: Transaction Mgr 11: 10 Some Simple Addressing Functions TRIDMyTrid(void); Returns transaction identifier of callers process. TransCBMyTrans(void); Returns a copy of callers transaction CB. TransCB *MyTransP(void); Returns pointer to callers transaction CB.

11 Gray& Reuter: Transaction Mgr 11: 11 Implementation of MyTrid TRID MyTrid(void) /*return curr. TRID of calling process*/ { TransCB * mytranp = MyTransP(); /*pointer to callers 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*/

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

13 Gray& Reuter: Transaction Mgr 11: 13 The TM Savepoint Log Record typedef struct { SAVE_PT_TYPE RecordType; longSaveptNum; tran_status Status; BooleanSoftOrPersistent; longNumRMs; RMTransCB RM[NumRMs]; longNumSess; SECBSession[NumSess]; contextContextData; } TM_savepoint;

14 Gray& Reuter: Transaction Mgr 11: 14 Implementation of Begin_Work TRID Begin_Work(context * it, Boolean soft) {TransCB *trans; /*the transactions descriptor */ TRIDhim;/*the newTRID */ TM_savepointsave;/*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

15 Gray& Reuter: Transaction Mgr 11: 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); };

16 Gray& Reuter: Transaction Mgr 11: 16 Implementation of Commit_Work Boolean Commit_Work(context * it, Boolean lazy) {TransCB *trans = MyTransP(); TM_savepointsave; long save_num Booleanvote; 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;};}

17 Gray& Reuter: Transaction Mgr 11: 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);

18 Gray& Reuter: Transaction Mgr 11: 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);};};

19 Gray& Reuter: Transaction Mgr 11: 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; };

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

21 Gray& Reuter: Transaction Mgr 11: 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();};

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

23 Gray& Reuter: Transaction Mgr 11: 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(); };

24 Gray& Reuter: Transaction Mgr 11: 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.

25 Gray& Reuter: Transaction Mgr 11: 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;};

26 Gray& Reuter: Transaction Mgr 11: 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; };

27 Gray& Reuter: Transaction Mgr 11: 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;

28 Gray& Reuter: Transaction Mgr 11: 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;};

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

30 Gray& Reuter: Transaction Mgr 11: 30 System Restart

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

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

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

34 Gray& Reuter: Transaction Mgr 11: 34 Why Restart Works


Download ppt "Gray& Reuter: Transaction Mgr 11: 1 Transaction Manager Software is like entropy. It is difficult to grasp, weighs nothing, and obeys the Second Law of."

Similar presentations


Ads by Google