|
| 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" |
0 commit comments