From b46bc47c879766f20f45c8216ab86b2444c61c58 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Tue, 7 Feb 2017 15:14:17 +0200 Subject: [PATCH] Add NullFilter filter module NullFilter is a filter module that does nothing, except reports capabilities as defined in the configuration file. It's purpose is only to make it simple to benchmark the performance impact various routing capabilities have. Note that since getCapabilities() currently does *not* take an instance pointer as parameter, all NullFilter instances will report the same capabilities, the ones specified for the last filter to have been loaded. --- server/modules/filter/CMakeLists.txt | 1 + .../modules/filter/nullfilter/CMakeLists.txt | 7 + .../modules/filter/nullfilter/nullfilter.cc | 133 ++++++++++++++++++ .../modules/filter/nullfilter/nullfilter.hh | 36 +++++ .../filter/nullfilter/nullfiltersession.cc | 31 ++++ .../filter/nullfilter/nullfiltersession.hh | 35 +++++ 6 files changed, 243 insertions(+) create mode 100644 server/modules/filter/nullfilter/CMakeLists.txt create mode 100644 server/modules/filter/nullfilter/nullfilter.cc create mode 100644 server/modules/filter/nullfilter/nullfilter.hh create mode 100644 server/modules/filter/nullfilter/nullfiltersession.cc create mode 100644 server/modules/filter/nullfilter/nullfiltersession.hh diff --git a/server/modules/filter/CMakeLists.txt b/server/modules/filter/CMakeLists.txt index f2ffcb730..7e046f9a2 100644 --- a/server/modules/filter/CMakeLists.txt +++ b/server/modules/filter/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory(hintfilter) add_subdirectory(luafilter) add_subdirectory(mqfilter) add_subdirectory(namedserverfilter) +add_subdirectory(nullfilter) add_subdirectory(qlafilter) add_subdirectory(regexfilter) add_subdirectory(tee) diff --git a/server/modules/filter/nullfilter/CMakeLists.txt b/server/modules/filter/nullfilter/CMakeLists.txt new file mode 100644 index 000000000..f72e4888b --- /dev/null +++ b/server/modules/filter/nullfilter/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(nullfilter SHARED + nullfilter.cc + nullfiltersession.cc + ) +target_link_libraries(nullfilter maxscale-common) +set_target_properties(nullfilter PROPERTIES VERSION "1.0.0") +install_module(nullfilter core) diff --git a/server/modules/filter/nullfilter/nullfilter.cc b/server/modules/filter/nullfilter/nullfilter.cc new file mode 100644 index 000000000..07e2b662f --- /dev/null +++ b/server/modules/filter/nullfilter/nullfilter.cc @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2016 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl. + * + * Change Date: 2019-07-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +#define MXS_MODULE_NAME "nullfilter" +#include "nullfilter.hh" +#include +#include + +using std::string; + +namespace +{ + +#define VERSION_STRING "V1.0.0" + +const char CAPABILITIES_PARAM[] = "capabilities"; + +MXS_ENUM_VALUE capability_values[] = +{ + { "RCAP_TYPE_STMT_INPUT", RCAP_TYPE_STMT_INPUT }, + { "RCAP_TYPE_CONTIGUOUS_INPUT", RCAP_TYPE_CONTIGUOUS_INPUT }, + { "RCAP_TYPE_TRANSACTION_TRACKING", RCAP_TYPE_TRANSACTION_TRACKING }, + { "RCAP_TYPE_STMT_OUTPUT", RCAP_TYPE_STMT_OUTPUT }, + { "RCAP_TYPE_CONTIGUOUS_OUTPUT", RCAP_TYPE_CONTIGUOUS_OUTPUT }, + { "RCAP_TYPE_RESULTSET_OUTPUT", RCAP_TYPE_RESULTSET_OUTPUT }, + { NULL, 0 } +}; + +struct unit_variables +{ + uint64_t capabilities; + bool capabilities_set; +} this_unit = +{ + 0, + false +}; + +} + +// +// Global symbols of the Module +// + +extern "C" MXS_MODULE* MXS_CREATE_MODULE() +{ + MXS_NOTICE("Nullfilter module %s initialized.", VERSION_STRING); + + static MXS_MODULE info = + { + MXS_MODULE_API_FILTER, + MXS_MODULE_IN_DEVELOPMENT, + MXS_FILTER_VERSION, + "A null filter that does nothing.", + VERSION_STRING, + &NullFilter::s_object, + NULL, /* Process init. */ + NULL, /* Process finish. */ + NULL, /* Thread init. */ + NULL, /* Thread finish. */ + { + { CAPABILITIES_PARAM, MXS_MODULE_PARAM_ENUM, NULL, MXS_MODULE_OPT_REQUIRED, capability_values }, + { MXS_END_MODULE_PARAMS } + } + }; + + return &info; +} + +// +// NullFilter +// + +NullFilter::NullFilter(const char* zName) +{ + MXS_NOTICE("Null filter [%s] created.", zName); +} + +NullFilter::~NullFilter() +{ +} + +// static +NullFilter* NullFilter::create(const char* zName, char**, MXS_CONFIG_PARAMETER* pParams) +{ + NullFilter* pFilter = NULL; + + uint64_t capabilities = config_get_enum(pParams, CAPABILITIES_PARAM, capability_values); + + if (this_unit.capabilities_set) + { + MXS_WARNING("The capabilities reported by NullFilter are currently global, " + "and not specific for a particular NullFilter instance."); + } + + this_unit.capabilities = capabilities; + this_unit.capabilities_set = true; + + return new NullFilter(zName); +} + + +NullFilterSession* NullFilter::newSession(MXS_SESSION* pSession) +{ + return NullFilterSession::create(pSession, this); +} + +// static +void NullFilter::diagnostics(DCB* pDcb) +{ + dcb_printf(pDcb, "Hello, World!\n"); +} + +// static +uint64_t NullFilter::getCapabilities() +{ + if (!this_unit.capabilities_set) + { + MXS_ERROR("getCapabilities() called before they have been set."); + } + + return this_unit.capabilities; +} diff --git a/server/modules/filter/nullfilter/nullfilter.hh b/server/modules/filter/nullfilter/nullfilter.hh new file mode 100644 index 000000000..459a1bcff --- /dev/null +++ b/server/modules/filter/nullfilter/nullfilter.hh @@ -0,0 +1,36 @@ +#pragma once +/* + * Copyright (c) 2016 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl. + * + * Change Date: 2019-07-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +#include +#include +#include "nullfiltersession.hh" + +class NullFilter : public maxscale::Filter +{ +public: + ~NullFilter(); + static NullFilter* create(const char* zName, char** pzOptions, MXS_CONFIG_PARAMETER* pParams); + + NullFilterSession* newSession(MXS_SESSION* pSession); + + void diagnostics(DCB* pDcb); + + static uint64_t getCapabilities(); + +private: + NullFilter(const char* zName); + + NullFilter(const NullFilter&); + NullFilter& operator = (const NullFilter&); +}; diff --git a/server/modules/filter/nullfilter/nullfiltersession.cc b/server/modules/filter/nullfilter/nullfiltersession.cc new file mode 100644 index 000000000..5fbc48472 --- /dev/null +++ b/server/modules/filter/nullfilter/nullfiltersession.cc @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl. + * + * Change Date: 2019-07-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +#define MXS_MODULE_NAME "nullfilter" +#include "nullfiltersession.hh" + +NullFilterSession::NullFilterSession(MXS_SESSION* pSession, const NullFilter* pFilter) + : maxscale::FilterSession(pSession) + , m_filter(*pFilter) +{ +} + +NullFilterSession::~NullFilterSession() +{ +} + +//static +NullFilterSession* NullFilterSession::create(MXS_SESSION* pSession, const NullFilter* pFilter) +{ + return new NullFilterSession(pSession, pFilter); +} diff --git a/server/modules/filter/nullfilter/nullfiltersession.hh b/server/modules/filter/nullfilter/nullfiltersession.hh new file mode 100644 index 000000000..3102b8cb3 --- /dev/null +++ b/server/modules/filter/nullfilter/nullfiltersession.hh @@ -0,0 +1,35 @@ +#pragma once +/* + * Copyright (c) 2016 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl. + * + * Change Date: 2019-07-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ + +#include +#include + +class NullFilter; + +class NullFilterSession : public maxscale::FilterSession +{ +public: + ~NullFilterSession(); + + static NullFilterSession* create(MXS_SESSION* pSession, const NullFilter* pFilter); + +private: + NullFilterSession(MXS_SESSION* pSession, const NullFilter* pFilter); + + NullFilterSession(const NullFilterSession&); + NullFilterSession& operator = (const NullFilterSession&); + +private: + const NullFilter& m_filter; +};