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

Commit 7982f20

Browse files
author
Andrzej Religa
committed
WL#12030 Decrease the cluster metadata TTL to 0.5 second
Decreased default metadata cache ttl to 0.5 second Allowed millisecond resolution for metadata cache ttl Adjusted metadata cache refresh logic accordingly
1 parent 6e624eb commit 7982f20

39 files changed

+1062
-292
lines changed

cmake/testing.cmake

+161
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,167 @@
2222

2323
set(_TEST_RUNTIME_DIR ${PROJECT_BINARY_DIR}/tests)
2424

25+
# We include GMock without touching the compile flags. GMock can
26+
# handle that itself. It will also indirectly create targets for gmock
27+
# and gtest.
28+
#
29+
# Two alternatives for locating GMock *source code*:
30+
# 1. If WITH_GMOCK is given, this is expected to be the location of
31+
# the *source code*.
32+
# 2. If WITH_GMOCK is not given, it will look in the 'ext' directory
33+
# in the source root.
34+
if(ENABLE_TESTS)
35+
if(TARGET gmock)
36+
# don't build gmock, if the parent already built it
37+
38+
# copying from unittest/gunit/CMakeFiles.txt
39+
# this should all be global-variables or a cmake/ file
40+
if(NOT DOWNLOAD_ROOT)
41+
set(DOWNLOAD_ROOT ${CMAKE_SOURCE_DIR}/source_downloads)
42+
endif()
43+
44+
# We want googletest version 1.8, which also contains googlemock.
45+
set(GMOCK_PACKAGE_NAME "release-1.8.0")
46+
47+
if(DEFINED ENV{WITH_GMOCK} AND NOT DEFINED WITH_GMOCK)
48+
file(TO_CMAKE_PATH "$ENV{WITH_GMOCK}" WITH_GMOCK)
49+
ENDIF()
50+
51+
if(LOCAL_GMOCK_ZIP
52+
AND NOT ${LOCAL_GMOCK_ZIP} MATCHES ".*${GMOCK_PACKAGE_NAME}\\.zip")
53+
set(LOCAL_GMOCK_ZIP 0)
54+
endif()
55+
56+
if(WITH_GMOCK)
57+
## Did we get a full path name, including file name?
58+
if(${WITH_GMOCK} MATCHES ".*\\.zip")
59+
GET_FILENAME_COMPONENT(GMOCK_DIR ${WITH_GMOCK} PATH)
60+
GET_FILENAME_COMPONENT(GMOCK_ZIP ${WITH_GMOCK} NAME)
61+
FIND_FILE(LOCAL_GMOCK_ZIP
62+
NAMES ${GMOCK_ZIP}
63+
PATHS ${GMOCK_DIR}
64+
NO_DEFAULT_PATH
65+
)
66+
else()
67+
## Did we get a path name to the directory of the .zip file?
68+
## Check for both release-x.y.z.zip and googletest-release-x.y.z.zip
69+
FIND_FILE(LOCAL_GMOCK_ZIP
70+
NAMES "${GMOCK_PACKAGE_NAME}.zip" "googletest-${GMOCK_PACKAGE_NAME}.zip"
71+
PATHS ${WITH_GMOCK}
72+
NO_DEFAULT_PATH
73+
)
74+
## If WITH_GMOCK is a directory, use it for download.
75+
set(DOWNLOAD_ROOT ${WITH_GMOCK})
76+
endif()
77+
MESSAGE(STATUS "Local gmock zip ${LOCAL_GMOCK_ZIP}")
78+
endif()
79+
80+
set(GMOCK_SOURCE_DIR ${DOWNLOAD_ROOT}/googletest-${GMOCK_PACKAGE_NAME}/googlemock)
81+
set(GTEST_SOURCE_DIR ${DOWNLOAD_ROOT}/googletest-${GMOCK_PACKAGE_NAME}/googletest)
82+
83+
# introduce some compat
84+
set(GTEST_INCLUDE_DIRS ${GMOCK_INCLUDE_DIRS})
85+
message("yyy seting GTEST_INCLUDE_DIRS to ${GTEST_INCLUDE_DIRS}")
86+
87+
ADD_LIBRARY(gmock_main STATIC ${GMOCK_SOURCE_DIR}/src/gmock_main.cc)
88+
target_link_libraries(gmock_main gmock)
89+
target_include_directories(gmock_main
90+
PUBLIC ${GMOCK_INCLUDE_DIRS})
91+
ADD_LIBRARY(gtest_main STATIC ${GTEST_SOURCE_DIR}/src/gtest_main.cc)
92+
target_include_directories(gtest_main
93+
PUBLIC ${GMOCK_INCLUDE_DIRS})
94+
95+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
96+
set_target_properties(gtest_main gmock_main
97+
PROPERTIES
98+
COMPILE_FLAGS "-Wno-undef -Wno-conversion")
99+
endif()
100+
101+
set(TEST_LIBRARIES gmock gtest gmock_main gtest_main)
102+
else()
103+
if(WITH_GMOCK)
104+
105+
# There is a known gtest/gmock bug that surfaces with the gcc-6.x causing tests crashes:
106+
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833450
107+
# We have a patch for it in the gmock we bundle but if the user wants to use
108+
# it's own gtest/gmock we need to prevent it if the gcc-6.x is used
109+
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
110+
AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "6.0" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "6.0"))
111+
message(FATAL_ERROR "Parameter WITH_GMOCK is not supported for gcc-6 or greater."
112+
"You need to either disable the tests or use the bundled gmock (removing WITH_GMOCK parameter).")
113+
endif()
114+
115+
set(_gmock_root ${WITH_GMOCK})
116+
set(_gtest_root ${WITH_GMOCK}/gtest)
117+
elseif(EXISTS "${CMAKE_SOURCE_DIR}/ext/gmock/CMakeLists.txt")
118+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/ext/gtest/CMakeLists.txt")
119+
message(FATAL_ERROR "Cannot find GTest repository under ${CMAKE_SOURCE_DIR}/ext/gtest")
120+
endif()
121+
set(_gmock_root "${CMAKE_SOURCE_DIR}/ext/gmock")
122+
set(_gtest_root "${CMAKE_SOURCE_DIR}/ext/gtest")
123+
elseif(GMOCK_SOURCE_DIR)
124+
# means we are part of the server and GMOCK was downloaded
125+
set(_gmock_root ${GMOCK_SOURCE_DIR})
126+
set(_gtest_root ${GMOCK_SOURCE_DIR}/gtest)
127+
else()
128+
# means we are part of the server and GMOCK is missing
129+
# act as other server components, disable the tests
130+
SET (ENABLE_TESTS 0)
131+
SET (ENABLE_TESTS 0 PARENT_SCOPE)
132+
endif()
133+
134+
if (ENABLE_TESTS)
135+
if(NOT EXISTS "${_gmock_root}/CMakeLists.txt")
136+
message(WARNING
137+
"Unable to find GMock source, not possible to build tests. Either "
138+
"disable tests with ENABLE_TESTS=no or download the source code "
139+
"for GMock (available at https://github.com/google/googlemock) and "
140+
"set WITH_GMOCK to the directory of the unpacked source code.")
141+
endif()
142+
143+
message(STATUS "Found GMock source under ${_gmock_root}")
144+
add_subdirectory(${_gmock_root} ext/gmock)
145+
146+
# Setting variables that are normally discovered using FindXXX.cmake
147+
set(GTEST_INCLUDE_DIRS ${_gtest_root}/include)
148+
message("yyy seting GTEST_INCLUDE_DIRS to ${GTEST_INCLUDE_DIRS}")
149+
set(GTEST_LIBRARIES gtest)
150+
set(GTEST_MAIN_LIBRARIES gtest_main)
151+
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
152+
153+
set(GMOCK_INCLUDE_DIRS ${_gmock_root}/include)
154+
set(GMOCK_LIBRARIES gmock)
155+
set(GMOCK_MAIN_LIBRARIES gmock_main)
156+
set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES})
157+
158+
set(TEST_LIBRARIES ${GMOCK_BOTH_LIBRARIES} ${GTEST_BOTH_LIBRARIES})
159+
160+
# Since GMock and GTest do not set
161+
# INTERFACE_SYSTEM_INCLUDE_DIRECTORIES, we do that here. This means
162+
# that any targets that reference one of these libraries will
163+
# "automatically" have the include directories for these libraries
164+
# added to their build flags. We cannot use "SYSTEM" since that is
165+
# not available in 2.8.9 (it was introduced in 2.8.12).
166+
target_include_directories(gmock PUBLIC ${GMOCK_INCLUDE_DIRS})
167+
target_include_directories(gmock_main PUBLIC ${GMOCK_INCLUDE_DIRS})
168+
target_include_directories(gtest PUBLIC ${GTEST_INCLUDE_DIRS})
169+
target_include_directories(gtest_main PUBLIC ${GTEST_INCLUDE_DIRS})
170+
171+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
172+
173+
set (comp_flags_ "-Wno-undef -Wno-missing-field-initializers")
174+
if(COMPILER_HAS_WARNING_MISSING_FORMAT_ATTRIBUTE)
175+
set(comp_flags_ "${comp_flags_} -Wno-missing-format-attribute")
176+
endif()
177+
178+
set_target_properties(gtest gtest_main gmock gmock_main
179+
PROPERTIES
180+
COMPILE_FLAGS "${comp_flags_}")
181+
endif()
182+
endif()
183+
endif()
184+
endif()
185+
25186
# Set {RUNTIME,LIBRARY}_OUTPUT_DIRECTORY properties of a target to the stage dir.
26187
# On unix platforms this is just one directory, but on Windows it's per build-type,
27188
# e.g. build/stage/Debug/lib, build/stage/Release/lib, etc

src/harness/CMakeLists.txt

-159
Original file line numberDiff line numberDiff line change
@@ -35,165 +35,6 @@ set(HARNESS_INSTALL_PLUGINS YES CACHE BOOL
3535

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

38-
# We include GMock without touching the compile flags. GMock can
39-
# handle that itself. It will also indirectly create targets for gmock
40-
# and gtest.
41-
#
42-
# Two alternatives for locating GMock *source code*:
43-
# 1. If WITH_GMOCK is given, this is expected to be the location of
44-
# the *source code*.
45-
# 2. If WITH_GMOCK is not given, it will look in the 'ext' directory
46-
# in the source root.
47-
if(ENABLE_TESTS)
48-
if(TARGET gmock)
49-
# don't build gmock, if the parent already built it
50-
51-
# copying from unittest/gunit/CMakeFiles.txt
52-
# this should all be global-variables or a cmake/ file
53-
if(NOT DOWNLOAD_ROOT)
54-
set(DOWNLOAD_ROOT ${CMAKE_SOURCE_DIR}/source_downloads)
55-
endif()
56-
57-
# We want googletest version 1.8, which also contains googlemock.
58-
set(GMOCK_PACKAGE_NAME "release-1.8.0")
59-
60-
if(DEFINED ENV{WITH_GMOCK} AND NOT DEFINED WITH_GMOCK)
61-
file(TO_CMAKE_PATH "$ENV{WITH_GMOCK}" WITH_GMOCK)
62-
ENDIF()
63-
64-
if(LOCAL_GMOCK_ZIP
65-
AND NOT ${LOCAL_GMOCK_ZIP} MATCHES ".*${GMOCK_PACKAGE_NAME}\\.zip")
66-
set(LOCAL_GMOCK_ZIP 0)
67-
endif()
68-
69-
if(WITH_GMOCK)
70-
## Did we get a full path name, including file name?
71-
if(${WITH_GMOCK} MATCHES ".*\\.zip")
72-
GET_FILENAME_COMPONENT(GMOCK_DIR ${WITH_GMOCK} PATH)
73-
GET_FILENAME_COMPONENT(GMOCK_ZIP ${WITH_GMOCK} NAME)
74-
FIND_FILE(LOCAL_GMOCK_ZIP
75-
NAMES ${GMOCK_ZIP}
76-
PATHS ${GMOCK_DIR}
77-
NO_DEFAULT_PATH
78-
)
79-
else()
80-
## Did we get a path name to the directory of the .zip file?
81-
## Check for both release-x.y.z.zip and googletest-release-x.y.z.zip
82-
FIND_FILE(LOCAL_GMOCK_ZIP
83-
NAMES "${GMOCK_PACKAGE_NAME}.zip" "googletest-${GMOCK_PACKAGE_NAME}.zip"
84-
PATHS ${WITH_GMOCK}
85-
NO_DEFAULT_PATH
86-
)
87-
## If WITH_GMOCK is a directory, use it for download.
88-
set(DOWNLOAD_ROOT ${WITH_GMOCK})
89-
endif()
90-
MESSAGE(STATUS "Local gmock zip ${LOCAL_GMOCK_ZIP}")
91-
endif()
92-
93-
set(GMOCK_SOURCE_DIR ${DOWNLOAD_ROOT}/googletest-${GMOCK_PACKAGE_NAME}/googlemock)
94-
set(GTEST_SOURCE_DIR ${DOWNLOAD_ROOT}/googletest-${GMOCK_PACKAGE_NAME}/googletest)
95-
96-
# introduce some compat
97-
set(GTEST_INCLUDE_DIRS ${GMOCK_INCLUDE_DIRS})
98-
99-
ADD_LIBRARY(gmock_main STATIC ${GMOCK_SOURCE_DIR}/src/gmock_main.cc)
100-
target_link_libraries(gmock_main gmock)
101-
target_include_directories(gmock_main
102-
PUBLIC ${GMOCK_INCLUDE_DIRS})
103-
ADD_LIBRARY(gtest_main STATIC ${GTEST_SOURCE_DIR}/src/gtest_main.cc)
104-
target_include_directories(gtest_main
105-
PUBLIC ${GMOCK_INCLUDE_DIRS})
106-
107-
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
108-
set_target_properties(gtest_main gmock_main
109-
PROPERTIES
110-
COMPILE_FLAGS "-Wno-undef -Wno-conversion")
111-
endif()
112-
113-
set(TEST_LIBRARIES gmock gtest gmock_main gtest_main)
114-
else()
115-
if(WITH_GMOCK)
116-
117-
# There is a known gtest/gmock bug that surfaces with the gcc-6.x causing tests crashes:
118-
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833450
119-
# We have a patch for it in the gmock we bundle but if the user wants to use
120-
# it's own gtest/gmock we need to prevent it if the gcc-6.x is used
121-
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
122-
AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "6.0" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "6.0"))
123-
message(FATAL_ERROR "Parameter WITH_GMOCK is not supported for gcc-6 or greater."
124-
"You need to either disable the tests or use the bundled gmock (removing WITH_GMOCK parameter).")
125-
endif()
126-
127-
set(_gmock_root ${WITH_GMOCK})
128-
set(_gtest_root ${WITH_GMOCK}/gtest)
129-
elseif(EXISTS "${CMAKE_SOURCE_DIR}/ext/gmock/CMakeLists.txt")
130-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/ext/gtest/CMakeLists.txt")
131-
message(FATAL_ERROR "Cannot find GTest repository under ${CMAKE_SOURCE_DIR}/ext/gtest")
132-
endif()
133-
set(_gmock_root "${CMAKE_SOURCE_DIR}/ext/gmock")
134-
set(_gtest_root "${CMAKE_SOURCE_DIR}/ext/gtest")
135-
elseif(GMOCK_SOURCE_DIR)
136-
# means we are part of the server and GMOCK was downloaded
137-
set(_gmock_root ${GMOCK_SOURCE_DIR})
138-
set(_gtest_root ${GMOCK_SOURCE_DIR}/gtest)
139-
else()
140-
# means we are part of the server and GMOCK is missing
141-
# act as other server components, disable the tests
142-
SET (ENABLE_TESTS 0)
143-
SET (ENABLE_TESTS 0 PARENT_SCOPE)
144-
endif()
145-
146-
if (ENABLE_TESTS)
147-
if(NOT EXISTS "${_gmock_root}/CMakeLists.txt")
148-
message(WARNING
149-
"Unable to find GMock source, not possible to build tests. Either "
150-
"disable tests with ENABLE_TESTS=no or download the source code "
151-
"for GMock (available at https://github.com/google/googlemock) and "
152-
"set WITH_GMOCK to the directory of the unpacked source code.")
153-
endif()
154-
155-
message(STATUS "Found GMock source under ${_gmock_root}")
156-
add_subdirectory(${_gmock_root} ext/gmock)
157-
158-
# Setting variables that are normally discovered using FindXXX.cmake
159-
set(GTEST_INCLUDE_DIRS ${_gtest_root}/include)
160-
set(GTEST_LIBRARIES gtest)
161-
set(GTEST_MAIN_LIBRARIES gtest_main)
162-
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
163-
164-
set(GMOCK_INCLUDE_DIRS ${_gmock_root}/include)
165-
set(GMOCK_LIBRARIES gmock)
166-
set(GMOCK_MAIN_LIBRARIES gmock_main)
167-
set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARIES} ${GMOCK_MAIN_LIBRARIES})
168-
169-
set(TEST_LIBRARIES ${GMOCK_BOTH_LIBRARIES} ${GTEST_BOTH_LIBRARIES})
170-
171-
# Since GMock and GTest do not set
172-
# INTERFACE_SYSTEM_INCLUDE_DIRECTORIES, we do that here. This means
173-
# that any targets that reference one of these libraries will
174-
# "automatically" have the include directories for these libraries
175-
# added to their build flags. We cannot use "SYSTEM" since that is
176-
# not available in 2.8.9 (it was introduced in 2.8.12).
177-
target_include_directories(gmock PUBLIC ${GMOCK_INCLUDE_DIRS})
178-
target_include_directories(gmock_main PUBLIC ${GMOCK_INCLUDE_DIRS})
179-
target_include_directories(gtest PUBLIC ${GTEST_INCLUDE_DIRS})
180-
target_include_directories(gtest_main PUBLIC ${GTEST_INCLUDE_DIRS})
181-
182-
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
183-
184-
set (comp_flags_ "-Wno-undef -Wno-missing-field-initializers")
185-
if(COMPILER_HAS_WARNING_MISSING_FORMAT_ATTRIBUTE)
186-
set(comp_flags_ "${comp_flags_} -Wno-missing-format-attribute")
187-
endif()
188-
189-
set_target_properties(gtest gtest_main gmock gmock_main
190-
PROPERTIES
191-
COMPILE_FLAGS "${comp_flags_}")
192-
endif()
193-
endif()
194-
endif()
195-
endif()
196-
19738
# Basic variables
19839
set(HARNESS_NAME "harness"
19940
CACHE STRING "Name of Harness")

src/metadata_cache/include/mysqlrouter/metadata_cache.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifndef MYSQLROUTER_METADATA_CACHE_INCLUDED
2626
#define MYSQLROUTER_METADATA_CACHE_INCLUDED
2727

28+
#include <chrono>
2829
#include <stdexcept>
2930
#include <exception>
3031
#include <vector>
@@ -57,7 +58,7 @@ extern const uint16_t kDefaultMetadataPort;
5758
extern const std::string kDefaultMetadataAddress;
5859
extern const std::string kDefaultMetadataUser;
5960
extern const std::string kDefaultMetadataPassword;
60-
extern const unsigned int kDefaultMetadataTTL;
61+
extern const std::chrono::milliseconds kDefaultMetadataTTL;
6162
extern const std::string kDefaultMetadataCluster;
6263
extern const unsigned int kDefaultConnectTimeout;
6364
extern const unsigned int kDefaultReadTimeout;
@@ -254,7 +255,7 @@ METADATA_API class MetadataCacheAPIBase : public ReplicasetStateNotifierInterfac
254255
*/
255256
virtual void cache_init(const std::vector<mysql_harness::TCPAddress> &bootstrap_servers,
256257
const std::string &user, const std::string &password,
257-
unsigned int ttl, const mysqlrouter::SSLOptions &ssl_options,
258+
std::chrono::milliseconds ttl, const mysqlrouter::SSLOptions &ssl_options,
258259
const std::string &cluster_name,
259260
int connect_timeout, int read_timeout,
260261
size_t thread_stack_size = mysql_harness::kDefaultStackSizeInKiloBytes) = 0;
@@ -326,7 +327,7 @@ METADATA_API class MetadataCacheAPI: public MetadataCacheAPIBase {
326327

327328
void cache_init(const std::vector<mysql_harness::TCPAddress> &bootstrap_servers,
328329
const std::string &user, const std::string &password,
329-
unsigned int ttl, const mysqlrouter::SSLOptions &ssl_options,
330+
std::chrono::milliseconds ttl, const mysqlrouter::SSLOptions &ssl_options,
330331
const std::string &cluster_name,
331332
int connect_timeout, int read_timeout, size_t thread_stack_size) override;
332333

src/metadata_cache/src/cache_api.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static std::unique_ptr<MetadataCache> g_metadata_cache(nullptr);
3939
namespace metadata_cache {
4040

4141
const uint16_t kDefaultMetadataPort = 32275;
42-
const unsigned int kDefaultMetadataTTL = 5;
42+
const std::chrono::milliseconds kDefaultMetadataTTL = std::chrono::milliseconds(500);
4343
const std::string kDefaultMetadataAddress{"127.0.0.1:" + mysqlrouter::to_string(
4444
kDefaultMetadataPort)};
4545
const std::string kDefaultMetadataUser = "";
@@ -82,7 +82,7 @@ MetadataCacheAPIBase* MetadataCacheAPI::instance() {
8282
void MetadataCacheAPI::cache_init(const std::vector<mysql_harness::TCPAddress> &bootstrap_servers,
8383
const std::string &user,
8484
const std::string &password,
85-
unsigned int ttl,
85+
std::chrono::milliseconds ttl,
8686
const mysqlrouter::SSLOptions &ssl_options,
8787
const std::string &cluster_name,
8888
int connect_timeout,

src/metadata_cache/src/cluster_metadata.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ClusterMetadata::ClusterMetadata(const std::string &user,
6868
int connect_timeout,
6969
int read_timeout,
7070
int /*connection_attempts*/,
71-
unsigned int ttl,
71+
std::chrono::milliseconds ttl,
7272
const mysqlrouter::SSLOptions &ssl_options) {
7373
this->ttl_ = ttl;
7474
this->user_ = user;

0 commit comments

Comments
 (0)