| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2017, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU General Public License, version 2.0, |
| 7 |
as published by the 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, |
| 18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
GNU General Public License, version 2.0, for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License |
| 23 |
along with this program; if not, write to the Free Software |
| 24 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
#include "lob0undo.h" |
| 29 |
#include "dict0dict.h" |
| 30 |
#include "sql-common/json_binary.h" |
| 31 |
|
| 32 |
namespace lob { |
| 33 |
|
| 34 |
/** Apply the undo information to the given LOB. |
| 35 |
@param[in] index clustered index containing the LOB. |
| 36 |
@param[in] lob_mem LOB on which the given undo will be |
| 37 |
applied. |
| 38 |
@param[in] len length of LOB. |
| 39 |
@param[in] lob_version lob version number |
| 40 |
@param[in] first_page_no the first page number of lob */ |
| 41 |
void undo_data_t::apply(dict_index_t *index, byte *lob_mem, size_t len, |
| 42 |
size_t lob_version, page_no_t first_page_no) { |
| 43 |
DBUG_TRACE; |
| 44 |
|
| 45 |
DBUG_LOG("undo_data_t", "lob_version=" << lob_version); |
| 46 |
|
| 47 |
#ifdef UNIV_DEBUG |
| 48 |
if (!dict_table_has_atomic_blobs(index->table)) { |
| 49 |
/* For compact and redundant row format, remove the local |
| 50 |
prefix length from the offset. */ |
| 51 |
|
| 52 |
ut_ad(m_offset >= DICT_ANTELOPE_MAX_INDEX_COL_LEN); |
| 53 |
} |
| 54 |
#endif /* UNIV_DEBUG */ |
| 55 |
|
| 56 |
/* Ensure that the undo log applied on the LOB is matching. */ |
| 57 |
if (first_page_no == m_page_no) { |
| 58 |
byte *ptr = lob_mem + m_offset; |
| 59 |
ut_ad((m_offset + m_length) <= len); |
| 60 |
memcpy(ptr, m_old_data, m_length); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
std::ostream &undo_data_t::print(std::ostream &out) const { |
| 65 |
out << "[undo_data_t: m_version=" << m_version << ", m_offset=" << m_offset |
| 66 |
<< ", m_length=" << m_length |
| 67 |
<< ", m_old_data=" << PrintBuffer(m_old_data, m_length) << "]"; |
| 68 |
return (out); |
| 69 |
} |
| 70 |
|
| 71 |
/** Copy the old data from the undo page into this object. |
| 72 |
@param[in] undo_ptr the pointer into the undo log record. |
| 73 |
@param[in] len length of the old data. |
| 74 |
@return pointer past the old data. */ |
| 75 |
const byte *undo_data_t::copy_old_data(const byte *undo_ptr, ulint len) { |
| 76 |
m_length = len; |
| 77 |
m_old_data = |
| 78 |
ut::new_arr_withkey<byte>(UT_NEW_THIS_FILE_PSI_KEY, ut::Count{m_length}); |
| 79 |
if (m_old_data == nullptr) { |
| 80 |
return (nullptr); |
| 81 |
} |
| 82 |
memcpy(m_old_data, undo_ptr, m_length); |
| 83 |
return (undo_ptr + m_length); |
| 84 |
} |
| 85 |
|
| 86 |
/** Free allocated memory for old data. */ |
| 87 |
void undo_data_t::destroy() { |
| 88 |
if (m_old_data != nullptr) { |
| 89 |
ut::delete_arr(m_old_data); |
| 90 |
m_old_data = nullptr; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
} /* namespace lob */ |