From 3632e7823ca0d5fc2e66f43775f3a50274d5acb8 Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Tue, 3 Jul 2018 07:48:35 +0300 Subject: [PATCH] Pass high_priority_service instead of void ptr for provider methods. --- CMakeLists.txt | 2 +- dbsim/db_high_priority_service.cpp | 12 ++++++------ dbsim/db_high_priority_service.hpp | 10 ++-------- include/wsrep/high_priority_service.hpp | 14 +++++++++++--- include/wsrep/provider.hpp | 8 +++++--- src/wsrep_provider_v26.cpp | 7 ++++--- src/wsrep_provider_v26.hpp | 5 +++-- test/mock_high_priority_service.hpp | 4 +--- test/mock_provider.hpp | 9 +++++---- 9 files changed, 38 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index baf9004..d5988f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ include(CheckIncludeFile) include(CTest) # Options -option(WITH_AUTO_TEST "Run unit tests automatically after build" OFF) +option(WITH_AUTO_TEST "Run unit tests automatically after build" ON) option(WITH_ASAN "Enable address sanitizer" OFF) option(WITH_TSAN "Enable thread sanitizer" OFF) diff --git a/dbsim/db_high_priority_service.cpp b/dbsim/db_high_priority_service.cpp index df64295..1f9b58d 100644 --- a/dbsim/db_high_priority_service.cpp +++ b/dbsim/db_high_priority_service.cpp @@ -6,12 +6,12 @@ #include "db_server.hpp" #include "db_client.hpp" -int db::high_priority_service::apply(const wsrep::ws_handle& ws_handle, - const wsrep::ws_meta& ws_meta, - const wsrep::const_buffer& data) -{ - return server_.server_state().on_apply(*this, ws_handle, ws_meta, data); -} +db::high_priority_service::high_priority_service( + db::server& server, db::client* client) + : wsrep::high_priority_service(server_.server_state()) + , server_(server) + , client_(client) +{ } int db::high_priority_service::start_transaction( const wsrep::ws_handle& ws_handle, diff --git a/dbsim/db_high_priority_service.hpp b/dbsim/db_high_priority_service.hpp index e250729..80c5be7 100644 --- a/dbsim/db_high_priority_service.hpp +++ b/dbsim/db_high_priority_service.hpp @@ -11,16 +11,10 @@ namespace db { class server; class client; - class high_priority_service : wsrep::high_priority_service + class high_priority_service : public wsrep::high_priority_service { public: - high_priority_service(db::server& server, db::client* client) - : server_(server) - , client_(client) - { } - - int apply(const wsrep::ws_handle&, const wsrep::ws_meta&, - const wsrep::const_buffer&) override; + high_priority_service(db::server& server, db::client* client); int start_transaction(const wsrep::ws_handle&, const wsrep::ws_meta&) override; void adopt_transaction(const wsrep::transaction&) override; diff --git a/include/wsrep/high_priority_service.hpp b/include/wsrep/high_priority_service.hpp index 4953de7..7cc8022 100644 --- a/include/wsrep/high_priority_service.hpp +++ b/include/wsrep/high_priority_service.hpp @@ -9,6 +9,8 @@ #ifndef WSREP_HIGH_PRIORITY_SERVICE_HPP #define WSREP_HIGH_PRIORITY_SERVICE_HPP +#include "server_state.hpp" + namespace wsrep { class ws_handle; @@ -18,10 +20,15 @@ namespace wsrep class high_priority_service { public: + high_priority_service(wsrep::server_state& server_state) + : server_state_(server_state) { } virtual ~high_priority_service() { } - virtual int apply(const ws_handle&, const ws_meta&, - const const_buffer&) = 0; + int apply(const ws_handle& ws_handle, const ws_meta& ws_meta, + const const_buffer& data) + { + return server_state_.on_apply(*this, ws_handle, ws_meta, data); + } /** * Start a new transaction */ @@ -71,7 +78,8 @@ namespace wsrep virtual int log_dummy_write_set(const ws_handle&, const ws_meta&) = 0; virtual bool is_replaying() const = 0; - private: + protected: + wsrep::server_state& server_state_; }; class high_priority_switch diff --git a/include/wsrep/provider.hpp b/include/wsrep/provider.hpp index f250cdc..933c31a 100644 --- a/include/wsrep/provider.hpp +++ b/include/wsrep/provider.hpp @@ -20,7 +20,7 @@ namespace wsrep { class server_state; - + class high_priority_service; class stid { public: @@ -237,7 +237,8 @@ namespace wsrep virtual int resume() = 0; // Applier interface - virtual enum status run_applier(void* applier_ctx) = 0; + virtual enum status run_applier(wsrep::high_priority_service* + applier_ctx) = 0; // Write set replication // TODO: Rename to assing_read_view() virtual int start_transaction(wsrep::ws_handle&) = 0; @@ -276,7 +277,8 @@ namespace wsrep * @return Zero in case of success, non-zero on failure. */ virtual enum status replay( - const wsrep::ws_handle& ws_handle, void* applier_ctx) = 0; + const wsrep::ws_handle& ws_handle, + wsrep::high_priority_service* applier_ctx) = 0; /** * Enter total order isolation critical section diff --git a/src/wsrep_provider_v26.cpp b/src/wsrep_provider_v26.cpp index 870d4b2..ba7b31b 100644 --- a/src/wsrep_provider_v26.cpp +++ b/src/wsrep_provider_v26.cpp @@ -554,7 +554,8 @@ int wsrep::wsrep_provider_v26::resume() } enum wsrep::provider::status -wsrep::wsrep_provider_v26::run_applier(void *applier_ctx) +wsrep::wsrep_provider_v26::run_applier( + wsrep::high_priority_service *applier_ctx) { return map_return_value(wsrep_->recv(wsrep_, applier_ctx)); } @@ -649,11 +650,11 @@ int wsrep::wsrep_provider_v26::release(wsrep::ws_handle& ws_handle) enum wsrep::provider::status wsrep::wsrep_provider_v26::replay(const wsrep::ws_handle& ws_handle, - void* applier_ctx) + wsrep::high_priority_service* reply_service) { const_ws_handle mwsh(ws_handle); return map_return_value( - wsrep_->replay_trx(wsrep_, mwsh.native(), applier_ctx)); + wsrep_->replay_trx(wsrep_, mwsh.native(), reply_service)); } enum wsrep::provider::status diff --git a/src/wsrep_provider_v26.hpp b/src/wsrep_provider_v26.hpp index 5ec1f7a..d5f241a 100644 --- a/src/wsrep_provider_v26.hpp +++ b/src/wsrep_provider_v26.hpp @@ -29,7 +29,7 @@ namespace wsrep wsrep::seqno pause(); int resume(); - enum wsrep::provider::status run_applier(void*); + enum wsrep::provider::status run_applier(wsrep::high_priority_service*); int start_transaction(wsrep::ws_handle&) { return 0; } int append_key(wsrep::ws_handle&, const wsrep::key&); enum wsrep::provider::status @@ -49,7 +49,8 @@ namespace wsrep int commit_order_leave(const wsrep::ws_handle&, const wsrep::ws_meta&); int release(wsrep::ws_handle&); - enum wsrep::provider::status replay(const wsrep::ws_handle&, void*); + enum wsrep::provider::status replay(const wsrep::ws_handle&, + wsrep::high_priority_service*); enum wsrep::provider::status enter_toi(wsrep::client_id, const wsrep::key_array&, const wsrep::const_buffer&, diff --git a/test/mock_high_priority_service.hpp b/test/mock_high_priority_service.hpp index 604a458..9f7daf0 100644 --- a/test/mock_high_priority_service.hpp +++ b/test/mock_high_priority_service.hpp @@ -17,10 +17,9 @@ namespace wsrep wsrep::server_state& server_state, wsrep::mock_client_state* client_state, bool replaying) - : wsrep::high_priority_service() + : wsrep::high_priority_service(server_state) , fail_next_applying_() , fail_next_toi_() - , server_state_(server_state) , client_state_(client_state) , replaying_(replaying) { } @@ -53,7 +52,6 @@ namespace wsrep private: mock_high_priority_service(const mock_high_priority_service&); mock_high_priority_service& operator=(const mock_high_priority_service&); - wsrep::server_state& server_state_; wsrep::mock_client_state* client_state_; bool replaying_; }; diff --git a/test/mock_provider.hpp b/test/mock_provider.hpp index 4ba2b8e..5698c30 100644 --- a/test/mock_provider.hpp +++ b/test/mock_provider.hpp @@ -50,7 +50,7 @@ namespace wsrep int resync() { return 0; } wsrep::seqno pause() { return wsrep::seqno(0); } int resume() { return 0; } - enum wsrep::provider::status run_applier(void*) + enum wsrep::provider::status run_applier(wsrep::high_priority_service*) { return wsrep::provider::success; } @@ -160,11 +160,12 @@ namespace wsrep return release_result_; } - enum wsrep::provider::status replay(const wsrep::ws_handle& ws_handle, - void* ctx) + enum wsrep::provider::status replay( + const wsrep::ws_handle& ws_handle, + wsrep::high_priority_service* hps) { wsrep::mock_high_priority_service& high_priority_service( - *static_cast(ctx)); + *static_cast(hps)); wsrep::mock_client_state& cc( *high_priority_service.client_state()); wsrep::high_priority_context high_priority_context(cc);