Skip to content

Commit 1f2a908

Browse files
committed
MENT-346: Performanche Schema tables support for Galera
This commit adds support for Performanche Schema tables for Galera using the new Pefrormance Schema (ps) service.
1 parent 9318a50 commit 1f2a908

File tree

7 files changed

+453
-0
lines changed

7 files changed

+453
-0
lines changed

include/wsrep/provider.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace wsrep
4646
class high_priority_service;
4747
class thread_service;
4848
class tls_service;
49+
class ps_service;
4950

5051
class stid
5152
{
@@ -422,9 +423,11 @@ namespace wsrep
422423
{
423424
wsrep::thread_service* thread_service;
424425
wsrep::tls_service* tls_service;
426+
wsrep::ps_service* ps_service;
425427
services()
426428
: thread_service()
427429
, tls_service()
430+
, ps_service()
428431
{
429432
}
430433
};

include/wsrep/ps_service.hpp

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2020 Codership Oy <[email protected]>
3+
*
4+
* This file is part of wsrep-lib.
5+
*
6+
* Wsrep-lib is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Wsrep-lib 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 for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
/** @file ps_service.hpp
21+
*
22+
* Service interface for interacting with Performance Scheme
23+
* tables at DBMS side.
24+
*/
25+
26+
#ifndef WSREP_PS_SERVICE_HPP
27+
#define WSREP_PS_SERVICE_HPP
28+
29+
#include "compiler.hpp"
30+
#include "provider.hpp"
31+
#include "wsrep_ps.h"
32+
33+
namespace wsrep
34+
{
35+
/** @class ps_service
36+
*
37+
* PS service interface. This provides an interface corresponding
38+
* to wsrep PS service. For details see wsrep-API/ps/wsrep_ps.h
39+
*/
40+
class ps_service
41+
{
42+
public:
43+
virtual ~ps_service() { }
44+
/**
45+
* Fetch cluster information to populate cluster members table.
46+
*/
47+
virtual wsrep_status_t
48+
fetch_pfs_info(provider* provider,
49+
wsrep_node_info_t* nodes,
50+
uint32_t* size) WSREP_NOEXCEPT = 0;
51+
/**
52+
* Fetch node information to populate node statistics table.
53+
*/
54+
virtual wsrep_status_t
55+
fetch_pfs_stat(provider* provider,
56+
wsrep_node_stat_t* node) WSREP_NOEXCEPT = 0;
57+
};
58+
}
59+
60+
#endif // WSREP_PS_SERVICE_HPP

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_library(wsrep-lib
1717
thread.cpp
1818
thread_service_v1.cpp
1919
tls_service_v1.cpp
20+
ps_service_v1.cpp
2021
transaction.cpp
2122
uuid.cpp
2223
wsrep_provider_v26.cpp)

src/ps_service_v1.cpp

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (C) 2020 Codership Oy <[email protected]>
3+
*
4+
* This file is part of wsrep-lib.
5+
*
6+
* Wsrep-lib is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Wsrep-lib 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 for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "ps_service_v1.hpp"
21+
22+
#include "wsrep/ps_service.hpp"
23+
#include "wsrep/logger.hpp"
24+
#include "wsrep/provider.hpp"
25+
#include "service_helpers.hpp"
26+
27+
#include <cassert>
28+
29+
namespace wsrep_ps_service_v1
30+
{
31+
static wsrep::ps_service* ps_service_impl{0};
32+
static std::atomic<size_t> use_count;
33+
34+
static wsrep_ps_service_v1_t ps_callbacks;
35+
}
36+
37+
int wsrep::ps_service_v1_probe(void* dlh)
38+
{
39+
typedef int (*init_fn)(wsrep_ps_service_v1_t*);
40+
typedef void (*deinit_fn)();
41+
if (wsrep_impl::service_probe<init_fn>(
42+
dlh, WSREP_PS_SERVICE_INIT_FUNC_V1, "ps service v1") ||
43+
wsrep_impl::service_probe<deinit_fn>(
44+
dlh, WSREP_PS_SERVICE_DEINIT_FUNC_V1, "ps service v1"))
45+
{
46+
wsrep::log_warning() << "Provider does not support PS service v1";
47+
return 1;
48+
}
49+
return 0;
50+
}
51+
52+
int wsrep::ps_service_v1_init(void* dlh,
53+
wsrep::ps_service* ps_service)
54+
{
55+
if (! (dlh && ps_service)) return EINVAL;
56+
57+
typedef int (*init_fn)(wsrep_ps_service_v1_t*);
58+
wsrep_ps_service_v1::ps_service_impl = ps_service;
59+
int ret(0);
60+
if ((ret = wsrep_impl::service_init<init_fn>(
61+
dlh, WSREP_PS_SERVICE_INIT_FUNC_V1,
62+
&wsrep_ps_service_v1::ps_callbacks,
63+
"PS service v1")))
64+
{
65+
wsrep_ps_service_v1::ps_service_impl = 0;
66+
}
67+
else
68+
{
69+
++wsrep_ps_service_v1::use_count;
70+
}
71+
return ret;
72+
}
73+
74+
void wsrep::ps_service_v1_deinit(void* dlh)
75+
{
76+
typedef int (*deinit_fn)();
77+
wsrep_impl::service_deinit<deinit_fn>(
78+
dlh, WSREP_PS_SERVICE_DEINIT_FUNC_V1, "ps service v1");
79+
--wsrep_ps_service_v1::use_count;
80+
if (wsrep_ps_service_v1::use_count == 0)
81+
{
82+
wsrep_ps_service_v1::ps_service_impl = 0;
83+
}
84+
}
85+
86+
namespace wsrep
87+
{
88+
89+
/**
90+
* Fetch cluster information to populate cluster members table.
91+
*/
92+
wsrep_status_t
93+
ps_service::fetch_pfs_info(provider* provider,
94+
wsrep_node_info_t* nodes,
95+
uint32_t* size) WSREP_NOEXCEPT
96+
{
97+
wsrep_t* wsrep_ = reinterpret_cast<wsrep_t*>(provider->native());
98+
return wsrep_ps_service_v1::
99+
ps_callbacks.fetch_cluster_info(wsrep_, nodes, size);
100+
}
101+
102+
/**
103+
* Fetch node information to populate node statistics table.
104+
*/
105+
wsrep_status_t
106+
ps_service::fetch_pfs_stat(provider* provider,
107+
wsrep_node_stat_t* node) WSREP_NOEXCEPT
108+
{
109+
wsrep_t* wsrep_ = reinterpret_cast<wsrep_t*>(provider->native());
110+
return wsrep_ps_service_v1::
111+
ps_callbacks.fetch_node_stat(wsrep_, node);
112+
}
113+
114+
} // namespace "wsrep"

src/ps_service_v1.hpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2020 Codership Oy <[email protected]>
3+
*
4+
* This file is part of wsrep-lib.
5+
*
6+
* Wsrep-lib is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Wsrep-lib 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 for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef WSREP_PS_SERVICE_V1_HPP
21+
#define WSREP_PS_SERVICE_V1_HPP
22+
23+
namespace wsrep
24+
{
25+
class ps_service;
26+
/**
27+
* Probe thread_service_v1 support in loaded library.
28+
*
29+
* @param dlh Handle returned by dlopen().
30+
*
31+
* @return Zero on success, non-zero system error code on failure.
32+
*/
33+
int ps_service_v1_probe(void *dlh);
34+
35+
/**
36+
* Initialize PS service.
37+
*
38+
* @param dlh Handle returned by dlopen().
39+
* @params thread_service Pointer to wsrep::thread_service implementation.
40+
*
41+
* @return Zero on success, non-zero system error code on failure.
42+
*/
43+
int ps_service_v1_init(void* dlh,
44+
wsrep::ps_service* ps_service);
45+
46+
/**
47+
* Deinitialize PS service.
48+
*
49+
* @param dlh Handler returned by dlopen().
50+
*/
51+
void ps_service_v1_deinit(void* dlh);
52+
}
53+
54+
#endif // WSREP_PS_SERVICE_V1_HPP

src/wsrep_provider_v26.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
#include "wsrep/logger.hpp"
2828
#include "wsrep/thread_service.hpp"
2929
#include "wsrep/tls_service.hpp"
30+
#include "wsrep/ps_service.hpp"
3031

3132
#include "thread_service_v1.hpp"
3233
#include "tls_service_v1.hpp"
34+
#include "ps_service_v1.hpp"
3335
#include "v26/wsrep_api.h"
3436

3537

@@ -635,6 +637,22 @@ namespace
635637
// assert(not wsrep::tls_service_v1_probe(dlh));
636638
wsrep::tls_service_v1_deinit(dlh);
637639
}
640+
641+
static int init_ps_service(void* dlh,
642+
wsrep::ps_service* ps_service)
643+
{
644+
assert(ps_service);
645+
if (! wsrep::ps_service_v1_probe(dlh))
646+
{
647+
return wsrep::ps_service_v1_init(dlh, ps_service);
648+
}
649+
return 1;
650+
}
651+
652+
static void deinit_ps_service(void* dlh)
653+
{
654+
wsrep::ps_service_v1_deinit(dlh);
655+
}
638656
}
639657

640658
void wsrep::wsrep_provider_v26::init_services(
@@ -656,10 +674,20 @@ void wsrep::wsrep_provider_v26::init_services(
656674
}
657675
services_enabled_.tls_service = services.tls_service;
658676
}
677+
if (services.ps_service)
678+
{
679+
if (init_ps_service(wsrep_->dlh, services.ps_service))
680+
{
681+
throw wsrep::runtime_error("Failed to initialze PS service");
682+
}
683+
services_enabled_.ps_service = services.ps_service;
684+
}
659685
}
660686

661687
void wsrep::wsrep_provider_v26::deinit_services()
662688
{
689+
if (services_enabled_.ps_service)
690+
deinit_ps_service(wsrep_->dlh);
663691
if (services_enabled_.tls_service)
664692
deinit_tls_service(wsrep_->dlh);
665693
if (services_enabled_.thread_service)

0 commit comments

Comments
 (0)