Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
WL#12030 Decrease the cluster metadata TTL to 0.5 second
Browse files Browse the repository at this point in the history
Decreased default metadata cache ttl to 0.5 second
Allowed millisecond resolution for metadata cache ttl
Adjusted metadata cache refresh logic accordingly
  • Loading branch information
Andrzej Religa committed Jun 15, 2018
1 parent 6e624eb commit 7982f20
Show file tree
Hide file tree
Showing 39 changed files with 1,062 additions and 292 deletions.
161 changes: 161 additions & 0 deletions cmake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,167 @@

set(_TEST_RUNTIME_DIR ${PROJECT_BINARY_DIR}/tests)

# We include GMock without touching the compile flags. GMock can
# handle that itself. It will also indirectly create targets for gmock
# and gtest.
#
# Two alternatives for locating GMock *source code*:
# 1. If WITH_GMOCK is given, this is expected to be the location of
# the *source code*.
# 2. If WITH_GMOCK is not given, it will look in the 'ext' directory
# in the source root.
if(ENABLE_TESTS)
if(TARGET gmock)
# don't build gmock, if the parent already built it

# copying from unittest/gunit/CMakeFiles.txt
# this should all be global-variables or a cmake/ file
if(NOT DOWNLOAD_ROOT)
set(DOWNLOAD_ROOT ${CMAKE_SOURCE_DIR}/source_downloads)
endif()

# We want googletest version 1.8, which also contains googlemock.
set(GMOCK_PACKAGE_NAME "release-1.8.0")

if(DEFINED ENV{WITH_GMOCK} AND NOT DEFINED WITH_GMOCK)
file(TO_CMAKE_PATH "$ENV{WITH_GMOCK}" WITH_GMOCK)
ENDIF()

if(LOCAL_GMOCK_ZIP
AND NOT ${LOCAL_GMOCK_ZIP} MATCHES ".*${GMOCK_PACKAGE_NAME}\\.zip")
set(LOCAL_GMOCK_ZIP 0)
endif()

if(WITH_GMOCK)
## Did we get a full path name, including file name?
if(${WITH_GMOCK} MATCHES ".*\\.zip")
GET_FILENAME_COMPONENT(GMOCK_DIR ${WITH_GMOCK} PATH)
GET_FILENAME_COMPONENT(GMOCK_ZIP ${WITH_GMOCK} NAME)
FIND_FILE(LOCAL_GMOCK_ZIP
NAMES ${GMOCK_ZIP}
PATHS ${GMOCK_DIR}
NO_DEFAULT_PATH
)
else()
## Did we get a path name to the directory of the .zip file?
## Check for both release-x.y.z.zip and googletest-release-x.y.z.zip
FIND_FILE(LOCAL_GMOCK_ZIP
NAMES "${GMOCK_PACKAGE_NAME}.zip" "googletest-${GMOCK_PACKAGE_NAME}.zip"
PATHS ${WITH_GMOCK}
NO_DEFAULT_PATH
)
## If WITH_GMOCK is a directory, use it for download.
set(DOWNLOAD_ROOT ${WITH_GMOCK})
endif()
MESSAGE(STATUS "Local gmock zip ${LOCAL_GMOCK_ZIP}")
endif()

set(GMOCK_SOURCE_DIR ${DOWNLOAD_ROOT}/googletest-${GMOCK_PACKAGE_NAME}/googlemock)
set(GTEST_SOURCE_DIR ${DOWNLOAD_ROOT}/googletest-${GMOCK_PACKAGE_NAME}/googletest)

# introduce some compat
set(GTEST_INCLUDE_DIRS ${GMOCK_INCLUDE_DIRS})
message("yyy seting GTEST_INCLUDE_DIRS to ${GTEST_INCLUDE_DIRS}")

ADD_LIBRARY(gmock_main STATIC ${GMOCK_SOURCE_DIR}/src/gmock_main.cc)
target_link_libraries(gmock_main gmock)
target_include_directories(gmock_main
PUBLIC ${GMOCK_INCLUDE_DIRS})
ADD_LIBRARY(gtest_main STATIC ${GTEST_SOURCE_DIR}/src/gtest_main.cc)
target_include_directories(gtest_main
PUBLIC ${GMOCK_INCLUDE_DIRS})

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set_target_properties(gtest_main gmock_main
PROPERTIES
COMPILE_FLAGS "-Wno-undef -Wno-conversion")
endif()

set(TEST_LIBRARIES gmock gtest gmock_main gtest_main)
else()
if(WITH_GMOCK)

# There is a known gtest/gmock bug that surfaces with the gcc-6.x causing tests crashes:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833450
# We have a patch for it in the gmock we bundle but if the user wants to use
# it's own gtest/gmock we need to prevent it if the gcc-6.x is used
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "6.0" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "6.0"))
message(FATAL_ERROR "Parameter WITH_GMOCK is not supported for gcc-6 or greater."
"You need to either disable the tests or use the bundled gmock (removing WITH_GMOCK parameter).")
endif()

set(_gmock_root ${WITH_GMOCK})
set(_gtest_root ${WITH_GMOCK}/gtest)
elseif(EXISTS "${CMAKE_SOURCE_DIR}/ext/gmock/CMakeLists.txt")
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/ext/gtest/CMakeLists.txt")
message(FATAL_ERROR "Cannot find GTest repository under ${CMAKE_SOURCE_DIR}/ext/gtest")
endif()
set(_gmock_root "${CMAKE_SOURCE_DIR}/ext/gmock")
set(_gtest_root "${CMAKE_SOURCE_DIR}/ext/gtest")
elseif(GMOCK_SOURCE_DIR)
# means we are part of the server and GMOCK was downloaded
set(_gmock_root ${GMOCK_SOURCE_DIR})
set(_gtest_root ${GMOCK_SOURCE_DIR}/gtest)
else()
# means we are part of the server and GMOCK is missing
# act as other server components, disable the tests
SET (ENABLE_TESTS 0)
SET (ENABLE_TESTS 0 PARENT_SCOPE)
endif()

if (ENABLE_TESTS)
if(NOT EXISTS "${_gmock_root}/CMakeLists.txt")
message(WARNING
"Unable to find GMock source, not possible to build tests. Either "
"disable tests with ENABLE_TESTS=no or download the source code "
"for GMock (available at https://github.com/google/googlemock) and "
"set WITH_GMOCK to the directory of the unpacked source code.")
endif()

message(STATUS "Found GMock source under ${_gmock_root}")
add_subdirectory(${_gmock_root} ext/gmock)

# Setting variables that are normally discovered using FindXXX.cmake
set(GTEST_INCLUDE_DIRS ${_gtest_root}/include)
message("yyy seting GTEST_INCLUDE_DIRS to ${GTEST_INCLUDE_DIRS}")
set(GTEST_LIBRARIES gtest)
set(GTEST_MAIN_LIBRARIES gtest_main)
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})

set(GMOCK_INCLUDE_DIRS ${_gmock_root}/include)
set(GMOCK_LIBRARIES gmock)
set(GMOCK_MAIN_LIBRARIES gmock_main)
set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES})

set(TEST_LIBRARIES ${GMOCK_BOTH_LIBRARIES} ${GTEST_BOTH_LIBRARIES})

# Since GMock and GTest do not set
# INTERFACE_SYSTEM_INCLUDE_DIRECTORIES, we do that here. This means
# that any targets that reference one of these libraries will
# "automatically" have the include directories for these libraries
# added to their build flags. We cannot use "SYSTEM" since that is
# not available in 2.8.9 (it was introduced in 2.8.12).
target_include_directories(gmock PUBLIC ${GMOCK_INCLUDE_DIRS})
target_include_directories(gmock_main PUBLIC ${GMOCK_INCLUDE_DIRS})
target_include_directories(gtest PUBLIC ${GTEST_INCLUDE_DIRS})
target_include_directories(gtest_main PUBLIC ${GTEST_INCLUDE_DIRS})

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

set (comp_flags_ "-Wno-undef -Wno-missing-field-initializers")
if(COMPILER_HAS_WARNING_MISSING_FORMAT_ATTRIBUTE)
set(comp_flags_ "${comp_flags_} -Wno-missing-format-attribute")
endif()

set_target_properties(gtest gtest_main gmock gmock_main
PROPERTIES
COMPILE_FLAGS "${comp_flags_}")
endif()
endif()
endif()
endif()

# Set {RUNTIME,LIBRARY}_OUTPUT_DIRECTORY properties of a target to the stage dir.
# On unix platforms this is just one directory, but on Windows it's per build-type,
# e.g. build/stage/Debug/lib, build/stage/Release/lib, etc
Expand Down
159 changes: 0 additions & 159 deletions src/harness/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,165 +35,6 @@ set(HARNESS_INSTALL_PLUGINS YES CACHE BOOL

message(STATUS "Harness will install plugins in ${HARNESS_INSTALL_LIBRARY_DIR}/${HARNESS_NAME}")

# We include GMock without touching the compile flags. GMock can
# handle that itself. It will also indirectly create targets for gmock
# and gtest.
#
# Two alternatives for locating GMock *source code*:
# 1. If WITH_GMOCK is given, this is expected to be the location of
# the *source code*.
# 2. If WITH_GMOCK is not given, it will look in the 'ext' directory
# in the source root.
if(ENABLE_TESTS)
if(TARGET gmock)
# don't build gmock, if the parent already built it

# copying from unittest/gunit/CMakeFiles.txt
# this should all be global-variables or a cmake/ file
if(NOT DOWNLOAD_ROOT)
set(DOWNLOAD_ROOT ${CMAKE_SOURCE_DIR}/source_downloads)
endif()

# We want googletest version 1.8, which also contains googlemock.
set(GMOCK_PACKAGE_NAME "release-1.8.0")

if(DEFINED ENV{WITH_GMOCK} AND NOT DEFINED WITH_GMOCK)
file(TO_CMAKE_PATH "$ENV{WITH_GMOCK}" WITH_GMOCK)
ENDIF()

if(LOCAL_GMOCK_ZIP
AND NOT ${LOCAL_GMOCK_ZIP} MATCHES ".*${GMOCK_PACKAGE_NAME}\\.zip")
set(LOCAL_GMOCK_ZIP 0)
endif()

if(WITH_GMOCK)
## Did we get a full path name, including file name?
if(${WITH_GMOCK} MATCHES ".*\\.zip")
GET_FILENAME_COMPONENT(GMOCK_DIR ${WITH_GMOCK} PATH)
GET_FILENAME_COMPONENT(GMOCK_ZIP ${WITH_GMOCK} NAME)
FIND_FILE(LOCAL_GMOCK_ZIP
NAMES ${GMOCK_ZIP}
PATHS ${GMOCK_DIR}
NO_DEFAULT_PATH
)
else()
## Did we get a path name to the directory of the .zip file?
## Check for both release-x.y.z.zip and googletest-release-x.y.z.zip
FIND_FILE(LOCAL_GMOCK_ZIP
NAMES "${GMOCK_PACKAGE_NAME}.zip" "googletest-${GMOCK_PACKAGE_NAME}.zip"
PATHS ${WITH_GMOCK}
NO_DEFAULT_PATH
)
## If WITH_GMOCK is a directory, use it for download.
set(DOWNLOAD_ROOT ${WITH_GMOCK})
endif()
MESSAGE(STATUS "Local gmock zip ${LOCAL_GMOCK_ZIP}")
endif()

set(GMOCK_SOURCE_DIR ${DOWNLOAD_ROOT}/googletest-${GMOCK_PACKAGE_NAME}/googlemock)
set(GTEST_SOURCE_DIR ${DOWNLOAD_ROOT}/googletest-${GMOCK_PACKAGE_NAME}/googletest)

# introduce some compat
set(GTEST_INCLUDE_DIRS ${GMOCK_INCLUDE_DIRS})

ADD_LIBRARY(gmock_main STATIC ${GMOCK_SOURCE_DIR}/src/gmock_main.cc)
target_link_libraries(gmock_main gmock)
target_include_directories(gmock_main
PUBLIC ${GMOCK_INCLUDE_DIRS})
ADD_LIBRARY(gtest_main STATIC ${GTEST_SOURCE_DIR}/src/gtest_main.cc)
target_include_directories(gtest_main
PUBLIC ${GMOCK_INCLUDE_DIRS})

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set_target_properties(gtest_main gmock_main
PROPERTIES
COMPILE_FLAGS "-Wno-undef -Wno-conversion")
endif()

set(TEST_LIBRARIES gmock gtest gmock_main gtest_main)
else()
if(WITH_GMOCK)

# There is a known gtest/gmock bug that surfaces with the gcc-6.x causing tests crashes:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833450
# We have a patch for it in the gmock we bundle but if the user wants to use
# it's own gtest/gmock we need to prevent it if the gcc-6.x is used
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "6.0" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "6.0"))
message(FATAL_ERROR "Parameter WITH_GMOCK is not supported for gcc-6 or greater."
"You need to either disable the tests or use the bundled gmock (removing WITH_GMOCK parameter).")
endif()

set(_gmock_root ${WITH_GMOCK})
set(_gtest_root ${WITH_GMOCK}/gtest)
elseif(EXISTS "${CMAKE_SOURCE_DIR}/ext/gmock/CMakeLists.txt")
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/ext/gtest/CMakeLists.txt")
message(FATAL_ERROR "Cannot find GTest repository under ${CMAKE_SOURCE_DIR}/ext/gtest")
endif()
set(_gmock_root "${CMAKE_SOURCE_DIR}/ext/gmock")
set(_gtest_root "${CMAKE_SOURCE_DIR}/ext/gtest")
elseif(GMOCK_SOURCE_DIR)
# means we are part of the server and GMOCK was downloaded
set(_gmock_root ${GMOCK_SOURCE_DIR})
set(_gtest_root ${GMOCK_SOURCE_DIR}/gtest)
else()
# means we are part of the server and GMOCK is missing
# act as other server components, disable the tests
SET (ENABLE_TESTS 0)
SET (ENABLE_TESTS 0 PARENT_SCOPE)
endif()

if (ENABLE_TESTS)
if(NOT EXISTS "${_gmock_root}/CMakeLists.txt")
message(WARNING
"Unable to find GMock source, not possible to build tests. Either "
"disable tests with ENABLE_TESTS=no or download the source code "
"for GMock (available at https://github.com/google/googlemock) and "
"set WITH_GMOCK to the directory of the unpacked source code.")
endif()

message(STATUS "Found GMock source under ${_gmock_root}")
add_subdirectory(${_gmock_root} ext/gmock)

# Setting variables that are normally discovered using FindXXX.cmake
set(GTEST_INCLUDE_DIRS ${_gtest_root}/include)
set(GTEST_LIBRARIES gtest)
set(GTEST_MAIN_LIBRARIES gtest_main)
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})

set(GMOCK_INCLUDE_DIRS ${_gmock_root}/include)
set(GMOCK_LIBRARIES gmock)
set(GMOCK_MAIN_LIBRARIES gmock_main)
set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES})

set(TEST_LIBRARIES ${GMOCK_BOTH_LIBRARIES} ${GTEST_BOTH_LIBRARIES})

# Since GMock and GTest do not set
# INTERFACE_SYSTEM_INCLUDE_DIRECTORIES, we do that here. This means
# that any targets that reference one of these libraries will
# "automatically" have the include directories for these libraries
# added to their build flags. We cannot use "SYSTEM" since that is
# not available in 2.8.9 (it was introduced in 2.8.12).
target_include_directories(gmock PUBLIC ${GMOCK_INCLUDE_DIRS})
target_include_directories(gmock_main PUBLIC ${GMOCK_INCLUDE_DIRS})
target_include_directories(gtest PUBLIC ${GTEST_INCLUDE_DIRS})
target_include_directories(gtest_main PUBLIC ${GTEST_INCLUDE_DIRS})

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

set (comp_flags_ "-Wno-undef -Wno-missing-field-initializers")
if(COMPILER_HAS_WARNING_MISSING_FORMAT_ATTRIBUTE)
set(comp_flags_ "${comp_flags_} -Wno-missing-format-attribute")
endif()

set_target_properties(gtest gtest_main gmock gmock_main
PROPERTIES
COMPILE_FLAGS "${comp_flags_}")
endif()
endif()
endif()
endif()

# Basic variables
set(HARNESS_NAME "harness"
CACHE STRING "Name of Harness")
Expand Down
7 changes: 4 additions & 3 deletions src/metadata_cache/include/mysqlrouter/metadata_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef MYSQLROUTER_METADATA_CACHE_INCLUDED
#define MYSQLROUTER_METADATA_CACHE_INCLUDED

#include <chrono>
#include <stdexcept>
#include <exception>
#include <vector>
Expand Down Expand Up @@ -57,7 +58,7 @@ extern const uint16_t kDefaultMetadataPort;
extern const std::string kDefaultMetadataAddress;
extern const std::string kDefaultMetadataUser;
extern const std::string kDefaultMetadataPassword;
extern const unsigned int kDefaultMetadataTTL;
extern const std::chrono::milliseconds kDefaultMetadataTTL;
extern const std::string kDefaultMetadataCluster;
extern const unsigned int kDefaultConnectTimeout;
extern const unsigned int kDefaultReadTimeout;
Expand Down Expand Up @@ -254,7 +255,7 @@ METADATA_API class MetadataCacheAPIBase : public ReplicasetStateNotifierInterfac
*/
virtual void cache_init(const std::vector<mysql_harness::TCPAddress> &bootstrap_servers,
const std::string &user, const std::string &password,
unsigned int ttl, const mysqlrouter::SSLOptions &ssl_options,
std::chrono::milliseconds ttl, const mysqlrouter::SSLOptions &ssl_options,
const std::string &cluster_name,
int connect_timeout, int read_timeout,
size_t thread_stack_size = mysql_harness::kDefaultStackSizeInKiloBytes) = 0;
Expand Down Expand Up @@ -326,7 +327,7 @@ METADATA_API class MetadataCacheAPI: public MetadataCacheAPIBase {

void cache_init(const std::vector<mysql_harness::TCPAddress> &bootstrap_servers,
const std::string &user, const std::string &password,
unsigned int ttl, const mysqlrouter::SSLOptions &ssl_options,
std::chrono::milliseconds ttl, const mysqlrouter::SSLOptions &ssl_options,
const std::string &cluster_name,
int connect_timeout, int read_timeout, size_t thread_stack_size) override;

Expand Down
4 changes: 2 additions & 2 deletions src/metadata_cache/src/cache_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static std::unique_ptr<MetadataCache> g_metadata_cache(nullptr);
namespace metadata_cache {

const uint16_t kDefaultMetadataPort = 32275;
const unsigned int kDefaultMetadataTTL = 5;
const std::chrono::milliseconds kDefaultMetadataTTL = std::chrono::milliseconds(500);
const std::string kDefaultMetadataAddress{"127.0.0.1:" + mysqlrouter::to_string(
kDefaultMetadataPort)};
const std::string kDefaultMetadataUser = "";
Expand Down Expand Up @@ -82,7 +82,7 @@ MetadataCacheAPIBase* MetadataCacheAPI::instance() {
void MetadataCacheAPI::cache_init(const std::vector<mysql_harness::TCPAddress> &bootstrap_servers,
const std::string &user,
const std::string &password,
unsigned int ttl,
std::chrono::milliseconds ttl,
const mysqlrouter::SSLOptions &ssl_options,
const std::string &cluster_name,
int connect_timeout,
Expand Down
2 changes: 1 addition & 1 deletion src/metadata_cache/src/cluster_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ClusterMetadata::ClusterMetadata(const std::string &user,
int connect_timeout,
int read_timeout,
int /*connection_attempts*/,
unsigned int ttl,
std::chrono::milliseconds ttl,
const mysqlrouter::SSLOptions &ssl_options) {
this->ttl_ = ttl;
this->user_ = user;
Expand Down
Loading

0 comments on commit 7982f20

Please sign in to comment.