gray& reuter: transaction mgr 11: 1 transaction manager software is like entropy. it is...

34
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 Path Groupware Benchmark Mon Tue Wed Thur Fri

Upload: caroline-coleman

Post on 26-Mar-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 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

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

Mon Tue Wed Thur Fri

Page 2: 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

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().

Page 3: 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

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().

Page 4: 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

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.

Page 5: 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

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 {TIMESTAMP BirhtdayOf TM; RMID IDofTM; long LocalSqncNo; char FutureUse[2]; } TRID;

Page 6: 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

Gray& Reuter: Transaction Mgr 11: 6

name TMid next_transid birthday RM_list tran_list

Transaction Manager Anchor

name rmid up? low_water_lsn checkpoint_lsn

transid status next_savepoint savepoint save point lsn rm_list max_lsn min_lsn lock_list session_list

rmid savepoint lsn vote

Maintained by Log Manager

Maintained by Lock Manager

session name polarity remote_TM_name birthday stuff

Locks

Log Records

Resource Manager Entries

Resource Managers Joined to This Transaction

Transaction Descriptors

TM

_an

chor

RM

CB

Tra

nsC

B

SE

CB

RM

Tra

nC

B

The TM´sDataStructures

Page 7: 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

Gray& Reuter: Transaction Mgr 11: 7

What the TM Knows About RMs

typedef struct { RMCB * NextRMCB;

char RMName[BIG];RMID IDofRM;Boolean RMisUP;LSN OldestLogRecForREDO;LSN CheckpointLSN;

} RMCB;

Page 8: 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

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

Page 9: 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

Gray& Reuter: Transaction Mgr 11: 9

RMTranCB * RMsAttachedToTran;SECB * SessionsAttachedToTran;pointer LocksHeldByTran;pointer LockTranWaitsFor;long TimeoutForLockWaits;TransCB * ForDeadlockDetector;

} TransCB;

. . . Knows About Transactions

Page 10: 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

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

Page 11: 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

Gray& Reuter: Transaction Mgr 11: 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*/

Page 12: 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

Gray& Reuter: Transaction Mgr 11: 12

Savepoints

There are seven basic types of savepoints:

Begin Save PrepareRollback Commit Abort Complete

Page 13: 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

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

Page 14: 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

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

Page 15: 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

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);};

Page 16: 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

Gray& Reuter: Transaction Mgr 11: 16

Implementation of Commit_Work

Boolean Commit_Work(context * it, Boolean lazy){ TransCB * trans = MyTransP();

TM_savepoint save;long save_numBoolean 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;};}

Page 17: 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

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);

Page 18: 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

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);};};

Page 19: 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

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;};

Page 20: 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

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

Page 21: 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

Gray& Reuter: Transaction Mgr 11: 21

Handling a Session Failurevoid 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(); };

Page 22: 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

Gray& Reuter: Transaction Mgr 11: 22

Distributed Commit

Ø1

Ø2

Ø1

Ø2

Ø1

Ø2

Ø1

Ø2

root

participant participant

participant

participant

Communications Manager TM.Prepare()

TM. Commit()

Ø1

Ø2

participant

Local TM callbacks

Ø1

Ø2

Page 23: 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

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();};

Page 24: 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

Gray& Reuter: Transaction Mgr 11: 24

Savepoint Logic

RM 1 Save Point Log Record

RM 2 Save Point Log Record

Transaction Manager's Save Point Log Record

Transaction's Log Records Increassing LSNs

In the TM´s savepoint record, the LSNs of theparticipating resource managers are recored, sothey can be reestablished later on.

Page 25: 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

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;};

Page 26: 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

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; };

Page 27: 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

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;

Page 28: 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

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;};

Page 29: 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

Gray& Reuter: Transaction Mgr 11: 29

Rollback Log RecordsB

egin

Do

Do Do

Sav

e

Do

Do

Do

UnD

o

Rol

lbac

k

UnD

oU

nDo

UnD

o

Do

Do

Do

Compensation log records

Page 30: 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

Gray& Reuter: Transaction Mgr 11: 30

System Restart

REDO Transaction ManagerCheckpoint Checkpoint

UNDO

Checkpoint

Compensation Log Records Generated By Undo Scan

Log at Restart: REDO scan forward from last checkpoint

Log unchanged: UNDO scan back from end of log along tran prev lsn

UNDO scan generated compensation records (undo logging)

At end of UNDO scan, checkpoint and mark resource manager as up

Identify(RMID)

REDO from that RMID low water lsn REDO callbacks

UNDO callbacks

Return from Identify()

Now Transaction Manager is "up"

TM(chkp_lsn)

Page 31: 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

Gray& Reuter: Transaction Mgr 11: 31

Transaction States at Restart

begin do do do

begin do commit complete

begin do do rollback undo undo abort complete

begin do do commit

begin do do rollback undo undo abort

begin do do persistent save

begin do do prepare

CompletedCompleting

Persistent

begin do do persistent save do do

Active

Failure & Restart REDO in persistent storage

REDO in persistent storage tell each resource manager then write completion record

REDO in persistent storage tell each resource manager to be prepared

REDO in persistent storage UNDO to persistent save if none, do abort logic

Page 32: 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

Gray& Reuter: Transaction Mgr 11: 32

Resource Manager at Restart

Identify()

TM_Startup()

UNDO()

REDO()

Commit()

Abort()

He's up!

Transaction Manager

Resource Manager

REDO scan

UNDO scan

resolution

Page 33: 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

Gray& Reuter: Transaction Mgr 11: 33

Using Two Checkpoints For RestartOne scan for ALL RMs

REDO

Checkpoint Checkpoint

UNDO

Checkpoint

Compensation Log Records

Generated By Undo Scan

Log at Restart: REDO scan forward from 2nd to last checkpoint

Log unchanged: UNDO scan back from end of log along tran prev lsn

UNDO scan generated compensation records (undo logging)

At end of UNDO scan, checkpoint and allow new transactions to begin

Page 34: 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

Gray& Reuter: Transaction Mgr 11: 34

Why Restart WorksA case analysis of the restart state of a transaction’s outcome,its log record and the state of the page in persistent memory.

Transaction

Logrecord

PersistentPage

Why Recovery Works

1 committed

volatile old impossible: force-log -at-commit

2 new impossible:WAL +force-log-at-commit

3 durable old REDO makes it new

4 new REDO idempotence

5 aborted volatile old no record at restart(implicit UNDO).

6 new impossible: WAL

7 durable old REDO then UNDO

8 new REDO idempotence +UNDO