~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/row/row0uins.c

  • Committer: Monty Taylor
  • Date: 2009-03-02 23:14:32 UTC
  • mto: This revision was merged to the branch mainline in revision 910.
  • Revision ID: mordred@inaugust.com-20090302231432-i35xehp7uzo6hjjw
Updated build system to use new version numbering. Just remember to run ./config/autorun.sh before running make distcheck for release and all should be peachy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1997, 2010, Innobase Oy. All Rights Reserved.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify it under
6
 
the terms of the GNU General Public License as published by the Free Software
7
 
Foundation; version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful, but WITHOUT
10
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
 
 
13
 
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file row/row0uins.c
 
1
/******************************************************
21
2
Fresh insert undo
22
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
23
6
Created 2/25/1997 Heikki Tuuri
24
7
*******************************************************/
25
8
 
46
29
#include "ibuf0ibuf.h"
47
30
#include "log0log.h"
48
31
 
49
 
/*************************************************************************
50
 
IMPORTANT NOTE: Any operation that generates redo MUST check that there
51
 
is enough space in the redo log before for that operation. This is
52
 
done by calling log_free_check(). The reason for checking the
53
 
availability of the redo log space before the start of the operation is
54
 
that we MUST not hold any synchonization objects when performing the
55
 
check.
56
 
If you make a change in this module make sure that no codepath is
57
 
introduced where a call to log_free_check() is bypassed. */
58
 
 
59
 
/*************************************************************************
60
 
IMPORTANT NOTE: Any operation that generates redo MUST check that there
61
 
is enough space in the redo log before for that operation. This is
62
 
done by calling log_free_check(). The reason for checking the
63
 
availability of the redo log space before the start of the operation is
64
 
that we MUST not hold any synchonization objects when performing the
65
 
check.
66
 
If you make a change in this module make sure that no codepath is
67
 
introduced where a call to log_free_check() is bypassed. */
68
 
 
69
 
/***************************************************************//**
 
32
/*******************************************************************
70
33
Removes a clustered index record. The pcur in node was positioned on the
71
 
record, now it is detached.
72
 
@return DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
 
34
record, now it is detached. */
73
35
static
74
36
ulint
75
37
row_undo_ins_remove_clust_rec(
76
38
/*==========================*/
77
 
        undo_node_t*    node)   /*!< in: undo node */
 
39
                                /* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
 
40
        undo_node_t*    node)   /* in: undo node */
78
41
{
79
42
        btr_cur_t*      btr_cur;
80
43
        ibool           success;
88
51
                                            &mtr);
89
52
        ut_a(success);
90
53
 
91
 
        if (node->table->id == DICT_INDEXES_ID) {
 
54
        if (ut_dulint_cmp(node->table->id, DICT_INDEXES_ID) == 0) {
92
55
                ut_ad(node->trx->dict_operation_lock_mode == RW_X_LATCH);
93
56
 
94
57
                /* Drop the index tree associated with the row in
152
115
        return(err);
153
116
}
154
117
 
155
 
/***************************************************************//**
156
 
Removes a secondary index entry if found.
157
 
@return DB_SUCCESS, DB_FAIL, or DB_OUT_OF_FILE_SPACE */
 
118
/*******************************************************************
 
119
Removes a secondary index entry if found. */
158
120
static
159
121
ulint
160
122
row_undo_ins_remove_sec_low(
161
123
/*========================*/
162
 
        ulint           mode,   /*!< in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
 
124
                                /* out: DB_SUCCESS, DB_FAIL, or
 
125
                                DB_OUT_OF_FILE_SPACE */
 
126
        ulint           mode,   /* in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
163
127
                                depending on whether we wish optimistic or
164
128
                                pessimistic descent down the index tree */
165
 
        dict_index_t*   index,  /*!< in: index */
166
 
        dtuple_t*       entry)  /*!< in: index entry to remove */
 
129
        dict_index_t*   index,  /* in: index */
 
130
        dtuple_t*       entry)  /* in: index entry to remove */
167
131
{
168
 
        btr_pcur_t              pcur;
169
 
        btr_cur_t*              btr_cur;
170
 
        ulint                   err;
171
 
        mtr_t                   mtr;
172
 
        enum row_search_result  search_result;
 
132
        btr_pcur_t      pcur;
 
133
        btr_cur_t*      btr_cur;
 
134
        ibool           found;
 
135
        ibool           success;
 
136
        ulint           err;
 
137
        mtr_t           mtr;
173
138
 
 
139
        log_free_check();
174
140
        mtr_start(&mtr);
175
141
 
 
142
        found = row_search_index_entry(index, entry, mode, &pcur, &mtr);
 
143
 
176
144
        btr_cur = btr_pcur_get_btr_cur(&pcur);
177
145
 
178
 
        ut_ad(mode == BTR_MODIFY_TREE || mode == BTR_MODIFY_LEAF);
179
 
 
180
 
        search_result = row_search_index_entry(index, entry, mode,
181
 
                                               &pcur, &mtr);
182
 
 
183
 
        switch (search_result) {
184
 
        case ROW_NOT_FOUND:
185
 
                err = DB_SUCCESS;
186
 
                goto func_exit;
187
 
        case ROW_FOUND:
188
 
                break;
189
 
        case ROW_BUFFERED:
190
 
        case ROW_NOT_DELETED_REF:
191
 
                /* These are invalid outcomes, because the mode passed
192
 
                to row_search_index_entry() did not include any of the
193
 
                flags BTR_INSERT, BTR_DELETE, or BTR_DELETE_MARK. */
194
 
                ut_error;
 
146
        if (!found) {
 
147
                /* Not found */
 
148
 
 
149
                btr_pcur_close(&pcur);
 
150
                mtr_commit(&mtr);
 
151
 
 
152
                return(DB_SUCCESS);
195
153
        }
196
154
 
197
155
        if (mode == BTR_MODIFY_LEAF) {
198
 
                err = btr_cur_optimistic_delete(btr_cur, &mtr)
199
 
                        ? DB_SUCCESS : DB_FAIL;
 
156
                success = btr_cur_optimistic_delete(btr_cur, &mtr);
 
157
 
 
158
                if (success) {
 
159
                        err = DB_SUCCESS;
 
160
                } else {
 
161
                        err = DB_FAIL;
 
162
                }
200
163
        } else {
201
164
                ut_ad(mode == BTR_MODIFY_TREE);
202
165
 
209
172
                btr_cur_pessimistic_delete(&err, FALSE, btr_cur,
210
173
                                           RB_NORMAL, &mtr);
211
174
        }
212
 
func_exit:
 
175
 
213
176
        btr_pcur_close(&pcur);
214
177
        mtr_commit(&mtr);
215
178
 
216
179
        return(err);
217
180
}
218
181
 
219
 
/***************************************************************//**
 
182
/*******************************************************************
220
183
Removes a secondary index entry from the index if found. Tries first
221
 
optimistic, then pessimistic descent down the tree.
222
 
@return DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
 
184
optimistic, then pessimistic descent down the tree. */
223
185
static
224
186
ulint
225
187
row_undo_ins_remove_sec(
226
188
/*====================*/
227
 
        dict_index_t*   index,  /*!< in: index */
228
 
        dtuple_t*       entry)  /*!< in: index entry to insert */
 
189
                                /* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
 
190
        dict_index_t*   index,  /* in: index */
 
191
        dtuple_t*       entry)  /* in: index entry to insert */
229
192
{
230
193
        ulint   err;
231
194
        ulint   n_tries = 0;
259
222
        return(err);
260
223
}
261
224
 
262
 
/***********************************************************//**
 
225
/***************************************************************
263
226
Parses the row reference and other info in a fresh insert undo record. */
264
227
static
265
228
void
266
229
row_undo_ins_parse_undo_rec(
267
230
/*========================*/
268
 
        undo_node_t*    node)   /*!< in/out: row undo node */
 
231
        undo_node_t*    node)   /* in/out: row undo node */
269
232
{
270
233
        dict_index_t*   clust_index;
271
234
        byte*           ptr;
272
 
        undo_no_t       undo_no;
273
 
        table_id_t      table_id;
 
235
        dulint          undo_no;
 
236
        dulint          table_id;
274
237
        ulint           type;
275
238
        ulint           dummy;
276
239
        ibool           dummy_extern;
308
271
        }
309
272
}
310
273
 
311
 
/***********************************************************//**
 
274
/***************************************************************
312
275
Undoes a fresh insert of a row to a table. A fresh insert means that
313
276
the same clustered index unique key did not have any record, even delete
314
 
marked, at the time of the insert.  InnoDB is eager in a rollback:
315
 
if it figures out that an index record will be removed in the purge
316
 
anyway, it will remove it in the rollback.
317
 
@return DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
 
277
marked, at the time of the insert. */
318
278
UNIV_INTERN
319
279
ulint
320
280
row_undo_ins(
321
281
/*=========*/
322
 
        undo_node_t*    node)   /*!< in: row undo node */
 
282
                                /* out: DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
 
283
        undo_node_t*    node)   /* in: row undo node */
323
284
{
324
285
        ut_ad(node);
325
286
        ut_ad(node->state == UNDO_NODE_INSERT);
356
317
                        transactions. */
357
318
                        ut_a(trx_is_recv(node->trx));
358
319
                } else {
359
 
                        log_free_check();
360
320
                        err = row_undo_ins_remove_sec(node->index, entry);
361
321
 
362
322
                        if (err != DB_SUCCESS) {
368
328
                node->index = dict_table_get_next_index(node->index);
369
329
        }
370
330
 
371
 
        log_free_check();
372
331
        return(row_undo_ins_remove_clust_rec(node));
373
332
}