mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-31 18:24:25 +03:00
Squashed commit of the following:
commit3b419aa6e2
Author: Teemu Ollakka <teemu.ollakka@galeracluster.com> Date: Sun Feb 19 10:29:34 2023 +0200 Skip fetching config options if provider not loaded via wsrep-API commit044220cc06
Author: Teemu Ollakka <teemu.ollakka@galeracluster.com> Date: Wed Jul 13 10:31:03 2022 +0300 Operation context pointer for client state commiteeb05a9238
Author: Teemu Ollakka <teemu.ollakka@galeracluster.com> Date: Mon Jul 4 09:03:23 2022 +0300 Add unit test log in gitignore commit92a04070fc
Author: Teemu Ollakka <teemu.ollakka@galeracluster.com> Date: Sun May 8 12:45:36 2022 +0300 Added convenience method prev() to seqno commitf83ca1917e
Author: Teemu Ollakka <teemu.ollakka@galeracluster.com> Date: Sun May 1 16:37:24 2022 +0300 Pass victim context for provider on BF abort This change is needed for custom provider implementations to have a way to access the victim in the application context. Helper interface operation_context to pass caller context for service/provider callbacks in more type safe way. commit244eabe8cf
Author: Teemu Ollakka <teemu.ollakka@galeracluster.com> Date: Wed May 25 07:39:43 2022 +0300 Handle disconnecting state in on_sync() When disconnecting from the group, the sync event from the provider must not change the state back to synced. commitba8e23df0d
Author: Teemu Ollakka <teemu.ollakka@galeracluster.com> Date: Tue Mar 22 17:43:52 2022 +0200 Add provider position field to ws_meta and view Provider position is needed in coordinated recovery between application and provider. Pass the position info from provider to application to allow making it durable. commit53e60f64c9
Author: Teemu Ollakka <teemu.ollakka@galeracluster.com> Date: Sat Mar 19 14:45:57 2022 +0200 Reset TOI meta after releasing total order in provider This is to keep the TOI meta available in case the provider implementation needs it. commitbccb9997f2
Author: Teemu Ollakka <teemu.ollakka@galeracluster.com> Date: Mon Jan 3 11:19:58 2022 +0200 Fixed id ostream operator to print human readable ids commit6d0b37daaf
Author: Teemu Ollakka <teemu.ollakka@galeracluster.com> Date: Wed Dec 15 16:37:45 2021 +0200 Silence unused variable warning commit4b8616f3d1
Author: Denis Protivensky <denis.protivensky@galeracluster.com> Date: Wed Dec 15 16:43:31 2021 +0300 Fix provider loading in test for release builds commit6df17812d9
Author: Denis Protivensky <denis.protivensky@galeracluster.com> Date: Tue Dec 14 20:28:56 2021 +0300 Introduce set_provider_factory() method for server_state This allows injecting an application allocated provider into server_state. After this virtual provider getter is unnecessary. Made the getter normal method and fixed unit tests accordingly.
This commit is contained in:
@ -40,6 +40,7 @@
|
||||
#include "thread.hpp"
|
||||
#include "xid.hpp"
|
||||
#include "chrono.hpp"
|
||||
#include "operation_context.hpp"
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
@ -544,7 +545,9 @@ namespace wsrep
|
||||
* @param lock Lock to protect client state.
|
||||
* @param bf_seqno Seqno of the BF aborter.
|
||||
*/
|
||||
int bf_abort(wsrep::unique_lock<wsrep::mutex>& lock, wsrep::seqno bf_seqno);
|
||||
int bf_abort(wsrep::unique_lock<wsrep::mutex>& lock,
|
||||
wsrep::seqno bf_seqno,
|
||||
wsrep::operation_context& victim_ctx);
|
||||
/**
|
||||
* Wrapper to bf_abort() call, grabs lock internally.
|
||||
*/
|
||||
@ -555,7 +558,9 @@ namespace wsrep
|
||||
* should be called by the TOI operation which needs to
|
||||
* BF abort a transaction.
|
||||
*/
|
||||
int total_order_bf_abort(wsrep::unique_lock<wsrep::mutex>& lock, wsrep::seqno bf_seqno);
|
||||
int total_order_bf_abort(wsrep::unique_lock<wsrep::mutex>& lock,
|
||||
wsrep::seqno bf_seqno,
|
||||
wsrep::operation_context& victim_ctx);
|
||||
|
||||
/**
|
||||
* Wrapper to total_order_bf_abort(), grabs lock internally.
|
||||
@ -911,6 +916,9 @@ namespace wsrep
|
||||
{
|
||||
return rollbacker_active_;
|
||||
}
|
||||
|
||||
void set_operation_context(wsrep::operation_context* context);
|
||||
wsrep::operation_context* operation_context();
|
||||
protected:
|
||||
/**
|
||||
* Client context constuctor. This is protected so that it
|
||||
@ -923,6 +931,7 @@ namespace wsrep
|
||||
const client_id& id,
|
||||
enum mode mode)
|
||||
: owning_thread_id_(wsrep::this_thread::get_id())
|
||||
, current_context_()
|
||||
, rollbacker_active_(false)
|
||||
, mutex_(mutex)
|
||||
, cond_(cond)
|
||||
@ -986,6 +995,7 @@ namespace wsrep
|
||||
void leave_toi_common();
|
||||
|
||||
wsrep::thread::id owning_thread_id_;
|
||||
wsrep::operation_context* current_context_;
|
||||
bool rollbacker_active_;
|
||||
wsrep::mutex& mutex_;
|
||||
wsrep::condition_variable& cond_;
|
||||
|
41
include/wsrep/operation_context.hpp
Normal file
41
include/wsrep/operation_context.hpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Codership Oy <info@codership.com>
|
||||
*
|
||||
* 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 operation_context.hpp
|
||||
*
|
||||
* A slightly more type safe way compared to void pointers to
|
||||
* pass operation contexts through wsrep-lib to callbacks.
|
||||
*/
|
||||
|
||||
#ifndef WSREP_OPERATION_CONTEXT_HPP
|
||||
#define WSREP_OPERATION_CONTEXT_HPP
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
struct operation_context
|
||||
{
|
||||
virtual ~operation_context() = default;
|
||||
};
|
||||
|
||||
struct null_operation_context : operation_context
|
||||
{
|
||||
};
|
||||
} // namespace wsrep
|
||||
|
||||
#endif /* WSREP_OPERATION_CONTEXT_HPP */
|
@ -26,9 +26,11 @@
|
||||
#include "client_id.hpp"
|
||||
#include "transaction_id.hpp"
|
||||
#include "compiler.hpp"
|
||||
#include "operation_context.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
@ -123,21 +125,25 @@ namespace wsrep
|
||||
, stid_()
|
||||
, depends_on_()
|
||||
, flags_()
|
||||
, provider_position_()
|
||||
{ }
|
||||
ws_meta(const wsrep::gtid& gtid,
|
||||
const wsrep::stid& stid,
|
||||
wsrep::seqno depends_on,
|
||||
int flags)
|
||||
int flags,
|
||||
int64_t provider_position)
|
||||
: gtid_(gtid)
|
||||
, stid_(stid)
|
||||
, depends_on_(depends_on)
|
||||
, flags_(flags)
|
||||
, provider_position_(provider_position)
|
||||
{ }
|
||||
ws_meta(const wsrep::stid& stid)
|
||||
: gtid_()
|
||||
, stid_(stid)
|
||||
, depends_on_()
|
||||
, flags_()
|
||||
, provider_position_()
|
||||
{ }
|
||||
const wsrep::gtid& gtid() const { return gtid_; }
|
||||
const wsrep::id& group_id() const
|
||||
@ -169,6 +175,8 @@ namespace wsrep
|
||||
|
||||
wsrep::seqno depends_on() const { return depends_on_; }
|
||||
|
||||
int64_t provider_position() const { return provider_position_; }
|
||||
|
||||
int flags() const { return flags_; }
|
||||
|
||||
bool operator==(const ws_meta& other) const
|
||||
@ -185,6 +193,8 @@ namespace wsrep
|
||||
wsrep::stid stid_;
|
||||
wsrep::seqno depends_on_;
|
||||
int flags_;
|
||||
/** Field reserved for provider to report its internal position. */
|
||||
int64_t provider_position_;
|
||||
};
|
||||
|
||||
std::string flags_to_string(int flags);
|
||||
@ -333,6 +343,7 @@ namespace wsrep
|
||||
*/
|
||||
virtual enum status bf_abort(wsrep::seqno bf_seqno,
|
||||
wsrep::transaction_id victim_trx,
|
||||
wsrep::operation_context& victim_ctx,
|
||||
wsrep::seqno& victim_seqno) = 0;
|
||||
virtual enum status rollback(wsrep::transaction_id) = 0;
|
||||
virtual enum status commit_order_enter(const wsrep::ws_handle&,
|
||||
@ -365,6 +376,7 @@ namespace wsrep
|
||||
* Leave total order isolation critical section
|
||||
*/
|
||||
virtual enum status leave_toi(wsrep::client_id,
|
||||
const wsrep::ws_meta& ws_meta,
|
||||
const wsrep::mutable_buffer& err) = 0;
|
||||
|
||||
/**
|
||||
@ -457,11 +469,12 @@ namespace wsrep
|
||||
* @param provider_options Initial options to provider
|
||||
* @param thread_service Optional thread service implementation.
|
||||
*/
|
||||
static provider* make_provider(wsrep::server_state&,
|
||||
const std::string& provider_spec,
|
||||
const std::string& provider_options,
|
||||
const wsrep::provider::services& services
|
||||
= wsrep::provider::services());
|
||||
static std::unique_ptr<provider> make_provider(
|
||||
wsrep::server_state&,
|
||||
const std::string& provider_spec,
|
||||
const std::string& provider_options,
|
||||
const wsrep::provider::services& services
|
||||
= wsrep::provider::services());
|
||||
|
||||
protected:
|
||||
wsrep::server_state& server_state_;
|
||||
|
@ -51,6 +51,11 @@ namespace wsrep
|
||||
return (seqno_ == -1);
|
||||
}
|
||||
|
||||
wsrep::seqno prev() const
|
||||
{
|
||||
return seqno{seqno_ - 1};
|
||||
}
|
||||
|
||||
bool operator<(seqno other) const
|
||||
{
|
||||
return (seqno_ < other.seqno_);
|
||||
|
@ -92,7 +92,9 @@
|
||||
#include "compiler.hpp"
|
||||
#include "xid.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
@ -188,8 +190,6 @@ namespace wsrep
|
||||
rm_sync
|
||||
};
|
||||
|
||||
virtual ~server_state();
|
||||
|
||||
wsrep::encryption_service* encryption_service()
|
||||
{ return encryption_service_; }
|
||||
|
||||
@ -299,6 +299,17 @@ namespace wsrep
|
||||
const wsrep::provider::services& services
|
||||
= wsrep::provider::services());
|
||||
|
||||
using provider_factory_func =
|
||||
std::function<decltype(wsrep::provider::make_provider)>;
|
||||
|
||||
/**
|
||||
* Set provider factory method.
|
||||
*
|
||||
* @param Factory method to create a provider.
|
||||
*/
|
||||
void set_provider_factory(const provider_factory_func&);
|
||||
|
||||
/** Unload/unset provider. */
|
||||
void unload_provider();
|
||||
|
||||
bool is_provider_loaded() const { return provider_ != 0; }
|
||||
@ -310,12 +321,8 @@ namespace wsrep
|
||||
*
|
||||
* @throw wsrep::runtime_error if provider has not been loaded
|
||||
*
|
||||
* @todo This should not be virtual. However, currently there
|
||||
* is no mechanism for tests and integrations to provide
|
||||
* their own provider implementations, so this is kept virtual
|
||||
* for time being.
|
||||
*/
|
||||
virtual wsrep::provider& provider() const
|
||||
wsrep::provider& provider() const
|
||||
{
|
||||
if (provider_ == 0)
|
||||
{
|
||||
@ -618,6 +625,7 @@ namespace wsrep
|
||||
, streaming_appliers_()
|
||||
, streaming_appliers_recovered_()
|
||||
, provider_()
|
||||
, provider_factory_(wsrep::provider::make_provider)
|
||||
, name_(name)
|
||||
, id_(wsrep::id::undefined())
|
||||
, incoming_address_(incoming_address)
|
||||
@ -702,7 +710,8 @@ namespace wsrep
|
||||
wsrep::high_priority_service*> streaming_appliers_map;
|
||||
streaming_appliers_map streaming_appliers_;
|
||||
bool streaming_appliers_recovered_;
|
||||
wsrep::provider* provider_;
|
||||
std::unique_ptr<wsrep::provider> provider_;
|
||||
provider_factory_func provider_factory_;
|
||||
std::string name_;
|
||||
wsrep::id id_;
|
||||
std::string incoming_address_;
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "sr_key_set.hpp"
|
||||
#include "buffer.hpp"
|
||||
#include "xid.hpp"
|
||||
#include "operation_context.hpp"
|
||||
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
@ -199,9 +200,11 @@ namespace wsrep
|
||||
void after_applying();
|
||||
|
||||
bool bf_abort(wsrep::unique_lock<wsrep::mutex>& lock,
|
||||
wsrep::seqno bf_seqno);
|
||||
wsrep::seqno bf_seqno,
|
||||
wsrep::operation_context&);
|
||||
bool total_order_bf_abort(wsrep::unique_lock<wsrep::mutex>&,
|
||||
wsrep::seqno bf_seqno);
|
||||
wsrep::seqno bf_seqno,
|
||||
wsrep::operation_context&);
|
||||
|
||||
void clone_for_replay(const wsrep::transaction& other);
|
||||
|
||||
|
@ -70,6 +70,7 @@ namespace wsrep
|
||||
, capabilities_()
|
||||
, own_index_(-1)
|
||||
, protocol_version_(0)
|
||||
, provider_position_()
|
||||
, members_()
|
||||
{ }
|
||||
view(const wsrep::gtid& state_id,
|
||||
@ -78,13 +79,15 @@ namespace wsrep
|
||||
int capabilities,
|
||||
ssize_t own_index,
|
||||
int protocol_version,
|
||||
const std::vector<wsrep::view::member>& members)
|
||||
const std::vector<wsrep::view::member>& members,
|
||||
int64_t provider_position)
|
||||
: state_id_(state_id)
|
||||
, view_seqno_(view_seqno)
|
||||
, status_(status)
|
||||
, capabilities_(capabilities)
|
||||
, own_index_(own_index)
|
||||
, protocol_version_(protocol_version)
|
||||
, provider_position_(provider_position)
|
||||
, members_(members)
|
||||
{ }
|
||||
|
||||
@ -111,6 +114,9 @@ namespace wsrep
|
||||
int protocol_version() const
|
||||
{ return protocol_version_; }
|
||||
|
||||
int64_t provider_position() const
|
||||
{ return provider_position_; }
|
||||
|
||||
const std::vector<member>& members() const
|
||||
{ return members_; }
|
||||
|
||||
@ -147,6 +153,8 @@ namespace wsrep
|
||||
int capabilities_;
|
||||
ssize_t own_index_;
|
||||
int protocol_version_;
|
||||
/** Field reserved for provider to report its internal position. */
|
||||
int64_t provider_position_;
|
||||
std::vector<wsrep::view::member> members_;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user