Source File modules/ud/ud_tr.h

    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)
    70   | #define tr_get_sequence_id(result, row)  tr_get_long(result, row, 2)
    71   | #define tr_get_serial_id(result, row)    tr_get_long(result, row, 3)
    72   | #define tr_get_class_type(result, row)  (C_Type_t)tr_get_int(result, row, 4)
    73   | #define tr_get_save(result, row)         tr_get_str(result, row, 5)
    74   | #define tr_get_escript(result, row)      tr_get_str(result, row, 6)
    75   | #define tr_get_mode(result, row)         tr_get_int(result, row, 7)
    76   | #define tr_get_success(result, row)      tr_get_int(result, row, 8)
    77   | #define tr_get_action(result, row)       tr_get_int(result, row, 9)
    78   | #define tr_get_status(result, row)       tr_get_int(result, row, 10)
    79   | #define tr_get_clean(result, row)        tr_get_int(result, row, 11)
    80   |
    81   |
    82   | #define TR_update_status(tr)  TR_update_record(tr, TF_STATUS)
    83   | #define TR_update_save(tr)    TR_update_record(tr, TF_STATUS)
    84   | #define TR_update_dummy(tr)   TR_update_record(tr, TF_DUMMY)
    85   | #define TR_update_escript(tr) TR_update_record(tr, TF_ESCRIPT)
    86   | #define TR_update_id(tr)      TR_update_record(tr, TF_ID)
    87   | #define TR_mark_clean(tr)     TR_update_record(tr, TF_CLEAN)
    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)
    111  | #define TS_ROLLBACK(a)            ((a)&TCP_ROLLBACK)
    112  | #define TS_ROLLBACKED(a)          ((a)&TCP_ROLLBACKED)
    113  | #define TS_COMMITTED_NH(a)        ((a)&TCP_COMMIT_NH)
    114  | #define TS_ROLLBACKED_NH(a)       ((a)&TCP_ROLLBACK_NH)
    115  | #define TS_COMMITTED_I(a)         ((a)&TCP_COMMIT_I)
    116  | #define TS_COMMITTED_II(a)        ((a)&TCP_COMMIT_II)
    117  | #define TS_DELETED(a)             ((a)&TCP_DELETE)
    118  | #define TS_CREATED_S(a)          ((a)&TCP_CREATE_S)
    119  |
    120  | #define TR_ACTION(a)              ((a)&0x00FF)
    121  | #define TR_STATUS(a)              ((a)>>8)
    122  |
    123  | /* some useful macros for checkpointing (CP)*/
    124  |
    125  | #define CP_ROLLBACK(a)         (a)=(TR_ACTION(a) + TCP_ROLLBACK)
    126  | #define CP_COMMIT(a)           (a)= TR_ACTION(a)
    127  | #define CP_ROLLBACK_PASSED(a)  ((a)|=TCP_ROLLBACKED)
    128  | #define CP_DELETE_PASSED(a)    ((a)|=TCP_DELETE)
    129  | #define CP_COMMIT_NH_PASSED(a) ((a)|=TCP_COMMIT_NH)
    130  | #define CP_ROLLBACK_NH_PASSED(a) ((a)|=TCP_ROLLBACK_NH)
    131  | #define CP_COMMIT_I_PASSED(a)  ((a)|=TCP_COMMIT_I)
    132  | #define CP_COMMIT_II_PASSED(a) ((a)|=TCP_COMMIT_II)
    133  | #define CP_CREATE_S_PASSED(a)  ((a)|=TCP_CREATE_S)
    134  | #define CP_CLEAN(a)            ((a)|=TCP_CLEAN)
    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  |