mirror of
				https://github.com/codership/wsrep-lib.git
				synced 2025-11-03 05:33:11 +03:00 
			
		
		
		
	MDEV-32363 Add interface to set node isolation mode in provider
This commit is contained in:
		@@ -288,6 +288,21 @@ namespace wsrep
 | 
				
			|||||||
            static std::string str(int);
 | 
					            static std::string str(int);
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * Node isolation mode.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        enum node_isolation
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            /** Node is not isolated. */
 | 
				
			||||||
 | 
					            not_isolated,
 | 
				
			||||||
 | 
					            /** Node is isolated from the rest of the cluster on
 | 
				
			||||||
 | 
					             * network level. */
 | 
				
			||||||
 | 
					            isolated,
 | 
				
			||||||
 | 
					            /** As on, but also force the provider to deliver a view with
 | 
				
			||||||
 | 
					             * disconnected status. */
 | 
				
			||||||
 | 
					            force_disconnect
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        provider(wsrep::server_state& server_state)
 | 
					        provider(wsrep::server_state& server_state)
 | 
				
			||||||
            : server_state_(server_state)
 | 
					            : server_state_(server_state)
 | 
				
			||||||
        { }
 | 
					        { }
 | 
				
			||||||
@@ -389,6 +404,16 @@ namespace wsrep
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        virtual std::string options() const = 0;
 | 
					        virtual std::string options() const = 0;
 | 
				
			||||||
        virtual enum status options(const std::string&) = 0;
 | 
					        virtual enum status options(const std::string&) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * Set node isolation mode.
 | 
				
			||||||
 | 
					         *
 | 
				
			||||||
 | 
					         * @param mode node_isolation mode.
 | 
				
			||||||
 | 
					         * @return Provider status indicating the result of the call.
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        virtual enum status set_node_isolation(enum node_isolation mode) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * Get provider name.
 | 
					         * Get provider name.
 | 
				
			||||||
         *
 | 
					         *
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -100,7 +100,29 @@ namespace wsrep_impl
 | 
				
			|||||||
                << service_name;
 | 
					                << service_name;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					
 | 
				
			||||||
 | 
					    template <typename Fn> Fn resolve_function(void* dlh, const char* symbol)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        union
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Fn fun;
 | 
				
			||||||
 | 
					            void* obj;
 | 
				
			||||||
 | 
					        } alias;
 | 
				
			||||||
 | 
					        (void)dlerror();
 | 
				
			||||||
 | 
					        alias.obj = dlsym(dlh, symbol);
 | 
				
			||||||
 | 
					        if (alias.obj)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            wsrep::log_info() << "Resolved symbol '" << symbol << "'";
 | 
				
			||||||
 | 
					            return alias.fun;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            wsrep::log_info()
 | 
				
			||||||
 | 
					                << "Symbol '" << symbol << "' not found from provider";
 | 
				
			||||||
 | 
					            return nullptr;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					} // namespace wsrep_impl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // WSREP_SERVICE_HELPERS_HPP
 | 
					#endif // WSREP_SERVICE_HELPERS_HPP
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,12 +29,13 @@
 | 
				
			|||||||
#include "wsrep/tls_service.hpp"
 | 
					#include "wsrep/tls_service.hpp"
 | 
				
			||||||
#include "wsrep/allowlist_service.hpp"
 | 
					#include "wsrep/allowlist_service.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "service_helpers.hpp"
 | 
				
			||||||
#include "thread_service_v1.hpp"
 | 
					#include "thread_service_v1.hpp"
 | 
				
			||||||
#include "tls_service_v1.hpp"
 | 
					#include "tls_service_v1.hpp"
 | 
				
			||||||
#include "allowlist_service_v1.hpp"
 | 
					#include "allowlist_service_v1.hpp"
 | 
				
			||||||
#include "event_service_v1.hpp"
 | 
					#include "event_service_v1.hpp"
 | 
				
			||||||
#include "v26/wsrep_api.h"
 | 
					#include "v26/wsrep_api.h"
 | 
				
			||||||
 | 
					#include "v26/wsrep_node_isolation.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <dlfcn.h>
 | 
					#include <dlfcn.h>
 | 
				
			||||||
#include <cassert>
 | 
					#include <cassert>
 | 
				
			||||||
@@ -671,6 +672,8 @@ namespace
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        wsrep::event_service_v1_deinit(dlh);
 | 
					        wsrep::event_service_v1_deinit(dlh);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    wsrep_node_isolation_mode_set_fn_v1 node_isolation_mode_set;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -714,6 +717,10 @@ void wsrep::wsrep_provider_v26::init_services(
 | 
				
			|||||||
            services_enabled_.event_service = services.event_service;
 | 
					            services_enabled_.event_service = services.event_service;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    node_isolation_mode_set
 | 
				
			||||||
 | 
					        = wsrep_impl::resolve_function<wsrep_node_isolation_mode_set_fn_v1>(
 | 
				
			||||||
 | 
					            wsrep_->dlh, WSREP_NODE_ISOLATION_MODE_SET_V1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void wsrep::wsrep_provider_v26::deinit_services()
 | 
					void wsrep::wsrep_provider_v26::deinit_services()
 | 
				
			||||||
@@ -726,6 +733,7 @@ void wsrep::wsrep_provider_v26::deinit_services()
 | 
				
			|||||||
        deinit_thread_service(wsrep_->dlh);
 | 
					        deinit_thread_service(wsrep_->dlh);
 | 
				
			||||||
    if (services_enabled_.allowlist_service)
 | 
					    if (services_enabled_.allowlist_service)
 | 
				
			||||||
        deinit_allowlist_service(wsrep_->dlh);
 | 
					        deinit_allowlist_service(wsrep_->dlh);
 | 
				
			||||||
 | 
					    node_isolation_mode_set = nullptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wsrep::wsrep_provider_v26::wsrep_provider_v26(
 | 
					wsrep::wsrep_provider_v26::wsrep_provider_v26(
 | 
				
			||||||
@@ -1162,6 +1170,40 @@ wsrep::wsrep_provider_v26::options(const std::string& opts)
 | 
				
			|||||||
    return map_return_value(wsrep_->options_set(wsrep_, opts.c_str()));
 | 
					    return map_return_value(wsrep_->options_set(wsrep_, opts.c_str()));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Set node isolation mode in the provider. This function may be called from
 | 
				
			||||||
 | 
					 * signal handler, so make sure that only 'safe' system calls and library
 | 
				
			||||||
 | 
					 * functions are used. See
 | 
				
			||||||
 | 
					 * https://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					enum wsrep::provider::status
 | 
				
			||||||
 | 
					wsrep::wsrep_provider_v26::set_node_isolation(node_isolation mode)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (not node_isolation_mode_set)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return error_not_implemented;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    enum wsrep_node_isolation_mode ws_mode = WSREP_NODE_ISOLATION_NOT_ISOLATED;
 | 
				
			||||||
 | 
					    switch (mode)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					    case node_isolation::not_isolated:
 | 
				
			||||||
 | 
					        ws_mode = WSREP_NODE_ISOLATION_NOT_ISOLATED;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    case node_isolation::isolated:
 | 
				
			||||||
 | 
					        ws_mode = WSREP_NODE_ISOLATION_ISOLATED;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    case node_isolation::force_disconnect:
 | 
				
			||||||
 | 
					        ws_mode = WSREP_NODE_ISOLATION_FORCE_DISCONNECT;
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if ((*node_isolation_mode_set)(ws_mode) != WSREP_NODE_ISOLATION_SUCCESS)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return error_warning;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return success;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::string wsrep::wsrep_provider_v26::name() const
 | 
					std::string wsrep::wsrep_provider_v26::name() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return (wsrep_->provider_name ? wsrep_->provider_name : "unknown");
 | 
					    return (wsrep_->provider_name ? wsrep_->provider_name : "unknown");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -100,6 +100,7 @@ namespace wsrep
 | 
				
			|||||||
        void reset_status() WSREP_OVERRIDE;
 | 
					        void reset_status() WSREP_OVERRIDE;
 | 
				
			||||||
        std::string options() const WSREP_OVERRIDE;
 | 
					        std::string options() const WSREP_OVERRIDE;
 | 
				
			||||||
        enum wsrep::provider::status options(const std::string&) WSREP_OVERRIDE;
 | 
					        enum wsrep::provider::status options(const std::string&) WSREP_OVERRIDE;
 | 
				
			||||||
 | 
					        enum status set_node_isolation(enum node_isolation mode) WSREP_OVERRIDE;
 | 
				
			||||||
        std::string name() const WSREP_OVERRIDE;
 | 
					        std::string name() const WSREP_OVERRIDE;
 | 
				
			||||||
        std::string version() const WSREP_OVERRIDE;
 | 
					        std::string version() const WSREP_OVERRIDE;
 | 
				
			||||||
        std::string vendor() const WSREP_OVERRIDE;
 | 
					        std::string vendor() const WSREP_OVERRIDE;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -294,6 +294,9 @@ namespace wsrep
 | 
				
			|||||||
        enum wsrep::provider::status options(const std::string&)
 | 
					        enum wsrep::provider::status options(const std::string&)
 | 
				
			||||||
            WSREP_OVERRIDE
 | 
					            WSREP_OVERRIDE
 | 
				
			||||||
        { return wsrep::provider::success; }
 | 
					        { return wsrep::provider::success; }
 | 
				
			||||||
 | 
					        enum status set_node_isolation(enum node_isolation) WSREP_OVERRIDE {
 | 
				
			||||||
 | 
					          return error_not_implemented;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        std::string name() const WSREP_OVERRIDE { return "mock"; }
 | 
					        std::string name() const WSREP_OVERRIDE { return "mock"; }
 | 
				
			||||||
        std::string version() const WSREP_OVERRIDE { return "0.0"; }
 | 
					        std::string version() const WSREP_OVERRIDE { return "0.0"; }
 | 
				
			||||||
        std::string vendor() const WSREP_OVERRIDE { return "mock"; }
 | 
					        std::string vendor() const WSREP_OVERRIDE { return "mock"; }
 | 
				
			||||||
 
 | 
				
			|||||||
 Submodule wsrep-API/v26 updated: 06ce602ade...427c73c5c8
									
								
							
		Reference in New Issue
	
	Block a user