| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2015, 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 |
#ifndef lob0del_h |
| 28 |
#define lob0del_h |
| 29 |
|
| 30 |
#include "lob0lob.h" |
| 31 |
|
| 32 |
namespace lob { |
| 33 |
|
| 34 |
/* Delete a LOB */ |
| 35 |
class Deleter { |
| 36 |
public: |
| 37 |
/** Constructor */ |
| 38 |
Deleter(DeleteContext &ctx) : m_ctx(ctx) { |
| 39 |
ut_ad(ctx.index()->is_clustered()); |
| 40 |
ut_ad(mtr_memo_contains_flagged(ctx.get_mtr(), |
| 41 |
dict_index_get_lock(ctx.index()), |
| 42 |
MTR_MEMO_X_LOCK | MTR_MEMO_SX_LOCK) || |
| 43 |
ctx.table()->is_intrinsic()); |
| 44 |
ut_ad(mtr_is_page_fix(ctx.get_mtr(), ctx.m_blobref.page_align(), |
| 45 |
MTR_MEMO_PAGE_X_FIX, ctx.table())); |
| 46 |
ut_ad(ctx.rec_offs_validate()); |
| 47 |
ut_ad(ctx.validate_blobref()); |
| 48 |
} |
| 49 |
|
| 50 |
/** Free the LOB object. |
| 51 |
@return DB_SUCCESS on success. */ |
| 52 |
dberr_t destroy(); |
| 53 |
|
| 54 |
/** Free the first page of the BLOB and update the BLOB reference |
| 55 |
in the clustered index. |
| 56 |
@return DB_SUCCESS on pass, error code on failure. */ |
| 57 |
dberr_t free_first_page(); |
| 58 |
|
| 59 |
private: |
| 60 |
/** Obtain an x-latch on the clustered index record page.*/ |
| 61 |
void x_latch_rec_page(); |
| 62 |
|
| 63 |
/** Validate the page type of the given page frame. |
| 64 |
@param[in] page the page frame. |
| 65 |
@return true if valid, false otherwise. */ |
| 66 |
bool validate_page_type(const page_t *page) const { |
| 67 |
return (m_ctx.is_compressed() ? validate_zblob_page_type(page) |
| 68 |
: validate_blob_page_type(page)); |
| 69 |
} |
| 70 |
|
| 71 |
/** Check if the page type is set correctly. |
| 72 |
@param[in] page the page frame. |
| 73 |
@return true if page type is correct. */ |
| 74 |
bool validate_zblob_page_type(const page_t *page) const { |
| 75 |
const page_type_t pt = fil_page_get_type(page); |
| 76 |
switch (pt) { |
| 77 |
case FIL_PAGE_TYPE_ZBLOB: |
| 78 |
case FIL_PAGE_TYPE_ZBLOB2: |
| 79 |
case FIL_PAGE_SDI_ZBLOB: |
| 80 |
break; |
| 81 |
default: |
| 82 |
ut_error; |
| 83 |
} |
| 84 |
return (true); |
| 85 |
} |
| 86 |
|
| 87 |
/** Check if the page type is set correctly. |
| 88 |
@param[in] page the page frame. |
| 89 |
@return true if page type is correct. */ |
| 90 |
bool validate_blob_page_type(const page_t *page) const { |
| 91 |
const page_type_t type = fil_page_get_type(page); |
| 92 |
|
| 93 |
switch (type) { |
| 94 |
case FIL_PAGE_TYPE_BLOB: |
| 95 |
case FIL_PAGE_SDI_BLOB: |
| 96 |
break; |
| 97 |
default: |
| 98 |
#ifndef UNIV_DEBUG /* Improve debug test coverage */ |
| 99 |
if (!m_ctx.has_atomic_blobs()) { |
| 100 |
/* Old versions of InnoDB did not initialize |
| 101 |
FIL_PAGE_TYPE on BLOB pages. Do not print |
| 102 |
anything about the type mismatch when reading |
| 103 |
a BLOB page that may be from old versions. */ |
| 104 |
return (true); |
| 105 |
} |
| 106 |
#endif /* !UNIV_DEBUG */ |
| 107 |
ut_error; |
| 108 |
} |
| 109 |
return (true); |
| 110 |
} |
| 111 |
|
| 112 |
/** Check if the BLOB can be freed. If the clustered index record |
| 113 |
is not the owner of the LOB, then it cannot be freed. Also, during |
| 114 |
rollback, if inherited flag is set, then LOB will not be freed. |
| 115 |
@return true if the BLOB can be freed, false otherwise. */ |
| 116 |
bool can_free() const; |
| 117 |
|
| 118 |
DeleteContext &m_ctx; |
| 119 |
mtr_t m_mtr; |
| 120 |
}; |
| 121 |
|
| 122 |
} // namespace lob |
| 123 |
|
| 124 |
#endif // lob0del_h |