Skip to content

Commit f8cdbbd

Browse files
author
Sven Sandberg
committed
BUG#34897236: Move binlog transaction compressor / decompressor classes to own files
Problem: Binlog transaction compressors and decompressors are defined in the same files. It would be better to have a class per file. Fix: Move each class definition to an own file: base.h/.cc: Base_compressor_decompressor compressor.h: Compressor decompressor.h: Decompressor zstd_comp.h/.cc: Zstd_comp zstd_dec.h/.cc: Zstd_dec none_comp.h/.cc: None_comp none_dec.h/.cc: None_dec Change-Id: I74edd19904918150c1ec642d609b71c6732db410
1 parent d88f0ec commit f8cdbbd

24 files changed

+524
-321
lines changed

libbinlogevents/include/compression/base.h

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
along with this program; if not, write to the Free Software
2121
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2222

23-
#ifndef COMPRESSION_BASE_INCLUDED
24-
#define COMPRESSION_BASE_INCLUDED
23+
#ifndef LIBBINLOGEVENTS_COMPRESSION_BASE_H_INCLUDED
24+
#define LIBBINLOGEVENTS_COMPRESSION_BASE_H_INCLUDED
2525

2626
#include <cstddef>
2727
#include <string>
@@ -137,82 +137,8 @@ class Base_compressor_decompressor {
137137
virtual bool reserve(std::size_t bytes);
138138
};
139139

140-
/**
141-
The base compressor abstract class.
142-
143-
It establishes the interface for compressors.
144-
*/
145-
class Compressor : public Base_compressor_decompressor {
146-
public:
147-
/**
148-
Sets the compression level for this compressor. It is
149-
only effective if done before opening the compressor.
150-
After opening the compressor setting the compression
151-
level, it is only effective when the compressor is
152-
closed and opened again.
153-
154-
@param compression_level the compression level for this compressor.
155-
*/
156-
virtual void set_compression_level(unsigned int compression_level) = 0;
157-
158-
/**
159-
This member function SHALL compress the data provided with the given
160-
length. Note that the buffer to store the compressed data must have
161-
already have been set through @c set_buffer.
162-
163-
If the output buffer is not large enough an error shall be returned.
164-
The contents of the output buffer may still have been modified in
165-
that case.
166-
167-
@param data the data to compress
168-
@param length the length of the data.
169-
170-
@return a tuple containing the bytes not compressed and an error state. If
171-
all bytes were decompressed, then it is returned 0 in the first
172-
element and false in the second. If not all bytes were compressed,
173-
it returns the number of remaining bytes not processed and false on
174-
the second element. If there was an error, then the second element
175-
returns true, and the first element returns the number of bytes
176-
processed until the error happened.
177-
178-
*/
179-
virtual std::tuple<std::size_t, bool> compress(const unsigned char *data,
180-
size_t length) = 0;
181-
};
182-
183-
/**
184-
The base decompressor abstract class.
185-
186-
It establishes the interface for decompressors.
187-
*/
188-
class Decompressor : public Base_compressor_decompressor {
189-
public:
190-
/**
191-
This member function SHALL decompress the data provided with the given
192-
length. Note that the buffer to store the compressed data must have
193-
already have been set through @c set_buffer.
194-
195-
If the output buffer is not large enough an error shall be returned.
196-
The contents of the output buffer may still have been modified in
197-
that case.
198-
199-
@param data the data to compress
200-
@param length the length of the data.
201-
202-
@return a tuple containing the bytes not decompressed and an error state. If
203-
all bytes were decompressed, then it is returned 0 in the first
204-
element and false in the second. If not all bytes were decompressed,
205-
it returns the number of remaining bytes not processed and false on
206-
the second element. If there was an error, then the second element
207-
returns true, and the first element returns the number of bytes
208-
processed until the error happened.
209-
*/
210-
virtual std::tuple<std::size_t, bool> decompress(const unsigned char *data,
211-
size_t length) = 0;
212-
};
213-
214140
} // namespace compression
215141
} // namespace transaction
216142
} // namespace binary_log
217143

218-
#endif
144+
#endif // ifndef LIBBINLOGEVENTS_COMPRESSION_BASE_H_INCLUDED
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* Copyright (c) 2019, 2022, 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 LIBBINLOGEVENTS_COMPRESSION_COMPRESSOR_H_INCLUDED
24+
#define LIBBINLOGEVENTS_COMPRESSION_COMPRESSOR_H_INCLUDED
25+
26+
#include <tuple>
27+
#include "base.h"
28+
29+
namespace binary_log {
30+
namespace transaction {
31+
namespace compression {
32+
33+
/**
34+
The base compressor abstract class.
35+
36+
It establishes the interface for compressors.
37+
*/
38+
class Compressor : public Base_compressor_decompressor {
39+
public:
40+
/**
41+
Sets the compression level for this compressor. It is
42+
only effective if done before opening the compressor.
43+
After opening the compressor setting the compression
44+
level, it is only effective when the compressor is
45+
closed and opened again.
46+
47+
@param compression_level the compression level for this compressor.
48+
*/
49+
virtual void set_compression_level(unsigned int compression_level) = 0;
50+
51+
/**
52+
This member function SHALL compress the data provided with the given
53+
length. Note that the buffer to store the compressed data must have
54+
already have been set through @c set_buffer.
55+
56+
If the output buffer is not large enough an error shall be returned.
57+
The contents of the output buffer may still have been modified in
58+
that case.
59+
60+
@param data the data to compress
61+
@param length the length of the data.
62+
63+
@return a tuple containing the bytes not compressed and an error state. If
64+
all bytes were decompressed, then it is returned 0 in the first
65+
element and false in the second. If not all bytes were compressed,
66+
it returns the number of remaining bytes not processed and false on
67+
the second element. If there was an error, then the second element
68+
returns true, and the first element returns the number of bytes
69+
processed until the error happened.
70+
71+
*/
72+
virtual std::tuple<std::size_t, bool> compress(const unsigned char *data,
73+
size_t length) = 0;
74+
};
75+
76+
} // namespace compression
77+
} // namespace transaction
78+
} // namespace binary_log
79+
80+
#endif // ifndef LIBBINLOGEVENTS_COMPRESSION_COMPRESSOR_H_INCLUDED
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* Copyright (c) 2019, 2022, 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 LIBBINLOGEVENTS_COMPRESSION_DECOMPRESSOR_H_INCLUDED
24+
#define LIBBINLOGEVENTS_COMPRESSION_DECOMPRESSOR_H_INCLUDED
25+
26+
#include <tuple>
27+
#include "base.h"
28+
29+
namespace binary_log {
30+
namespace transaction {
31+
namespace compression {
32+
33+
/**
34+
The base decompressor abstract class.
35+
36+
It establishes the interface for decompressors.
37+
*/
38+
class Decompressor : public Base_compressor_decompressor {
39+
public:
40+
/**
41+
This member function SHALL decompress the data provided with the given
42+
length. Note that the buffer to store the compressed data must have
43+
already have been set through @c set_buffer.
44+
45+
If the output buffer is not large enough an error shall be returned.
46+
The contents of the output buffer may still have been modified in
47+
that case.
48+
49+
@param data the data to compress
50+
@param length the length of the data.
51+
52+
@return a tuple containing the bytes not decompressed and an error state. If
53+
all bytes were decompressed, then it is returned 0 in the first
54+
element and false in the second. If not all bytes were decompressed,
55+
it returns the number of remaining bytes not processed and false on
56+
the second element. If there was an error, then the second element
57+
returns true, and the first element returns the number of bytes
58+
processed until the error happened.
59+
*/
60+
virtual std::tuple<std::size_t, bool> decompress(const unsigned char *data,
61+
size_t length) = 0;
62+
};
63+
64+
} // namespace compression
65+
} // namespace transaction
66+
} // namespace binary_log
67+
68+
#endif // ifndef LIBBINLOGEVENTS_COMPRESSION_DECOMPRESSOR_H_INCLUDED

libbinlogevents/include/compression/factory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#define COMPRESSION_FACTORY_INCLUDED
2525

2626
#include <memory>
27-
#include "base.h"
28-
#include "lz4.h"
27+
#include "compressor.h"
28+
#include "decompressor.h"
2929

3030
namespace binary_log {
3131
namespace transaction {

libbinlogevents/include/compression/iterator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define COMPRESSION_ITERATOR_INCLUDED
2525

2626
#include <memory>
27+
#include "libbinlogevents/include/compression/decompressor.h"
2728
#include "libbinlogevents/include/control_events.h"
2829
#include "libbinlogevents/include/event_reader.h"
2930

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/* Copyright (c) 2019, 2022, 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 LIBBINLOGEVENTS_COMPRESSION_NONE_COMP_H_INCLUDED
24+
#define LIBBINLOGEVENTS_COMPRESSION_NONE_COMP_H_INCLUDED
25+
26+
#include "compressor.h"
27+
28+
namespace binary_log {
29+
namespace transaction {
30+
namespace compression {
31+
32+
/**
33+
This compressor does not compress. The only thing that it does
34+
is to copy the data from the input to the output buffer.
35+
*/
36+
class None_comp : public Compressor {
37+
public:
38+
None_comp() = default;
39+
40+
/**
41+
No op member function.
42+
*/
43+
void set_compression_level(unsigned int compression_level) override;
44+
45+
/**
46+
Shall get the compressor type code.
47+
48+
@return the compressor type code.
49+
*/
50+
type compression_type_code() override;
51+
52+
/**
53+
No op member function.
54+
55+
@return false on success, true otherwise.
56+
*/
57+
bool open() override;
58+
59+
/**
60+
This member function shall simply copy the input buffer to the
61+
output buffer. It shall grow the output buffer if needed.
62+
63+
@param data a pointer to the buffer holding the data to compress
64+
@param length the size of the data to compress.
65+
66+
@return false on success, true otherwise.
67+
*/
68+
std::tuple<std::size_t, bool> compress(const unsigned char *data,
69+
size_t length) override;
70+
71+
/**
72+
No op member function.
73+
74+
@return false on success, true otherwise.
75+
*/
76+
bool close() override;
77+
};
78+
79+
} // namespace compression
80+
} // namespace transaction
81+
} // namespace binary_log
82+
83+
#endif // ifndef LIBBINLOGEVENTS_COMPRESSION_NONE_COMP_H_INCLUDED

0 commit comments

Comments
 (0)