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.
This commit is contained in:
parent
0e037e4005
commit
b46bc47c87
@ -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)
|
||||
|
7
server/modules/filter/nullfilter/CMakeLists.txt
Normal file
7
server/modules/filter/nullfilter/CMakeLists.txt
Normal file
@ -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)
|
133
server/modules/filter/nullfilter/nullfilter.cc
Normal file
133
server/modules/filter/nullfilter/nullfilter.cc
Normal file
@ -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 <string>
|
||||
#include <maxscale/utils.h>
|
||||
|
||||
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;
|
||||
}
|
36
server/modules/filter/nullfilter/nullfilter.hh
Normal file
36
server/modules/filter/nullfilter/nullfilter.hh
Normal file
@ -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 <maxscale/cppdefs.hh>
|
||||
#include <maxscale/filter.hh>
|
||||
#include "nullfiltersession.hh"
|
||||
|
||||
class NullFilter : public maxscale::Filter<NullFilter, NullFilterSession>
|
||||
{
|
||||
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&);
|
||||
};
|
31
server/modules/filter/nullfilter/nullfiltersession.cc
Normal file
31
server/modules/filter/nullfilter/nullfiltersession.cc
Normal file
@ -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);
|
||||
}
|
35
server/modules/filter/nullfilter/nullfiltersession.hh
Normal file
35
server/modules/filter/nullfilter/nullfiltersession.hh
Normal file
@ -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 <maxscale/cppdefs.hh>
|
||||
#include <maxscale/filter.hh>
|
||||
|
||||
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;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user