Skip to content

Commit

Permalink
feat(rapid): basic function (#1965)
Browse files Browse the repository at this point in the history
basic function
  • Loading branch information
derrickball committed Oct 13, 2023
1 parent 06d25fc commit 11cd494
Show file tree
Hide file tree
Showing 163 changed files with 19,399 additions and 583 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Expand Up @@ -42,4 +42,8 @@ scalability_jobs_*
*node_modules/
.docusaurus/
node_modules
website/.docusaurus
website/.docusaurus

build/
my.cnf
build_out/
8 changes: 4 additions & 4 deletions cmake/maintainer.cmake
Expand Up @@ -175,10 +175,10 @@ IF(MYSQL_MAINTAINER_MODE)
STRING_APPEND(CMAKE_MODULE_LINKER_FLAGS " /WX")
STRING_APPEND(CMAKE_SHARED_LINKER_FLAGS " /WX")
ENDIF()
IF(MY_COMPILER_IS_GNU_OR_CLANG)
STRING_APPEND(MY_C_WARNING_FLAGS " -Werror")
STRING_APPEND(MY_CXX_WARNING_FLAGS " -Werror")
ENDIF()
# IF(MY_COMPILER_IS_GNU_OR_CLANG)
# STRING_APPEND(MY_C_WARNING_FLAGS " -Werror")
# STRING_APPEND(MY_CXX_WARNING_FLAGS " -Werror")
# ENDIF()
ENDIF()

# Set warning flags for gcc/g++/clang/clang++
Expand Down
7 changes: 4 additions & 3 deletions include/field_types.h
Expand Up @@ -68,9 +68,10 @@ enum enum_field_types {
MYSQL_TYPE_VARCHAR,
MYSQL_TYPE_BIT,
MYSQL_TYPE_TIMESTAMP2,
MYSQL_TYPE_DATETIME2, /**< Internal to MySQL. Not used in protocol */
MYSQL_TYPE_TIME2, /**< Internal to MySQL. Not used in protocol */
MYSQL_TYPE_TYPED_ARRAY, /**< Used for replication only */
MYSQL_TYPE_DATETIME2, /**< Internal to MySQL. Not used in protocol */
MYSQL_TYPE_TIME2, /**< Internal to MySQL. Not used in protocol */
MYSQL_TYPE_TYPED_ARRAY, /**< Used for replication only */
MYSQL_SYS_TYPE_TRX_ID = 242, // for sys hindden col: DATA_TRX_ID
MYSQL_TYPE_INVALID = 243,
MYSQL_TYPE_BOOL = 244, /**< Currently just a placeholder */
MYSQL_TYPE_JSON = 245,
Expand Down
1 change: 1 addition & 0 deletions include/mysql.h.pp
Expand Up @@ -23,6 +23,7 @@
MYSQL_TYPE_DATETIME2,
MYSQL_TYPE_TIME2,
MYSQL_TYPE_TYPED_ARRAY,
MYSQL_SYS_TYPE_TRX_ID = 242,
MYSQL_TYPE_INVALID = 243,
MYSQL_TYPE_BOOL = 244,
MYSQL_TYPE_JSON = 245,
Expand Down
123 changes: 62 additions & 61 deletions include/mysql/plugin.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions router/src/CMakeLists.txt
Expand Up @@ -40,6 +40,7 @@ ADD_SUBDIRECTORY(rest_router)
ADD_SUBDIRECTORY(rest_routing)
ADD_SUBDIRECTORY(router)
ADD_SUBDIRECTORY(routing)
ADD_SUBDIRECTORY(tianmu_secondary_server)

# Directory layout after 'make install' is different.
# Create symlinks to ssl libraries for both: build and install layouts
Expand Down
26 changes: 26 additions & 0 deletions router/src/tianmu_secondary_server/CMakeLists.txt
@@ -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()
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 11cd494

Please sign in to comment.