MySQL 8.2.0
Source Code Documentation
gcs_message_stage_lz4.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef GCS_MESSAGE_STAGE_LZ4_H
24#define GCS_MESSAGE_STAGE_LZ4_H
25
26#include <lz4.h>
27#include <utility>
28#include <vector>
29
32
33/**
34 This class implements LZ4 compression. It is a stateless
35 service class, thence it is thread safe.
36 */
38 public:
39 /*
40 Methods inherited from the Gcs_message_stage class.
41 */
43 uint64_t const &original_payload_size) const override;
44
45 std::unique_ptr<Gcs_stage_metadata> get_stage_header() override;
46
47 protected:
48 std::pair<bool, std::vector<Gcs_packet>> apply_transformation(
49 Gcs_packet &&packet) override;
50
51 std::pair<Gcs_pipeline_incoming_result, Gcs_packet> revert_transformation(
52 Gcs_packet &&packet) override;
53
55 const Gcs_packet &packet) const override;
56
57 public:
58 /**
59 The default threshold value in bytes.
60 */
61 static constexpr unsigned long long DEFAULT_THRESHOLD = 1024;
62
63 /**
64 Creates an instance of the stage with the default threshold in bytes set.
65 */
67
68 /**
69 Creates an instance of the stage with the given threshold in bytes.
70
71 @param enabled enables this message stage
72 @param compress_threshold messages with the payload larger
73 than compress_threshold in bytes are compressed.
74 */
76 unsigned long long compress_threshold)
77 : Gcs_message_stage(enabled), m_threshold(compress_threshold) {}
78
79 ~Gcs_message_stage_lz4() override = default;
80
81 /*
82 Return the stage code.
83 */
84 Stage_code get_stage_code() const override { return Stage_code::ST_LZ4_V1; }
85
86 /**
87 Sets the threshold in bytes after which compression kicks in.
88
89 @param threshold if the payload exceeds these many bytes, then
90 the message is compressed.
91 */
92 void set_threshold(unsigned long long threshold) { m_threshold = threshold; }
93
94 /**
95 Return the maximum payload size in bytes that can be compressed.
96 */
97 static constexpr unsigned long long max_input_compression() noexcept {
98 /*
99 The code expects that the following assumption will always hold.
100 */
101 static_assert(
102 LZ4_MAX_INPUT_SIZE <= std::numeric_limits<int>::max(),
103 "Maximum input size for lz compression exceeds the expected value");
104 return LZ4_MAX_INPUT_SIZE;
105 }
106
107 private:
108 /**
109 This marks the threshold in bytes above which a message gets compressed.
110 Messages that are smaller than this threshold are not compressed.
111 */
112 unsigned long long m_threshold;
113};
114
116 public:
117 /**
118 Creates an instance of the stage with the default threshold in bytes.
119 */
121
122 /**
123 Creates an instance of the stage with the given threshold in bytes.
124
125 @param enabled enables this message stage
126 @param compress_threshold messages with the payload larger
127 than compress_threshold in bytes are compressed.
128 */
130 unsigned long long compress_threshold)
131 : Gcs_message_stage_lz4(enabled, compress_threshold) {}
132
133 ~Gcs_message_stage_lz4_v2() override = default;
134
135 /*
136 Return the stage code.
137 */
139};
140
142 public:
143 /**
144 Creates an instance of the stage with the default threshold in bytes.
145 */
147
148 /**
149 Creates an instance of the stage with the given threshold in bytes.
150
151 @param enabled enables this message stage
152 @param compress_threshold messages with the payload larger
153 than compress_threshold in bytes are compressed.
154 */
156 unsigned long long compress_threshold)
157 : Gcs_message_stage_lz4(enabled, compress_threshold) {}
158
160
161 /*
162 Return the stage code.
163 */
165};
166
167#endif /* GCS_MESSAGE_STAGE_LZ4_H */
Definition: gcs_message_stage_lz4.h:115
Gcs_message_stage_lz4_v2()
Creates an instance of the stage with the default threshold in bytes.
Definition: gcs_message_stage_lz4.h:120
Gcs_message_stage_lz4_v2(bool enabled, unsigned long long compress_threshold)
Creates an instance of the stage with the given threshold in bytes.
Definition: gcs_message_stage_lz4.h:129
Stage_code get_stage_code() const override
Return the unique stage code.
Definition: gcs_message_stage_lz4.h:138
~Gcs_message_stage_lz4_v2() override=default
Definition: gcs_message_stage_lz4.h:141
~Gcs_message_stage_lz4_v3() override
Definition: gcs_message_stage_lz4.h:159
Gcs_message_stage_lz4_v3()
Creates an instance of the stage with the default threshold in bytes.
Definition: gcs_message_stage_lz4.h:146
Gcs_message_stage_lz4_v3(bool enabled, unsigned long long compress_threshold)
Creates an instance of the stage with the given threshold in bytes.
Definition: gcs_message_stage_lz4.h:155
Stage_code get_stage_code() const override
Return the unique stage code.
Definition: gcs_message_stage_lz4.h:164
This class implements LZ4 compression.
Definition: gcs_message_stage_lz4.h:37
std::pair< bool, std::vector< Gcs_packet > > apply_transformation(Gcs_packet &&packet) override
Implements the logic of this stage's transformation to the packet, and returns a set of one,...
Definition: gcs_message_stage_lz4.cc:67
void set_threshold(unsigned long long threshold)
Sets the threshold in bytes after which compression kicks in.
Definition: gcs_message_stage_lz4.h:92
static constexpr unsigned long long DEFAULT_THRESHOLD
The default threshold value in bytes.
Definition: gcs_message_stage_lz4.h:61
Gcs_message_stage_lz4(bool enabled, unsigned long long compress_threshold)
Creates an instance of the stage with the given threshold in bytes.
Definition: gcs_message_stage_lz4.h:75
static constexpr unsigned long long max_input_compression() noexcept
Return the maximum payload size in bytes that can be compressed.
Definition: gcs_message_stage_lz4.h:97
Gcs_message_stage::stage_status skip_apply(uint64_t const &original_payload_size) const override
Check if the apply operation which affects outgoing packets should be executed (i....
Definition: gcs_message_stage_lz4.cc:35
~Gcs_message_stage_lz4() override=default
unsigned long long m_threshold
This marks the threshold in bytes above which a message gets compressed.
Definition: gcs_message_stage_lz4.h:112
Gcs_message_stage_lz4()
Creates an instance of the stage with the default threshold in bytes set.
Definition: gcs_message_stage_lz4.h:66
std::pair< Gcs_pipeline_incoming_result, Gcs_packet > revert_transformation(Gcs_packet &&packet) override
Implements the logic to revert this stage's transformation to the packet, and returns one,...
Definition: gcs_message_stage_lz4.cc:112
std::unique_ptr< Gcs_stage_metadata > get_stage_header() override
Definition: gcs_message_stage_lz4.cc:62
Gcs_message_stage::stage_status skip_revert(const Gcs_packet &packet) const override
Check if the revert operation which affects incoming packets should be executed (i....
Definition: gcs_message_stage_lz4.cc:166
Stage_code get_stage_code() const override
Return the unique stage code.
Definition: gcs_message_stage_lz4.h:84
This is a stage in the pipeline that processes messages when they are put through the send and receiv...
Definition: gcs_message_stages.h:81
stage_status
Definition: gcs_message_stages.h:83
This class is an abstraction for the packet concept.
Definition: gcs_internal_message.h:57
Stage_code
The different stages that are currently available.
Definition: gcs_internal_message_headers.h:72
required bool enabled
Definition: replication_group_member_actions.proto:32