Skip to content

Commit 4bf8aaf

Browse files
author
Peng Gu
committed
Move spectrum_storage.cc from plugin to libspectrum
1 parent b1a2725 commit 4bf8aaf

File tree

7 files changed

+100
-103
lines changed

7 files changed

+100
-103
lines changed

libspectrum/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,10 @@ ADD_STATIC_LIBRARY(spectrum_log
5454

5555
ADD_STATIC_LIBRARY(spectrum_compute
5656
${SPECTRUM_BASE_SRC_DIR}/spectrum_compute.cc
57+
LINK_LIBRARIES spectrum_pb spectrum_common
58+
)
59+
60+
ADD_STATIC_LIBRARY(spectrum_storage
61+
${SPECTRUM_BASE_SRC_DIR}/spectrum_storage.cc
5762
LINK_LIBRARIES spectrum_pb spectrum_common spectrum_log
5863
)

libspectrum/include/spectrum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ extern int spectrum_compute_acquire_mdl(THD *thd, MDL_ticket *ticket);
7474
extern int spectrum_compute_release_mdl(THD *thd, enum_mdl_duration duration, int32 ticket_number);
7575
extern int spectrum_compute_post_ddl(THD *thd);
7676

77+
extern int spectrum_storage_init();
78+
7779
extern int spectrum_log_create_table(THD *thd, const char* db_name, const char* table_name, uint64 handler_id);
7880
extern int spectrum_log_delete_table(THD *thd, const char* db_name, const char* table_name, const char* table_path);
7981
extern int spectrum_log_post_ddl(THD *thd);

plugin/spectrum_storage/spectrum_storage.cc renamed to libspectrum/src/spectrum_storage.cc

Lines changed: 9 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,8 @@
1616
along with this program; if not, write to the Free Software
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
1818

19-
#include <ctype.h>
20-
#include <fcntl.h>
21-
#include <mysql/plugin.h>
22-
#include <mysql_version.h>
23-
#include <stdio.h>
24-
#include <stdlib.h>
25-
#include <time.h>
26-
27-
#include "m_string.h" // strlen
28-
#include "my_dbug.h"
29-
#include "my_dir.h"
30-
#include "my_inttypes.h"
31-
#include "my_io.h"
32-
#include "my_psi_config.h"
33-
#include "my_sys.h" // my_write, my_malloc
3419
#include "my_thread.h"
3520
#include "thr_lock.h"
36-
#include "mysql/psi/mysql_memory.h"
37-
#include "sql/sql_plugin.h" // st_plugin_int
3821
#include "sql/sql_class.h"
3922
#include "sql/sql_base.h"
4023
#include "sql/sql_table.h"
@@ -869,88 +852,18 @@ class StorageReplicaNodeImpl final : public spectrum::StorageReplicaNode::Servic
869852
}
870853
};
871854

872-
struct spectrum_storage_plugin_context {
873-
std::unique_ptr<grpc::Server> server;
874-
};
875-
876-
PSI_memory_key key_memory_spectrum_storage_plugin_context;
877-
878-
/*
879-
Initialize the daemon example at server start or plugin installation.
880-
SYNOPSIS
881-
daemon_example_plugin_init()
882-
DESCRIPTION
883-
Starts up heartbeatbeat thread
884-
RETURN VALUE
885-
0 success
886-
1 failure (cannot happen)
887-
*/
888-
889-
static int daemon_example_plugin_init(void *p) {
890-
DBUG_TRACE;
891-
struct spectrum_storage_plugin_context *con;
892-
struct st_plugin_int *plugin = (struct st_plugin_int *)p;
893-
894-
con = (struct spectrum_storage_plugin_context *)my_malloc(
895-
key_memory_spectrum_storage_plugin_context,
896-
sizeof(struct spectrum_storage_plugin_context), MYF(0));
897-
plugin->data = (void *)con;
898-
899-
spectrum_config_init();
900-
901-
if (is_spectrum_storage()) {
902-
grpc::ServerBuilder serverBuilder;
855+
std::unique_ptr<grpc::Server> spectrum_storage_server;
903856

904-
grpc::Service *service = new StorageNodeImpl();
905-
serverBuilder.RegisterService(service);
857+
int spectrum_storage_init() {
858+
grpc::ServerBuilder serverBuilder;
906859

907-
grpc::Service *replicaService = new StorageReplicaNodeImpl();
908-
serverBuilder.RegisterService(replicaService);
860+
serverBuilder.RegisterService(new StorageNodeImpl());
861+
serverBuilder.RegisterService(new StorageReplicaNodeImpl());
909862

910-
node_config_t *node_config = find_current_node_config();
911-
serverBuilder.AddListeningPort(node_config->address, grpc::InsecureServerCredentials());
912-
con->server = serverBuilder.BuildAndStart();
913-
sql_print_information("Spectrum storage server started at %s", node_config->address.c_str());
914-
}
863+
node_config_t *node_config = find_current_node_config();
864+
serverBuilder.AddListeningPort(node_config->address, grpc::InsecureServerCredentials());
915865

866+
spectrum_storage_server = serverBuilder.BuildAndStart();
867+
sql_print_information("Spectrum storage server started at %s", node_config->address.c_str());
916868
return 0;
917869
}
918-
919-
/*
920-
Terminate the daemon example at server shutdown or plugin deinstallation.
921-
SYNOPSIS
922-
daemon_example_plugin_deinit()
923-
Does nothing.
924-
RETURN VALUE
925-
0 success
926-
1 failure (cannot happen)
927-
*/
928-
929-
static int daemon_example_plugin_deinit(void *p) {
930-
DBUG_TRACE;
931-
932-
return 0;
933-
}
934-
935-
struct st_mysql_daemon daemon_example_plugin = {MYSQL_DAEMON_INTERFACE_VERSION};
936-
937-
/*
938-
Plugin library descriptor
939-
*/
940-
941-
mysql_declare_plugin(spectrum_storage){
942-
MYSQL_DAEMON_PLUGIN,
943-
&daemon_example_plugin,
944-
"spectrum_storage",
945-
PLUGIN_AUTHOR_ORACLE,
946-
"Spectrum storage",
947-
PLUGIN_LICENSE_GPL,
948-
daemon_example_plugin_init, /* Plugin Init */
949-
nullptr, /* Plugin Check uninstall */
950-
daemon_example_plugin_deinit, /* Plugin Deinit */
951-
0x0100 /* 1.0 */,
952-
nullptr, /* status variables */
953-
nullptr, /* system variables */
954-
nullptr, /* config options */
955-
0, /* flags */
956-
} mysql_declare_plugin_end;
File renamed without changes.

plugin/spectrum_storage/CMakeLists.txt renamed to plugin/spectrum/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# along with this program; if not, write to the Free Software
2222
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323

24-
OPTION(WITH_SPECTRUM_STORAGE "Build Spectrum Storage Plugin" ON)
24+
OPTION(WITH_SPECTRUM "Build Spectrum Plugin" ON)
2525

2626
SET(SPECTRUM_PB_GENERATE_DIR ${CMAKE_BINARY_DIR}/libspectrum/generated/protobuf)
2727

@@ -31,14 +31,14 @@ INCLUDE_DIRECTORIES(
3131
${SPECTRUM_PB_GENERATE_DIR}
3232
)
3333

34-
MYSQL_ADD_PLUGIN(spectrum_storage
35-
spectrum_storage.cc
36-
LINK_LIBRARIES spectrum_pb spectrum_common
34+
MYSQL_ADD_PLUGIN(spectrum
35+
spectrum_plugin.cc
36+
LINK_LIBRARIES spectrum_compute spectrum_storage
3737
DEFAULT
3838
)
3939

4040
INSTALL(FILES
41-
spectrum_storage.ini
41+
spectrum_plugin.ini
4242
DESTINATION ${INSTALL_PLUGINDIR}
4343
COMPONENT Test
4444
)

plugin/spectrum/spectrum_plugin.cc

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Copyright (c) 2006, 2023, Oracle and/or its affiliates.
2+
This program is free software; you can redistribute it and/or modify
3+
it under the terms of the GNU General Public License, version 2.0,
4+
as published by the Free Software Foundation.
5+
This program is also distributed with certain software (including
6+
but not limited to OpenSSL) that is licensed under separate terms,
7+
as designated in a particular file or component or in included license
8+
documentation. The authors of MySQL hereby grant you an additional
9+
permission to link the program and your derivative works with the
10+
separately licensed software that they have included with MySQL.
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License, version 2.0, for more details.
15+
You should have received a copy of the GNU General Public License
16+
along with this program; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
18+
19+
#include <mysql/plugin.h>
20+
#include <stdio.h>
21+
#include <stdlib.h>
22+
23+
#include "mysql/psi/mysql_memory.h"
24+
#include "sql/sql_plugin.h" // st_plugin_int
25+
26+
#include "spectrum.h"
27+
#include "spectrum_config.h"
28+
29+
struct spectrum_plugin_context {
30+
};
31+
32+
PSI_memory_key key_memory_spectrum_plugin_context;
33+
34+
static int spectrum_plugin_init(void *p) {
35+
DBUG_TRACE;
36+
struct spectrum_plugin_context *plugin_context;
37+
struct st_plugin_int *plugin = (struct st_plugin_int *)p;
38+
39+
plugin_context = (struct spectrum_plugin_context *)my_malloc(
40+
key_memory_spectrum_plugin_context,
41+
sizeof(struct spectrum_plugin_context), MYF(0));
42+
plugin->data = (void *)plugin_context;
43+
44+
spectrum_config_init();
45+
46+
if (is_spectrum_storage()) {
47+
spectrum_storage_init();
48+
}
49+
return 0;
50+
}
51+
52+
static int spectrum_plugin_deinit(void *p) {
53+
DBUG_TRACE;
54+
55+
return 0;
56+
}
57+
58+
struct st_mysql_daemon spectrum_plugin = {MYSQL_DAEMON_INTERFACE_VERSION};
59+
60+
/*
61+
Plugin library descriptor
62+
*/
63+
mysql_declare_plugin(spectrum){
64+
MYSQL_DAEMON_PLUGIN,
65+
&spectrum_plugin,
66+
"spectrum",
67+
PLUGIN_AUTHOR_ORACLE,
68+
"Spectrum",
69+
PLUGIN_LICENSE_GPL,
70+
spectrum_plugin_init, /* Plugin Init */
71+
nullptr, /* Plugin Check uninstall */
72+
spectrum_plugin_deinit, /* Plugin Deinit */
73+
0x0100 /* 1.0 */,
74+
nullptr, /* status variables */
75+
nullptr, /* system variables */
76+
nullptr, /* config options */
77+
0, /* flags */
78+
} mysql_declare_plugin_end;

plugin/spectrum_storage/spectrum_storage.ini renamed to plugin/spectrum/spectrum_plugin.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@
2828
# component_name
2929
# [component_name] - additional components in plugin
3030
#
31-
libspectrum_storage
32-
spectrum_storage
31+
libspectrum_plugin

0 commit comments

Comments
 (0)