File: dict0sdi.h

package info (click to toggle)
mysql-8.0 8.0.44-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,272,892 kB
  • sloc: cpp: 4,685,345; ansic: 412,712; pascal: 108,395; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; python: 21,816; sh: 17,285; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,083; makefile: 1,793; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (158 lines) | stat: -rw-r--r-- 5,834 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*****************************************************************************

Copyright (c) 2017, 2025, Oracle and/or its affiliates.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License, version 2.0, as published by the
Free Software Foundation.

This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation.  The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

*****************************************************************************/

#ifndef DICT_SDI_H
#define DICT_SDI_H

#include <zconf.h>
#include <zlib.h>

/** Size of sdi_key_t::type */
constexpr const uint32_t SDI_TYPE_LEN = 4;

/** Size of sdi_key_t::id */
constexpr const uint32_t SDI_KEY_LEN = 8;

/** Compress SDI using zlib */
class Sdi_Compressor {
 public:
  Sdi_Compressor(uint32_t src_len, const void *sdi)
      : m_src_len(src_len), m_comp_len(), m_sdi(sdi), m_comp_sdi() {}

  ~Sdi_Compressor() { ut::free(m_comp_sdi); }

  /** Compress the SDI */
  inline void compress() {
    uLongf zlen = compressBound(static_cast<uLong>(m_src_len));
    auto src = reinterpret_cast<const Bytef *>(m_sdi);

    m_comp_sdi =
        static_cast<byte *>(ut::malloc_withkey(UT_NEW_THIS_FILE_PSI_KEY, zlen));
    ut_ad(m_comp_sdi != nullptr);

    switch (
        compress2(m_comp_sdi, &zlen, src, static_cast<uLong>(m_src_len), 6)) {
      case Z_BUF_ERROR:
        ib::fatal(UT_LOCATION_HERE, ER_IB_MSG_FAILED_SDI_Z_BUF_ERROR);
        break;

      case Z_MEM_ERROR:
        ib::fatal(UT_LOCATION_HERE, ER_IB_MSG_FAILED_SDI_Z_MEM_ERROR);
        break;

      case Z_STREAM_ERROR:
        ib::fatal(UT_LOCATION_HERE, ER_IB_MSG_SDI_Z_STREAM_ERROR);
        break;

      case Z_OK:
        m_comp_len = zlen;
        break;

      default:
        ib::fatal(UT_LOCATION_HERE, ER_IB_MSG_SDI_Z_UNKNOWN_ERROR);
        break;
    }
  }

  /** @return compressed SDI record */
  const byte *get_data() const { return (m_comp_sdi); }

  /** @return length of uncompressed SDI */
  uint32_t get_src_len() const { return (m_src_len); }

  /** @return length of compressed SDI */
  uint32_t get_comp_len() const { return (m_comp_len); }

 private:
  /** Length of uncompressed SDI */
  uint32_t m_src_len;
  /** Length of compressed SDI */
  uint32_t m_comp_len;
  /** Uncompressed SDI */
  const void *m_sdi;
  /** Compressed SDI */
  byte *m_comp_sdi;
};

/** Create SDI in a tablespace. This API should be used when
upgrading a tablespace with no SDI.
@param[in,out]  tablespace      tablespace object
@retval         false           success
@retval         true            failure */
bool dict_sdi_create(dd::Tablespace *tablespace);

/** Drop SDI in a tablespace. This API should be used only
when SDI is corrupted.
@param[in,out]  tablespace      tablespace object
@retval         false           success
@retval         true            failure */
bool dict_sdi_drop(dd::Tablespace *tablespace);

/** Get the SDI keys in a tablespace into the vector provided.
@param[in]      tablespace      tablespace object
@param[in,out]  vector          vector to hold SDI keys
@retval         false           success
@retval         true            failure */
bool dict_sdi_get_keys(const dd::Tablespace &tablespace, sdi_vector_t &vector);

/** Retrieve SDI from tablespace.
@param[in]      tablespace      tablespace object
@param[in]      sdi_key         SDI key
@param[in,out]  sdi             SDI retrieved from tablespace
@param[in,out]  sdi_len         in:  size of memory allocated
                                out: actual length of SDI
@retval         false           success
@retval         true            in case of failures like record not found,
                                sdi_len is UINT64MAX_T, else sdi_len is
                                actual length of SDI */
bool dict_sdi_get(const dd::Tablespace &tablespace, const sdi_key_t *sdi_key,
                  void *sdi, uint64_t *sdi_len);

/** Insert/Update SDI in tablespace.
@param[in]      hton            handlerton object
@param[in]      tablespace      tablespace object
@param[in]      table           table object
@param[in]      sdi_key         SDI key to uniquely identify the tablespace
object
@param[in]      sdi             SDI to be stored in tablespace
@param[in]      sdi_len         SDI length
@retval         false           success
@retval         true            failure */
bool dict_sdi_set(handlerton *hton, const dd::Tablespace &tablespace,
                  const dd::Table *table, const sdi_key_t *sdi_key,
                  const void *sdi, uint64_t sdi_len);

/** Delete SDI from tablespace.
@param[in]      tablespace      tablespace object
@param[in]      table           table object
@param[in]      sdi_key         SDI key to uniquely identify the tablespace
                                object
@retval         false           success
@retval         true            failure */
bool dict_sdi_delete(const dd::Tablespace &tablespace, const dd::Table *table,
                     const sdi_key_t *sdi_key);
#endif