Merge branch '2.1' into develop

This commit is contained in:
Johan Wikman 2017-02-14 17:54:27 +02:00
commit 0838401b32
46 changed files with 321 additions and 210 deletions

View File

@ -146,16 +146,6 @@ if(CMAKE_VERSION VERSION_GREATER 2.6)
endif()
endif()
IF(DEFINED OLEVEL)
if((OLEVEL GREATER -1) AND (OLEVEL LESS 4) )
set(FLAGS "${FLAGS} -O${OLEVEL}" CACHE STRING "Compilation flags" FORCE)
message(STATUS "Optimization level at: ${OLEVEL}")
else()
message(WARNING "Optimization level was set to a bad value, ignoring it. (Valid values are 0-3)")
endif()
endif()
if(GCOV)
set(FLAGS "${FLAGS} -fprofile-arcs -ftest-coverage" CACHE STRING "Compilation flags" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
@ -168,19 +158,19 @@ endif()
if(USE_C99)
message(STATUS "Using C99 standard")
set(CMAKE_C_FLAGS "-std=c99 -D_GNU_SOURCE=1 ${FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -D_GNU_SOURCE=1 ${FLAGS}")
else()
set(CMAKE_C_FLAGS "${FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}")
endif()
set(CMAKE_C_FLAGS_DEBUG "${DEBUG_FLAGS} -DSS_DEBUG -DLOG_ASSERT")
set(CMAKE_C_FLAGS_RELEASE "")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-ggdb")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS} -DSS_DEBUG -DLOG_ASSERT")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wno-uninitialized")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb -Wno-uninitialized")
set(CMAKE_CXX_FLAGS "${FLAGS} -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS_DEBUG "${DEBUG_FLAGS} -DSS_DEBUG -DLOG_ASSERT -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS_RELEASE "-Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-ggdb -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS} -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS} -DSS_DEBUG -DLOG_ASSERT -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-deprecated-declarations -Wno-uninitialized")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -ggdb -Wno-deprecated-declarations -Wno-uninitialized")
include_directories(include)
include_directories(server/inih)

View File

@ -994,7 +994,10 @@ bool getPassword(char *passwd, size_t len)
if (tcsetattr(STDIN_FILENO, 0, &tty_attr) == 0)
{
printf("Password: ");
fgets(passwd, len, stdin);
if (fgets(passwd, len, stdin) == NULL)
{
printf("Failed to read password\n");
}
tty_attr.c_lflag = c_lflag;

View File

@ -568,8 +568,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
INPUT = @CMAKE_SOURCE_DIR@/README @CMAKE_SOURCE_DIR@/server/core @CMAKE_SOURCE_DIR@/server/modules @CMAKE_SOURCE_DIR@/server/include \
@CMAKE_SOURCE_DIR@/log_manager @CMAKE_SOURCE_DIR@/query_classifier @CMAKE_SOURCE_DIR@/utils
INPUT = @CMAKE_SOURCE_DIR@/include/maxscale
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
@ -586,7 +585,7 @@ INPUT_ENCODING = UTF-8
# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90
FILE_PATTERNS = *.c *.h
FILE_PATTERNS = *.h *.hh
# The RECURSIVE tag can be used to turn specify whether or not subdirectories
# should be searched for input files as well. Possible values are YES and NO.

View File

@ -264,7 +264,7 @@ typedef enum skygw_chk_t
(SERVER_IS_SLAVE(s) ? "RUNNING SLAVE" : \
(SERVER_IS_JOINED(s) ? "RUNNING JOINED" : \
(SERVER_IS_NDB(s) ? "RUNNING NDB" : \
((SERVER_IS_RUNNING(s) && SERVER_IN_MAINT(s)) ? "RUNNING MAINTENANCE" : \
((!SERVER_IS_DOWN(s) && SERVER_IN_MAINT(s)) ? "RUNNING MAINTENANCE" : \
(SERVER_IS_RELAY_SERVER(s) ? "RUNNING RELAY" : \
(SERVER_IS_RUNNING(s) ? "RUNNING (only)" : \
(SERVER_IS_DOWN(s) ? "DOWN" : "UNKNOWN STATUS"))))))))

View File

@ -68,17 +68,126 @@ typedef void *MXS_FILTER_SESSION;
*/
typedef struct mxs_filter_object
{
/**
* @brief Create a new instance of the filter
*
* This function is called when a new filter instance is created. The return
* value of this function will be passed as the first parameter to the
* other API functions.
*
* @param name Name of the filter instance
* @param options Filter options
* @param params Filter parameters
*
* @return New filter instance on NULL on error
*/
MXS_FILTER *(*createInstance)(const char *name, char **options, MXS_CONFIG_PARAMETER *params);
/**
* Called to create a new user session within the filter
*
* This function is called when a new filter session is created for a client.
* The return value of this function will be passed as the second parameter
* to the @c routeQuery, @c clientReply, @c closeSession, @c freeSession,
* @c setDownstream and @c setUpstream functions.
*
* @param instance Filter instance
* @param session Client SESSION object
*
* @return New filter session or NULL on error
*/
MXS_FILTER_SESSION *(*newSession)(MXS_FILTER *instance, MXS_SESSION *session);
/**
* @brief Called when a session is closed
*
* The filter should close all objects but not free any memory.
*
* @param instance Filter instance
* @param fsession Filter session
*/
void (*closeSession)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
/**
* @brief Called when a session is freed
*
* The session should free all allocated memory in this function.
*
* @param instance Filter instance
* @param fsession Filter session
*/
void (*freeSession)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
/**
* @brief Sets the downstream component of the filter pipeline
*
* @param instance Filter instance
* @param fsession Filter session
*/
void (*setDownstream)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
/**
* @brief Sets the upstream component of the filter pipeline
*
* @param instance Filter instance
* @param fsession Filter session
*/
void (*setUpstream)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_UPSTREAM *downstream);
/**
* @brief Called on each query that requires routing
*
* TODO: Document how routeQuery should be used
*
* @param instance Filter instance
* @param fsession Filter session
* @param queue Request from the client
*
* @return If successful, the function returns 1. If an error occurs
* and the session should be closed, the function returns 0.
*/
int32_t (*routeQuery)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
/**
* @brief Called for each reply packet
*
* TODO: Document how clientReply should be used
*
* @param instance Filter instance
* @param fsession Filter session
* @param queue Response from the server
*
* @return If successful, the function returns 1. If an error occurs
* and the session should be closed, the function returns 0.
*/
int32_t (*clientReply)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
/**
* @brief Called for diagnostic output
*
* @param instance Filter instance
* @param fsession Filter session, NULL if general information about the filter is queried
* @param dcb DCB where the diagnostic information should be written
*/
void (*diagnostics)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
uint64_t (*getCapabilities)(void);
/**
* @brief Called to obtain the capabilities of the filter
*
* @return Zero or more bitwise-or'd values from the mxs_routing_capability_t enum
*
* @see routing.h
*/
uint64_t (*getCapabilities)(MXS_FILTER *instance);
/**
* @brief Called for destroying a filter instance
*
* @param instance Filter instance
*/
void (*destroyInstance)(MXS_FILTER *instance);
} MXS_FILTER_OBJECT;
/**

View File

@ -183,7 +183,7 @@ protected:
* MyFilterSession* newSession(MXS_SESSION* pSession);
*
* void diagnostics(DCB* pDcb);
* static uint64_t getCapabilities();
* uint64_t getCapabilities();
* };
* @endcode
*
@ -290,11 +290,13 @@ public:
}
}
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* pInstance)
{
uint64_t rv = 0;
MXS_EXCEPTION_GUARD(rv = FilterType::getCapabilities());
FilterType* pFilter = reinterpret_cast<FilterType*>(pInstance);
MXS_EXCEPTION_GUARD(rv = pFilter->getCapabilities());
return rv;
}

View File

@ -16,6 +16,20 @@
MXS_BEGIN_DECLS
extern unsigned int random_jkiss(void);
/**
* @brief Initialize the random number generator
*
* Uses /dev/urandom if available, and warms the generator up with 1000 iterations.
*/
void random_jkiss_init(void);
/**
* @brief Return a pseudo-random number
*
* Return a pseudo-random number that satisfies major tests for random sequences.
*
* @return A random number
*/
unsigned int random_jkiss(void);
MXS_END_DECLS

View File

@ -79,7 +79,7 @@ typedef struct mxs_router_object
DCB* backend_dcb,
mxs_error_action_t action,
bool* succp);
uint64_t (*getCapabilities)(void);
uint64_t (*getCapabilities)(MXS_ROUTER *instance);
void (*destroyInstance)(MXS_ROUTER *instance);
} MXS_ROUTER_OBJECT;

View File

@ -260,8 +260,14 @@ static const char* admin_remove_user(USERS *users, const char* fname,
/** one step back */
MXS_ERROR("Unable to set stream position. ");
}
fgets(line, LINELEN, fp);
fputs(line, fp_tmp);
if (fgets(line, LINELEN, fp))
{
fputs(line, fp_tmp);
}
else
{
MXS_ERROR("Failed to read line from admin users file");
}
}
if (fgetpos(fp, &rpos) != 0)

View File

@ -2512,9 +2512,6 @@ void config_add_defaults(CONFIG_CONTEXT *ctx, const MXS_MODULE_PARAM *params)
if (params[i].default_value &&
config_get_param(ctx->parameters, params[i].name) == NULL)
{
ss_dassert(config_param_is_valid(params, params[i].name,
params[i].default_value, ctx));
bool rv = config_add_param(ctx, params[i].name, params[i].default_value);
MXS_ABORT_IF_FALSE(rv);
}

View File

@ -67,6 +67,7 @@
#include <maxscale/thread.h>
#include <maxscale/utils.h>
#include <maxscale/version.h>
#include <maxscale/random_jkiss.h>
#include "maxscale/config.h"
#include "maxscale/maxscale.h"
@ -303,7 +304,10 @@ static void sigterm_handler(int i)
if (n_shutdowns == 1)
{
write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1);
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
{
printf("Failed to write shutdown message!\n");
}
}
else
{
@ -319,11 +323,17 @@ sigint_handler(int i)
if (n_shutdowns == 1)
{
write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1);
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
{
printf("Failed to write shutdown message!\n");
}
}
else if (n_shutdowns == 2)
{
write(STDERR_FILENO, patience_msg, sizeof(patience_msg) - 1);
if (write(STDERR_FILENO, patience_msg, sizeof(patience_msg) - 1) == -1)
{
printf("Failed to write shutdown message!\n");
}
}
else
{
@ -1666,6 +1676,9 @@ int main(int argc, char **argv)
goto return_main;
}
/** Initialize the random number generator */
random_jkiss_init();
if (!utils_init())
{
const char* logerr = "Failed to initialise utility library.";
@ -2617,7 +2630,10 @@ static int set_user(const char* user)
void write_child_exit_code(int fd, int code)
{
/** Notify the parent process that an error has occurred */
write(fd, &code, sizeof (int));
if (write(fd, &code, sizeof (int)) == -1)
{
printf("Failed to write child process message!\n");
}
close(fd);
}

View File

@ -17,6 +17,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <maxscale/alloc.h>
#include <maxscale/atomic.h>
#include <maxscale/hashtable.h>
@ -741,7 +742,12 @@ hashtable_save(HASHTABLE *table, const char *filename,
close(fd);
return -1;
}
write(fd, &rval, sizeof(rval)); // Write zero counter, will be overrwriten at end
if (write(fd, &rval, sizeof(rval)) == -1) // Write zero counter, will be overrwriten at end
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to write hashtable item count: %d, %s", errno,
strerror_r(errno, err, sizeof(err)));
}
if ((iter = hashtable_iterator(table)) != NULL)
{
while ((key = hashtable_next(iter)) != NULL)
@ -766,7 +772,12 @@ hashtable_save(HASHTABLE *table, const char *filename,
/* Now go back and write the count of entries */
if (lseek(fd, 7L, SEEK_SET) != -1)
{
write(fd, &rval, sizeof(rval));
if (write(fd, &rval, sizeof(rval)) == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to write hashtable item count: %d, %s", errno,
strerror_r(errno, err, sizeof(err)));
}
}
close(fd);

View File

@ -2986,7 +2986,8 @@ int mxs_log_message(int priority,
assert(!true);
}
assert(len == augmentation_len);
(void)len;
ss_dassert(len == augmentation_len);
}
va_start(valist, format);

View File

@ -958,17 +958,23 @@ static const char* mon_get_event_name(MXS_MONITOR_SERVERS* node)
static void mon_append_node_names(MXS_MONITOR_SERVERS* servers, char* dest, int len, int status)
{
char *separator = "";
char arr[MAX_SERVER_NAME_LEN + 32]; // Some extra space for port
char arr[MAX_SERVER_NAME_LEN + 64]; // Some extra space for port and separator
dest[0] = '\0';
while (servers && strlen(dest) < (len - strlen(separator)))
while (servers && len)
{
if (status == 0 || servers->server->status & status)
{
strncat(dest, separator, len);
snprintf(arr, sizeof(arr), "%s%s:%d", separator, servers->server->name,
servers->server->port);
separator = ",";
snprintf(arr, sizeof(arr), "%s:%d", servers->server->name, servers->server->port);
strncat(dest, arr, len - strlen(dest) - 1);
int arrlen = strlen(arr);
if (arrlen < len)
{
strcat(dest, arr);
len -= arrlen;
}
}
servers = servers->next;
}

View File

@ -16,14 +16,6 @@
*
* See http://www0.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf for discussion of random
* number generators (RNGs).
*
* @verbatim
* Revision History
*
* Date Who Description
* 26/08/15 Martin Brampton Initial implementation
*
* @endverbatim
*/
#include <stdbool.h>
@ -32,6 +24,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <maxscale/random_jkiss.h>
#include <maxscale/debug.h>
/* Public domain code for JKISS RNG - Comment header added */
@ -41,28 +34,12 @@
static unsigned int x = 123456789, y = 987654321, z = 43219876, c = 6543217; /* Seed variables */
static bool init = false;
static unsigned int random_jkiss_devrand(void);
static void random_init_jkiss(void);
/***
*
* Return a pseudo-random number that satisfies major tests for random sequences
*
* @return uint Random number
*
*/
unsigned int
random_jkiss(void)
unsigned int random_jkiss(void)
{
unsigned long long t;
unsigned int result;
ss_dassert(init);
if (!init)
{
/* Must set init first because initialisation calls this function */
init = true;
random_init_jkiss();
}
x = 314527869 * x + 1234567;
y ^= y << 5;
y ^= y >> 7;
@ -83,8 +60,7 @@ random_jkiss(void)
* @return uint Random number
*
*/
static unsigned int
random_jkiss_devrand(void)
static unsigned int random_jkiss_devrand(void)
{
int fn;
unsigned int r;
@ -102,40 +78,32 @@ random_jkiss_devrand(void)
return r;
}
/***
*
* Initialise the generator using /dev/urandom if available, and warm up
* with 1000 iterations
*
*/
static void
random_init_jkiss(void)
void random_jkiss_init(void)
{
int newrand, i;
if ((newrand = random_jkiss_devrand()) != 0)
if (!init)
{
x = newrand;
}
int newrand, i;
if ((newrand = random_jkiss_devrand()) != 0)
{
y = newrand;
}
if ((newrand = random_jkiss_devrand()) != 0)
{
x = newrand;
}
if ((newrand = random_jkiss_devrand()) != 0)
{
z = newrand;
}
if ((newrand = random_jkiss_devrand()) != 0)
{
y = newrand;
}
if ((newrand = random_jkiss_devrand()) != 0)
{
c = newrand % 698769068 + 1; /* Should be less than 698769069 */
}
if ((newrand = random_jkiss_devrand()) != 0)
{
z = newrand;
}
/* "Warm up" our random number generator */
for (i = 0; i < 100; i++)
{
random_jkiss();
if ((newrand = random_jkiss_devrand()) != 0)
{
c = newrand % 698769068 + 1; /* Should be less than 698769069 */
}
init = true;
}
}

View File

@ -142,7 +142,7 @@ SERVICE* service_alloc(const char *name, const char *router)
return NULL;
}
service->capabilities = service->router->getCapabilities();
service->capabilities = 0;
service->client_count = 0;
service->n_dbref = 0;
service->name = my_name;
@ -485,6 +485,8 @@ int serviceInitialize(SERVICE *service)
if ((service->router_instance = service->router->createInstance(service, router_options)))
{
service->capabilities |= service->router->getCapabilities(service->router_instance);
if (!config_get_global_options()->config_check)
{
listeners = serviceStartAllPorts(service);
@ -1237,7 +1239,7 @@ serviceSetFilters(SERVICE *service, char *filters)
{
if (filter_load(flist[n - 1]))
{
capabilities |= flist[n - 1]->obj->getCapabilities();
capabilities |= flist[n - 1]->obj->getCapabilities(flist[n - 1]->filter);
}
else
{

View File

@ -271,7 +271,6 @@ void CacheFilter::diagnostics(DCB* pDcb)
m_sCache->show(pDcb);
}
// static
uint64_t CacheFilter::getCapabilities()
{
return RCAP_TYPE_TRANSACTION_TRACKING;

View File

@ -39,7 +39,7 @@ public:
void diagnostics(DCB* pDcb);
static uint64_t getCapabilities();
uint64_t getCapabilities();
private:
CacheFilter();

View File

@ -56,7 +56,7 @@ static void freeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER* instance);
#define CCR_DEFAULT_TIME "60"
@ -386,7 +386,7 @@ diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_CONTIGUOUS_INPUT;
}

View File

@ -102,7 +102,7 @@ static void freeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER* instance);
/**
* Rule types
@ -2505,7 +2505,7 @@ diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_STMT_INPUT;
}

View File

@ -33,7 +33,7 @@ static void freeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER* instance);
/**
* The module entry point routine. It is this routine that
@ -238,7 +238,7 @@ diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_CONTIGUOUS_INPUT;
}

View File

@ -38,7 +38,7 @@ static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MX
static void setUpstream(MXS_FILTER *instance, MXS_FILTER_SESSION *session, MXS_UPSTREAM *upstream);
static int32_t routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER *instance);
static int32_t clientReply(MXS_FILTER* instance, MXS_FILTER_SESSION *session, GWBUF *reply);
static bool extract_insert_target(GWBUF *buffer, char* target, int len);
static GWBUF* create_load_data_command(const char *target);
@ -517,7 +517,7 @@ static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *
*
* @return Filter capabilities
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_TRANSACTION_TRACKING;
}

View File

@ -35,7 +35,7 @@ public:
void diagnostics(DCB* pDcb);
static uint64_t getCapabilities();
uint64_t getCapabilities();
void reload(DCB* pOut);

View File

@ -55,7 +55,7 @@ static void setUpstream(MXS_FILTER *instance, MXS_FILTER_SESSION *sdata, MXS_
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *sdata, GWBUF *queue);
static int clientReply(MXS_FILTER *instance, MXS_FILTER_SESSION *sdata, GWBUF *queue);
static void diagnostics(MXS_FILTER *instance, MXS_FILTER_SESSION *sdata, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER *instance);
/* Global symbols of the Module */
@ -419,7 +419,7 @@ static void diagnostics(MXS_FILTER *instance, MXS_FILTER_SESSION *sdata, DCB *dc
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_STMT_INPUT | RCAP_TYPE_STMT_OUTPUT;
}

View File

@ -95,7 +95,7 @@ static void setUpstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static int clientReply(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER *instance);
/**
*Structure used to store messages and their properties.
@ -1510,7 +1510,7 @@ diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_CONTIGUOUS_INPUT;
}

View File

@ -50,7 +50,7 @@ static void freeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER* instance);
typedef struct source_host
{
@ -378,7 +378,7 @@ diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_CONTIGUOUS_INPUT;
}

View File

@ -36,16 +36,6 @@ MXS_ENUM_VALUE capability_values[] =
{ NULL, 0 }
};
struct unit_variables
{
uint64_t capabilities;
bool capabilities_set;
} this_unit =
{
0,
false
};
}
//
@ -81,7 +71,8 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
// NullFilter
//
NullFilter::NullFilter(const char* zName)
NullFilter::NullFilter(const char* zName, uint64_t capabilities)
: m_capabilities(capabilities)
{
MXS_NOTICE("Null filter [%s] created.", zName);
}
@ -97,16 +88,7 @@ NullFilter* NullFilter::create(const char* zName, char**, MXS_CONFIG_PARAMETER*
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);
return new NullFilter(zName, capabilities);
}
@ -121,13 +103,7 @@ 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;
return m_capabilities;
}

View File

@ -26,11 +26,14 @@ public:
void diagnostics(DCB* pDcb);
static uint64_t getCapabilities();
uint64_t getCapabilities();
private:
NullFilter(const char* zName);
NullFilter(const char* zName, uint64_t m_capabilities);
NullFilter(const NullFilter&);
NullFilter& operator = (const NullFilter&);
private:
uint64_t m_capabilities;
};

View File

@ -82,7 +82,7 @@ static void freeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER* instance);
/**
* A instance structure, the assumption is that the option passed
@ -619,7 +619,7 @@ diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_CONTIGUOUS_INPUT;
}

View File

@ -49,7 +49,7 @@ static void freeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER* instance);
static char *regex_replace(const char *sql, pcre2_code *re, pcre2_match_data *study,
const char *replace);
@ -490,7 +490,7 @@ void log_nomatch(REGEX_INSTANCE* inst, char* re, char* old)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_CONTIGUOUS_INPUT;
}

View File

@ -107,7 +107,7 @@ static void setUpstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static int clientReply(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER* instance);
/**
* The instance structure for the TEE filter - this holds the configuration
@ -753,7 +753,7 @@ diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_CONTIGUOUS_INPUT;
}

View File

@ -37,7 +37,7 @@ static void freeSession(MXS_FILTER *instance, MXS_FILTER_SESSION *session);
static void setDownstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_DOWNSTREAM *downstream);
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER* instance);
static void destroyInstance(MXS_FILTER *instance);
@ -243,7 +243,7 @@ diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_NONE;
}

View File

@ -59,7 +59,7 @@ static void setUpstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, MXS_
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static int clientReply(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER* instance);
/**
* A instance structure, the assumption is that the option passed
@ -628,7 +628,7 @@ diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_CONTIGUOUS_INPUT;
}

View File

@ -86,7 +86,7 @@ static void setUpstream(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession,
static int routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static int clientReply(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
static void diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_FILTER* instance);
static void checkNamedPipe(void *args);
/**
@ -602,7 +602,7 @@ diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb)
*
* @return The capabilities of the filter.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_FILTER* instance)
{
return RCAP_TYPE_CONTIGUOUS_INPUT;
}

View File

@ -81,7 +81,7 @@ static void clientReply(MXS_ROUTER *instance, void *router_session, GWBUF *queue
DCB *backend_dcb);
static void errorReply(MXS_ROUTER *instance, void *router_session, GWBUF *message,
DCB *backend_dcb, mxs_error_action_t action, bool *succp);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_ROUTER* instance);
extern int MaxScaleUptime();
extern void avro_get_used_tables(AVRO_INSTANCE *router, DCB *dcb);
void converter_func(void* data);
@ -998,7 +998,7 @@ errorReply(MXS_ROUTER *instance, void *router_session, GWBUF *message, DCB *back
ss_dassert(false);
}
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_ROUTER* instance)
{
return RCAP_TYPE_NO_RSESSION;
}

View File

@ -519,10 +519,9 @@ avro_binlog_end_t avro_read_all_events(AVRO_INSTANCE *router)
case -1:
{
char err_msg[BLRM_STRERROR_R_MSG_SIZE + 1] = "";
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
MXS_ERROR("Failed to read binlog file %s at position %llu"
" (%s).", router->binlog_name,
pos, err_msg);
MXS_ERROR("Failed to read binlog file %s at position %llu (%s).",
router->binlog_name, pos,
strerror_r(errno, err_msg, sizeof(err_msg)));
if (errno == EBADF)
MXS_ERROR("Bad file descriptor in read binlog for file %s"
@ -630,7 +629,6 @@ avro_binlog_end_t avro_read_all_events(AVRO_INSTANCE *router)
{
int event_header_length;
int event_header_ntypes;
int n_events;
/** Extract the event header lengths */
event_header_length = ptr[2 + 50 + 4];
@ -653,15 +651,10 @@ avro_binlog_end_t avro_read_all_events(AVRO_INSTANCE *router)
break;
}
n_events = hdr.event_size - event_header_length - (2 + 50 + 4 + 1);
if (event_header_ntypes < n_events)
uint8_t *checksum = ptr + hdr.event_size - event_header_length - event_header_ntypes;
if (checksum[0] == 1)
{
uint8_t *checksum = ptr + hdr.event_size - event_header_length - event_header_ntypes;
if (checksum[0] == 1)
{
found_chksum = true;
}
found_chksum = true;
}
}
/* Decode CLOSE/STOP Event */
@ -892,7 +885,10 @@ void avro_flush_all_tables(AVRO_INSTANCE *router, enum avrorouter_file_op flush)
}
/** Update the GTID index */
avro_update_index(router);
if (flush == AVROROUTER_FLUSH)
{
avro_update_index(router);
}
}
/**

View File

@ -106,7 +106,7 @@ static void errorReply(MXS_ROUTER *instance,
mxs_error_action_t action,
bool *succp);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_ROUTER* instance);
static int blr_handler_config(void *userdata, const char *section, const char *name, const char *value);
static int blr_handle_config_item(const char *name, const char *value, ROUTER_INSTANCE *inst);
static int blr_load_dbusers(const ROUTER_INSTANCE *router);
@ -1906,7 +1906,7 @@ static void rses_end_locked_router_action(ROUTER_SLAVE *rses)
}
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_ROUTER* instance)
{
return RCAP_TYPE_NO_RSESSION | RCAP_TYPE_CONTIGUOUS_OUTPUT | RCAP_TYPE_RESULTSET_OUTPUT;
}

View File

@ -1197,8 +1197,12 @@ blr_cache_response(ROUTER_INSTANCE *router, char *response, GWBUF *buf)
{
return;
}
write(fd, GWBUF_DATA(buf), GWBUF_LENGTH(buf));
// TODO: Check result.
if (write(fd, GWBUF_DATA(buf), GWBUF_LENGTH(buf)) == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to write cached response: %d, %s",
errno, strerror_r(errno, err, sizeof(err)));
}
close(fd);
}
@ -1251,7 +1255,12 @@ blr_cache_read_response(ROUTER_INSTANCE *router, char *response)
close(fd);
return NULL;
}
read(fd, GWBUF_DATA(buf), statb.st_size);
if (read(fd, GWBUF_DATA(buf), statb.st_size) == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to read cached response: %d, %s",
errno, strerror_r(errno, err, sizeof(err)));
}
close(fd);
return buf;
}
@ -1421,11 +1430,10 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, int fix, int debug)
break;
case -1:
{
char err_msg[BLRM_STRERROR_R_MSG_SIZE + 1] = "";
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to read binlog file %s at position %llu"
" (%s).", router->binlog_name,
pos, err_msg);
" (%s).", router->binlog_name, pos,
strerror_r(errno, err, sizeof(err)));
if (errno == EBADF)
{
@ -1533,7 +1541,7 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, int fix, int debug)
}
else
{
char errmsg[BLRM_STRERROR_R_MSG_SIZE + 1] = "";
char errmsg[BINLOG_ERROR_MSG_LEN + 1] = "";
/* fill replication header struct */
hdr.timestamp = EXTRACT32(hdbuf);
hdr.event_type = hdbuf[4];
@ -1641,12 +1649,12 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, int fix, int debug)
{
if (n == -1)
{
char err_msg[BLRM_STRERROR_R_MSG_SIZE + 1] = "";
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Error reading the event at %llu in %s. "
"%s, expected %d bytes.",
pos, router->binlog_name,
err_msg, hdr.event_size - BINLOG_EVENT_HDR_LEN);
strerror_r(errno, err, sizeof(err)),
hdr.event_size - BINLOG_EVENT_HDR_LEN);
}
else
{
@ -1709,7 +1717,7 @@ blr_read_events_all_events(ROUTER_INSTANCE *router, int fix, int debug)
uint32_t event_size = EXTRACT32(hdbuf + BINLOG_EVENT_LEN_OFFSET);
uint8_t *decrypt_ptr;
unsigned long next_pos;
char errmsg[BLRM_STRERROR_R_MSG_SIZE + 1] = "";
char errmsg[BINLOG_ERROR_MSG_LEN + 1] = "";
/**
* Events are encrypted.

View File

@ -3664,7 +3664,12 @@ blr_start_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave)
router->prevbinlog,
router->last_safe_pos);
/* Truncate previous binlog file to last_safe pos */
truncate(file, router->last_safe_pos);
if (truncate(file, router->last_safe_pos) == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to truncate file: %d, %s",
errno, strerror_r(errno, err, sizeof(err)));
}
/* Log it */
MXS_WARNING("A transaction is still opened at pos %lu"

View File

@ -49,7 +49,7 @@ static void closeSession(MXS_ROUTER *instance, void *router_session);
static void freeSession(MXS_ROUTER *instance, void *router_session);
static int execute(MXS_ROUTER *instance, void *router_session, GWBUF *queue);
static void diagnostics(MXS_ROUTER *instance, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_ROUTER* instance);
extern int execute_cmd(CLI_SESSION *cli);
@ -288,7 +288,7 @@ diagnostics(MXS_ROUTER *instance, DCB *dcb)
return; /* Nothing to do currently */
}
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_ROUTER *instance)
{
return 0;
}

View File

@ -48,7 +48,7 @@ static void closeSession(MXS_ROUTER *instance, void *router_session);
static void freeSession(MXS_ROUTER *instance, void *router_session);
static int execute(MXS_ROUTER *instance, void *router_session, GWBUF *queue);
static void diagnostics(MXS_ROUTER *instance, DCB *dcb);
static uint64_t getCapabilities ();
static uint64_t getCapabilities(MXS_ROUTER* instance);
extern int execute_cmd(CLI_SESSION *cli);
@ -293,7 +293,7 @@ diagnostics(MXS_ROUTER *instance, DCB *dcb)
return; /* Nothing to do currently */
}
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_ROUTER* instance)
{
return 0;
}

View File

@ -70,7 +70,7 @@ static void closeSession(MXS_ROUTER *instance, void *router_session);
static void freeSession(MXS_ROUTER *instance, void *router_session);
static int execute(MXS_ROUTER *instance, void *router_session, GWBUF *queue);
static void diagnostics(MXS_ROUTER *instance, DCB *dcb);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_ROUTER* instance);
static void handleError(MXS_ROUTER *instance,
void *router_session,
GWBUF *errbuf,
@ -392,7 +392,7 @@ diagnostics(MXS_ROUTER *instance, DCB *dcb)
* Not used for the maxinfo router
*/
static uint64_t
getCapabilities(void)
getCapabilities(MXS_ROUTER* instance)
{
return 0;
}

View File

@ -98,7 +98,7 @@ static void clientReply(MXS_ROUTER *instance, void *router_session, GWBUF *queue
DCB *backend_dcb);
static void handleError(MXS_ROUTER *instance, void *router_session, GWBUF *errbuf,
DCB *problem_dcb, mxs_error_action_t action, bool *succp);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_ROUTER* instance);
static bool rses_begin_locked_router_action(ROUTER_CLIENT_SES* rses);
static void rses_end_locked_router_action(ROUTER_CLIENT_SES* rses);
static SERVER_REF *get_root_master(SERVER_REF *servers);
@ -785,7 +785,7 @@ static void rses_end_locked_router_action(ROUTER_CLIENT_SES* rses)
spinlock_release(&rses->rses_lock);
}
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_ROUTER* instance)
{
return RCAP_TYPE_NONE;
}

View File

@ -79,7 +79,7 @@ static void clientReply(MXS_ROUTER *instance, void *router_session, GWBUF *queue
static void handleError(MXS_ROUTER *instance, void *router_session,
GWBUF *errmsgbuf, DCB *backend_dcb,
mxs_error_action_t action, bool *succp);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_ROUTER* instance);
/*
* End of the API functions; now the module structure that links to them.
@ -864,7 +864,7 @@ lock_failed:
*
* @return RCAP_TYPE_STMT_INPUT.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_ROUTER* instance)
{
return RCAP_TYPE_STMT_INPUT | RCAP_TYPE_TRANSACTION_TRACKING;
}

View File

@ -81,7 +81,7 @@ static route_target_t get_shard_route_target(qc_query_type_t qtype,
bool trx_active,
HINT* hint);
static uint64_t getCapabilities(void);
static uint64_t getCapabilities(MXS_ROUTER* instance);
static bool connect_backend_servers(backend_ref_t* backend_ref,
int router_nservers,
@ -3320,7 +3320,7 @@ static rses_property_t* mysql_sescmd_get_property(mysql_sescmd_t* scmd)
/**
* Return RCAP_TYPE_STMT_INPUT.
*/
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_ROUTER* instance)
{
return RCAP_TYPE_STMT_INPUT;
}

View File

@ -22,7 +22,7 @@ static void freeSession(MXS_ROUTER *instance, void *session);
static int routeQuery(MXS_ROUTER *instance, void *session, GWBUF *queue);
static void clientReply(MXS_ROUTER *instance, void *session, GWBUF *queue, DCB*);
static void diagnostic(MXS_ROUTER *instance, DCB *dcb);
static uint64_t getCapabilities ();
static uint64_t getCapabilities(MXS_ROUTER* instance);
static void handleError(MXS_ROUTER *instance,
void *router_session,
GWBUF *errbuf,
@ -150,7 +150,7 @@ diagnostic(MXS_ROUTER *instance, DCB *dcb)
{
}
static uint64_t getCapabilities(void)
static uint64_t getCapabilities(MXS_ROUTER* instance)
{
return 0;
}