Skip to content

Commit e6ac2ce

Browse files
committed
WL#8879 : PERFORMANCE_SCHEMA, TABLE PLUGIN
1 parent 341a5f5 commit e6ac2ce

File tree

155 files changed

+10490
-186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+10490
-186
lines changed

Doxyfile

+1
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ INPUT = ./client \
871871
./plugin/test_services \
872872
./plugin/test_service_sql_api \
873873
./plugin/version_token \
874+
./plugin/pfs_table_plugin \
874875
./rapid \
875876
./sql \
876877
./sql-common \

components/mysql_server/server_component.cc

+14-7
Original file line numberDiff line numberDiff line change
@@ -348,21 +348,28 @@ bool mysql_services_bootstrap(SERVICE_TYPE(registry)** registry)
348348
return false;
349349
}
350350

351-
/**
352-
Shutdowns service registry and dynamic loader making sure all basic services
353-
are unregistered. Will fail if any service implementation is in use.
354351

355-
@return Status of performed operation
356-
@retval false success
357-
@retval true failure
352+
/**
353+
Shutdowns dynamic loader.
358354
*/
359-
bool mysql_services_shutdown()
355+
void shutdown_dynamic_loader()
360356
{
361357
/* Dynamic loader deinitialization still needs all scheme service
362358
implementations to be functional. */
363359
dynamic_loader_deinit();
364360
dynamic_loader_scheme_file_deinit();
361+
}
365362

363+
/**
364+
Shutdowns service registry making sure all basic services are unregistered.
365+
Will fail if any service implementation is in use.
366+
367+
@return Status of performed operation
368+
@retval false success
369+
@retval true failure
370+
*/
371+
bool mysql_services_shutdown()
372+
{
366373
for (int inx= 0;
367374
mysql_component_mysql_server.provides[inx].implementation != NULL;
368375
++inx)

components/mysql_server/server_component.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ void mysql_string_services_init();
6161
bool mysql_services_bootstrap(SERVICE_TYPE(registry)** registry);
6262

6363
/**
64-
Shutdowns service registry and dynamic loader making sure all basic services
65-
are unregistered. Will fail if any service implementation is in use.
64+
Shutdowns dynamic loader.
65+
*/
66+
void shutdown_dynamic_loader();
67+
68+
/**
69+
Shutdowns service registry making sure all basic services are unregistered.
70+
Will fail if any service implementation is in use.
6671
6772
@return Status of performed operation
6873
@retval false success
@@ -75,4 +80,6 @@ void mysql_components_handle_std_exception(const char* funcname);
7580
/* A declaration of registry service required for my_service<> to work. */
7681
extern SERVICE_TYPE(registry) imp_mysql_server_registry;
7782

83+
extern SERVICE_TYPE(registry_registration) imp_mysql_server_registry_registration;
84+
7885
#endif /* MYSQL_SERVER_COMPONENT_H */
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
#
4+
# This program is free software; you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation; version 2 of the License.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program; if not, write to the Free Software Foundation,
15+
# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16+
17+
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/components/pfs_component)
18+
19+
REMOVE_DEFINITIONS(-DMYSQL_SERVER)
20+
21+
SET(PFS_EXAMPLE_COMPONENT_POPULATION_SOURCE
22+
pfs_example_component_population.cc
23+
pfs_example_continent.cc
24+
pfs_example_country.cc)
25+
26+
MYSQL_ADD_COMPONENT(pfs_example_component_population ${PFS_EXAMPLE_COMPONENT_POPULATION_SOURCE} TEST MODULE)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15+
16+
#include <cstring>
17+
#include "pfs_example_component_population.h"
18+
#include "pfs_example_continent.h"
19+
#include "pfs_example_country.h"
20+
#include "my_sys.h"
21+
22+
/**
23+
@page EXAMPLE_COMPONENT An example component
24+
25+
Component Name : pfs_example_component_population \n
26+
Source location : components/pfs_component
27+
28+
This file contains a definition of the pfs_example_component_population.
29+
*/
30+
31+
/* clang-format off */
32+
/* Records to be inserted into pfs_example_continent table from component code */
33+
Continent_record continent_array[] =
34+
{
35+
{"bar1", 4, true},
36+
{"bar2", 4, true}
37+
};
38+
39+
/* Records to be inserted into pfs_example_country table from component code */
40+
Country_record country_array[] =
41+
{
42+
{"foo1", 4, "bar1", 4, {2016, false}, {10000, false}, {1.11, false}, true},
43+
{"foo2", 4, "bar2", 4, {2016, false}, {1000, false}, {2.22, false}, true}
44+
};
45+
/* clang-format on */
46+
47+
#define MAX_BUFFER_LENGTH 80
48+
49+
#define WRITE_LOG(lit_log_text) \
50+
if (outfile) \
51+
{ \
52+
strcpy (log_text, lit_log_text); \
53+
fwrite((uchar*)log_text, sizeof(char), strlen(log_text), outfile); \
54+
}
55+
56+
/* Log file */
57+
FILE *outfile = NULL;
58+
const char *filename= "pfs_example_component_population.log";
59+
char log_text[MAX_BUFFER_LENGTH] = {'\0'};
60+
61+
/* Collection of table shares to be added to performance schema */
62+
PFS_engine_table_share_proxy *share_list[2] = {NULL, NULL};
63+
unsigned int share_list_count = 2;
64+
65+
/* Prepare and insert rows in pfs_example_continent table */
66+
int
67+
continent_prepare_insert_row()
68+
{
69+
int result = 0;
70+
Continent_Table_Handle handle;
71+
int array_size = sizeof(continent_array) / sizeof(continent_array[0]);
72+
73+
for (int i = 0; i < array_size; i++)
74+
{
75+
/* Prepare a sample row to be inserted from here */
76+
strncpy(handle.current_row.name,
77+
continent_array[i].name,
78+
continent_array[i].name_length);
79+
handle.current_row.name_length = continent_array[i].name_length;
80+
handle.current_row.m_exist = continent_array[i].m_exist;
81+
82+
/* Insert a row in the table to be added */
83+
result = write_rows_from_component(&handle);
84+
if (result)
85+
break;
86+
}
87+
88+
return result;
89+
}
90+
91+
/* Prepare and insert rows in pfs_example_country table */
92+
int
93+
country_prepare_insert_row()
94+
{
95+
int result = 0;
96+
Country_Table_Handle handle;
97+
int array_size = sizeof(country_array) / sizeof(country_array[0]);
98+
99+
for (int i = 0; i < array_size; i++)
100+
{
101+
/* Prepare a sample row to be inserted from here */
102+
strncpy(handle.current_row.name,
103+
country_array[i].name,
104+
country_array[i].name_length);
105+
handle.current_row.name_length = country_array[i].name_length;
106+
strncpy(handle.current_row.continent_name,
107+
country_array[i].continent_name,
108+
country_array[i].continent_name_length);
109+
handle.current_row.continent_name_length =
110+
country_array[i].continent_name_length;
111+
handle.current_row.year = country_array[i].year;
112+
handle.current_row.population = country_array[i].population;
113+
handle.current_row.growth_factor = country_array[i].growth_factor;
114+
handle.current_row.m_exist = country_array[i].m_exist;
115+
116+
/* Insert a row in the table to be added */
117+
result = country_write_row_values((PSI_table_handle *)&handle);
118+
if (result)
119+
break;
120+
}
121+
122+
return result;
123+
}
124+
125+
/**
126+
* Initialize the pfs_example_component_population at server start or
127+
* component installation.
128+
*
129+
* - Instantiate and initialize PFS_engine_table_share_proxy.
130+
* - Prepare and insert rows in tables from here.
131+
* - Call add_table method of pfs_plugin_table service.
132+
*
133+
* @retval 0 success
134+
* @retval non-zero failure
135+
*/
136+
137+
mysql_service_status_t
138+
pfs_example_component_population_init()
139+
{
140+
mysql_service_status_t result = 0;
141+
/* If fopen fails, outfile will be NULL so there will be no write
142+
in WRITE_LOG
143+
*/
144+
outfile= fopen(filename, "w+");
145+
146+
WRITE_LOG("pfs_example_component_population init:\n");
147+
148+
/* Initialize mutex */
149+
native_mutex_init(&LOCK_continent_records_array, NULL);
150+
native_mutex_init(&LOCK_country_records_array, NULL);
151+
152+
/* Instantiate and initialize PFS_engine_table_share_proxy */
153+
init_continent_share(&continent_st_share);
154+
init_country_share(&country_st_share);
155+
156+
/* From here, prepare rows for tables and insert */
157+
if (continent_prepare_insert_row() || country_prepare_insert_row())
158+
{
159+
WRITE_LOG("Error returned from prepare_insert_row()\n");
160+
result = true;
161+
goto error;
162+
}
163+
164+
/* Prepare the shares list to be passed to the service call */
165+
share_list[0] = &continent_st_share;
166+
share_list[1] = &country_st_share;
167+
168+
/**
169+
* Call add_table function of pfs_plugin_table service to
170+
* add component tables in performance schema.
171+
*/
172+
if (mysql_service_pfs_plugin_table->add_tables(&share_list[0],
173+
share_list_count))
174+
{
175+
WRITE_LOG("Error returned from add_tables()\n");
176+
result = true;
177+
goto error;
178+
}
179+
else
180+
{
181+
WRITE_LOG ("Passed add_tables()\n");
182+
}
183+
184+
error:
185+
WRITE_LOG ("End of init\n\n");
186+
fclose(outfile);
187+
if (result)
188+
{
189+
/* Destroy mutexes */
190+
native_mutex_destroy(&LOCK_continent_records_array);
191+
native_mutex_destroy(&LOCK_country_records_array);
192+
}
193+
return result;
194+
}
195+
196+
/**
197+
* Terminate the pfs_example_component_population at server shutdown or
198+
* component deinstallation.
199+
*
200+
* - Delete/Drop component tables from Performance Schema.
201+
*
202+
* @retval 0 success
203+
* @retval non-zero failure
204+
*/
205+
mysql_service_status_t
206+
pfs_example_component_population_deinit()
207+
{
208+
mysql_service_status_t result = 0;
209+
/* If fopen fails, outfile will be NULL so there will be no write
210+
in WRITE_LOG
211+
*/
212+
outfile= fopen(filename, "a+");
213+
214+
WRITE_LOG("pfs_example_component_population_deinit:\n");
215+
216+
/**
217+
* Call delete_tables function of pfs_plugin_table service to
218+
* delete component tables from performance schema
219+
*/
220+
if (mysql_service_pfs_plugin_table->delete_tables(&share_list[0],
221+
share_list_count))
222+
{
223+
WRITE_LOG("Error returned from delete_table()\n");
224+
result = 1;
225+
goto error;
226+
}
227+
else
228+
{
229+
WRITE_LOG ("Passed delete_tables()\n");
230+
}
231+
232+
error:
233+
if (!result)
234+
{
235+
/* Destroy mutexes */
236+
native_mutex_destroy(&LOCK_continent_records_array);
237+
native_mutex_destroy(&LOCK_country_records_array);
238+
}
239+
240+
WRITE_LOG ("End of deinit\n\n");
241+
fclose(outfile);
242+
return result;
243+
}
244+
245+
/* pfs_example_component_population doesn't provide any service */
246+
BEGIN_COMPONENT_PROVIDES(pfs_example_component_population)
247+
END_COMPONENT_PROVIDES()
248+
249+
/* pfs_example_component requires/uses pfs_plugin_table service */
250+
REQUIRES_SERVICE_PLACEHOLDER(pfs_plugin_table);
251+
252+
BEGIN_COMPONENT_REQUIRES(pfs_example_component_population)
253+
REQUIRES_SERVICE(pfs_plugin_table)
254+
END_COMPONENT_REQUIRES()
255+
256+
/* A list of metadata to describe the Component. */
257+
BEGIN_COMPONENT_METADATA(pfs_example_component_population)
258+
METADATA("mysql.author", "Oracle Corporation")
259+
METADATA("mysql.license", "GPL")
260+
METADATA("test_property", "1")
261+
END_COMPONENT_METADATA()
262+
263+
/* Declaration of the Component. */
264+
DECLARE_COMPONENT(pfs_example_component_population, "mysql:pfs_example_component_population")
265+
pfs_example_component_population_init,
266+
pfs_example_component_population_deinit
267+
END_DECLARE_COMPONENT()
268+
269+
/* Defines list of Components contained in this library. Note that for now we
270+
assume that library will have exactly one Component. */
271+
DECLARE_LIBRARY_COMPONENTS
272+
&COMPONENT_REF(pfs_example_component_population)
273+
END_DECLARE_LIBRARY_COMPONENTS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA */
15+
16+
#ifndef PFS_EXAMPLE_COMPONENT_H
17+
#define PFS_EXAMPLE_COMPONENT_H
18+
19+
#include <mysql/components/component_implementation.h>
20+
#include <mysql/components/service_implementation.h>
21+
#include <mysql/components/services/pfs_plugin_table_service.h>
22+
23+
/* A place to specify component-wide declarations, including declarations of
24+
placeholders for Service dependencies. */
25+
26+
extern REQUIRES_SERVICE_PLACEHOLDER(pfs_plugin_table);
27+
28+
#endif /* PFS_EXAMPLE_COMPONENT_H */

0 commit comments

Comments
 (0)