MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
api0misc.cc
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 2008, 2012, Oracle and/or its affiliates. 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.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
27 #include <errno.h>
28 
29 #ifdef HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif /* HAVE_UNISTD_H */
32 
33 #include "api0misc.h"
34 #include "trx0roll.h"
35 #include "srv0srv.h"
36 #include "dict0mem.h"
37 #include "dict0dict.h"
38 #include "pars0pars.h"
39 #include "row0sel.h"
40 #include "lock0lock.h"
41 #include "ha_prototypes.h"
42 #include <m_ctype.h>
43 #include <mysys_err.h>
44 #include <mysql/plugin.h>
45 
46 /*********************************************************************/
49 UNIV_INTERN
50 dberr_t
52 /*=========================*/
53  trx_t* trx,
55  enum lock_mode mode)
56 {
57  que_thr_t* thr;
58  dberr_t err;
60  sel_node_t* node;
61 
62  heap = mem_heap_create(512);
63 
64  trx->op_info = "setting table lock";
65 
66  node = sel_node_create(heap);
67  thr = pars_complete_graph_for_exec(node, trx, heap);
68  thr->graph->state = QUE_FORK_ACTIVE;
69 
70  /* We use the select query graph as the dummy graph needed
71  in the lock module call */
72 
73  thr = que_fork_get_first_thr(static_cast<que_fork_t*>(
74  que_node_get_parent(thr)));
76 
77 run_again:
78  thr->run_node = thr;
79  thr->prev_node = thr->common.parent;
80 
81  err = lock_table(0, table, mode, thr);
82 
83  trx->error_state = err;
84 
85  if (UNIV_LIKELY(err == DB_SUCCESS)) {
87  } else {
89 
90  if (err != DB_QUE_THR_SUSPENDED) {
91  ibool was_lock_wait;
92 
93  was_lock_wait = ib_handle_errors(&err, trx, thr, NULL);
94 
95  if (was_lock_wait) {
96  goto run_again;
97  }
98  } else {
99  que_thr_t* run_thr;
100  que_node_t* parent;
101 
102  parent = que_node_get_parent(thr);
103  run_thr = que_fork_start_command(
104  static_cast<que_fork_t*>(parent));
105 
106  ut_a(run_thr == thr);
107 
108  /* There was a lock wait but the thread was not
109  in a ready to run or running state. */
110  trx->error_state = DB_LOCK_WAIT;
111 
112  goto run_again;
113  }
114  }
115 
116  que_graph_free(thr->graph);
117  trx->op_info = "";
118 
119  return(err);
120 }
121 /****************************************************************/
125 UNIV_INTERN
126 ibool
128 /*=============*/
129  dberr_t* new_err,
133  trx_t* trx,
134  que_thr_t* thr,
135  trx_savept_t* savept)
136 {
137  dberr_t err;
138 handle_new_error:
139  err = trx->error_state;
140 
141  ut_a(err != DB_SUCCESS);
142 
143  trx->error_state = DB_SUCCESS;
144 
145  switch (err) {
148  break;
149  /* fall through */
150  case DB_DUPLICATE_KEY:
152  case DB_TOO_BIG_RECORD:
157  case DB_OUT_OF_FILE_SPACE:
158  if (savept) {
159  /* Roll back the latest, possibly incomplete
160  insertion or update */
161 
162  trx_rollback_to_savepoint(trx, savept);
163  }
164  break;
165  case DB_LOCK_WAIT:
167 
168  if (trx->error_state != DB_SUCCESS) {
170 
171  goto handle_new_error;
172  }
173 
174  *new_err = err;
175 
176  return(TRUE); /* Operation needs to be retried. */
177 
178  case DB_DEADLOCK:
179  case DB_LOCK_TABLE_FULL:
180  /* Roll back the whole transaction; this resolution was added
181  to version 3.23.43 */
182 
184  break;
185 
187 
188  exit(1);
189 
190  case DB_CORRUPTION:
192  break;
193  default:
194  ut_error;
195  }
196 
197  if (trx->error_state != DB_SUCCESS) {
198  *new_err = trx->error_state;
199  } else {
200  *new_err = err;
201  }
202 
203  trx->error_state = DB_SUCCESS;
204 
205  return(FALSE);
206 }