MySQL 8.0.31
Source Code Documentation
lob0zip.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2016, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26#ifndef lob0zip_h
27#define lob0zip_h
28
29#include "lob0ins.h"
30
31namespace lob {
32
33/** Insert or write the compressed BLOB as a single zlib stream. */
34class zInserter : private BaseInserter {
35 public:
36 /** Constructor.
37 @param[in] ctx blob operation context. */
39
40 /** Destructor. */
41 ~zInserter();
42
43 /** Prepare to write a compressed BLOB. Setup the zlib
44 compression stream.
45 @return DB_SUCCESS on success, error code on failure. */
47
48 /** Write all the BLOBs of the clustered index record.
49 @return DB_SUCCESS on success, error code on failure. */
50 dberr_t write();
51
52 /** Write one blob field data.
53 @param[in] blob_j the blob field number
54 @return DB_SUCCESS on success, error code on failure. */
55 dberr_t write_one_blob(size_t blob_j);
56
57 /** Cleanup after completing the write of compressed BLOB.
58 @param[in] validate if true, validate all the
59 lob references. if false,
60 skip this validation.
61 @return DB_SUCCESS on success, error code on failure. */
62 dberr_t finish(bool validate = true) {
63 int ret = deflateEnd(&m_stream);
64 ut_ad(ret == Z_OK);
66
67 if (ret != Z_OK) {
68 m_err = DB_FAIL;
69 }
70 return (m_err);
71 }
72
73 /** Write the page type of the BLOB page and also generate the
74 redo log record.
75 @param[in] blob_page the BLOB page
76 @param[in] nth_blob_page the count of BLOB page from
77 the beginning of the BLOB. */
78 void log_page_type(page_t *blob_page, ulint nth_blob_page) {
79 page_type_t page_type;
80
81 if (is_index_sdi()) {
82 page_type = FIL_PAGE_SDI_ZBLOB;
83 } else if (nth_blob_page == 0) {
84 page_type = FIL_PAGE_TYPE_ZBLOB;
85 } else {
86 page_type = FIL_PAGE_TYPE_ZBLOB2;
87 }
88
89 mlog_write_ulint(blob_page + FIL_PAGE_TYPE, page_type, MLOG_2BYTES,
90 &m_blob_mtr);
91 }
92
93 /** Calculate the total number of pages needed to store
94 the given blobs */
96 const page_size_t page_size = m_ctx->page_size();
97
98 /* Space available in compressed page to carry blob data */
99 const ulint payload_size_zip = page_size.physical() - FIL_PAGE_DATA;
100
101 const big_rec_t *vec = m_ctx->get_big_rec_vec();
102
103 ulint total_blob_pages = 0;
104 for (ulint i = 0; i < vec->n_fields; i++) {
105 total_blob_pages +=
106 static_cast<ulint>(
107 deflateBound(&m_stream, static_cast<uLong>(vec->fields[i].len)) +
108 payload_size_zip - 1) /
109 payload_size_zip;
110 }
111
112 return (total_blob_pages);
113 }
114
115 /** Write contents into a single BLOB page.
116 @return code as returned by zlib. */
118
119 /** Commit the BLOB mtr. */
121
122 /** Write one blob page. This function will be repeatedly called
123 with an increasing nth_blob_page to completely write a BLOB.
124 @param[in] field the big record field.
125 @param[in] nth_blob_page count of the BLOB page (starting from 1).
126 @return code as returned by the zlib. */
127 int write_single_blob_page(big_rec_field_t &field, ulint nth_blob_page);
128
129 /** Write first blob page.
130 @param[in] field the big record field.
131 @return code as returned by the zlib. */
133
134 /** Verify that all pointers to externally stored columns in the record
135 is be valid. If validation fails, this function doesn't return.
136 @return true if valid. */
137 bool validate_blobrefs() const {
138 const ulint *offsets = m_ctx->get_offsets();
139
140 for (ulint i = 0; i < rec_offs_n_fields(offsets); i++) {
141 if (!rec_offs_nth_extern(m_ctx->index(), offsets, i)) {
142 continue;
143 }
144
145 byte *field_ref =
146 btr_rec_get_field_ref(m_ctx->index(), m_ctx->rec(), offsets, i);
147
148 ref_t blobref(field_ref);
149
150 /* The pointer must not be zero if the operation
151 succeeded. */
152 ut_a(!blobref.is_null() || m_err != DB_SUCCESS);
153
154 /* The column must not be disowned by this record. */
155 ut_a(blobref.is_owner());
156 }
157 return (true);
158 }
159
160 /** For the given blob field, update its length in the blob reference
161 which is available in the clustered index record.
162 @param[in] field the concerned blob field. */
164
165 /** Make the current page as next page of previous page. In other
166 words, make the page m_cur_blob_page_no as the next page
167 (FIL_PAGE_NEXT) of page m_prev_page_no.
168 @return DB_SUCCESS on success, or error code on failure. */
170
171 /** Write one small blob field data. Refer to ref_t to determine
172 the definition of small blob.
173 @param[in] blob_j the blob field number
174 @return DB_SUCCESS on success, error code on failure. */
175 dberr_t write_one_small_blob(size_t blob_j);
176
177 private:
178 /** Add the BLOB page information to the directory
179 @param[in] page_info BLOB page information. */
180 void add_to_blob_dir(const blob_page_info_t &page_info) {
181 m_dir.add(page_info);
182 }
183
185 z_stream m_stream;
186
187 /** The BLOB directory information. */
189};
190
192 if (m_heap != nullptr) {
194 }
195}
196
197} // namespace lob
198
199#endif // lob0zip_h
#define Z_OK
Definition: azlib.h:163
rec_t * rec() const
Get the clustered index record pointer.
Definition: lob0lob.h:824
ulint * get_offsets() const
Get the record offsets array.
Definition: lob0lob.h:1027
dict_index_t * index() const
Get the index object.
Definition: lob0lob.h:973
const page_size_t page_size() const
Obtain the page size of the underlying table.
Definition: lob0lob.h:993
Insert or write the compressed BLOB as a single zlib stream.
Definition: lob0zip.h:34
z_stream m_stream
Definition: lob0zip.h:185
dberr_t write_one_blob(size_t blob_j)
Write one blob field data.
Definition: zlob0ins.cc:131
blob_dir_t m_dir
The BLOB directory information.
Definition: lob0zip.h:188
bool validate_blobrefs() const
Verify that all pointers to externally stored columns in the record is be valid.
Definition: lob0zip.h:137
void add_to_blob_dir(const blob_page_info_t &page_info)
Add the BLOB page information to the directory.
Definition: lob0zip.h:180
int write_single_blob_page(big_rec_field_t &field, ulint nth_blob_page)
Write one blob page.
Definition: zlob0ins.cc:232
~zInserter()
Destructor.
Definition: lob0zip.h:191
dberr_t write_one_small_blob(size_t blob_j)
Write one small blob field data.
Definition: zlob0ins.cc:107
int write_into_single_page()
Write contents into a single BLOB page.
Definition: zlob0ins.cc:162
void log_page_type(page_t *blob_page, ulint nth_blob_page)
Write the page type of the BLOB page and also generate the redo log record.
Definition: lob0zip.h:78
ulint calc_total_pages()
Calculate the total number of pages needed to store the given blobs.
Definition: lob0zip.h:95
dberr_t finish(bool validate=true)
Cleanup after completing the write of compressed BLOB.
Definition: lob0zip.h:62
zInserter(InsertContext *ctx)
Constructor.
Definition: lob0zip.h:38
dberr_t prepare()
Prepare to write a compressed BLOB.
Definition: zlob0ins.cc:268
void update_length_in_blobref(big_rec_field_t &field)
For the given blob field, update its length in the blob reference which is available in the clustered...
Definition: zlob0ins.cc:86
int write_first_page(big_rec_field_t &field)
Write first blob page.
Definition: zlob0ins.cc:32
dberr_t write()
Write all the BLOBs of the clustered index record.
Definition: zlob0ins.cc:292
mem_heap_t * m_heap
Definition: lob0zip.h:184
void commit_blob_mtr()
Commit the BLOB mtr.
Definition: lob0zip.h:120
dberr_t set_page_next()
Make the current page as next page of previous page.
Definition: zlob0ins.cc:308
Page size descriptor.
Definition: page0size.h:49
size_t physical() const
Retrieve the physical page size (on-disk).
Definition: page0size.h:120
dberr_t
Definition: db0err.h:38
@ DB_FAIL
Definition: db0err.h:207
@ DB_SUCCESS
Definition: db0err.h:42
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
constexpr page_type_t FIL_PAGE_TYPE_ZBLOB
First compressed BLOB page.
Definition: fil0fil.h:1231
uint16_t page_type_t
Definition: fil0fil.h:1184
constexpr page_type_t FIL_PAGE_TYPE_ZBLOB2
Subsequent compressed BLOB page.
Definition: fil0fil.h:1234
constexpr page_type_t FIL_PAGE_SDI_ZBLOB
Compressed SDI BLOB page.
Definition: fil0fil.h:1256
constexpr uint32_t FIL_PAGE_TYPE
file page type: FIL_PAGE_INDEX,..., 2 bytes.
Definition: fil0types.h:75
constexpr uint32_t FIL_PAGE_DATA
start of the data on the page
Definition: fil0types.h:110
static void mem_heap_free(mem_heap_t *heap)
Frees the space occupied by a memory heap.
void mlog_write_ulint(byte *ptr, ulint val, mlog_id_t type, mtr_t *mtr)
Writes 1, 2 or 4 bytes to a file page.
Definition: mtr0log.cc:255
#define mtr_commit(m)
Commit a mini-transaction.
Definition: mtr0mtr.h:58
@ MLOG_2BYTES
2 bytes ...
Definition: mtr0types.h:72
Provides the large objects (LOB) module.
Definition: lob0del.h:31
static const byte * btr_rec_get_field_ref(const dict_index_t *index, const byte *rec, const ulint *offsets, ulint n)
Gets a pointer to the externally stored part of a field.
Definition: lob0lob.h:627
static mysql_service_status_t validate(reference_caching_channel channel) noexcept
Definition: component.cc:66
byte page_t
Type of the index page.
Definition: page0types.h:151
static ulint rec_offs_n_fields(const ulint *offsets)
The following function returns the number of fields in a record.
Definition: rec.h:459
ulint rec_offs_nth_extern(const dict_index_t *index, const ulint *offsets, ulint n)
Returns nonzero if the extern bit is set in nth field of rec.
Definition: rem0wrec.cc:91
A slot for a field in a big rec vector.
Definition: data0data.h:786
ulint len
stored data length, in bytes
Definition: data0data.h:801
Storage format for overflow data in a big record, that is, a clustered index record which needs exter...
Definition: data0data.h:829
big_rec_field_t * fields
stored fields
Definition: data0data.h:834
ulint n_fields
number of stored fields
Definition: data0data.h:833
This struct can hold BLOB routines/functions, and state variables, that are common for compressed and...
Definition: lob0ins.h:35
mtr_t m_blob_mtr
The mini trx used to write into blob pages.
Definition: lob0ins.h:86
bool is_index_sdi()
Check if the index is SDI index.
Definition: lob0ins.h:72
InsertContext * m_ctx
The BLOB operation context.
Definition: lob0ins.h:80
dberr_t m_err
Success or failure status of the operation so far.
Definition: lob0ins.h:83
The context for a LOB operation.
Definition: lob0lob.h:1099
const big_rec_t * get_big_rec_vec()
Get the vector containing fields to be stored externally.
Definition: lob0lob.h:1108
The in-memory blob directory.
Definition: lob0lob.h:1174
dberr_t add(const blob_page_info_t &page)
Append the given blob page information.
Definition: lob0lob.h:1188
Information about data stored in one BLOB page.
Definition: lob0lob.h:1122
The struct 'lob::ref_t' represents an external field reference.
Definition: lob0lob.h:197
bool is_null() const
Check if the field reference is made of zeroes.
Definition: lob0lob.h:278
bool is_owner() const
Check if the current row is the owner of the blob.
Definition: lob0lob.h:367
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:299
unsigned long int ulint
Definition: univ.i:407
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:68
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:56