Skip to content

Mariadb4.x galera ps API v2 #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/wsrep/provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace wsrep
class high_priority_service;
class thread_service;
class tls_service;
class ps_service;

class stid
{
Expand Down Expand Up @@ -422,9 +423,11 @@ namespace wsrep
{
wsrep::thread_service* thread_service;
wsrep::tls_service* tls_service;
wsrep::ps_service* ps_service;
services()
: thread_service()
, tls_service()
, ps_service()
{
}
};
Expand Down
60 changes: 60 additions & 0 deletions include/wsrep/ps_service.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2020 Codership Oy <[email protected]>
*
* This file is part of wsrep-lib.
*
* Wsrep-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Wsrep-lib 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 wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
*/

/** @file ps_service.hpp
*
* Service interface for interacting with Performance Scheme
* tables at DBMS side.
*/

#ifndef WSREP_PS_SERVICE_HPP
#define WSREP_PS_SERVICE_HPP

#include "compiler.hpp"
#include "provider.hpp"
#include "wsrep_ps.h"

namespace wsrep
{
/** @class ps_service
*
* PS service interface. This provides an interface corresponding
* to wsrep PS service. For details see wsrep-API/ps/wsrep_ps.h
*/
class ps_service
{
public:
virtual ~ps_service() { }
/**
* Fetch cluster information to populate cluster members table.
*/
virtual wsrep_status_t
fetch_pfs_info(provider* provider,
wsrep_node_info_t* nodes,
uint32_t* size) WSREP_NOEXCEPT = 0;
/**
* Fetch node information to populate node statistics table.
*/
virtual wsrep_status_t
fetch_pfs_stat(provider* provider,
wsrep_node_stat_t* node) WSREP_NOEXCEPT = 0;
};
}

#endif // WSREP_PS_SERVICE_HPP
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ add_library(wsrep-lib
thread.cpp
thread_service_v1.cpp
tls_service_v1.cpp
ps_service_v1.cpp
transaction.cpp
uuid.cpp
wsrep_provider_v26.cpp)
Expand Down
114 changes: 114 additions & 0 deletions src/ps_service_v1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright (C) 2020 Codership Oy <[email protected]>
*
* This file is part of wsrep-lib.
*
* Wsrep-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Wsrep-lib 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 wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
*/

#include "ps_service_v1.hpp"

#include "wsrep/ps_service.hpp"
#include "wsrep/logger.hpp"
#include "wsrep/provider.hpp"
#include "service_helpers.hpp"

#include <cassert>

namespace wsrep_ps_service_v1
{
static wsrep::ps_service* ps_service_impl{0};
static std::atomic<size_t> use_count;

static wsrep_ps_service_v1_t ps_callbacks;
}

int wsrep::ps_service_v1_probe(void* dlh)
{
typedef int (*init_fn)(wsrep_ps_service_v1_t*);
typedef void (*deinit_fn)();
if (wsrep_impl::service_probe<init_fn>(
dlh, WSREP_PS_SERVICE_INIT_FUNC_V1, "ps service v1") ||
wsrep_impl::service_probe<deinit_fn>(
dlh, WSREP_PS_SERVICE_DEINIT_FUNC_V1, "ps service v1"))
{
wsrep::log_warning() << "Provider does not support PS service v1";
return 1;
}
return 0;
}

int wsrep::ps_service_v1_init(void* dlh,
wsrep::ps_service* ps_service)
{
if (! (dlh && ps_service)) return EINVAL;

typedef int (*init_fn)(wsrep_ps_service_v1_t*);
wsrep_ps_service_v1::ps_service_impl = ps_service;
int ret(0);
if ((ret = wsrep_impl::service_init<init_fn>(
dlh, WSREP_PS_SERVICE_INIT_FUNC_V1,
&wsrep_ps_service_v1::ps_callbacks,
"PS service v1")))
{
wsrep_ps_service_v1::ps_service_impl = 0;
}
else
{
++wsrep_ps_service_v1::use_count;
}
return ret;
}

void wsrep::ps_service_v1_deinit(void* dlh)
{
typedef int (*deinit_fn)();
wsrep_impl::service_deinit<deinit_fn>(
dlh, WSREP_PS_SERVICE_DEINIT_FUNC_V1, "ps service v1");
--wsrep_ps_service_v1::use_count;
if (wsrep_ps_service_v1::use_count == 0)
{
wsrep_ps_service_v1::ps_service_impl = 0;
}
}

namespace wsrep
{

/**
* Fetch cluster information to populate cluster members table.
*/
wsrep_status_t
ps_service::fetch_pfs_info(provider* provider,
wsrep_node_info_t* nodes,
uint32_t* size) WSREP_NOEXCEPT
{
wsrep_t* wsrep_ = reinterpret_cast<wsrep_t*>(provider->native());
return wsrep_ps_service_v1::
ps_callbacks.fetch_cluster_info(wsrep_, nodes, size);
}

/**
* Fetch node information to populate node statistics table.
*/
wsrep_status_t
ps_service::fetch_pfs_stat(provider* provider,
wsrep_node_stat_t* node) WSREP_NOEXCEPT
{
wsrep_t* wsrep_ = reinterpret_cast<wsrep_t*>(provider->native());
return wsrep_ps_service_v1::
ps_callbacks.fetch_node_stat(wsrep_, node);
}

} // namespace "wsrep"
54 changes: 54 additions & 0 deletions src/ps_service_v1.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2020 Codership Oy <[email protected]>
*
* This file is part of wsrep-lib.
*
* Wsrep-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Wsrep-lib 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 wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef WSREP_PS_SERVICE_V1_HPP
#define WSREP_PS_SERVICE_V1_HPP

namespace wsrep
{
class ps_service;
/**
* Probe thread_service_v1 support in loaded library.
*
* @param dlh Handle returned by dlopen().
*
* @return Zero on success, non-zero system error code on failure.
*/
int ps_service_v1_probe(void *dlh);

/**
* Initialize PS service.
*
* @param dlh Handle returned by dlopen().
* @params thread_service Pointer to wsrep::thread_service implementation.
*
* @return Zero on success, non-zero system error code on failure.
*/
int ps_service_v1_init(void* dlh,
wsrep::ps_service* ps_service);

/**
* Deinitialize PS service.
*
* @param dlh Handler returned by dlopen().
*/
void ps_service_v1_deinit(void* dlh);
}

#endif // WSREP_PS_SERVICE_V1_HPP
28 changes: 28 additions & 0 deletions src/wsrep_provider_v26.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
#include "wsrep/logger.hpp"
#include "wsrep/thread_service.hpp"
#include "wsrep/tls_service.hpp"
#include "wsrep/ps_service.hpp"

#include "thread_service_v1.hpp"
#include "tls_service_v1.hpp"
#include "ps_service_v1.hpp"
#include "v26/wsrep_api.h"


Expand Down Expand Up @@ -635,6 +637,22 @@ namespace
// assert(not wsrep::tls_service_v1_probe(dlh));
wsrep::tls_service_v1_deinit(dlh);
}

static int init_ps_service(void* dlh,
wsrep::ps_service* ps_service)
{
assert(ps_service);
if (! wsrep::ps_service_v1_probe(dlh))
{
return wsrep::ps_service_v1_init(dlh, ps_service);
}
return 1;
}

static void deinit_ps_service(void* dlh)
{
wsrep::ps_service_v1_deinit(dlh);
}
}

void wsrep::wsrep_provider_v26::init_services(
Expand All @@ -656,10 +674,20 @@ void wsrep::wsrep_provider_v26::init_services(
}
services_enabled_.tls_service = services.tls_service;
}
if (services.ps_service)
{
if (init_ps_service(wsrep_->dlh, services.ps_service))
{
throw wsrep::runtime_error("Failed to initialze PS service");
}
services_enabled_.ps_service = services.ps_service;
}
}

void wsrep::wsrep_provider_v26::deinit_services()
{
if (services_enabled_.ps_service)
deinit_ps_service(wsrep_->dlh);
if (services_enabled_.tls_service)
deinit_tls_service(wsrep_->dlh);
if (services_enabled_.thread_service)
Expand Down
Loading