~jaypipes/drizzle/new-test-runner

« back to all changes in this revision

Viewing changes to storage/innobase/include/trx0trx.ic

  • Committer: Jay Pipes
  • Date: 2008-12-11 17:52:34 UTC
  • mfrom: (482.16.152 testable)
  • Revision ID: jpipes@serialcoder-20081211175234-uqsfvmgxejvmellq
merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
The transaction
 
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
 
6
Created 3/26/1996 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
/*****************************************************************
 
10
Starts the transaction if it is not yet started. */
 
11
UNIV_INLINE
 
12
void
 
13
trx_start_if_not_started(
 
14
/*=====================*/
 
15
        trx_t*  trx)    /* in: transaction */
 
16
{
 
17
        ut_ad(trx->conc_state != TRX_COMMITTED_IN_MEMORY);
 
18
 
 
19
        if (trx->conc_state == TRX_NOT_STARTED) {
 
20
 
 
21
                trx_start(trx, ULINT_UNDEFINED);
 
22
        }
 
23
}
 
24
 
 
25
/*****************************************************************
 
26
Starts the transaction if it is not yet started. Assumes we have reserved
 
27
the kernel mutex! */
 
28
UNIV_INLINE
 
29
void
 
30
trx_start_if_not_started_low(
 
31
/*=========================*/
 
32
        trx_t*  trx)    /* in: transaction */
 
33
{
 
34
        ut_ad(trx->conc_state != TRX_COMMITTED_IN_MEMORY);
 
35
 
 
36
        if (trx->conc_state == TRX_NOT_STARTED) {
 
37
 
 
38
                trx_start_low(trx, ULINT_UNDEFINED);
 
39
        }
 
40
}
 
41
 
 
42
/*****************************************************************
 
43
Resets the new record lock info in a transaction struct. */
 
44
UNIV_INLINE
 
45
void
 
46
trx_reset_new_rec_lock_info(
 
47
/*========================*/
 
48
        trx_t*  trx)    /* in: transaction struct */
 
49
{
 
50
        trx->new_rec_locks[0] = NULL;
 
51
        trx->new_rec_locks[1] = NULL;
 
52
}
 
53
 
 
54
/*****************************************************************
 
55
Registers that we have set a new record lock on an index. We only have space
 
56
to store 2 indexes! If this is called to store more than 2 indexes after
 
57
trx_reset_new_rec_lock_info(), then this function does nothing. */
 
58
UNIV_INLINE
 
59
void
 
60
trx_register_new_rec_lock(
 
61
/*======================*/
 
62
        trx_t*          trx,    /* in: transaction struct */
 
63
        dict_index_t*   index)  /* in: trx sets a new record lock on this
 
64
                                index */
 
65
{
 
66
        if (trx->new_rec_locks[0] == NULL) {
 
67
                trx->new_rec_locks[0] = index;
 
68
 
 
69
                return;
 
70
        }
 
71
 
 
72
        if (trx->new_rec_locks[0] == index) {
 
73
 
 
74
                return;
 
75
        }
 
76
 
 
77
        if (trx->new_rec_locks[1] != NULL) {
 
78
 
 
79
                return;
 
80
        }
 
81
 
 
82
        trx->new_rec_locks[1] = index;
 
83
}
 
84
 
 
85
/*****************************************************************
 
86
Checks if trx has set a new record lock on an index. */
 
87
UNIV_INLINE
 
88
ibool
 
89
trx_new_rec_locks_contain(
 
90
/*======================*/
 
91
                                /* out: TRUE if trx has set a new record lock
 
92
                                on index */
 
93
        trx_t*          trx,    /* in: transaction struct */
 
94
        dict_index_t*   index)  /* in: index */
 
95
{
 
96
        return(trx->new_rec_locks[0] == index
 
97
               || trx->new_rec_locks[1] == index);
 
98
}
 
99
 
 
100
/********************************************************************
 
101
Retrieves the error_info field from a trx. */
 
102
UNIV_INLINE
 
103
const dict_index_t*
 
104
trx_get_error_info(
 
105
/*===============*/
 
106
                                /* out: the error info */
 
107
        const trx_t*    trx)    /* in: trx object */
 
108
{
 
109
        return(trx->error_info);
 
110
}
 
111
 
 
112
/***********************************************************************
 
113
Retrieves transacion's id, represented as unsigned long long. */
 
114
UNIV_INLINE
 
115
ullint
 
116
trx_get_id(
 
117
/*=======*/
 
118
                                /* out: transaction's id */
 
119
        const trx_t*    trx)    /* in: transaction */
 
120
{
 
121
        return((ullint)ut_conv_dulint_to_longlong(trx->id));
 
122
}
 
123
 
 
124
/***********************************************************************
 
125
Retrieves transaction's que state in a human readable string. The string
 
126
should not be free()'d or modified. */
 
127
UNIV_INLINE
 
128
const char*
 
129
trx_get_que_state_str(
 
130
/*==================*/
 
131
                                /* out: string in the data segment */
 
132
        const trx_t*    trx)    /* in: transaction */
 
133
{
 
134
        /* be sure to adjust TRX_QUE_STATE_STR_MAX_LEN if you change this */
 
135
        switch (trx->que_state) {
 
136
        case TRX_QUE_RUNNING:
 
137
                return("RUNNING");
 
138
        case TRX_QUE_LOCK_WAIT:
 
139
                return("LOCK WAIT");
 
140
        case TRX_QUE_ROLLING_BACK:
 
141
                return("ROLLING BACK");
 
142
        case TRX_QUE_COMMITTING:
 
143
                return("COMMITTING");
 
144
        default:
 
145
                return("UNKNOWN");
 
146
        }
 
147
}
 
148
 
 
149
/**************************************************************************
 
150
Determine if a transaction is a dictionary operation. */
 
151
UNIV_INLINE
 
152
enum trx_dict_op
 
153
trx_get_dict_operation(
 
154
/*===================*/
 
155
                                /* out: dictionary operation mode */
 
156
        const trx_t*    trx)    /* in: transaction */
 
157
{
 
158
        enum trx_dict_op op = (enum trx_dict_op) trx->dict_operation;
 
159
 
 
160
#ifdef UNIV_DEBUG
 
161
        switch (op) {
 
162
        case TRX_DICT_OP_NONE:
 
163
        case TRX_DICT_OP_TABLE:
 
164
        case TRX_DICT_OP_INDEX:
 
165
                return(op);
 
166
        }
 
167
        ut_error;
 
168
#endif /* UNIV_DEBUG */
 
169
        return((enum trx_dict_op) UNIV_EXPECT(op, TRX_DICT_OP_NONE));
 
170
}
 
171
/**************************************************************************
 
172
Flag a transaction a dictionary operation. */
 
173
UNIV_INLINE
 
174
void
 
175
trx_set_dict_operation(
 
176
/*===================*/
 
177
        trx_t*                  trx,    /* in/out: transaction */
 
178
        enum trx_dict_op        op)     /* in: operation, not
 
179
                                        TRX_DICT_OP_NONE */
 
180
{
 
181
#ifdef UNIV_DEBUG
 
182
        enum trx_dict_op        old_op = trx_get_dict_operation(trx);
 
183
 
 
184
        switch (op) {
 
185
        case TRX_DICT_OP_NONE:
 
186
                ut_error;
 
187
                break;
 
188
        case TRX_DICT_OP_TABLE:
 
189
                switch (old_op) {
 
190
                case TRX_DICT_OP_NONE:
 
191
                case TRX_DICT_OP_INDEX:
 
192
                case TRX_DICT_OP_TABLE:
 
193
                        goto ok;
 
194
                }
 
195
                ut_error;
 
196
                break;
 
197
        case TRX_DICT_OP_INDEX:
 
198
                ut_ad(old_op == TRX_DICT_OP_NONE);
 
199
                break;
 
200
        }
 
201
ok:
 
202
#endif /* UNIV_DEBUG */
 
203
 
 
204
        trx->dict_operation = op;
 
205
}