1 /* ====== BEGIN INCLUDE FILE rmdb_finish_transaction.incl.pl1 =========================== */ 2 3 /* 4 BEGIN_DESCRIPTION 5 6 A generalized routine accessed by 5 MRDS modules (create_mrds_db.pl1, 7 rmdb_create_index.pl1, rmdb_create_relation.pl1, rmdb_delete_index.pl1, 8 rmdb_delete_relation.pl1) that begin and commit transactions. The intent 9 is that it be executed as inline code. It is assumed that 10 rmdb_start_transaction was executed previously in the procedure. Prior 11 to this include file the program should assign the value of its local 12 error code to mftxn_code. The program utilizing this include file must 13 supply a function labeled should_rollback that returns bit (1). This 14 routine should examine the error code mftxn_code and whether the 15 transaction should be aborted or rolled back. "0"b means abort and "1"b 16 means rollback. This procedure may choose to simply return "0"b as it 17 appears that MRDS will generally NOT rollback transactions. This routine 18 does rollback and restart if the before journal is full but only attempts it 19 once. A procedure labelled restore_significant_data must also be supplied, 20 where any data that was saved prior to the transaction is restored. A 21 procedure consisting solely of a return statement can be supplied if 22 necessary. After execution of this include file, mftxn_code must be 23 examined. If it was 0 before entering the code and is non-zero afterward, 24 then the commit has failed. Otherwise it will be unchanged. 25 26 END_DESCRIPTION 27 28 Written 82-09-30 by Paul W. Benjamin. 29 Modified 83-01-13 by PWB to add retry on deadlocks and to return a non-zero 30 error code only when the transaction is in an error state. 31 Modified 83-02-04 by PWB to reset transaction id to 0 upon completion. 32 Modified 83-05-05 by PWB to abort when rollback fails, abandon when abort 33 fails, and to abort rather than rollback when bj is full. 34 Modified 83-05-18 by PWB to use mftxn_temp_code in calls to abandon, abort 35 and rollback. 36 Modified 83-05-19 by PWB to add mftxn_check_code label. It is transferred 37 to by the mstxn_any_other procedure. 38 */ 39 40 dcl dm_error_$bj_journal_full fixed bin(35) ext static; 41 dcl dm_error_$lock_deadlock fixed bin(35) ext static; 42 dcl mftxn_code fixed bin (35); 43 dcl mftxn_temp_code fixed bin (35); 44 dcl transaction_manager_$commit_txn entry (bit (36) aligned, fixed bin (35)); 45 dcl transaction_manager_$rollback_txn entry (bit (36) aligned, fixed bin (17), fixed bin (35)); 46 47 48 if mstxn_txn_id = "0"b /* No transaction */ 49 then do; 50 mftxn_code = 0; 51 goto mftxn_exit; 52 end; 53 mftxn_check_code: 54 if mftxn_code = 0 55 then do; 56 call transaction_manager_$commit_txn (mstxn_txn_id, mftxn_code); 57 if mftxn_code ^= 0 58 then do; 59 call transaction_manager_$abort_txn (mstxn_txn_id, mftxn_temp_code); 60 if mftxn_temp_code ^= 0 61 then call transaction_manager_$abandon_txn (mstxn_txn_id, mftxn_temp_code); 62 end; 63 end; 64 else do; 65 call restore_significant_data; 66 if mftxn_code = dm_error_$lock_deadlock /* retry just once if deadlock */ 67 & mstxn_retries < 1 68 then do; 69 mstxn_retries = mstxn_retries + 1; 70 call transaction_manager_$rollback_txn (mstxn_txn_id, 0, mftxn_temp_code); 71 if mftxn_temp_code ^= 0 72 then do; 73 call transaction_manager_$abort_txn (mstxn_txn_id, mftxn_temp_code); 74 if mftxn_temp_code ^= 0 75 then call transaction_manager_$abandon_txn (mstxn_txn_id, mftxn_temp_code); 76 end; 77 else do; 78 mstxn_code = 0; 79 goto mstxn_exit; /* go back and try again */ 80 end; 81 end; 82 else if should_rollback () /* let the program decide */ 83 then do; 84 call transaction_manager_$rollback_txn (mstxn_txn_id, 0, mftxn_temp_code); 85 if mftxn_temp_code ^= 0 86 then do; 87 call transaction_manager_$abort_txn (mstxn_txn_id, mftxn_temp_code); 88 if mftxn_temp_code ^= 0 89 then call transaction_manager_$abandon_txn (mstxn_txn_id, mftxn_temp_code); 90 end; 91 else do; 92 mstxn_code = 0; 93 goto mstxn_exit; /* go back and try again */ 94 end; 95 end; 96 else do; 97 call transaction_manager_$abort_txn (mstxn_txn_id, mftxn_temp_code); 98 if mftxn_temp_code ^= 0 99 then call transaction_manager_$abandon_txn (mstxn_txn_id, mftxn_temp_code); 100 end; 101 end; 102 mstxn_txn_id = "0"b; /* should never be nonzero unless there is a txn */ 103 mftxn_exit: 104 105 /* ------ END INCLUDE FILE rmdb_finish_transaction.incl.pl1 --------------------------- */