summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2021-06-13 15:31:41 +0200
committerSergei Golubchik <serg@mariadb.org>2021-06-13 15:36:31 +0200
commita2f1bf0390480e00d1421475d2a7526da0652a49 (patch)
tree47218bfc3b359011860020e10802a79ccd027b08
parentc84b51756cc2cbb50d52745535140842b692e8c7 (diff)
downloadmariadb-git-a2f1bf0390480e00d1421475d2a7526da0652a49.tar.gz
snappy-c
-rw-r--r--include/service_versions.h1
-rw-r--r--include/wrappers/snappy-c.h69
-rw-r--r--libservices/CMakeLists.txt1
-rw-r--r--libservices/wrapper_service_snappy.c17
-rw-r--r--mysql-test/suite/plugins/r/compression,innodb-snappy.rdiff21
-rw-r--r--mysql-test/suite/plugins/t/compression.combinations4
-rw-r--r--mysql-test/suite/plugins/t/compression.test10
-rw-r--r--plugin/wrapper_snappy/CMakeLists.txt11
-rw-r--r--plugin/wrapper_snappy/plugin.c49
-rw-r--r--sql/sql_plugin_services.ic13
-rw-r--r--storage/innobase/snappy.cmake12
11 files changed, 196 insertions, 12 deletions
diff --git a/include/service_versions.h b/include/service_versions.h
index 68f11e0ce2a..eaa62b69d4a 100644
--- a/include/service_versions.h
+++ b/include/service_versions.h
@@ -47,3 +47,4 @@
#define VERSION_wrapper_bzip2 0x0100
#define VERSION_wrapper_lzma 0x0100
#define VERSION_wrapper_lzo 0x0100
+#define VERSION_wrapper_snappy 0x0100
diff --git a/include/wrappers/snappy-c.h b/include/wrappers/snappy-c.h
new file mode 100644
index 00000000000..99623ccddce
--- /dev/null
+++ b/include/wrappers/snappy-c.h
@@ -0,0 +1,69 @@
+/**
+ @file snappy-c.h
+ This service provides dynamic access to Snappy as a C header.
+*/
+
+#ifndef SNAPPY_C_INCLUDED
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef MYSQL_ABI_CHECK
+#include <stddef.h>
+#include <stdbool.h>
+#endif
+
+#ifndef SNAPPY_C
+typedef enum
+{
+ SNAPPY_OK = 0,
+ SNAPPY_INVALID_INPUT = 1,
+ SNAPPY_BUFFER_TOO_SMALL = 2
+} snappy_status;
+
+#define snappy_max_compressed_length(...) wrapper_service_snappy->snappy_max_compressed_length_ptr (__VA_ARGS__)
+#define snappy_compress(...) wrapper_service_snappy->snappy_compress_ptr (__VA_ARGS__)
+#define snappy_uncompressed_length(...) wrapper_service_snappy->snappy_uncompressed_length_ptr (__VA_ARGS__)
+#define snappy_uncompress(...) wrapper_service_snappy->snappy_uncompress_ptr (__VA_ARGS__)
+#endif
+
+#define DEFINE_snappy_max_compressed_length(NAME) NAME( \
+ size_t source_length \
+)
+
+#define DEFINE_snappy_compress(NAME) NAME( \
+ const char *input, \
+ size_t input_length, \
+ char *compressed, \
+ size_t *compressed_length \
+)
+
+#define DEFINE_snappy_uncompressed_length(NAME) NAME( \
+ const char *compressed, \
+ size_t compressed_length, \
+ size_t *result \
+)
+
+#define DEFINE_snappy_uncompress(NAME) NAME( \
+ const char *compressed, \
+ size_t compressed_length, \
+ char *uncompressed, \
+ size_t *uncompressed_length \
+)
+
+struct wrapper_service_snappy_st
+{
+ size_t DEFINE_snappy_max_compressed_length((*snappy_max_compressed_length_ptr));
+ snappy_status DEFINE_snappy_compress((*snappy_compress_ptr));
+ snappy_status DEFINE_snappy_uncompressed_length((*snappy_uncompressed_length_ptr));
+ snappy_status DEFINE_snappy_uncompress((*snappy_uncompress_ptr));
+};
+
+extern struct wrapper_service_snappy_st *wrapper_service_snappy;
+
+#ifdef __cplusplus
+}
+#endif
+
+#define SNAPPY_C_INCLUDED
+#endif
diff --git a/libservices/CMakeLists.txt b/libservices/CMakeLists.txt
index 3ae0d484098..3977008fad3 100644
--- a/libservices/CMakeLists.txt
+++ b/libservices/CMakeLists.txt
@@ -41,6 +41,7 @@ SET(MYSQLSERVICES_SOURCES
wrapper_service_bzip2.c
wrapper_service_lzma.c
wrapper_service_lzo.c
+ wrapper_service_snappy.c
)
ADD_CONVENIENCE_LIBRARY(mysqlservices ${MYSQLSERVICES_SOURCES})
diff --git a/libservices/wrapper_service_snappy.c b/libservices/wrapper_service_snappy.c
new file mode 100644
index 00000000000..29c0bec6285
--- /dev/null
+++ b/libservices/wrapper_service_snappy.c
@@ -0,0 +1,17 @@
+/* Copyright (C) 2021 MariaDB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
+
+#include <service_versions.h>
+SERVICE_VERSION wrapper_service_snappy= (void*) VERSION_wrapper_snappy;
diff --git a/mysql-test/suite/plugins/r/compression,innodb-snappy.rdiff b/mysql-test/suite/plugins/r/compression,innodb-snappy.rdiff
new file mode 100644
index 00000000000..c7b08e1f84c
--- /dev/null
+++ b/mysql-test/suite/plugins/r/compression,innodb-snappy.rdiff
@@ -0,0 +1,21 @@
+--- suite/plugins/r/compression.result
++++ suite/plugins/r/compression.reject
+@@ -1,7 +1,7 @@
+ #
+-# Testing lzma compression with innodb
++# Testing snappy compression with innodb
+ #
+-set global innodb_compression_algorithm = lzma;
++set global innodb_compression_algorithm = snappy;
+ call mtr.add_suppression("InnoDB: Background Page read failed to read or decrypt \\[page id: space=\\d+, page number=\\d+\\]");
+ call mtr.add_suppression("InnoDB: Table `test`.`t1` is corrupted. Please drop the table and recreate.");
+ CREATE TABLE t1 (a int, b text) engine = innodb page_compressed = 1;
+@@ -13,7 +13,7 @@
+ 0 abcabcabc 300
+ 1 defdefdef 3000
+ 2 ghighighi 30000
+-# restart: --disable-lzma
++# restart: --disable-snappy
+ SELECT * FROM t1;
+ ERROR 42S02: Table 'test.t1' doesn't exist in engine
+ drop table t1;
diff --git a/mysql-test/suite/plugins/t/compression.combinations b/mysql-test/suite/plugins/t/compression.combinations
index 485a47ad3c7..27bd3535aac 100644
--- a/mysql-test/suite/plugins/t/compression.combinations
+++ b/mysql-test/suite/plugins/t/compression.combinations
@@ -9,3 +9,7 @@ plugin-load-add=$LZO_SO
[innodb-bzip2]
innodb
plugin-load-add=$BZIP2_SO
+
+[innodb-snappy]
+innodb
+plugin-load-add=$SNAPPY_SO
diff --git a/mysql-test/suite/plugins/t/compression.test b/mysql-test/suite/plugins/t/compression.test
index 92f174be428..954276dde04 100644
--- a/mysql-test/suite/plugins/t/compression.test
+++ b/mysql-test/suite/plugins/t/compression.test
@@ -1,6 +1,16 @@
let $engine=`select regexp_replace('$MTR_COMBINATIONS', '-.*', '')`;
let $alg=`select regexp_replace('$MTR_COMBINATIONS', '.*-', '')`;
+if (`select count(*) = 0 from information_schema.plugins where plugin_name = '$engine' and plugin_status='active'`)
+{
+ --skip Needs $engine plugin
+}
+
+if (`select count(*) = 0 from information_schema.plugins where plugin_name = '$alg' and plugin_status='active'`)
+{
+ --skip Needs $alg plugin
+}
+
--echo #
--echo # Testing $alg compression with $engine
--echo #
diff --git a/plugin/wrapper_snappy/CMakeLists.txt b/plugin/wrapper_snappy/CMakeLists.txt
new file mode 100644
index 00000000000..a84e94c4fed
--- /dev/null
+++ b/plugin/wrapper_snappy/CMakeLists.txt
@@ -0,0 +1,11 @@
+CHECK_INCLUDE_FILES(snappy-c.h HAVE_SNAPPY_H)
+CHECK_LIBRARY_EXISTS(snappy snappy_uncompress "" HAVE_SNAPPY_UNCOMPRESS)
+
+IF (HAVE_SNAPPY_H AND HAVE_SNAPPY_UNCOMPRESS)
+ MYSQL_ADD_PLUGIN(snappy_plugin plugin.c MODULE_OUTPUT_NAME snappy
+ COMPONENT snappy LINK_LIBRARIES snappy)
+
+ GET_PROPERTY(dirs TARGET snappy_plugin PROPERTY INCLUDE_DIRECTORIES)
+ LIST(REMOVE_ITEM dirs ${CMAKE_SOURCE_DIR}/include/wrappers)
+ SET_PROPERTY(TARGET snappy_plugin PROPERTY INCLUDE_DIRECTORIES "${dirs}")
+ENDIF()
diff --git a/plugin/wrapper_snappy/plugin.c b/plugin/wrapper_snappy/plugin.c
new file mode 100644
index 00000000000..5a43b30ec30
--- /dev/null
+++ b/plugin/wrapper_snappy/plugin.c
@@ -0,0 +1,49 @@
+/* Copyright (c) 2021, MariaDB Corporation
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
+
+#include <mysql_version.h>
+#include <mysql/plugin.h>
+#include <snappy-c.h>
+#define SNAPPY_C
+#include <wrappers/snappy-c.h>
+
+static int init(void* h)
+{
+ wrapper_service_snappy->snappy_max_compressed_length_ptr= snappy_max_compressed_length;
+ wrapper_service_snappy->snappy_compress_ptr= snappy_compress;
+ wrapper_service_snappy->snappy_uncompressed_length_ptr= snappy_uncompressed_length;
+ wrapper_service_snappy->snappy_uncompress_ptr= snappy_uncompress;
+ return 0;
+}
+
+struct st_mysql_daemon info= { MYSQL_DAEMON_INTERFACE_VERSION };
+
+maria_declare_plugin(snappy)
+{
+ MYSQL_DAEMON_PLUGIN,
+ &info,
+ "snappy",
+ "Sergei Golubchik",
+ "SNAPPY compression service",
+ PLUGIN_LICENSE_GPL,
+ init,
+ NULL,
+ 0x0100,
+ NULL,
+ NULL,
+ "1.0",
+ MariaDB_PLUGIN_MATURITY_STABLE
+}
+maria_declare_plugin_end;
diff --git a/sql/sql_plugin_services.ic b/sql/sql_plugin_services.ic
index e3777d258b2..6164f4e2ad4 100644
--- a/sql/sql_plugin_services.ic
+++ b/sql/sql_plugin_services.ic
@@ -259,6 +259,16 @@ static struct wrapper_service_bzip2_st wrapper_handler_bzip2=
};
struct wrapper_service_bzip2_st *wrapper_service_bzip2= &wrapper_handler_bzip2;
+#include <wrappers/snappy-c.h>
+static struct wrapper_service_snappy_st wrapper_handler_snappy=
+{
+ DEFINE_snappy_max_compressed_length([]) -> size_t { return 0; },
+ DEFINE_snappy_compress([]) { return SNAPPY_INVALID_INPUT; },
+ DEFINE_snappy_uncompressed_length([]) { return SNAPPY_INVALID_INPUT; },
+ DEFINE_snappy_uncompress([]) { return SNAPPY_INVALID_INPUT; }
+};
+struct wrapper_service_snappy_st *wrapper_service_snappy= &wrapper_handler_snappy;
+
static struct st_service_ref list_of_services[]=
{
{ "base64_service", VERSION_base64, &base64_handler },
@@ -286,5 +296,6 @@ static struct st_service_ref list_of_services[]=
{ "thd_mdl_service", VERSION_thd_mdl, &thd_mdl_handler },
{ "wrapper_service_bzip2", VERSION_wrapper_bzip2, &wrapper_handler_bzip2 },
{ "wrapper_service_lzma", VERSION_wrapper_lzma, &wrapper_handler_lzma },
- { "wrapper_service_lzo", VERSION_wrapper_lzo, &wrapper_handler_lzo }
+ { "wrapper_service_lzo", VERSION_wrapper_lzo, &wrapper_handler_lzo },
+ { "wrapper_service_snappy", VERSION_wrapper_snappy, &wrapper_handler_snappy }
};
diff --git a/storage/innobase/snappy.cmake b/storage/innobase/snappy.cmake
index 2810472cef6..be1809b378b 100644
--- a/storage/innobase/snappy.cmake
+++ b/storage/innobase/snappy.cmake
@@ -17,16 +17,6 @@ SET(WITH_INNODB_SNAPPY AUTO CACHE STRING
MACRO (MYSQL_CHECK_SNAPPY)
IF (WITH_INNODB_SNAPPY STREQUAL "ON" OR WITH_INNODB_SNAPPY STREQUAL "AUTO")
- CHECK_INCLUDE_FILES(snappy-c.h HAVE_SNAPPY_H)
- CHECK_LIBRARY_EXISTS(snappy snappy_uncompress "" HAVE_SNAPPY_SHARED_LIB)
-
- IF(HAVE_SNAPPY_SHARED_LIB AND HAVE_SNAPPY_H)
- ADD_DEFINITIONS(-DHAVE_SNAPPY=1)
- LINK_LIBRARIES(snappy)
- ELSE()
- IF (WITH_INNODB_SNAPPY STREQUAL "ON")
- MESSAGE(FATAL_ERROR "Required snappy library is not found")
- ENDIF()
- ENDIF()
+ ADD_DEFINITIONS(-DHAVE_SNAPPY=1)
ENDIF()
ENDMACRO()