This commit is contained in:
vraatikka 2013-08-14 11:27:14 +03:00
commit 4051796653
9 changed files with 61 additions and 290 deletions

View File

@ -1047,7 +1047,7 @@ int Binlog_tcp_driver::set_position(const std::string &str, unsigned long positi
against the server. The binlog dump command is executed asynchronously
in another thread.
*/
if (connect(m_user, m_passwd, m_host, m_port, gtid, str, position) == 0)
if (connect(m_user, m_passwd, m_host, m_port, gtid, str, (size_t)position) == 0)
return ERR_OK;
else
return ERR_FAIL;

View File

@ -37,8 +37,8 @@
* that is required for each of the backend servers.
*/
typedef struct backend {
SERVER *server; /**< The server itself */
int count; /**< Number of connections to the server */
SERVER *server; /**< The server itself */
int current_connection_count; /**< Number of connections to the server */
} BACKEND;
/**

View File

@ -59,6 +59,7 @@
* 22/07/2013 Mark Riddoch Addition of joined router option for Galera
* clusters
* 31/07/2013 Massimiliano Pinto Added a check for candidate server, if NULL return
* 12/08/2013 Mark Riddoch Log unsupported router options
*
* @endverbatim
*/
@ -186,7 +187,7 @@ int i, n;
return NULL;
}
inst->servers[n]->server = server;
inst->servers[n]->count = 0;
inst->servers[n]->current_connection_count = 0;
n++;
}
inst->servers[n] = NULL;
@ -215,6 +216,11 @@ int i, n;
inst->bitmask |= (SERVER_JOINED);
inst->bitvalue |= SERVER_JOINED;
}
else
{
skygw_log_write(LOGFILE_ERROR,
"Unsupported router option %s for readconnroute\n", options[i]);
}
}
}
@ -246,8 +252,7 @@ CLIENT_SESSION *client;
BACKEND *candidate = NULL;
int i;
if ((client = (CLIENT_SESSION *)malloc(sizeof(CLIENT_SESSION))) == NULL)
{
if ((client = (CLIENT_SESSION *)malloc(sizeof(CLIENT_SESSION))) == NULL) {
return NULL;
}
/*
@ -256,23 +261,6 @@ int i;
* connection router.
*/
/* First find a running server to set as our initial candidate server */
for (i = 0; inst->servers[i]; i++)
{
if (inst->servers[i] && SERVER_IS_RUNNING(inst->servers[i]->server)
&& (inst->servers[i]->server->status & inst->bitmask) == inst->bitvalue)
{
candidate = inst->servers[i];
skygw_log_write(
LOGFILE_TRACE,
"Selected server in port %d to as candidate. "
"Connections : %d\n",
candidate->server->port,
candidate->count);
break;
}
}
/*
* Loop over all the servers and find any that have fewer connections than our
* candidate server.
@ -285,33 +273,40 @@ int i;
* become the new candidate. This has the effect of spreading the connections
* over different servers during periods of very low load.
*/
for (i = 1; inst->servers[i]; i++)
{
skygw_log_write(
LOGFILE_TRACE,
"Examine server in port %d with %d connections. Status is %d, "
"inst->bitvalue is %d",
inst->servers[i]->server->port,
inst->servers[i]->count,
inst->servers[i]->server->status,
inst->bitmask);
for (i = 0; inst->servers[i]; i++) {
if(inst->servers[i]) {
skygw_log_write(
LOGFILE_TRACE,
"Examine server in port %d with %d connections. Status is %d, "
"inst->bitvalue is %d",
inst->servers[i]->server->port,
inst->servers[i]->current_connection_count,
inst->servers[i]->server->status,
inst->bitmask);
}
if (inst->servers[i] && SERVER_IS_RUNNING(inst->servers[i]->server)
&& (inst->servers[i]->server->status & inst->bitmask) == inst->bitvalue)
{
if (inst->servers[i]->count < candidate->count)
{
candidate = inst->servers[i];
if (inst->servers[i] && SERVER_IS_RUNNING(inst->servers[i]->server)
&& (inst->servers[i]->server->status & inst->bitmask) == inst->bitvalue) {
/* If no candidate set, set first running server as
our initial candidate server */
if (candidate == NULL) {
candidate = inst->servers[i];
} else if (inst->servers[i]->current_connection_count < candidate->current_connection_count) {
/* This running server has fewer
connections, set it as a new candidate */
candidate = inst->servers[i];
} else if (inst->servers[i]->current_connection_count == candidate->current_connection_count &&
inst->servers[i]->server->stats.n_connections
< candidate->server->stats.n_connections) {
/* This running server has the same number
of connections currently as the candidate
but has had fewer connections over time
than candidate, set this server to candidate*/
candidate = inst->servers[i];
}
else if (inst->servers[i]->count == candidate->count &&
inst->servers[i]->server->stats.n_connections
< candidate->server->stats.n_connections)
{
candidate = inst->servers[i];
}
}
}
/* no candidate server here, clean and return NULL */
if (!candidate) {
free(client);
@ -322,15 +317,16 @@ int i;
* We now have the server with the least connections.
* Bump the connection count for this server
*/
atomic_add(&candidate->count, 1);
atomic_add(&candidate->current_connection_count, 1);
client->backend = candidate;
skygw_log_write(
LOGFILE_TRACE,
"Final selection is server in port %d. "
"Connections : %d\n",
candidate->server->port,
candidate->count);
candidate->current_connection_count);
/*
* Open a backend connection, putting the DCB for this
* connection in the client->dcb
@ -339,7 +335,7 @@ int i;
if ((client->dcb = dcb_connect(candidate->server, session,
candidate->server->protocol)) == NULL)
{
atomic_add(&candidate->count, -1);
atomic_add(&candidate->current_connection_count, -1);
free(client);
return NULL;
}
@ -371,7 +367,7 @@ CLIENT_SESSION *session = (CLIENT_SESSION *)router_session;
* Close the connection to the backend
*/
session->dcb->func.close(session->dcb);
atomic_add(&session->backend->count, -1);
atomic_add(&session->backend->current_connection_count, -1);
atomic_add(&session->backend->server->stats.n_current, -1);
spinlock_acquire(&inst->lock);

View File

@ -33,35 +33,11 @@ IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
FOREACH(file
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libtable_replication_consistency.so.0.1"
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libtable_replication_consistency.so.1"
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libtable_replication_consistency.so"
)
IF(EXISTS "${file}" AND
NOT IS_SYMLINK "${file}")
FILE(RPATH_CHECK
FILE "${file}"
RPATH "")
ENDIF()
ENDFOREACH()
FILE(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" TYPE SHARED_LIBRARY FILES
"/home/jan/skysql/maxscale/table_replication_consistency/libtable_replication_consistency.so.0.1"
"/home/jan/skysql/maxscale/table_replication_consistency/libtable_replication_consistency.so.1"
"/home/jan/skysql/maxscale/table_replication_consistency/libtable_replication_consistency.so"
"/home/jan/skysql/maxscale/table_replication_consistency/CMakeFiles/CMakeRelink.dir/libtable_replication_consistency.so.0.1"
"/home/jan/skysql/maxscale/table_replication_consistency/CMakeFiles/CMakeRelink.dir/libtable_replication_consistency.so.1"
"/home/jan/skysql/maxscale/table_replication_consistency/CMakeFiles/CMakeRelink.dir/libtable_replication_consistency.so"
)
FOREACH(file
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libtable_replication_consistency.so.0.1"
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libtable_replication_consistency.so.1"
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libtable_replication_consistency.so"
)
IF(EXISTS "${file}" AND
NOT IS_SYMLINK "${file}")
IF(CMAKE_INSTALL_DO_STRIP)
EXECUTE_PROCESS(COMMAND "/usr/bin/strip" "${file}")
ENDIF(CMAKE_INSTALL_DO_STRIP)
ENDIF()
ENDFOREACH()
ENDIF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")

View File

@ -2,13 +2,16 @@ project (test)
cmake_minimum_required (VERSION 2.6)
# --------- Find crypt
FIND_LIBRARY(LIB_CRYPTO crypto /opt/local/lib /opt/lib /usr/lib /usr/local/lib)
FIND_LIBRARY(CRYPTO NAMES libcrypto.a /opt/local/lib /opt/lib /usr/lib /usr/local/lib /usr/local/ssl/lib)
FIND_LIBRARY(SSL NAMES libssl.a /opt/local/lib /opt/lib /usr/lib /usr/local/lib /usr/local/ssl/lib)
FIND_LIBRARY(REPLICATION replication /opt/local/lib /opt/lib /usr/lib /usr/local/lib ../)
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
# Find MySQL client library and header files
find_path(MySQL_INCLUDE_DIR mysql.h
/usr/local/include/mysql /usr/include/mysql)
/usr/local/include/mysql /usr/include/mysql /usr/local/mysql/include)
include_directories(${MySQL_INCLUDE_DIR})
#SkySQL
@ -23,10 +26,10 @@ include_directories(${TRC_INCLUDE_DIR})
# Build rule for example
foreach(prog Example)
ADD_EXECUTABLE(${prog} ${prog}.c ../../utils/skygw_utils.o /usr/local/mysql/lib/libmysqld.a)
TARGET_LINK_LIBRARIES(${prog} table_replication_consistency.a replication boost_system boost_thread pthread stdc++ crypt aio log_manager)
TARGET_LINK_LIBRARIES(${prog} table_replication_consistency.a replication boost_system boost_thread pthread stdc++ ${SSL} ${CRYPTO} crypt z dl aio log_manager)
endforeach()
foreach(prog test)
ADD_EXECUTABLE(${prog} ${prog}.cpp ../../utils/skygw_utils.o /usr/local/mysql/lib/libmysqld.a)
TARGET_LINK_LIBRARIES(${prog} table_replication_consistency.a replication boost_system boost_thread pthread stdc++ crypt aio log_manager)
TARGET_LINK_LIBRARIES(${prog} table_replication_consistency.a replication boost_system boost_thread pthread stdc++ ${SSL} ${CRYPTO} crypt z dl aio log_manager)
endforeach()

View File

@ -1,204 +0,0 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file.
RM = /usr/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/jan/skysql/skygateway/skygateway/table_replication_consistency/test
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/jan/skysql/skygateway/skygateway/table_replication_consistency/test
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..."
/usr/bin/cmake -i .
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /home/jan/skysql/skygateway/skygateway/table_replication_consistency/test/CMakeFiles /home/jan/skysql/skygateway/skygateway/table_replication_consistency/test/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /home/jan/skysql/skygateway/skygateway/table_replication_consistency/test/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast
# clear depends
depend:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
#=============================================================================
# Target rules for targets named Example
# Build rule for target.
Example: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 Example
.PHONY : Example
# fast build rule for target.
Example/fast:
$(MAKE) -f CMakeFiles/Example.dir/build.make CMakeFiles/Example.dir/build
.PHONY : Example/fast
#=============================================================================
# Target rules for targets named test
# Build rule for target.
test: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 test
.PHONY : test
# fast build rule for target.
test/fast:
$(MAKE) -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
.PHONY : test/fast
Example.o: Example.c.o
.PHONY : Example.o
# target to build an object file
Example.c.o:
$(MAKE) -f CMakeFiles/Example.dir/build.make CMakeFiles/Example.dir/Example.c.o
.PHONY : Example.c.o
Example.i: Example.c.i
.PHONY : Example.i
# target to preprocess a source file
Example.c.i:
$(MAKE) -f CMakeFiles/Example.dir/build.make CMakeFiles/Example.dir/Example.c.i
.PHONY : Example.c.i
Example.s: Example.c.s
.PHONY : Example.s
# target to generate assembly for a file
Example.c.s:
$(MAKE) -f CMakeFiles/Example.dir/build.make CMakeFiles/Example.dir/Example.c.s
.PHONY : Example.c.s
test.o: test.cpp.o
.PHONY : test.o
# target to build an object file
test.cpp.o:
$(MAKE) -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/test.cpp.o
.PHONY : test.cpp.o
test.i: test.cpp.i
.PHONY : test.i
# target to preprocess a source file
test.cpp.i:
$(MAKE) -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/test.cpp.i
.PHONY : test.cpp.i
test.s: test.cpp.s
.PHONY : test.s
# target to generate assembly for a file
test.cpp.s:
$(MAKE) -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/test.cpp.s
.PHONY : test.cpp.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... Example"
@echo "... edit_cache"
@echo "... rebuild_cache"
@echo "... test"
@echo "... Example.o"
@echo "... Example.i"
@echo "... Example.s"
@echo "... test.o"
@echo "... test.i"
@echo "... test.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

View File

@ -1,4 +1,4 @@
# Install script for directory: /home/jan/skysql/skygateway/skygateway/table_replication_consistency/test
# Install script for directory: /home/jan/skysql/maxscale/table_replication_consistency/test
# Set the install prefix
IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
@ -12,7 +12,7 @@ IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
ELSE(BUILD_TYPE)
SET(CMAKE_INSTALL_CONFIG_NAME "Debug")
SET(CMAKE_INSTALL_CONFIG_NAME "")
ENDIF(BUILD_TYPE)
MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
@ -38,7 +38,7 @@ ELSE(CMAKE_INSTALL_COMPONENT)
SET(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
ENDIF(CMAKE_INSTALL_COMPONENT)
FILE(WRITE "/home/jan/skysql/skygateway/skygateway/table_replication_consistency/test/${CMAKE_INSTALL_MANIFEST}" "")
FILE(WRITE "/home/jan/skysql/maxscale/table_replication_consistency/test/${CMAKE_INSTALL_MANIFEST}" "")
FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES})
FILE(APPEND "/home/jan/skysql/skygateway/skygateway/table_replication_consistency/test/${CMAKE_INSTALL_MANIFEST}" "${file}\n")
FILE(APPEND "/home/jan/skysql/maxscale/table_replication_consistency/test/${CMAKE_INSTALL_MANIFEST}" "${file}\n")
ENDFOREACH(file)

View File

@ -72,7 +72,7 @@ int main(int argc, char** argv)
NULL
};
skygw_logmanager_init(NULL, 3, (char **)&opts);
skygw_logmanager_init(3, (char **)&opts);
err = tb_replication_consistency_init(mrl, k, 5, TBR_TRACE_DEBUG);