modules/ud/ud_tr.h

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. tr_get_object_id
  2. tr_get_sequence_id
  3. tr_get_serial_id
  4. tr_get_class_type
  5. tr_get_save
  6. tr_get_escript
  7. tr_get_mode
  8. tr_get_success
  9. tr_get_action
  10. tr_get_status
  11. tr_get_clean
  12. TR_update_status
  13. TR_update_save
  14. TR_update_dummy
  15. TR_update_escript
  16. TR_update_id
  17. TR_mark_clean
  18. TS_CLEAN
  19. TS_ROLLBACK
  20. TS_ROLLBACKED
  21. TS_COMMITTED_NH
  22. TS_ROLLBACKED_NH
  23. TS_COMMITTED_I
  24. TS_COMMITTED_II
  25. TS_DELETED
  26. TS_CREATED_S
  27. TR_ACTION
  28. TR_STATUS
  29. CP_ROLLBACK
  30. CP_COMMIT
  31. CP_ROLLBACK_PASSED
  32. CP_DELETE_PASSED
  33. CP_COMMIT_NH_PASSED
  34. CP_ROLLBACK_NH_PASSED
  35. CP_COMMIT_I_PASSED
  36. CP_COMMIT_II_PASSED
  37. CP_CREATE_S_PASSED
  38. CP_CLEAN

   1 /***************************************
   2   $Revision: 1.1 $
   3 
   4   Semi-internal header file for UD module
   5 
   6   Status: NOT REVUED, NOT TESTED
   7 
   8  Author(s):       Andrei Robachevsky
   9 
  10   ******************/ /******************
  11   Modification History:
  12         andrei (17/01/2000) Created.
  13   ******************/ /******************
  14   Copyright (c) 2000                              RIPE NCC
  15  
  16   All Rights Reserved
  17   
  18   Permission to use, copy, modify, and distribute this software and its
  19   documentation for any purpose and without fee is hereby granted,
  20   provided that the above copyright notice appear in all copies and that
  21   both that copyright notice and this permission notice appear in
  22   supporting documentation, and that the name of the author not be
  23   used in advertising or publicity pertaining to distribution of the
  24   software without specific, written prior permission.
  25   
  26   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  27   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  28   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  29   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  30   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  31   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  32  ***************************************/
  33 #ifndef _UD_TR_H
  34 #define _UD_TR_H
  35 
  36 
  37 #include "ud_int.h"
  38 
  39 /*
  40 
  41 SQL Tables used to keep records needed for crash recovery
  42 
  43 CREATE TABLE transaction_rec (
  44 0  transaction_id int(11) DEFAULT '0' NOT NULL auto_increment,
  45 1  object_id int(10) unsigned DEFAULT '0' NOT NULL,
  46 2  sequence_id int(10) unsigned DEFAULT '1' NOT NULL,
  47 3  serial_id int(10) unsigned DEFAULT '1' NOT NULL,
  48 4  object_type tinyint(3) unsigned DEFAULT '0' NOT NULL,
  49 5  save varchar(256) DEFAULT '' NOT NULL,
  50 6  error_script blob DEFAULT '' NOT NULL,
  51 7  mode tinyint(4) unsigned DEFAULT '0' NOT NULL,
  52 8  succeeded tinyint(4) unsigned DEFAULT '0' NOT NULL,
  53 9  action tinyint(4) unsigned DEFAULT '0' NOT NULL,
  54 10 status tinyint(10) unsigned DEFAULT '0' NOT NULL,
  55 11 clean tinyint(3) DEFAULT '0' NOT NULL,
  56   PRIMARY KEY (transaction_id)
  57 );
  58 
  59 CREATE TABLE dummy_rec (
  60   transaction_id int(11) DEFAULT '0' NOT NULL,
  61   object_id int(10) unsigned DEFAULT '0' NOT NULL,
  62   PRIMARY KEY (transaction_id, object_id)
  63 );
  64 */
  65 
  66 #define DUMMY_OBJECT_ID  1
  67 
  68 
  69 #define tr_get_object_id(result, row)    tr_get_long(result, row, 1)
     /* [<][>][^][v][top][bottom][index][help] */
  70 #define tr_get_sequence_id(result, row)  tr_get_long(result, row, 2)
     /* [<][>][^][v][top][bottom][index][help] */
  71 #define tr_get_serial_id(result, row)    tr_get_long(result, row, 3)
     /* [<][>][^][v][top][bottom][index][help] */
  72 #define tr_get_class_type(result, row)  (C_Type_t)tr_get_int(result, row, 4)
     /* [<][>][^][v][top][bottom][index][help] */
  73 #define tr_get_save(result, row)         tr_get_str(result, row, 5)
     /* [<][>][^][v][top][bottom][index][help] */
  74 #define tr_get_escript(result, row)      tr_get_str(result, row, 6)
     /* [<][>][^][v][top][bottom][index][help] */
  75 #define tr_get_mode(result, row)         tr_get_int(result, row, 7)
     /* [<][>][^][v][top][bottom][index][help] */
  76 #define tr_get_success(result, row)      tr_get_int(result, row, 8)
     /* [<][>][^][v][top][bottom][index][help] */
  77 #define tr_get_action(result, row)       tr_get_int(result, row, 9)
     /* [<][>][^][v][top][bottom][index][help] */
  78 #define tr_get_status(result, row)       tr_get_int(result, row, 10)
     /* [<][>][^][v][top][bottom][index][help] */
  79 #define tr_get_clean(result, row)        tr_get_int(result, row, 11)
     /* [<][>][^][v][top][bottom][index][help] */
  80 
  81 
  82 #define TR_update_status(tr)  TR_update_record(tr, TF_STATUS)
     /* [<][>][^][v][top][bottom][index][help] */
  83 #define TR_update_save(tr)    TR_update_record(tr, TF_STATUS)
     /* [<][>][^][v][top][bottom][index][help] */
  84 #define TR_update_dummy(tr)   TR_update_record(tr, TF_DUMMY)
     /* [<][>][^][v][top][bottom][index][help] */
  85 #define TR_update_escript(tr) TR_update_record(tr, TF_ESCRIPT)
     /* [<][>][^][v][top][bottom][index][help] */
  86 #define TR_update_id(tr)      TR_update_record(tr, TF_ID)
     /* [<][>][^][v][top][bottom][index][help] */
  87 #define TR_mark_clean(tr)     TR_update_record(tr, TF_CLEAN)
     /* [<][>][^][v][top][bottom][index][help] */
  88 
  89 
  90 
  91 
  92 
  93 
  94 /* Transaction Status & CheckPoints
  95    76543210
  96       21NRC
  97 */
  98 
  99 #define TCP_UNCLEAN         0x0000
 100 #define TCP_CLEAN           0x0100
 101 #define TCP_ROLLBACK        0x0200
 102 #define TCP_COMMIT_NH       0x0400
 103 #define TCP_ROLLBACK_NH     TCP_COMMIT_NH
 104 #define TCP_COMMIT_I        0x0800
 105 #define TCP_ROLLBACKED      TCP_COMMIT_I
 106 #define TCP_COMMIT_II       0x1000
 107 #define TCP_DELETE          0x2000
 108 #define TCP_CREATE_S        0x4000
 109 
 110 #define TS_CLEAN(a)               ((a)&TCP_CLEAN)
     /* [<][>][^][v][top][bottom][index][help] */
 111 #define TS_ROLLBACK(a)            ((a)&TCP_ROLLBACK)
     /* [<][>][^][v][top][bottom][index][help] */
 112 #define TS_ROLLBACKED(a)          ((a)&TCP_ROLLBACKED)
     /* [<][>][^][v][top][bottom][index][help] */
 113 #define TS_COMMITTED_NH(a)        ((a)&TCP_COMMIT_NH)
     /* [<][>][^][v][top][bottom][index][help] */
 114 #define TS_ROLLBACKED_NH(a)       ((a)&TCP_ROLLBACK_NH)
     /* [<][>][^][v][top][bottom][index][help] */
 115 #define TS_COMMITTED_I(a)         ((a)&TCP_COMMIT_I)
     /* [<][>][^][v][top][bottom][index][help] */
 116 #define TS_COMMITTED_II(a)        ((a)&TCP_COMMIT_II)
     /* [<][>][^][v][top][bottom][index][help] */
 117 #define TS_DELETED(a)             ((a)&TCP_DELETE)
     /* [<][>][^][v][top][bottom][index][help] */
 118 #define TS_CREATED_S(a)          ((a)&TCP_CREATE_S)
     /* [<][>][^][v][top][bottom][index][help] */
 119 
 120 #define TR_ACTION(a)              ((a)&0x00FF)
     /* [<][>][^][v][top][bottom][index][help] */
 121 #define TR_STATUS(a)              ((a)>>8)
     /* [<][>][^][v][top][bottom][index][help] */
 122 
 123 /* some useful macros for checkpointing (CP)*/
 124 
 125 #define CP_ROLLBACK(a)         (a)=(TR_ACTION(a) + TCP_ROLLBACK)
     /* [<][>][^][v][top][bottom][index][help] */
 126 #define CP_COMMIT(a)           (a)= TR_ACTION(a)
     /* [<][>][^][v][top][bottom][index][help] */
 127 #define CP_ROLLBACK_PASSED(a)  ((a)|=TCP_ROLLBACKED)
     /* [<][>][^][v][top][bottom][index][help] */
 128 #define CP_DELETE_PASSED(a)    ((a)|=TCP_DELETE) 
     /* [<][>][^][v][top][bottom][index][help] */
 129 #define CP_COMMIT_NH_PASSED(a) ((a)|=TCP_COMMIT_NH)
     /* [<][>][^][v][top][bottom][index][help] */
 130 #define CP_ROLLBACK_NH_PASSED(a) ((a)|=TCP_ROLLBACK_NH)
     /* [<][>][^][v][top][bottom][index][help] */
 131 #define CP_COMMIT_I_PASSED(a)  ((a)|=TCP_COMMIT_I)
     /* [<][>][^][v][top][bottom][index][help] */
 132 #define CP_COMMIT_II_PASSED(a) ((a)|=TCP_COMMIT_II)
     /* [<][>][^][v][top][bottom][index][help] */
 133 #define CP_CREATE_S_PASSED(a)  ((a)|=TCP_CREATE_S)
     /* [<][>][^][v][top][bottom][index][help] */
 134 #define CP_CLEAN(a)            ((a)|=TCP_CLEAN)
     /* [<][>][^][v][top][bottom][index][help] */
 135 
 136 
 137 /* Transaction record fields */
 138 enum {
 139  TF_STATUS=1,
 140  TF_CLEAN,
 141  TF_DUMMY,
 142  TF_SAVE,
 143  TF_ESCRIPT,
 144  TF_ID
 145 };
 146 
 147 /* for crash recovery we need to handle only the transaction that failed */
 148 #define TR_LAST  (-1)
 149 
 150 long TR_create_record(Transaction_t *tr);
 151 long TR_update_record(Transaction_t *tr, int field);
 152 Transaction_t *TR_get_record(SQ_connection_t *sql_connection, long transaction_id);
 153 void TR_delete_record(Transaction_t *tr);
 154 int TR_recover(SQ_connection_t *sql_connection);
 155 int TR_check(SQ_connection_t *sql_connection, long transaction_id, int sockfd);
 156 SQ_result_set_t *tr_get_sql_record(SQ_connection_t *sql_connection, long transaction_id);
 157 long tr_get_long(SQ_result_set_t *result, SQ_row_t *row, int col);
 158 int tr_get_int(SQ_result_set_t *result, SQ_row_t *row, int col);
 159 char *tr_get_str(SQ_result_set_t *result, SQ_row_t *row, int col);
 160 int tr_get_dummies(Transaction_t *tr);
 161 
 162 
 163 #endif /* _UD_TR_H */
 164 
 165 
 166 

/* [<][>][^][v][top][bottom][index][help] */