MySQL 9.1.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:
41
42 /**
43 Compression Type
44 */
46 /* Data not compressed */
48 /* Data Compressed using ZSTD compression */
50 };
51
52 /**
53 Compression Error
54 */
56 /* No Error */
58 /* Unkown compression type. */
60 /* Compression library initialization error. */
62 /* Exceed max output buffer size. */
64 /* Memory allocation failure. */
66 };
67
68 /*
69 Constructor
70
71 @param[in] compression_type the enum_compression_type compression type
72 */
73 GR_compress(enum_compression_type compression_type =
75
76 /*
77 Destructor
78 */
80
81 /**
82 This shall compress the buffer provided and put the compressed payload
83 into the m_managed_buffer_sequence which is non-contiguous growable memory
84 buffer.
85
86 @param data a pointer to the buffer holding the data to compress
87 @param length the size of the data to compress.
88
89 @return enum_compression_error error type. The compressed data is stored in
90 m_managed_buffer_sequence which can be retrieved using
91 allocate_and_get_buffer().
92 */
94 size_t length);
95
96 /*
97 Return the pointer to compressed data and the size.
98 The compressed data is stored in managed_buffer_sequence which is
99 non-contiguous growable memory buffer. So to return the compressed
100 contiguous output from managed_buffer_sequence, a buffer is allocated in
101 this function. The compressed data is added and returned in it.
102
103 Note: A buffer shall be allocated in this function to return the compressed
104 data and it's the caller responsibility to release allocates memory.
105
106 @return a pair containing the pointer to the compressed data and it's size.
107 In case of error or memory allocation failure the pair containing
108 nullptr and 0 size is returned.
109 */
110 std::pair<unsigned char *, std::size_t> allocate_and_get_buffer();
111
112 /*
113 Return the uncompressed data size.
114
115 @return the the size of the uncompressed data
116 */
118
119 private:
120 /** ZSTD compressor class object. */
122
123 /** The compression type. */
126
127 /** The compression library name. */
128 std::string m_compressor_name{"Zstandard"};
129
130 /** The compression status. */
132
133 /** The buffer holding compressed data. */
135
136 /** The uncompressed data size. */
138
139 /** The compressed data size. */
141};
142#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:140
Managed_buffer_sequence_t::Char_t Char_t
Definition: gr_compression.h:40
size_t m_uncompressed_data_size
The uncompressed data size.
Definition: gr_compression.h:137
enum_compression_type
Compression Type.
Definition: gr_compression.h:45
Managed_buffer_sequence_t m_managed_buffer_sequence
The buffer holding compressed data.
Definition: gr_compression.h:134
enum_compression_error
Compression Error.
Definition: gr_compression.h:55
Compressor_t * m_compressor
ZSTD compressor class object.
Definition: gr_compression.h:121
enum_compression_type m_compression_type
The compression type.
Definition: gr_compression.h:124
size_t get_uncompressed_data_size()
Definition: gr_compression.cc:162
std::string m_compressor_name
The compression library name.
Definition: gr_compression.h:128
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:131
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