MySQL 8.4.0
Source Code Documentation
gr_compression.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef GROUP_REPLICATION_COMPRESSION_INCLUDE
25#define GROUP_REPLICATION_COMPRESSION_INCLUDE
26
30
31/*
32 Implements Compressor.
33*/
35 public:
42
43 /**
44 Compression Type
45 */
47 /* Data not compressed */
49 /* Data Compressed using ZSTD compression */
51 };
52
53 /**
54 Compression Error
55 */
57 /* No Error */
59 /* Unkown compression type. */
61 /* Compression library initialization error. */
63 /* Exceed max output buffer size. */
65 /* Memory allocation failure. */
67 };
68
69 /*
70 Constructor
71
72 @param[in] compression_type the enum_compression_type compression type
73 */
74 GR_compress(enum_compression_type compression_type =
76
77 /*
78 Destructor
79 */
81
82 /**
83 This shall compress the buffer provided and put the compressed payload
84 into the m_managed_buffer_sequence which is non-contiguous growable memory
85 buffer.
86
87 @param data a pointer to the buffer holding the data to compress
88 @param length the size of the data to compress.
89
90 @return enum_compression_error error type. The compressed data is stored in
91 m_managed_buffer_sequence which can be retrieved using
92 allocate_and_get_buffer().
93 */
95 size_t length);
96
97 /*
98 Return the pointer to compressed data and the size.
99 The compressed data is stored in managed_buffer_sequence which is
100 non-contiguous growable memory buffer. So to return the compressed
101 contiguous output from managed_buffer_sequence, a buffer is allocated in
102 this function. The compressed data is added and returned in it.
103
104 Note: A buffer shall be allocated in this function to return the compressed
105 data and it's the caller responsibility to release allocates memory.
106
107 @return a pair containing the pointer to the compressed data and it's size.
108 In case of error or memory allocation failure the pair containing
109 nullptr and 0 size is returned.
110 */
111 std::pair<unsigned char *, std::size_t> allocate_and_get_buffer();
112
113 /*
114 Return the uncompressed data size.
115
116 @return the the size of the uncompressed data
117 */
119
120 private:
121 /** ZSTD compressor class object. */
123
124 /** The compression type. */
127
128 /** The compression library name. */
129 std::string m_compressor_name{"Zstandard"};
130
131 /** The compression status. */
133
134 /** The buffer holding compressed data. */
136
137 /** The uncompressed data size. */
139
140 /** The compressed data size. */
142};
143#endif /* GROUP_REPLICATION_COMPRESSION_INCLUDE */
Definition: gr_compression.h:34
std::pair< unsigned char *, std::size_t > allocate_and_get_buffer()
Definition: gr_compression.cc:136
~GR_compress()
Definition: gr_compression.cc:69
size_t m_compressed_data_size
The compressed data size.
Definition: gr_compression.h:141
Managed_buffer_sequence_t::Char_t Char_t
Definition: gr_compression.h:41
size_t m_uncompressed_data_size
The uncompressed data size.
Definition: gr_compression.h:138
enum_compression_type
Compression Type.
Definition: gr_compression.h:46
Managed_buffer_sequence_t m_managed_buffer_sequence
The buffer holding compressed data.
Definition: gr_compression.h:135
enum_compression_error
Compression Error.
Definition: gr_compression.h:56
Compressor_t * m_compressor
ZSTD compressor class object.
Definition: gr_compression.h:122
enum_compression_type m_compression_type
The compression type.
Definition: gr_compression.h:125
size_t get_uncompressed_data_size()
Definition: gr_compression.cc:162
std::string m_compressor_name
The compression library name.
Definition: gr_compression.h:129
GR_compress::enum_compression_error compress(unsigned char *data, size_t length)
This shall compress the buffer provided and put the compressed payload into the m_managed_buffer_sequ...
Definition: gr_compression.cc:76
GR_compress(enum_compression_type compression_type=enum_compression_type::ZSTD_COMPRESSION)
Definition: gr_compression.cc:33
Compress_status_t m_status
The compression status.
Definition: gr_compression.h:132
Abstract base class for compressors.
Definition: compressor.h:80
Owned, non-contiguous, growable memory buffer.
Definition: managed_buffer_sequence.h:115
typename Buffer_sequence_view_t::Char_t Char_t
Definition: rw_buffer_sequence.h:110
Container class that provides a contiguous memory buffer to the caller, which the caller can request ...
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Grow_status
Error statuses for classes that use Grow_calculator.
Definition: grow_status.h:38