-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
163 changed files
with
19,399 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) 2018, 2022, Oracle and/or its affiliates. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License, version 2.0, | ||
# as published by the Free Software Foundation. | ||
# | ||
# This program is also distributed with certain software (including | ||
# but not limited to OpenSSL) that is licensed under separate terms, | ||
# as designated in a particular file or component or in included license | ||
# documentation. The authors of MySQL hereby grant you an additional | ||
# permission to link the program and your derivative works with the | ||
# separately licensed software that they have included with MySQL. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
ADD_SUBDIRECTORY(src) | ||
IF(WITH_UNIT_TESTS) | ||
ADD_SUBDIRECTORY(tests) | ||
ENDIF() |
60 changes: 60 additions & 0 deletions
60
router/src/tianmu_secondary_server/include/mysqlrouter/tianmu_secondary_server_component.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright (c) 2018, 2022, Oracle and/or its affiliates. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License, version 2.0, | ||
as published by the Free Software Foundation. | ||
This program is also distributed with certain software (including | ||
but not limited to OpenSSL) that is licensed under separate terms, | ||
as designated in a particular file or component or in included license | ||
documentation. The authors of MySQL hereby grant you an additional | ||
permission to link the program and your derivative works with the | ||
separately licensed software that they have included with MySQL. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef MYSQLROUTER_TIANMU_SECONDARY_SERVER_COMPONENT_INCLUDED | ||
#define MYSQLROUTER_TIANMU_SECONDARY_SERVER_COMPONENT_INCLUDED | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include "mysql/harness/stdx/monitor.h" | ||
#include "mysqlrouter/tianmu_secondary_server_export.h" | ||
#include "mysqlrouter/tianmu_secondary_server_global_scope.h" | ||
|
||
namespace server_tianmu_secondary { | ||
class MySQLServerTianmuSecondary; | ||
} | ||
|
||
class TIANMU_SECONDARY_SERVER_EXPORT TianmuSecondaryServerComponent { | ||
public: | ||
// disable copy, as we are a single-instance | ||
TianmuSecondaryServerComponent(TianmuSecondaryServerComponent const &) = delete; | ||
void operator=(TianmuSecondaryServerComponent const &) = delete; | ||
|
||
static TianmuSecondaryServerComponent &get_instance(); | ||
|
||
void register_server(const std::string &name, | ||
std::shared_ptr<server_tianmu_secondary::MySQLServerTianmuSecondary> srv); | ||
|
||
std::shared_ptr<TianmuSecondaryServerGlobalScope> get_global_scope(); | ||
void close_all_connections(); | ||
|
||
private: | ||
Monitor<std::map<std::string, std::weak_ptr<server_tianmu_secondary::MySQLServerTianmuSecondary>>> | ||
srvs_{{}}; | ||
|
||
TianmuSecondaryServerComponent() = default; | ||
}; | ||
|
||
#endif //MYSQLROUTER_TIANMU_SECONDARY_SERVER_COMPONENT_INCLUDED |
42 changes: 42 additions & 0 deletions
42
router/src/tianmu_secondary_server/include/mysqlrouter/tianmu_secondary_server_export.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Copyright (c) 2018, 2022, Oracle and/or its affiliates. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License, version 2.0, | ||
as published by the Free Software Foundation. | ||
This program is also distributed with certain software (including | ||
but not limited to OpenSSL) that is licensed under separate terms, | ||
as designated in a particular file or component or in included license | ||
documentation. The authors of MySQL hereby grant you an additional | ||
permission to link the program and your derivative works with the | ||
separately licensed software that they have included with MySQL. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef MYSQLROUTER_TIANMU_SECONDARY_SERVER_EXPORT_INCLUDED | ||
#define MYSQLROUTER_TIANMU_SECONDARY_SERVER_EXPORT_INCLUDED | ||
|
||
#ifdef _WIN32 | ||
#ifdef tianmu_secondary_server_DEFINE_STATIC | ||
#define TIANMU_SECONDARY_SERVER_EXPORT | ||
#else | ||
#ifdef tianmu_secondary_server_EXPORTS | ||
#define TIANMU_SECONDARY_SERVER_EXPORT __declspec(dllexport) | ||
#else | ||
#define TIANMU_SECONDARY_SERVER_EXPORT __declspec(dllimport) | ||
#endif | ||
#endif | ||
#else | ||
#define TIANMU_SECONDARY_SERVER_EXPORT | ||
#endif | ||
|
||
#endif //MYSQLROUTER_TIANMU_SECONDARY_SERVER_EXPORT_INCLUDED |
80 changes: 80 additions & 0 deletions
80
...er/src/tianmu_secondary_server/include/mysqlrouter/tianmu_secondary_server_global_scope.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Copyright (c) 2018, 2022, Oracle and/or its affiliates. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License, version 2.0, | ||
as published by the Free Software Foundation. | ||
This program is also distributed with certain software (including | ||
but not limited to OpenSSL) that is licensed under separate terms, | ||
as designated in a particular file or component or in included license | ||
documentation. The authors of MySQL hereby grant you an additional | ||
permission to link the program and your derivative works with the | ||
separately licensed software that they have included with MySQL. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef MYSQLROUTER_TIANMU_SECONDARY_SERVER_GLOBAL_SCOPE_INCLUDED | ||
#define MYSQLROUTER_TIANMU_SECONDARY_SERVER_GLOBAL_SCOPE_INCLUDED | ||
|
||
#include <map> | ||
#include <mutex> | ||
#include <string> | ||
#include <vector> | ||
|
||
/** | ||
* stores global data as pair of <string, jsonfied-string> | ||
*/ | ||
class TianmuSecondaryServerGlobalScope { | ||
public: | ||
using key_type = std::string; | ||
using value_type = std::string; | ||
using type = std::map<key_type, value_type>; | ||
|
||
type get_all() { | ||
std::lock_guard<std::mutex> lk(global_mutex_); | ||
return global_; | ||
} | ||
|
||
std::vector<key_type> get_keys() { | ||
std::lock_guard<std::mutex> lk(global_mutex_); | ||
|
||
std::vector<key_type> keys; | ||
for (const auto &k : global_) { | ||
keys.emplace_back(k.first); | ||
} | ||
|
||
return keys; | ||
} | ||
|
||
void set(const key_type &key, const value_type &value) { | ||
std::lock_guard<std::mutex> lk(global_mutex_); | ||
|
||
global_[key] = value; | ||
} | ||
|
||
size_t erase(const key_type &key) { | ||
std::lock_guard<std::mutex> lk(global_mutex_); | ||
|
||
return global_.erase(key); | ||
} | ||
|
||
void reset(type globals) { | ||
std::lock_guard<std::mutex> lk(global_mutex_); | ||
global_ = globals; | ||
} | ||
|
||
private: | ||
type global_; | ||
std::mutex global_mutex_; | ||
}; | ||
|
||
#endif //MYSQLROUTER_TIANMU_SECONDARY_SERVER_GLOBAL_SCOPE_INCLUDED |
106 changes: 106 additions & 0 deletions
106
router/src/tianmu_secondary_server/include/mysqlrouter/tianmu_secondary_server_rest_client.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
Copyright (c) 2018, 2022, Oracle and/or its affiliates. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License, version 2.0, | ||
as published by the Free Software Foundation. | ||
This program is also distributed with certain software (including | ||
but not limited to OpenSSL) that is licensed under separate terms, | ||
as designated in a particular file or component or in included license | ||
documentation. The authors of MySQL hereby grant you an additional | ||
permission to link the program and your derivative works with the | ||
separately licensed software that they have included with MySQL. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef MYSQLROUTER_TIANMU_SECONDARY_SERVER_REST_CLIENT_INCLUDED | ||
#define MYSQLROUTER_TIANMU_SECONDARY_SERVER_REST_CLIENT_INCLUDED | ||
|
||
#include <chrono> | ||
#include <string> | ||
|
||
/** @brief URI for the tianmu secondary server globals */ | ||
static constexpr const char kTianmuSecondaryServerGlobalsRestUri[] = | ||
"/api/v1/tianmu_secondary_server/globals/"; | ||
|
||
/** @class TianmuSecondaryServerHttpClient | ||
* | ||
* Allows communicating with mysql server tianmu secondary via | ||
* HTTP port | ||
* | ||
**/ | ||
class TianmuSecondaryServerRestClient { | ||
public: | ||
/** @brief Constructor | ||
* | ||
* @param http_port port on which http server handles the http requests | ||
* @param http_hostname hostname of the http server that handles the http | ||
* requests | ||
*/ | ||
TianmuSecondaryServerRestClient(const uint16_t http_port, | ||
const std::string &http_hostname = "127.0.0.1"); | ||
|
||
/** @brief Sets values of the all globals in the server tianmu secondary via | ||
* http inteface. | ||
* Example: | ||
* set_globals("{\"secondary_removed\": true}"); | ||
* | ||
* @param globals_json json string with the globals names and values to set | ||
*/ | ||
void set_globals(const std::string &globals_json); | ||
|
||
/** @brief Gets all the tianmu secondary server globals as a json string | ||
*/ | ||
std::string get_globals_as_json_string(); | ||
|
||
/** @brief Gets a selected tianmu secondary server int global value | ||
* | ||
* @param global_name name of the global | ||
*/ | ||
int get_int_global(const std::string &global_name); | ||
|
||
/** @brief Gets a selected tianmu secondary server bool global value | ||
* | ||
* @param global_name name of the global | ||
*/ | ||
bool get_bool_global(const std::string &global_name); | ||
|
||
/** @brief Sends Delete request to the tianmu secondary server | ||
* on the selected URI | ||
* | ||
* @param uri uri for the Delete request | ||
*/ | ||
void send_delete(const std::string &uri); | ||
|
||
/** | ||
* @brief Wait until a REST endpoint returns !404. | ||
* | ||
* at tianmu secondary startup the socket starts to listen before the REST endpoint gets | ||
* registered. As long as it returns 404 Not Found we should wait and retry. | ||
* | ||
* @param max_wait_time max time to wait for endpoint being ready | ||
* @returns true once endpoint doesn't return 404 anymore, fails otherwise | ||
*/ | ||
bool wait_for_rest_endpoint_ready( | ||
std::chrono::milliseconds max_wait_time = | ||
kTianmuSecondaryServerDefaultRestEndpointTimeout) const noexcept; | ||
|
||
private: | ||
static constexpr std::chrono::milliseconds kTianmuSecondaryServerMaxRestEndpointStepTime{ | ||
100}; | ||
static constexpr std::chrono::milliseconds | ||
kTianmuSecondaryServerDefaultRestEndpointTimeout{1000}; | ||
const std::string http_hostname_; | ||
const uint16_t http_port_; | ||
}; | ||
|
||
#endif // MYSQLROUTER_MOCK_SERVER_REST_CLIENT_INCLUDED |
Oops, something went wrong.