| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2008, 2026, Oracle and/or its affiliates. |
| 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, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file api/api0misc.cc |
| 29 |
InnoDB Native API |
| 30 |
|
| 31 |
2008-08-01 Created by Sunny Bains |
| 32 |
3/20/2011 Jimmy Yang extracted from Embedded InnoDB |
| 33 |
*******************************************************/ |
| 34 |
|
| 35 |
#include "api0misc.h" |
| 36 |
#include "dict0dict.h" |
| 37 |
#include "dict0mem.h" |
| 38 |
#include "ha_prototypes.h" |
| 39 |
#include "lock0lock.h" |
| 40 |
|
| 41 |
#include "pars0pars.h" |
| 42 |
#include "row0sel.h" |
| 43 |
#include "srv0srv.h" |
| 44 |
#include "trx0roll.h" |
| 45 |
|
| 46 |
/** Sets a lock on a table. |
| 47 |
@return error code or DB_SUCCESS */ |
| 48 |
dberr_t ib_trx_lock_table_with_retry( |
| 49 |
trx_t *trx, /*!< in/out: transaction */ |
| 50 |
dict_table_t *table, /*!< in: table to lock */ |
| 51 |
enum lock_mode mode) /*!< in: LOCK_X or LOCK_S */ |
| 52 |
{ |
| 53 |
trx->op_info = "setting table lock"; |
| 54 |
|
| 55 |
return (lock_table_for_trx(table, trx, mode)); |
| 56 |
} |
| 57 |
/** Handles user errors and lock waits detected by the database engine. |
| 58 |
@param[out] new_err possible new error encountered in lock wait, or if no |
| 59 |
new error, the value of trx->error_state at the entry of this function |
| 60 |
@param[in] trx transaction |
| 61 |
@param[in] thr query thread |
| 62 |
@param[in] savept savepoint or NULL |
| 63 |
@param[in] is_sdi true if table is SDI |
| 64 |
@return true if it was a lock wait and we should continue running |
| 65 |
the query thread. */ |
| 66 |
bool ib_handle_errors(dberr_t *new_err, trx_t *trx, que_thr_t *thr, |
| 67 |
trx_savept_t *savept, bool is_sdi) { |
| 68 |
dberr_t err; |
| 69 |
handle_new_error: |
| 70 |
err = trx->error_state; |
| 71 |
|
| 72 |
ut_a(err != DB_SUCCESS); |
| 73 |
|
| 74 |
trx->error_state = DB_SUCCESS; |
| 75 |
|
| 76 |
switch (err) { |
| 77 |
case DB_LOCK_WAIT_TIMEOUT: |
| 78 |
if (!is_sdi) { |
| 79 |
trx_rollback_for_mysql(trx); |
| 80 |
} |
| 81 |
break; |
| 82 |
[[fallthrough]]; |
| 83 |
case DB_DUPLICATE_KEY: |
| 84 |
case DB_FOREIGN_DUPLICATE_KEY: |
| 85 |
case DB_TOO_BIG_RECORD: |
| 86 |
case DB_ROW_IS_REFERENCED: |
| 87 |
case DB_NO_REFERENCED_ROW: |
| 88 |
case DB_CANNOT_ADD_CONSTRAINT: |
| 89 |
case DB_TOO_MANY_CONCURRENT_TRXS: |
| 90 |
case DB_OUT_OF_FILE_SPACE: |
| 91 |
if (savept) { |
| 92 |
/* Roll back the latest, possibly incomplete |
| 93 |
insertion or update */ |
| 94 |
|
| 95 |
trx_rollback_to_savepoint(trx, savept); |
| 96 |
} |
| 97 |
break; |
| 98 |
case DB_LOCK_WAIT: |
| 99 |
lock_wait_suspend_thread(thr); |
| 100 |
|
| 101 |
if (trx->error_state != DB_SUCCESS) { |
| 102 |
que_thr_stop_for_mysql(thr); |
| 103 |
|
| 104 |
goto handle_new_error; |
| 105 |
} |
| 106 |
|
| 107 |
*new_err = err; |
| 108 |
|
| 109 |
return true; /* Operation needs to be retried. */ |
| 110 |
|
| 111 |
case DB_DEADLOCK: |
| 112 |
case DB_LOCK_TABLE_FULL: |
| 113 |
/* Roll back the whole transaction; this resolution was added |
| 114 |
to version 3.23.43 */ |
| 115 |
ut_ad(!is_sdi); |
| 116 |
trx_rollback_for_mysql(trx); |
| 117 |
break; |
| 118 |
|
| 119 |
case DB_MUST_GET_MORE_FILE_SPACE: |
| 120 |
|
| 121 |
ut_error; |
| 122 |
|
| 123 |
case DB_CORRUPTION: |
| 124 |
case DB_FOREIGN_EXCEED_MAX_CASCADE: |
| 125 |
break; |
| 126 |
default: |
| 127 |
ut_error; |
| 128 |
} |
| 129 |
|
| 130 |
if (trx->error_state != DB_SUCCESS) { |
| 131 |
*new_err = trx->error_state; |
| 132 |
} else { |
| 133 |
*new_err = err; |
| 134 |
} |
| 135 |
|
| 136 |
trx->error_state = DB_SUCCESS; |
| 137 |
|
| 138 |
return false; |
| 139 |
} |