MySQL 8.4.0
Source Code Documentation
gcs_message_stage_lz4.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 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 GCS_MESSAGE_STAGE_LZ4_H
25#define GCS_MESSAGE_STAGE_LZ4_H
26
27#include <lz4.h>
28#include <utility>
29#include <vector>
30
33
34/**
35 This class implements LZ4 compression. It is a stateless
36 service class, thence it is thread safe.
37 */
39 public:
40 /*
41 Methods inherited from the Gcs_message_stage class.
42 */
44 uint64_t const &original_payload_size) const override;
45
46 std::unique_ptr<Gcs_stage_metadata> get_stage_header() override;
47
48 protected:
49 std::pair<bool, std::vector<Gcs_packet>> apply_transformation(
50 Gcs_packet &&packet) override;
51
52 std::pair<Gcs_pipeline_incoming_result, Gcs_packet> revert_transformation(
53 Gcs_packet &&packet) override;
54
56 const Gcs_packet &packet) const override;
57
58 public:
59 /**
60 The default threshold value in bytes.
61 */
62 static constexpr unsigned long long DEFAULT_THRESHOLD = 1024;
63
64 /**
65 Creates an instance of the stage with the default threshold in bytes set.
66 */
68
69 /**
70 Creates an instance of the stage with the given threshold in bytes.
71
72 @param enabled enables this message stage
73 @param compress_threshold messages with the payload larger
74 than compress_threshold in bytes are compressed.
75 */
77 unsigned long long compress_threshold)
78 : Gcs_message_stage(enabled), m_threshold(compress_threshold) {}
79
80 ~Gcs_message_stage_lz4() override = default;
81
82 /*
83 Return the stage code.
84 */
85 Stage_code get_stage_code() const override { return Stage_code::ST_LZ4_V1; }
86
87 /**
88 Sets the threshold in bytes after which compression kicks in.
89
90 @param threshold if the payload exceeds these many bytes, then
91 the message is compressed.
92 */
93 void set_threshold(unsigned long long threshold) { m_threshold = threshold; }
94
95 /**
96 Return the maximum payload size in bytes that can be compressed.
97 */
98 static constexpr unsigned long long max_input_compression() noexcept {
99 /*
100 The code expects that the following assumption will always hold.
101 */
102 static_assert(
103 LZ4_MAX_INPUT_SIZE <= std::numeric_limits<int>::max(),
104 "Maximum input size for lz compression exceeds the expected value");
105 return LZ4_MAX_INPUT_SIZE;
106 }
107
108 private:
109 /**
110 This marks the threshold in bytes above which a message gets compressed.
111 Messages that are smaller than this threshold are not compressed.
112 */
113 unsigned long long m_threshold;
114};
115
117 public:
118 /**
119 Creates an instance of the stage with the default threshold in bytes.
120 */
122
123 /**
124 Creates an instance of the stage with the given threshold in bytes.
125
126 @param enabled enables this message stage
127 @param compress_threshold messages with the payload larger
128 than compress_threshold in bytes are compressed.
129 */
131 unsigned long long compress_threshold)
132 : Gcs_message_stage_lz4(enabled, compress_threshold) {}
133
134 ~Gcs_message_stage_lz4_v2() override = default;
135
136 /*
137 Return the stage code.
138 */
140};
141
143 public:
144 /**
145 Creates an instance of the stage with the default threshold in bytes.
146 */
148
149 /**
150 Creates an instance of the stage with the given threshold in bytes.
151
152 @param enabled enables this message stage
153 @param compress_threshold messages with the payload larger
154 than compress_threshold in bytes are compressed.
155 */
157 unsigned long long compress_threshold)
158 : Gcs_message_stage_lz4(enabled, compress_threshold) {}
159
161
162 /*
163 Return the stage code.
164 */
166};
167
168#endif /* GCS_MESSAGE_STAGE_LZ4_H */
Definition: gcs_message_stage_lz4.h:116
Gcs_message_stage_lz4_v2()
Creates an instance of the stage with the default threshold in bytes.
Definition: gcs_message_stage_lz4.h:121
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:130
Stage_code get_stage_code() const override
Return the unique stage code.
Definition: gcs_message_stage_lz4.h:139
~Gcs_message_stage_lz4_v2() override=default
Definition: gcs_message_stage_lz4.h:142
~Gcs_message_stage_lz4_v3() override
Definition: gcs_message_stage_lz4.h:160
Gcs_message_stage_lz4_v3()
Creates an instance of the stage with the default threshold in bytes.
Definition: gcs_message_stage_lz4.h:147
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:156
Stage_code get_stage_code() const override
Return the unique stage code.
Definition: gcs_message_stage_lz4.h:165
This class implements LZ4 compression.
Definition: gcs_message_stage_lz4.h:38
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:68
void set_threshold(unsigned long long threshold)
Sets the threshold in bytes after which compression kicks in.
Definition: gcs_message_stage_lz4.h:93
static constexpr unsigned long long DEFAULT_THRESHOLD
The default threshold value in bytes.
Definition: gcs_message_stage_lz4.h:62
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:76
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:98
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:36
~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:113
Gcs_message_stage_lz4()
Creates an instance of the stage with the default threshold in bytes set.
Definition: gcs_message_stage_lz4.h:67
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:113
std::unique_ptr< Gcs_stage_metadata > get_stage_header() override
Definition: gcs_message_stage_lz4.cc:63
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:167
Stage_code get_stage_code() const override
Return the unique stage code.
Definition: gcs_message_stage_lz4.h:85
This is a stage in the pipeline that processes messages when they are put through the send and receiv...
Definition: gcs_message_stages.h:82
stage_status
Definition: gcs_message_stages.h:84
This class is an abstraction for the packet concept.
Definition: gcs_internal_message.h:58
Stage_code
The different stages that are currently available.
Definition: gcs_internal_message_headers.h:73
required bool enabled
Definition: replication_group_member_actions.proto:33