diff options
author | hcpp <hcpp@ydb.tech> | 2023-11-08 12:09:41 +0300 |
---|---|---|
committer | hcpp <hcpp@ydb.tech> | 2023-11-08 12:56:14 +0300 |
commit | a361f5b98b98b44ea510d274f6769164640dd5e1 (patch) | |
tree | c47c80962c6e2e7b06798238752fd3da0191a3f6 /contrib/libs/libmysql_r/include/mysql/components | |
parent | 9478806fde1f4d40bd5a45e7cbe77237dab613e9 (diff) | |
download | ydb-a361f5b98b98b44ea510d274f6769164640dd5e1.tar.gz |
metrics have been added
Diffstat (limited to 'contrib/libs/libmysql_r/include/mysql/components')
34 files changed, 6977 insertions, 0 deletions
diff --git a/contrib/libs/libmysql_r/include/mysql/components/component_implementation.h b/contrib/libs/libmysql_r/include/mysql/components/component_implementation.h new file mode 100644 index 0000000000..199eb07c0f --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/component_implementation.h @@ -0,0 +1,329 @@ +/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License, version 2.0, +as published by the Free Software Foundation. + +This program is also distributed with certain software (including +but not limited to OpenSSL) that is licensed under separate terms, +as designated in a particular file or component or in included license +documentation. The authors of MySQL hereby grant you an additional +permission to link the program and your derivative works with the +separately licensed software that they have included with MySQL. + +This program 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, version 2.0, for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENT_IMPLEMENTATION_H +#define COMPONENT_IMPLEMENTATION_H + +#include <mysql/components/services/dynamic_loader.h> +#include <mysql/components/services/registry.h> +#include <cstddef> // NULL +#include "service_implementation.h" + +/** + @page PAGE_COMPONENTS_COMPONENT A Component + + A component is a code container that contains one or more Service + Implementations. Components can be internal (part of the MySQL Server binary) + and external (hosted in a OS binary file different from the one of the MySQL + Server). + + Each component will have: + - Name + - List of service implementations it provides. + - List of services or service implementations it needs. + - Initialization function that's called when a container is loaded. Takes a + reference to the currently active service registry implementation. + - De-initialization function that's called when a container unload is + requested. + + Opposite to old plugin infrastructure, Components don't need linkage against + mysqld executable, neither on Linux nor Windows. In fact, in Components we + strongly discourage from linking against mysqld executable at all, as it + presents significant threat to them being independent and using only + Components infrastructure to communicate with other parts of software. + + @subpage PAGE_COMPONENTS_IMPLEMENTATION + + @page PAGE_COMPONENTS_IMPLEMENTATION MySQL Component - creating implementation + The Component for the Dynamic Loader needs to be a dynamic library (for + example .so or .dll) with specified entry-point method. The only exception is + the MySQL server, for which, for now, it will be statically linked. All these + implementation details are hidden away by macros defined in header files. + All macros to define Services are specified in service.h, for defining Service + Implementations in service_implementation.h and for specifying Components in + component_implementation.h. + + @section EXAMPLE The Component example + Example Components are located in components/example directory. These + Components are used also for unit and MTR test, which assures these Components + are fully functional and they quality is maintained. The example Services are + defined in example_services.h, while implemented in three example Components + defined in files example_component1.cc, example_component2.cc, + and example_component3.cc. These files are specifically prepared to be used as + examples as they provide simplicity and an extensive documentation. The + following tutorial bases on these Components and will try to show a process to + create similar. + + @subsection EXAMPLE_SERVICES Services defined in the example + Example contains definition of 3 Services which will be used to show a general + idea of services, basic implementations and simple example of one of concepts + possible with the Component Infrastructure. These example Services are defined + in example_services.h and are s_mysql_greetings, + s_mysql_greetings_localization and s_mysql_example_math. + + @section TROUBLESHOOTING Common problems + + -# If you have problem during linking on GCC with similar message: + + ../../../components/mysql_server/component_mysql_server.a(server_component.cc.o):%server_component.cc:imp_...: + error: undefined reference to '..._impl::...' + + In such case you should add a new `%init()` method (it can be dummy/empty) + to your source file that contains service methods implementations and a call + to that method somewhere in mysqld.cc. This will help GCC not to optimize + the required object file out of linkage. Take `mysql_string_services_init()` + as an example. This applies only to service implementations added to the + server component. + + @section TUTORIAL Step by step tutorial for creating new Component + The creation of component is a mean to get some functionality exported for the + Components infrastructure. It can be divided into several steps: + -# %List all high level functionalities Component is planned to have + implemented. This will assure we know exactly what we need to benefit from + next steps. In the example, we would like to have a "Hello, World!" string + provider and simple math functions. + -# Look for existing Services, that are designed specifically to provide some + part of the new functionalities to reuse them, or other that are in any + degree similar in functionality, design or use cases to use as an example. + The Component infrastructure is highly oriented on reuse of Services and + will benefit with every reuse case, as it will decrease total size of + Services. In the example the existing base of Services is really small, + with the core Components infrastructure Services available only leading to + no reuse possible. + -# Design list of functions needed to provide all functionalities. Try to make + they follow existing patterns and ideas, possibly having some identical to + existing ones. + -# Try to separate groups of functions that specify some complete part of + functionality into separate small Services to improve re-usability. Also, + try to separate groups that seem to have more potential to be extended or + modified in future, because changing existing Services is forbidden, in + such a case this will lead to a lot of functions in Services that will be + duplicates and will introduce more boilerplate code to implement them. + Remove all functions that can be found in fully reused existing Services. + -# Create definitions of Services, ideally one Service per file, or a group of + really closely connected Services. In most cases you want to make these + definitions public, in case of MySQL that means placing them in + include/mysql/components/services/ directory to include them in mysql-dev + package. See example_services.h, which in contrary is not made public and + resides in example component source directory. + -# Create declarations of all handles, the Opaque pointers for all opaque + objects that are meant to be returned to the Services users. See usages of + DEFINE_SERVICE_HANDLE in registry.h. + -# Create basic structure of new Component. Use BEGIN_COMPONENT_PROVIDES, + BEGIN_COMPONENT_REQUIRES, BEGIN_COMPONENT_METADATA, DECLARE_COMPONENT and + DECLARE_LIBRARY_COMPONENTS. Fill in all information necessary to describe + the new Component extensively. The example_component1.cc and + example_component2.cc shows how structure should look like, and in + example_component3.cc there is an example with additional Service + references, for which placeholder definitions are kept in header file of the + new Component, see example_component3.h. Note the placeholder for the + Registry Service, which is available by default in every component. + -# Create implementations of the desired Service interfaces. Implement handles + used, as for example my_h_service_iterator_imp and + my_h_service_metadata_iterator_imp in registry.cc. Create separate + source and header files for each Service or closely connected group of + Services. Remember to include the header file for Service Implementation in + the Service Implementation source file to have no linkage problems. + The Service Implementations in english_greeting_service_imp.cc and + simple_example_math_imp.cc are implementations used in example_component1, + polish_greeting_service_imp.cc and example_math_wrapping_imp.cc are + implementations for example_component2 and example_component3 respectively. + -# Make sure component is loaded/initialized before using its services. + Atomic variable is_intialized represents the state of the component. + Please check the details about the variable from validate_password_imp.cc + file. + . + + @file include/mysql/components/component_implementation.h + Specifies macros to define Components. +*/ + +/** + Declares a component. For specified name following macros must be executed + earlier: BEGIN_COMPONENT_PROVIDES, BEGIN_COMPONENT_REQUIRES and + BEGIN_COMPONENT_METADATA. + It fills mysql_component_t structure with all of the component data. The + info object will be named mysql_component_{source_name}. + After this macro it is required to specify comma-separated pointers to + initialize and deinitialize methods for components to be used during loading + and unloading of component. + + @param source_name The source name used in other macros. + @param name Name string with human readable name. +*/ +#define DECLARE_COMPONENT(source_name, name) \ + mysql_component_t mysql_component_##source_name = { \ + name, __##source_name##_provides, __##source_name##_requires, \ + __##source_name##_metadata, + +/** + A macro to end the last declaration of a Component. +*/ +#define END_DECLARE_COMPONENT() } + +/** + Creates a service implementation list that are provided by specified + component. Only a series of PROVIDES_SERVICE and PROVIDES_CUSTOM_SERVICE + macros are expected to be used after this macro and before the + END_COMPONENT_PROVIDES counterpart. + + @param name Component name. +*/ +#define BEGIN_COMPONENT_PROVIDES(name) \ + static struct mysql_service_ref_t __##name##_provides[] = { +/** + Declare a Service Implementation provided by a Component. It assumes standard + Service Implementation name to be referenced. + @sa SERVICE_IMPLEMENTATION + + @param component Component name. + @param service A Service name for which the Service Implementation will be + added. +*/ +#define PROVIDES_SERVICE(component, service) \ + { \ +#service "." #component, \ + (void *)&SERVICE_IMPLEMENTATION(component, service) \ + } + +/** + A macro to end the last declaration started with the BEGIN_COMPONENT_PROVIDES. +*/ +#define END_COMPONENT_PROVIDES() \ + { NULL, NULL } \ + } + +/** + A macro to specify requirements of the component. Creates a placeholder for + the Registry service and structure with a list for requirements and + pointers to their placeholders, adding the Registry service as first element. + + @param name Name of component. +*/ +#define BEGIN_COMPONENT_REQUIRES(name) \ + REQUIRES_SERVICE_PLACEHOLDER(registry); \ + static struct mysql_service_placeholder_ref_t __##name##_requires[] = { \ + REQUIRES_SERVICE(registry), + +/** + Creates a definition for placeholder, in which the specified required service + will be provided upon component load. The placeholder will be named + mysql_service_{service name}. Use the "extern" keyword before macro invocation + to define a reference to the one real placeholder defined in component source. + + @param service A referenced Service name. +*/ +#define REQUIRES_SERVICE_PLACEHOLDER(service) \ + SERVICE_TYPE(service) * mysql_service_##service + +/** + Adds a Service requirement with a pointer to placeholder to the list of + components. + + @param service A referenced Service name. +*/ +#define REQUIRES_SERVICE(service) \ + { \ +#service, \ + static_cast < void **> \ + (static_cast <void *>(const_cast <mysql_service_##service##_t **>( \ + &mysql_service_##service))) \ + } + +/** + A macro to end the last declaration started with the BEGIN_COMPONENT_REQUIRES. +*/ +#define END_COMPONENT_REQUIRES() \ + { NULL, NULL } \ + } + +/** + A macro to specify metadata of the component. Creates a list of metadata. + Only a series of METADATA macros are expected to be used after this macro and + before the END_COMPONENT_METADATA counterpart. + + @param name Name of component. +*/ +#define BEGIN_COMPONENT_METADATA(name) \ + static struct mysql_metadata_ref_t __##name##_metadata[] = { +/** + Adds a Service requirement with a pointer to placeholder to the list of + components. + + @param key A string name of the metadata to add. + @param value A string value of the metadata to add. +*/ +#define METADATA(key, value) \ + { key, value } + +/** + A macro to end the last declaration started with the BEGIN_COMPONENT_METADATA. +*/ +#define END_COMPONENT_METADATA() \ + { NULL, NULL } \ + } + +/* On Windows, exports from DLL need to be declared. + Also, plug-in needs to be declared as extern "C" because MSVC + unlike other compilers, uses C++ mangling for variables not only + for functions. */ +#if defined(_MSC_VER) +#ifdef __cplusplus +#define DLL_EXPORT extern "C" __declspec(dllexport) +#else +#define DLL_EXPORT __declspec(dllexport) +#endif +#else /*_MSC_VER */ +#ifdef __cplusplus +#define DLL_EXPORT extern "C" +#else +#define DLL_EXPORT +#endif +#endif + +/** + Creates a list of component implementations included in this dynamic library. + It can be used only once in whole library. It defines an entry point method + for library to be used with the Dynamic Loader. A list of pointers to + Component structures is required after this macro up to the usage of + the END_DECLARE_LIBRARY_COMPONENTS macro. Current implementation of the + Dynamic Loader supports only one Component being specified in the library. +*/ +#define DECLARE_LIBRARY_COMPONENTS \ + mysql_component_t *library_components_list = { +/** + A macro to end the last declaration started with the + DECLARE_LIBRARY_COMPONENTS. +*/ +#define END_DECLARE_LIBRARY_COMPONENTS \ + } \ + ; \ + DLL_EXPORT mysql_component_t *list_components() { \ + return library_components_list; \ + } + +/** + Defines a reference to the specified Component data info structure. +*/ +#define COMPONENT_REF(name) mysql_component_##name + +#endif /* COMPONENT_IMPLEMENTATION_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/my_service.h b/contrib/libs/libmysql_r/include/mysql/components/my_service.h new file mode 100644 index 0000000000..581af27f10 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/my_service.h @@ -0,0 +1,113 @@ +/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License, version 2.0, +as published by the Free Software Foundation. + +This program is also distributed with certain software (including +but not limited to OpenSSL) that is licensed under separate terms, +as designated in a particular file or component or in included license +documentation. The authors of MySQL hereby grant you an additional +permission to link the program and your derivative works with the +separately licensed software that they have included with MySQL. + +This program 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, version 2.0, for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef MY_SERVICE_H +#define MY_SERVICE_H + +#include <mysql/components/service.h> +#include <mysql/components/services/registry.h> + +/** + Wraps my_h_service struct conforming ABI into RAII C++ object with ability to + cast to desired service type. +*/ +template <typename TService> +class my_service { + public: + /** + Acquires service by name. + + @param name Name of service, with or without component name, to acquire. + @param registry Handle to registry service to use. The registry service + must be valid (i.e. not released) up to the moment when this instance + dies. + */ + my_service(const char *name, SERVICE_TYPE(registry) * registry) + : m_registry(registry) { + if (registry->acquire(name, &m_service)) { + /* NULLed service handle means no valid service managed. */ + m_service = {}; + } + } + /** + Acquires service by name. + + @param name Name of service, with or without component name, to acquire. + @param related_service Handle to service to acquire related to. + @param registry Handle to registry service to use. + */ + my_service(const char *name, my_h_service related_service, + SERVICE_TYPE(registry) * registry) + : m_registry(registry) { + if (registry->acquire_related(name, related_service, &m_service)) { + /* NULLed service handle means no valid service managed. */ + m_service = nullptr; + } + } + /** + Wraps service implementation already acquired. + + @param service Service handle to manage. + @param registry Handle to registry service to use. + */ + my_service(my_h_service service, SERVICE_TYPE(registry) * registry) + : m_service(service), m_registry(registry) {} + + my_service(const my_service<TService> &other) = delete; + + my_service(my_service<TService> &&other) + : m_service(other.m_service), m_registry(other.m_registry) { + other.m_service = nullptr; + } + + ~my_service() { + if (this->is_valid()) { + m_registry->release(m_service); + } + } + + operator TService *() const { + return reinterpret_cast<TService *>(m_service); + } + + operator my_h_service() const { return m_service; } + /** + Returns managed service typed as desired service type to execute + operations specified after -> on it. + */ + TService *operator->() const { return static_cast<TService *>(*this); } + /** + @retval false Object manages valid service. + @retval true Object does not manage any service. + */ + operator bool() const { return !is_valid(); } + bool is_valid() const { + /* NULLed service handle means no valid service managed. */ + return static_cast<const my_h_service_imp *>(this->m_service) != nullptr; + } + + private: + my_h_service m_service; + SERVICE_TYPE(registry) * m_registry; +}; + +#endif /* MY_SERVICE_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/service.h b/contrib/libs/libmysql_r/include/mysql/components/service.h new file mode 100644 index 0000000000..13dcb813a4 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/service.h @@ -0,0 +1,130 @@ +/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License, version 2.0, +as published by the Free Software Foundation. + +This program is also distributed with certain software (including +but not limited to OpenSSL) that is licensed under separate terms, +as designated in a particular file or component or in included license +documentation. The authors of MySQL hereby grant you an additional +permission to link the program and your derivative works with the +separately licensed software that they have included with MySQL. + +This program 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, version 2.0, for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef SERVICE_H +#define SERVICE_H + +/** + Specific type for the service status return values. + + 0 is false, non-zero is true. Corresponds to C++ bool. + + @sa DEFINE_BOOL_METHOD, DECLARE_BOOL_METHOD +*/ +typedef int mysql_service_status_t; + +/** + @page PAGE_COMPONENTS_SERVICE A Service and a Service Implementation + + The Service is basic concept of the Components subsystem. A Service is a + named, well-defined stateless interface to one functionality, expressed as a + list of pointers to a specific methods. The service name will consist of ASCII + symbols excluding the dot ('.') symbol. Each Service will be accompanied with + a (part of a) header file that defines the Service allowing other Components + to consume it. Each Service should work only on basic C types and structures + of these types to prevent problems with not fully-defined C++ objects ABI. The + Service is a default way to operate inside the Components subsystem as a mean + to show that one is interested only on functionality interface, not its exact + implementation. The Services are not versioned - any change to interface must + require Service being copied to one with different name before applying + changes. The Services by itself do not carry any state, all methods are + stateless. This does not prevent one from having some state-carrying objects + created and returned as handles to them. Such concept is shown for example in + create(), get() and release() methods of the registry_query Service. This + concept relies on implementation of generator of the Opaque pointers with + d-pointer described here: https://en.wikipedia.org/wiki/Opaque_pointer . + + For any specific Service a Service Implementation is defined as a structure + of the Service type filled with pointers to methods of specified + implementation. The name of the Service Implementation is a name of the + Service and the implementation related name separated with a dot. In most + cases the implementation related name should be the Component name in which it + is being defined. Each Service can have several Service Implementations. + + @file include/mysql/components/service.h +*/ + +/** + Generates the standard Service type name. It does not have const specifier, + it should be used only when really necessary. +*/ +#define SERVICE_TYPE_NO_CONST(name) mysql_service_##name##_t + +/** + Generates the standard Service type name. +*/ +#define SERVICE_TYPE(name) const SERVICE_TYPE_NO_CONST(name) + +/** + Declares a new Service. It creates a structure for pointers to Service + methods. A list of methods defined using DECLARE_METHOD and + DECLARE_BOOL_METHOD macros must follow this macro, with a closing + END_SERVICE_DEFINITION macro usage. + + @param name Service name, must be a valid C name. +*/ +#define BEGIN_SERVICE_DEFINITION(name) typedef struct s_mysql_##name { +/** + A macro to end the last Service definition started with the + BEGIN_SERVICE_DEFINITION macro. +*/ +#define END_SERVICE_DEFINITION(name) \ + } \ + SERVICE_TYPE_NO_CONST(name); +/** + Declares a method as a part of the Service definition. To be used within the + SERVICE_DEFINITION macro. + + @param retval Type of the return value for the method declaration. Should be a + simple type or structure, not a C++ object with undefined ABI. + @param name Name of the method, must be a valid C name. + @param args The list of arguments of the method taken in parentheses. +*/ +#define DECLARE_METHOD(retval, name, args) retval(*name) args + +/** + Declares a method that returns bool as a part of the Service definition. To be + used within the SERVICE_DEFINITION macro. + + @param name Name of the method, must be a valid C name. + @param args The list of arguments of the method taken in parentheses. +*/ +#define DECLARE_BOOL_METHOD(name, args) \ + DECLARE_METHOD(mysql_service_status_t, name, args) + +/** + Defines an object type that is meant for carrying handles to the + implementation-specific objects used in the Service interface, but without + their structure exposed, keeping it as an abstraction. This follows a Opaque + Pointer design pattern, see more: https://en.wikipedia.org/wiki/Opaque_pointer + If you would like to have a C++ RAII class to manage the resource with + additional methods to call raw service calls, please create your class + {handle_name} instead of following macro. Please make sure it does not use any + virtual methods to keep binary compatibility, and try use only one member, the + d-pointer to hide all implementation details and keep headers unmodified from + the point of publishing it. + + @param name Handle name, must be a valid C name. +*/ +#define DEFINE_SERVICE_HANDLE(name) typedef struct name##_imp *name + +#endif /* SERVICE_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/service_implementation.h b/contrib/libs/libmysql_r/include/mysql/components/service_implementation.h new file mode 100644 index 0000000000..74043efd2f --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/service_implementation.h @@ -0,0 +1,90 @@ +/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License, version 2.0, +as published by the Free Software Foundation. + +This program is also distributed with certain software (including +but not limited to OpenSSL) that is licensed under separate terms, +as designated in a particular file or component or in included license +documentation. The authors of MySQL hereby grant you an additional +permission to link the program and your derivative works with the +separately licensed software that they have included with MySQL. + +This program 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, version 2.0, for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef SERVICE_IMPLEMENTATION_H +#define SERVICE_IMPLEMENTATION_H + +#include "service.h" + +/** + @file include/mysql/components/service_implementation.h + Specifies macros to define Service Implementations. +*/ + +/** + Reference to the name of the service implementation variable + + @ref BEGIN_SERVICE_IMPLEMENTATION defines a local variable of + the structure type for the service (see @ref SERVICE_TYPE). + The variable is then used by the @ref PROVIDES_SERVICE macro to + construct the list of service provided by the component. + This macro allows one to use @ref BEGIN_SERVICE_IMPLEMENTATION , + @ref DEFINE_METHOD and @ref END_SERVICE_IMPLEMENTATION macros to build + a service defintion structure and variable to be used outside of the + component definition context. + + @param component Name of the implementation of the service. + Usually a component name. + @param service Name of the service to create the implementation for. + +*/ +#define SERVICE_IMPLEMENTATION(component, service) imp_##component##_##service + +/** + Declares a Service Implementation. It builds standard implementation + info structure. Only a series of pointers to methods the Service + Implementation implements as respective Service methods are expected to be + used after this macro and before the END_SERVICE_IMPLEMENTATION counterpart. + + @param component Name of the Component to create implementation in. + @param service Name of the Service to create implementation for. +*/ +#define BEGIN_SERVICE_IMPLEMENTATION(component, service) \ + SERVICE_TYPE(service) SERVICE_IMPLEMENTATION(component, service) = { +/** + A macro to end the last declaration of a Service Implementation. +*/ +#define END_SERVICE_IMPLEMENTATION() } + +/** + A macro to ensure method implementation has required properties, that is it + does not throw exceptions and is static. This macro should be used with + exactly the same arguments as DECLARE_METHOD. + + @param retval Type of return value. It cannot contain comma characters, but + as only simple structures are possible, this shouldn't be a problem. + @param name Method name. + @param args a list of arguments in parenthesis. +*/ +#define DEFINE_METHOD(retval, name, args) retval name args noexcept + +/** + A short macro to define method that returns bool, which is the most common + case. + + @param name Method name. + @param args a list of arguments in parenthesis. +*/ +#define DEFINE_BOOL_METHOD(name, args) \ + DEFINE_METHOD(mysql_service_status_t, name, args) + +#endif /* SERVICE_IMPLEMENTATION_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/dynamic_loader.h b/contrib/libs/libmysql_r/include/mysql/components/services/dynamic_loader.h new file mode 100644 index 0000000000..c4fad4e3b0 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/dynamic_loader.h @@ -0,0 +1,300 @@ +/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License, version 2.0, +as published by the Free Software Foundation. + +This program is also distributed with certain software (including +but not limited to OpenSSL) that is licensed under separate terms, +as designated in a particular file or component or in included license +documentation. The authors of MySQL hereby grant you an additional +permission to link the program and your derivative works with the +separately licensed software that they have included with MySQL. + +This program 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, version 2.0, for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef MYSQL_DYNAMIC_LOADER_H +#define MYSQL_DYNAMIC_LOADER_H + +#include <mysql/components/service.h> + +/** + A handle type for a iterator to a Component. +*/ +DEFINE_SERVICE_HANDLE(my_h_component_iterator); +/** + A handle type for a iterator to metadata of some Component. +*/ +DEFINE_SERVICE_HANDLE(my_h_component_metadata_iterator); + +/** + Service for managing the list of loaded Components. +*/ +BEGIN_SERVICE_DEFINITION(dynamic_loader) +/** + Loads specified group of components by URN, initializes them and + registers all Service Implementations present in these components. + Assures all dependencies will be met after loading specified components. + The dependencies may be circular, in such case it's necessary to specify + all components on cycle to load in one batch. From URNs specified the + scheme part of URN (part before "://") is extracted and used to acquire + Service Implementation of scheme component loader Service for specified + scheme. + + @param urns List of URNs of components to load. + @param component_count Number of components on list to load. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(load, (const char *urns[], int component_count)); +/** + Unloads specified group of components by URN, deinitializes them and + unregisters all Service Implementations present in these components. + Assumes, thous does not check it, all dependencies of not unloaded + components will still be met after unloading specified components. + The dependencies may be circular, in such case it's necessary to specify + all components on cycle to unload in one batch. From URNs specified the + scheme part of URN (part before "://") is extracted and used to acquire + Service Implementation of scheme component loader Service for specified + scheme. + + @param urns List of URNs of components to unload. + @param component_count Number of components on list to unload. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(unload, (const char *urns[], int component_count)); +END_SERVICE_DEFINITION(dynamic_loader) + +/** + Service for listing all Components by iterator. +*/ +BEGIN_SERVICE_DEFINITION(dynamic_loader_query) +/** + Creates iterator that iterates through all loaded components. + If successful it leaves read lock on dynamic loader until iterator is + released. + + @param [out] out_iterator Pointer to component iterator handle. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(create, (my_h_component_iterator * out_iterator)); +/** + Gets name and URN of Service pointed to by iterator. + + @param iterator Component iterator handle. + @param [out] out_name Pointer to string with component name to set result + pointer to. + @param [out] out_urn Pointer to string with URN from which the component was + loaded from, to set result pointer to. + @return Status of performed operation + @retval false success + @retval true Failure, may be caused when called on iterator that went + through all values already. +*/ +DECLARE_BOOL_METHOD(get, (my_h_component_iterator iter, const char **out_name, + const char **out_urn)); +/** + Advances specified iterator to next element. Will succeed but return true if + it reaches one-past-last element. + + @param iterator Component iterator handle. + @return Status of performed operation and validity of iterator after + operation. + @retval false success + @retval true Failure or called on iterator that was on last element. +*/ +DECLARE_BOOL_METHOD(next, (my_h_component_iterator iter)); +/** + Checks if specified iterator is valid, i.e. have not reached one-past-last + element. + + @param iterator Component iterator handle. + @return Validity of iterator + @retval false Valid + @retval true Invalid or reached one-past-last element. +*/ +DECLARE_BOOL_METHOD(is_valid, (my_h_component_iterator iter)); +/** + Releases component iterator. Releases read lock on dynamic loader. + + @param iterator Component iterator handle. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_METHOD(void, release, (my_h_component_iterator iter)); +END_SERVICE_DEFINITION(dynamic_loader_query) + +/** + Service for listing all metadata for a Component specified by the iterator. +*/ +BEGIN_SERVICE_DEFINITION(dynamic_loader_metadata_enumerate) +/** + Creates iterator that iterates through all metadata for object pointed by + the specified iterator. If successful it leaves read lock on the registry + until the iterator is released. + + @param iterator A iterator that points to object to get the metadata + iterator for. + @param [out] out_iterator Pointer to metadata iterator handle. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(create, (my_h_component_iterator iterator, + my_h_component_metadata_iterator *out_iterator)); +/** + Gets the key and value of the metadata pointed to by the specified iterator. + + @param iterator Metadata iterator handle. + @param [out] out_name A pointer to the string with the key to set the result + pointer to. + @param [out] out_value A pointer to the string with the metadata value to + set the result pointer to. + @return Status of performed operation + @retval false success + @retval true Failure, may be caused when called on the iterator that went + through all values already. +*/ +DECLARE_BOOL_METHOD(get, (my_h_component_metadata_iterator iterator, + const char **name, const char **value)); +/** + Advances specified iterator to next element. Will fail if it reaches + one-past-last element. + + @param iterator Metadata iterator handle. + @return Status of performed operation + @retval false success + @retval true Failure, may be caused when called on iterator that was on the + last element. +*/ +DECLARE_BOOL_METHOD(next, (my_h_component_metadata_iterator iterator)); +/** + Checks if specified iterator is valid, i.e. have not reached one-past-last + element. + + @param iterator Metadata iterator handle. + @return Validity of iterator + @retval false Valid + @retval true Invalid or reached one-past-last element. +*/ +DECLARE_BOOL_METHOD(is_valid, (my_h_component_metadata_iterator iterator)); +/** + Releases the specified iterator. Releases read lock on the registry. + + @param iterator Metadata iterator handle. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_METHOD(void, release, (my_h_component_metadata_iterator iterator)); +END_SERVICE_DEFINITION(dynamic_loader_metadata_enumerate) + +/** + Service to query specified metadata key directly for the specified Component + by iterator to it. +*/ +BEGIN_SERVICE_DEFINITION(dynamic_loader_metadata_query) +/** + Gets the key and value of the metadata pointed to by the specified object + iterator. + + @param iterator A iterator that points to object to get the metadata + iterator for. + @param name A pointer to the string with the key to set the result + pointer to. + @param [out] out_value A pointer to the string with the metadata value to + set the result pointer to. + @return Status of performed operation + @retval false success + @retval true Failure, may be caused when called on the iterator that went + through all values already. +*/ +DECLARE_BOOL_METHOD(get_value, (my_h_component_iterator iterator, + const char *name, const char **value)); +END_SERVICE_DEFINITION(dynamic_loader_metadata_query) + +/** + Carries information on specific Service Implementation. +*/ +struct mysql_service_ref_t { + const char *name; + void *implementation; +}; + +/** + Carries information on the specific Service requirement for some Component and + a pointer to member where to store the acquired Service Implementation to + satisfy this requirement. +*/ +struct mysql_service_placeholder_ref_t { + const char *name; + void **implementation; +}; + +/** + Specifies a key and value pair of the single Component metadata. +*/ +struct mysql_metadata_ref_t { + const char *key; + const char *value; +}; + +/** + Carries information on the specific Component, all Service Implementations it + provides, all its requirements and metadata. +*/ +struct mysql_component_t { + const char *name; + struct mysql_service_ref_t *provides; + struct mysql_service_placeholder_ref_t *requires_; + struct mysql_metadata_ref_t *metadata; + mysql_service_status_t (*init)(); + mysql_service_status_t (*deinit)(); +}; + +/** + Service for providing Components from a specified scheme of URN. + + All scheme loading Services are the same although they have separate names + (aliased to the main type) to allow a single component implement several + scheme loaders, to not break the recommendation to keep implementation names + the same as the component name, and to be able to create wrappers and other + solutions that require to have multiple implementations of a single type. +*/ +BEGIN_SERVICE_DEFINITION(dynamic_loader_scheme) +/** + Loads all Components that are located under the URN specified. + + @param urn URN to location of the component to load from. + @param [out] out_data Pointer to pointer to MySQL component data structures + to set result components data retrieved from specified file. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(load, (const char *urn, mysql_component_t **out_data)); +/** + Unloads all Components that were previously loaded. + + @param urn URN to location to unload all components from. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(unload, (const char *urn)); +END_SERVICE_DEFINITION(dynamic_loader_scheme) + +#endif /* MYSQL_DYNAMIC_LOADER_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/log_builtins.h b/contrib/libs/libmysql_r/include/mysql/components/services/log_builtins.h new file mode 100644 index 0000000000..2bdf5dd97d --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/log_builtins.h @@ -0,0 +1,1448 @@ +/* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +/** + This defines built-in functions for use by logging services. + These helpers are organized into a number of APIs grouping + related functionality. + + For documentation of the individual functions, see log_builtins.cc +*/ + +#ifndef LOG_BUILTINS_H +#define LOG_BUILTINS_H + +#include <mysql/components/component_implementation.h> +#include <mysql/components/my_service.h> +#include <mysql/components/service_implementation.h> +#include <mysql/components/services/log_shared.h> +#if defined(MYSQL_DYNAMIC_PLUGIN) +#include <mysql/service_plugin_registry.h> +#endif +#include <stdarg.h> +#include <stdio.h> + +#include <my_compiler.h> +#if defined(MYSQL_SERVER) && !defined(MYSQL_DYNAMIC_PLUGIN) +#error #include "sql/log.h" +#endif + +/** + Primitives for services to interact with the structured logger: + functions pertaining to log_line and log_item data +*/ +BEGIN_SERVICE_DEFINITION(log_builtins) +/** + See whether a type is wellknown. + + @param t log item type to examine + + @retval LOG_ITEM_TYPE_NOT_FOUND: key not found + @retval >0: index in array of wellknowns +*/ +DECLARE_METHOD(int, wellknown_by_type, (log_item_type t)); + +/** + See whether a string is a wellknown field name. + + @param key potential key starts here + @param length length of the string to examine + + @retval LOG_ITEM_TYPE_RESERVED: reserved, but not "wellknown" key + @retval LOG_ITEM_TYPE_NOT_FOUND: key not found + @retval >0: index in array of wellknowns +*/ +DECLARE_METHOD(int, wellknown_by_name, (const char *key, size_t length)); + +/** + Accessor: from a record describing a wellknown key, get its type + + @param idx index in array of wellknowns, see log_item_wellknown_by_...() + + @retval the log item type for the wellknown key +*/ +DECLARE_METHOD(log_item_type, wellknown_get_type, (uint idx)); + +/** + Accessor: from a record describing a wellknown key, get its name + + @param idx index in array of wellknowns, see log_item_wellknown_by_...() + + @retval name (NTBS) +*/ +DECLARE_METHOD(const char *, wellknown_get_name, (uint idx)); + +/** + Sanity check an item. + Certain log sinks have very low requirements with regard to the data + they receive; they write keys as strings, and then data according to + the item's class (string, integer, or float), formatted to the sink's + standards (e.g. JSON, XML, ...). + Code that has higher requirements can use this check to see whether + the given item is of a known type (whether generic or wellknown), + whether the given type and class agree, and whether in case of a + well-known type, the given key is correct for that type. + If your code generates items that don't pass this check, you should + probably go meditate on it. + + @param li the log_item to check + + @retval LOG_ITEM_OK no problems + @retval LOG_ITEM_TYPE_NOT_FOUND unknown item type + @retval LOG_ITEM_CLASS_MISMATCH item_class derived from type isn't + what's set on the item + @retval LOG_ITEM_KEY_MISMATCH class not generic, so key should + match wellknown + @retval LOG_ITEM_STRING_NULL class is string, pointer is nullptr + @retval LOG_ITEM_KEY_NULL no key set (this is legal e.g. on aux + items of filter rules, but should not + occur in a log_line, i.e., log_sinks are + within their rights to discard such items) +*/ +DECLARE_METHOD(int, item_inconsistent, (log_item * li)); + +// helpers: predicates to find out about types and classes + +/** + Predicate used to determine whether a type is generic + (generic string, generic float, generic integer) rather + than a well-known type. + + @param t log item type to examine + + @retval true if generic type + @retval false if wellknown type +*/ +DECLARE_METHOD(bool, item_generic_type, (log_item_type t)); + +/** + Predicate used to determine whether a class is a string + class (C-string or Lex-string). + + @param c log item class to examine + + @retval true if of a string class + @retval false if not of a string class +*/ +DECLARE_METHOD(bool, item_string_class, (log_item_class c)); + +/** + Predicate used to determine whether a class is a numeric + class (integer or float). + + @param c log item class to examine + + @retval true if of a numeric class + @retval false if not of a numeric class +*/ +DECLARE_METHOD(bool, item_numeric_class, (log_item_class c)); + +/** + Set an integer value on a log_item. + Fails gracefully if no log_item_data is supplied, so it can safely + wrap log_line_item_set[_with_key](). + + @param lid log_item_data struct to set the value on + @param i integer to set + + @retval true lid was nullptr (possibly: OOM, could not set up log_item) + @retval false all's well +*/ +DECLARE_METHOD(bool, item_set_int, (log_item_data * lid, longlong i)); +/** + Set a floating point value on a log_item. + Fails gracefully if no log_item_data is supplied, so it can safely + wrap log_line_item_set[_with_key](). + + @param lid log_item_data struct to set the value on + @param f float to set + + @retval true lid was nullptr (possibly: OOM, could not set up log_item) + @retval false all's well +*/ +DECLARE_METHOD(bool, item_set_float, (log_item_data * lid, double f)); + +/** + Set a string value on a log_item. + Fails gracefully if no log_item_data is supplied, so it can safely + wrap log_line_item_set[_with_key](). + + @param lid log_item_data struct to set the value on + @param s pointer to string + @param s_len length of string + + @retval true lid was nullptr (possibly: OOM, could not set up log_item) + @retval false all's well +*/ +DECLARE_METHOD(bool, item_set_lexstring, + (log_item_data * lid, const char *s, size_t s_len)); + +/** + Set a string value on a log_item. + Fails gracefully if no log_item_data is supplied, so it can safely + wrap log_line_item_set[_with_key](). + + @param lid log_item_data struct to set the value on + @param s pointer to NTBS + + @retval true lid was nullptr (possibly: OOM, could not set up log_item) + @retval false all's well +*/ +DECLARE_METHOD(bool, item_set_cstring, (log_item_data * lid, const char *s)); + +/** + Create new log item with key name "key", and allocation flags of + "alloc" (see enum_log_item_free). + Will return a pointer to the item's log_item_data struct for + convenience. + This is mostly interesting for filters and other services that create + items that are not part of a log_line; sources etc. that intend to + create an item for a log_line (the more common case) should usually + use the below line_item_set_with_key() which creates an item (like + this function does), but also correctly inserts it into a log_line. + + @param li the log_item to work on + @param t the item-type + @param key the key to set on the item. + ignored for non-generic types (may pass nullptr for those) + see alloc + @param alloc LOG_ITEM_FREE_KEY if key was allocated by caller + LOG_ITEM_FREE_NONE if key was not allocated + Allocated keys will automatically free()d when the + log_item is. + The log_item's alloc flags will be set to the + submitted value; specifically, any pre-existing + value will be clobbered. It is therefore WRONG + a) to use this on a log_item that already has a key; + it should only be used on freshly init'd log_items; + b) to use this on a log_item that already has a + value (specifically, an allocated one); the correct + order is to init a log_item, then set up type and + key, and finally to set the value. If said value is + an allocated string, the log_item's alloc should be + bitwise or'd with LOG_ITEM_FREE_VALUE. + + @retval a pointer to the log_item's log_data, for easy chaining: + log_item_set_with_key(...)->data_integer= 1; +*/ +DECLARE_METHOD(log_item_data *, item_set_with_key, + (log_item * li, log_item_type t, const char *key, uint32 alloc)); + +/** + As log_item_set_with_key(), except that the key is automatically + derived from the wellknown log_item_type t. + + Create new log item with type "t". + Will return a pointer to the item's log_item_data struct for + convenience. + This is mostly interesting for filters and other services that create + items that are not part of a log_line; sources etc. that intend to + create an item for a log_line (the more common case) should usually + use the below line_item_set_with_key() which creates an item (like + this function does), but also correctly inserts it into a log_line. + + The allocation of this item will be LOG_ITEM_FREE_NONE; + specifically, any pre-existing value will be clobbered. + It is therefore WRONG + a) to use this on a log_item that already has a key; + it should only be used on freshly init'd log_items; + b) to use this on a log_item that already has a + value (specifically, an allocated one); the correct + order is to init a log_item, then set up type and + key, and finally to set the value. If said value is + an allocated string, the log_item's alloc should be + bitwise or'd with LOG_ITEM_FREE_VALUE. + + @param li the log_item to work on + @param t the item-type + + @retval a pointer to the log_item's log_data, for easy chaining: + log_item_set_with_key(...)->data_integer= 1; +*/ +DECLARE_METHOD(log_item_data *, item_set, (log_item * li, log_item_type t)); + +/** + Create new log item in log line "ll", with key name "key", and + allocation flags of "alloc" (see enum_log_item_free). + On success, the number of registered items on the log line is increased, + the item's type is added to the log_line's "seen" property, + and a pointer to the item's log_item_data struct is returned for + convenience. + + @param ll the log_line to work on + @param t the item-type + @param key the key to set on the item. + ignored for non-generic types (may pass nullptr for those) + see alloc + @param alloc LOG_ITEM_FREE_KEY if key was allocated by caller + LOG_ITEM_FREE_NONE if key was not allocated + Allocated keys will automatically free()d when the + log_item is. + The log_item's alloc flags will be set to the + submitted value; specifically, any pre-existing + value will be clobbered. It is therefore WRONG + a) to use this on a log_item that already has a key; + it should only be used on freshly init'd log_items; + b) to use this on a log_item that already has a + value (specifically, an allocated one); the correct + order is to init a log_item, then set up type and + key, and finally to set the value. If said value is + an allocated string, the log_item's alloc should be + bitwise or'd with LOG_ITEM_FREE_VALUE. + + @retval a pointer to the log_item's log_data, for easy chaining: + log_line_item_set_with_key(...)->data_integer= 1; +*/ +DECLARE_METHOD(log_item_data *, line_item_set_with_key, + (log_line * ll, log_item_type t, const char *key, uint32 alloc)); + +/** + Create a new log item of well-known type "t" in log line "ll". + On success, the number of registered items on the log line is increased, + the item's type is added to the log_line's "seen" property, + and a pointer to the item's log_item_data struct is returned for + convenience. + + The allocation of this item will be LOG_ITEM_FREE_NONE; + specifically, any pre-existing value will be clobbered. + It is therefore WRONG + a) to use this on a log_item that already has a key; + it should only be used on freshly init'd log_items; + b) to use this on a log_item that already has a + value (specifically, an allocated one); the correct + order is to init a log_item, then set up type and + key, and finally to set the value. If said value is + an allocated string, the log_item's alloc should be + bitwise or'd with LOG_ITEM_FREE_VALUE. + + @param ll the log_line to work on + @param t the item-type + + @retval a pointer to the log_item's log_data, for easy chaining: + log_line_item_set_with_key(...)->data_integer= 1; +*/ +DECLARE_METHOD(log_item_data *, line_item_set, + (log_line * ll, log_item_type t)); + +/** + Dynamically allocate and initialize a log_line. + + @retval nullptr could not set up buffer (too small?) + @retval other address of the newly initialized log_line +*/ +DECLARE_METHOD(log_line *, line_init, ()); + +/** + Release a log_line allocated with line_init() + + @param ll a log_line previously allocated with line_init() +*/ +DECLARE_METHOD(void, line_exit, (log_line * ll)); + +/** + How many items are currently set on the given log_line? + + @param ll the log-line to examine + + @retval the number of items set +*/ +DECLARE_METHOD(int, line_item_count, (log_line * ll)); + +/** + Test whether a given type is presumed present on the log line. + + @param ll the log_line to examine + @param m the log_type to test for + + @retval 0 not present + @retval !=0 present +*/ +DECLARE_METHOD(log_item_type_mask, line_item_types_seen, + (log_line * ll, log_item_type_mask m)); + +/** + Get an iterator for the items in a log_line. + For now, only one iterator may exist per log_line. + + @param ll the log_line to examine + + @retval a log_iterm_iter, or nullptr on failure +*/ +DECLARE_METHOD(log_item_iter *, line_item_iter_acquire, (log_line * ll)); + +/** + Release an iterator for the items in a log_line. + + @param it the iterator to release +*/ +DECLARE_METHOD(void, line_item_iter_release, (log_item_iter * it)); +/** + Use the log_line iterator to get the first item from the set. + + @param it the iterator to use + + @retval pointer to the first log_item in the collection, or nullptr +*/ +DECLARE_METHOD(log_item *, line_item_iter_first, (log_item_iter * it)); + +/** + Use the log_line iterator to get the next item from the set. + + @param it the iterator to use + + @retval pointer to the next log_item in the collection, or nullptr +*/ +DECLARE_METHOD(log_item *, line_item_iter_next, (log_item_iter * it)); + +/** + Use the log_line iterator to get the current item from the set. + + @param it the iterator to use + + @retval pointer to the current log_item in the collection, or nullptr +*/ +DECLARE_METHOD(log_item *, line_item_iter_current, (log_item_iter * it)); + +/** + Complete, filter, and write submitted log items. + + This expects a log_line collection of log-related key/value pairs, + e.g. from log_message(). + + Where missing, timestamp, priority, thread-ID (if any) and so forth + are added. + + Log item source services, log item filters, and log item sinks are + then called; then all applicable resources are freed. + + This interface is intended to facilitate the building of submission + interfaces other than the variadic message() one below. See the + example fluent C++ LogEvent() wrapper for an example of how to leverage + it. + + @param ll key/value pairs describing info to log + + @retval int number of fields in created log line +*/ +DECLARE_METHOD(int, line_submit, (log_line * ll)); + +/** + Submit a log-message for log "log_type". + Variadic convenience function for logging. + + This fills in the array that is used by the filter and log-writer + services. Where missing, timestamp, priority, and thread-ID (if any) + are added. Log item source services, log item filters, and log item + writers are called. + + + The variadic list accepts a list of "assignments" of the form + - log_item_type, value, for well-known types, and + - log_item_type, key, value, for ad-hoc types (LOG_ITEM_GEN_*) + + As its last item, the list should have + - an element of type LOG_ITEM_LOG_MESSAGE, containing a printf-style + format string, followed by all variables necessary to satisfy the + substitutions in that string + + OR + + - an element of type LOG_ITEM_LOG_LOOKUP, containing a MySQL error code, + which will be looked up in the list or regular error messages, followed + by all variables necessary to satisfy the substitutions in that string + + OR + + - an element of type LOG_ITEM_LOG_VERBATIM, containing a string that will + be used directly, with no % substitutions + + see log_vmessage() for more information. +*/ +DECLARE_METHOD(int, message, (int log_type, ...)); + +/** + Escape \0 bytes, add \0 terminator. For log-writers and other sinks + that terminate in an API using C-strings. + + + @param li list_item to process + + @retval -1 out of memory + @retval 0 success +*/ +DECLARE_METHOD(int, sanitize, (log_item * li)); + +/** + Return MySQL error message for a given error code. + + @param mysql_errcode the error code the message for which to look up + + @retval the message (a printf-style format string) +*/ +DECLARE_METHOD(const char *, errmsg_by_errcode, (int mysql_errcode)); + +/** + Return MySQL error code for a given error symbol. + + @param sym the symbol to look up + + @retval -1 failure + @retval >=0 the MySQL error code +*/ +DECLARE_METHOD(longlong, errcode_by_errsymbol, (const char *sym)); + +/** + Convenience function: Derive a log label ("error", "warning", + "information") from a severity. + + @param prio the severity/prio in question + + @return a label corresponding to that priority. + @retval "System" for prio of SYSTEM_LEVEL + @retval "Error" for prio of ERROR_LEVEL + @retval "Warning" for prio of WARNING_LEVEL + @retval "Note" for prio of INFORMATION_LEVEL +*/ +DECLARE_METHOD(const char *, label_from_prio, (int prio)); + +/** + open an error log file + + @param file if beginning with '.': + @@global.log_error, except with this extension + otherwise: + use this as file name in the same location as + @@global.log_error + + Value not contain folder separators! + + @param[out] my_errstream an error log handle, or nullptr on failure + + @retval 0 success + @retval !0 failure +*/ +DECLARE_METHOD(int, open_errstream, (const char *file, void **my_errstream)); + +/** + write to an error log file previously opened with open_errstream() + + @param my_errstream a handle describing the log file + @param buffer pointer to the string to write + @param length length of the string to write + + @retval 0 success + @retval !0 failure +*/ +DECLARE_METHOD(int, write_errstream, + (void *my_errstream, const char *buffer, size_t length)); + +/** + are we writing to a dedicated errstream, or are we sharing it? + + @param my_errstream a handle describing the log file + + @retval 0 not dedicated (multiplexed, stderr, ...) + @retval 1 dedicated +*/ +DECLARE_METHOD(int, dedicated_errstream, (void *my_errstream)); + +/** + close an error log file previously opened with open_errstream() + + @param my_stream a handle describing the log file + + @retval 0 success + @retval !0 failure +*/ +DECLARE_METHOD(int, close_errstream, (void **my_errstream)); + +END_SERVICE_DEFINITION(log_builtins) + +/** + String primitives for logging services. +*/ +BEGIN_SERVICE_DEFINITION(log_builtins_string) +// alloc (len+1) bytes +DECLARE_METHOD(void *, malloc, (size_t len)); +// alloc (len+1) bytes, then copy len bytes from fm, and \0 terminate +// like my_strndup(), and unlike strndup(), \0 in input won't end copying +DECLARE_METHOD(char *, strndup, (const char *fm, size_t len)); +// free allocated memory +DECLARE_METHOD(void, free, (void *ptr)); + +// length of nul terminated byte string +DECLARE_METHOD(size_t, length, (const char *s)); +// find char in string, from the left +DECLARE_METHOD(char *, find_first, (const char *s, int c)); +// find char in string, from the right +DECLARE_METHOD(char *, find_last, (const char *s, int c)); + +// compare two NUL-terminated byte-strings +DECLARE_METHOD(int, compare, + (const char *a, const char *b, size_t len, + bool case_insensitive)); + +/** + Wrapper for std::snprintf() + Replace all % in format string with variables from list. + Do not use in new code; use std::snprintf() instead. + + @param to buffer to write the result to + @param n size of that buffer + @param fmt format string + @param ap va_list with valuables for all substitutions in format string + + @retval return value of snprintf +*/ +DECLARE_METHOD(size_t, substitutev, + (char *to, size_t n, const char *fmt, va_list ap)) +MY_ATTRIBUTE((format(printf, 3, 0))); + +// replace all % in format string with variables from list (std::snprintf()) +DECLARE_METHOD(size_t, substitute, (char *to, size_t n, const char *fmt, ...)) +MY_ATTRIBUTE((format(printf, 3, 4))); + +END_SERVICE_DEFINITION(log_builtins_string) + +/** + Temporary primitives for logging services. +*/ +BEGIN_SERVICE_DEFINITION(log_builtins_tmp) +// Are we shutting down yet? Windows EventLog needs to know. +DECLARE_METHOD(size_t, notify_client, + (void *thd, uint severity, uint code, char *to, size_t n, + const char *format, ...)) +MY_ATTRIBUTE((format(printf, 6, 7))); +END_SERVICE_DEFINITION(log_builtins_tmp) + +/** + Syslog/Eventlog functions for logging services. +*/ +BEGIN_SERVICE_DEFINITION(log_builtins_syseventlog) +DECLARE_METHOD(int, open, (const char *name, int option, int facility)); +DECLARE_METHOD(int, write, (enum loglevel level, const char *msg)); +DECLARE_METHOD(int, close, (void)); +END_SERVICE_DEFINITION(log_builtins_syseventlog) + +#ifdef __cplusplus + +#if !defined(LOG_H) + +extern SERVICE_TYPE(log_builtins) * log_bi; +extern SERVICE_TYPE(log_builtins_string) * log_bs; + +#define log_line_init log_bi->line_init +#define log_line_exit log_bi->line_exit +#define log_line_item_set_with_key log_bi->line_item_set_with_key +#define log_line_item_set log_bi->line_item_set +#define log_line_item_types_seen log_bi->line_item_types_seen +#define log_line_submit log_bi->line_submit +#define log_set_int log_bi->item_set_int +#define log_set_float log_bi->item_set_float +#define log_set_lexstring log_bi->item_set_lexstring +#define log_set_cstring log_bi->item_set_cstring +#define log_malloc log_bs->malloc +#define log_free log_bs->free +#define log_msg log_bs->substitutev +#define error_msg_by_errcode log_bi->errmsg_by_errcode +#define error_code_by_errsymbol log_bi->errcode_by_errsymbol +#else + +#error #include "sql/derror.h" + +#define log_malloc(s) my_malloc(0, (s), MYF(0)) +#define log_free my_free +#define log_msg vsnprintf +#define error_msg_by_errcode error_message_for_error_log +#define error_code_by_errsymbol mysql_symbol_to_errno +#define log_set_int log_item_set_int +#define log_set_float log_item_set_float +#define log_set_lexstring log_item_set_lexstring +#define log_set_cstring log_item_set_cstring + +/** + Very long-running functions during server start-up can use this + function to check whether the time-out for buffered logging has + been reached. If so and we have urgent information, all buffered + log events will be flushed to the log using built-in default-logger + for the time being. The information will be kept until start-up + completes in case it later turns out the user configured a loadable + logger, in which case we'll also flush the buffered information to + that logger later once the logger becomes available. + + This function should only be used during start-up; once external + components are loaded by the component framework, this function + should no longer be called (as log events are no longer buffered, + but logged immediately). +*/ +void log_sink_buffer_check_timeout(void); +#endif // LOG_H + +#ifndef DISABLE_ERROR_LOGGING + +#if defined(LOG_COMPONENT_TAG) + +#define LogErr(severity, ecode, ...) \ + LogEvent() \ + .prio(severity) \ + .errcode(ecode) \ + .subsys(LOG_SUBSYSTEM_TAG) \ + .component(LOG_COMPONENT_TAG) \ + .source_line(__LINE__) \ + .source_file(MY_BASENAME) \ + .function(__FUNCTION__) \ + .lookup(ecode, ##__VA_ARGS__) + +#define LogPluginErr(severity, ecode, ...) \ + LogEvent() \ + .prio(severity) \ + .errcode(ecode) \ + .subsys(LOG_SUBSYSTEM_TAG) \ + .component("plugin:" LOG_COMPONENT_TAG) \ + .source_line(__LINE__) \ + .source_file(MY_BASENAME) \ + .function(__FUNCTION__) \ + .lookup_quoted(ecode, "Plugin " LOG_COMPONENT_TAG " reported", \ + ##__VA_ARGS__) + +#define LogPluginErrV(severity, ecode, vl) \ + LogEvent() \ + .prio(severity) \ + .errcode(ecode) \ + .subsys(LOG_SUBSYSTEM_TAG) \ + .component("plugin:" LOG_COMPONENT_TAG) \ + .source_line(__LINE__) \ + .source_file(MY_BASENAME) \ + .function(__FUNCTION__) \ + .lookup_quotedv(ecode, "Plugin " LOG_COMPONENT_TAG " reported", vl) + +#define LogPluginErrMsg(severity, ecode, ...) \ + LogEvent() \ + .prio(severity) \ + .errcode(ecode) \ + .subsys(LOG_SUBSYSTEM_TAG) \ + .component("plugin:" LOG_COMPONENT_TAG) \ + .source_line(__LINE__) \ + .source_file(MY_BASENAME) \ + .function(__FUNCTION__) \ + .message_quoted("Plugin " LOG_COMPONENT_TAG " reported", ##__VA_ARGS__) + +#else + +#define LogErr(severity, ecode, ...) \ + LogEvent() \ + .prio(severity) \ + .errcode(ecode) \ + .subsys(LOG_SUBSYSTEM_TAG) \ + .source_line(__LINE__) \ + .source_file(MY_BASENAME) \ + .function(__FUNCTION__) \ + .lookup(ecode, ##__VA_ARGS__) + +#endif + +#else + +inline void dummy_log_message(longlong severity MY_ATTRIBUTE((unused)), + longlong ecode MY_ATTRIBUTE((unused)), ...) { + return; +} + +#define LogErr(severity, ecode, ...) \ + dummy_log_message(severity, ecode, ##__VA_ARGS__) + +#define LogPluginErr(severity, ecode, ...) \ + dummy_log_message(severity, ecode, ##__VA_ARGS__) +#define LogPluginErrV(severity, ecode, ...) \ + dummy_log_message(severity, ecode, ##__VA_ARGS__) +#define LogPluginErrMsg(severity, ecode, ...) \ + dummy_log_message(severity, ecode, ##__VA_ARGS__) + +#endif // DISABLE_ERROR_LOGGING + +/** + Modular logger: fluid API. Server-internal. Lets you use safe and + expressive syntax, like so: + + LogEvent(LOG_TYPE_ERROR).prio(INFORMATION_LEVEL).message("Meow! %d", 4711); +*/ + +class LogEvent { + private: + log_line *ll; + char *msg; + const char *msg_tag; + + /** + Set MySQL error-code if none has been set yet. + + @param errcode the error code (not operating system errno!) + + @retval true an error occurred, value not set (OOM?) + @retval false value was set without incident, or did not need to be set + */ + bool set_errcode(longlong errcode) { + if (ll == nullptr) return true; + + if (!log_line_item_types_seen(ll, LOG_ITEM_SQL_ERRCODE) && + !log_line_item_types_seen(ll, LOG_ITEM_SQL_ERRSYMBOL)) { + return log_set_int(log_line_item_set(ll, LOG_ITEM_SQL_ERRCODE), errcode); + } + return false; // already set, that's OK then + } + + /** + Set the error message. + + @param fmt format string. % substitution will be performed. + @param ap va_list of the arguments for % substitution. + */ + void set_message(const char *fmt, va_list ap) + MY_ATTRIBUTE((format(printf, 2, 0))); + + /** + Set the error message (by MySQL error code). + The actual message will be looked up using this errcode. + As the message is a printf-style format string, % substitution + will be performed. + + @param errcode MySQL error code to fetch the message string for + @param ap va_list of the arguments for % substitution. + */ + void set_message_by_errcode(longlong errcode, va_list ap); + + public: + /** + Destructor automatically sends the event on. + It is auto-free()d after processing. + */ + ~LogEvent() { + if (ll != nullptr) { + log_line_submit(this->ll); + log_line_exit(ll); + log_free(msg); + } + } + + /** + "Full customization" constructor. Use one of the LogErr() macro + where possible; it's there to help you remember the minimum set + of particles and their data-types. Be prepared for stern looks + from your reviewers if you use this constructor except for external + (loadable) services that have no error messages registered with the + server, and therefore need to submit them free-form. + */ + LogEvent() { + if ((ll = log_line_init()) != nullptr) { + if ((msg = (char *)log_malloc(LOG_BUFF_MAX)) == nullptr) { + log_line_exit(ll); + ll = nullptr; + } + } else + msg = nullptr; + msg_tag = nullptr; + } + + /** + + Set log type. + + @param val the log type (LOG_TYPE_ERROR) + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &type(enum_log_type val) { + log_set_int(log_line_item_set(this->ll, LOG_ITEM_LOG_TYPE), val); + return *this; + } + + /** + Append a numeric error code + + @param val the MySQL error code (not operating system errno!). + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &errcode(longlong val) { + log_set_int(log_line_item_set(this->ll, LOG_ITEM_SQL_ERRCODE), val); + return *this; + } + + /** + Append a (string) error symbol + + @param val error symbol. NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &errsymbol(const char *val) { + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_SQL_ERRSYMBOL), val); + return *this; + } + + /** + Append a (string) SQL state + + @param val the SQLstate. NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &sqlstate(const char *val) { + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_SQL_STATE), val); + return *this; + } + + /** + Append a numeric (operating system, as opposed to MySQL) error number. + + @param val the operating system errno. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &os_errno(longlong val) { + log_set_int(log_line_item_set(this->ll, LOG_ITEM_SYS_ERRNO), val); + return *this; + } + + /** + Append a textual (operating system, as opposed to MySQL) error message, + vulgo, strerror() + + @param val the error message returned by the operating system. NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &os_errmsg(const char *val) { + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_SYS_STRERROR), val); + return *this; + } + + /** + Which source file was the problem detected in? + + @param val the source file's name. NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &source_file(const char *val) { + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_SRC_FILE), val); + return *this; + } + + /** + Which line in the source file was the problem detected on? + + @param val the line number. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &source_line(longlong val) { + log_set_int(log_line_item_set(this->ll, LOG_ITEM_SRC_LINE), val); + return *this; + } + + /** + Which function in the source was the problem detected in? + + @param val the function's name. NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &function(const char *val) { + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_SRC_FUNC), val); + return *this; + } + + /** + Which subsystem in the source was the problem detected in? + ("Repl"/"InnoDB"/"Server") + + @param val the subsystem. NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &subsys(const char *val) { + if (val != nullptr) + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_SRV_SUBSYS), val); + return *this; + } + + /** + Which component in the source was the problem detected in? + This should be the same string that is given to the + component/service framework. + + @param val the component. NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &component(const char *val) { + if (val != nullptr) + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_SRV_COMPONENT), val); + return *this; + } + + /** + What user were we working for at the time of the issue? + + @param val the user part (of "user@host"). LEX_CSTRING. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &user(LEX_CSTRING val) { + log_set_lexstring(log_line_item_set(this->ll, LOG_ITEM_MSC_USER), val.str, + val.length); + return *this; + } + + /** + What user were we working for at the time of the issue? + + @param val the user part (of "user@host"). NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &user(const char *val) { + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_MSC_USER), val); + return *this; + } + + /** + Whose session did the issue appear in? + + @param val the host part (of "user@host"). LEX_CSTRING. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &host(LEX_CSTRING val) { + log_set_lexstring(log_line_item_set(this->ll, LOG_ITEM_MSC_HOST), val.str, + val.length); + return *this; + } + + /** + Whose session did the issue appear in? + + @param val the host part (of "user@host"). NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &host(const char *val) { + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_MSC_HOST), val); + return *this; + } + + /** + What thread / "connection ID" was the issue detected in? + + @param val the thread_ID of the session the issue appeared in + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &thread_id(longlong val) { + log_set_int(log_line_item_set(this->ll, LOG_ITEM_SRV_THREAD), val); + return *this; + } + + /** + What query apparently caused the issue? + + @param val the query_ID of the offending query + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &query_id(longlong val) { + log_set_int(log_line_item_set(this->ll, LOG_ITEM_SQL_QUERY_ID), val); + return *this; + } + + /** + What table were we working on? + + @param val the table's name/alias. NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &table_name(const char *val) { + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_SQL_TABLE_NAME), val); + return *this; + } + + /** + Set error message priority. + Assign one of ERROR_LEVEL, WARNING_LEVEL, INFORMATION_LEVEL. + log-writers and other sinks should use this value (rather + than that of LOG_ITEM_LOG_EPRIO): + + - file writers should use the value to determine + what label to write (perhaps by submitting it to label_from_prio()) + + - sinks that submit the event data to a sub-system outside of + the MySQL server (such as syslog, EventLog, systemd journal, etc.) + should translate this value into a priority/log level understood + by that target subsystem. + + @param val The priority for this LogEvent. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &prio(longlong val) { + log_set_int(log_line_item_set(this->ll, LOG_ITEM_LOG_PRIO), val); + return *this; + } + + /** + Set a label (usually "warning"/"error"/"information"). + Will be derived from prio if not set explicitly. + Some log services may ignore custom labels. + + @param val the (custom) label to set + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &label(const char *val) { + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_LOG_LABEL), val); + return *this; + } + + /** + Add a message to the event, verbatim (i.e. with no % substitutions). + This is an analog of message("%s", message); it can be used when + message may contain user input or a message from another subsystem + that could contain % that must not be interpreted as an invitation + to do % substitutions. + + If you use this in a context other than an external service that + has no messages registered with the server, your reviewers will + say unkind things about you. Use registered messages and their + error codes wherever possible! + + @param msg_arg the message. % substitution will not happen. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &verbatim(const char *msg_arg) { + log_set_cstring(log_line_item_set(this->ll, LOG_ITEM_LOG_MESSAGE), msg_arg); + return *this; + } + + /** + Fill in a format string by substituting the % with the given + arguments, then add the result as the event's message. + This should be used very sparingly; use registered messages + and their error codes wherever possible! + + @param fmt message (treated as a printf-style format-string, + so % substitution will happen) + @param ap valist to satisfy any % in the message + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &messagev(const char *fmt, va_list ap) + MY_ATTRIBUTE((format(printf, 2, 0))) { + set_message(fmt, ap); + return *this; + } + + /** + Fill in a format string by substituting the % with the given + arguments, then add the result as the event's message. + + If you use this in a context other than an external service that + has no messages registered with the server, your reviewers will + say unkind things about you. Use registered messages and their + error codes wherever possible! + + @param fmt message (treated as a printf-style format-string, + so % substitution will happen) + @param ... varargs to satisfy any % in the message + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &message(const char *fmt, ...) MY_ATTRIBUTE((format(printf, 2, 3))); + + /** + Fill in a format string by substituting the % with the given + arguments and tag, then add the result as the event's message. + + @param tag Tag to prefix to message. + @param fmt message (treated as a printf-style format-string, + so % substitution will happen) + @param ... varargs to satisfy any % in the message + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &message_quoted(const char *tag, const char *fmt, ...) + MY_ATTRIBUTE((format(printf, 3, 4))) { + msg_tag = tag; + + va_list args; + va_start(args, fmt); + set_message(fmt, args); + va_end(args); + + return *this; + } + + /** + Find an error message by its MySQL error code. + Substitute the % in that message with the given + arguments, then add the result as the event's message. + + @param errcode MySQL error code for the message in question, + e.g. ER_STARTUP + @param ... varargs to satisfy any % in the message + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &lookup(longlong errcode, ...) { + va_list args; + va_start(args, errcode); + set_message_by_errcode(errcode, args); + va_end(args); + + return *this; + } + + /** + Find an error message by its MySQL error code. Substitute the % in that + message with the given arguments list, then add the result as the event's + message. + + @param errcode MySQL error code for the message in question, + e.g. ER_STARTUP + @param args varargs to satisfy any % in the message + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &lookupv(longlong errcode, va_list args) { + set_message_by_errcode(errcode, args); + + return *this; + } + + LogEvent &lookup_quoted(longlong errcode, const char *tag, ...) { + msg_tag = tag; + + va_list args; + va_start(args, tag); + set_message_by_errcode(errcode, args); + va_end(args); + + return *this; + } + + LogEvent &lookup_quotedv(longlong errcode, const char *tag, va_list vl) { + msg_tag = tag; + set_message_by_errcode(errcode, vl); + + return *this; + } + + /** + Add a ad hoc integer value with the given key. + + @param key user-defined key (i.e. not wellknown). NTBS. + @param val value. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &int_value(const char *key, longlong val) { + log_set_int(log_line_item_set_with_key(this->ll, LOG_ITEM_GEN_INTEGER, key, + LOG_ITEM_FREE_NONE), + val); + return *this; + } + + /** + Add a ad hoc (not "well-known") float value with the given key. + + @param key user-defined key (i.e. not wellknown). NTBS. + @param val value. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &float_value(const char *key, double val) { + log_set_float(log_line_item_set_with_key(this->ll, LOG_ITEM_GEN_FLOAT, key, + LOG_ITEM_FREE_NONE), + val); + return *this; + } + + /** + Add a ad hoc string value with the given key. + + @param key user-defined key (i.e. not wellknown). NTBS. + @param val value. + @param len length in bytes of the value. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &string_value(const char *key, const char *val, size_t len) { + log_set_lexstring( + log_line_item_set_with_key(this->ll, LOG_ITEM_GEN_LEX_STRING, key, + LOG_ITEM_FREE_NONE), + val, len); + return *this; + } + + /** + Add a ad hoc string value with the given key. + + @param key user-defined key (i.e. not wellknown). NTBS. + @param val value. NTBS. + + @retval the LogEvent, for easy fluent-style chaining. + */ + LogEvent &string_value(const char *key, const char *val) { + log_set_cstring( + log_line_item_set_with_key(this->ll, LOG_ITEM_GEN_LEX_STRING, key, + LOG_ITEM_FREE_NONE), + val); + return *this; + } +}; + +inline void LogEvent::set_message_by_errcode(longlong errcode, va_list ap) { + const char *fmt = error_msg_by_errcode((int)errcode); + + if ((fmt == nullptr) || (*fmt == '\0')) fmt = "invalid error code"; + + set_errcode(errcode); + set_message(fmt, ap); +} + +inline void LogEvent::set_message(const char *fmt, va_list ap) { + if ((ll != nullptr) && (msg != nullptr)) { + char buf[LOG_BUFF_MAX]; + if (msg_tag != nullptr) { + snprintf(buf, LOG_BUFF_MAX - 1, "%s: \'%s\'", msg_tag, fmt); + fmt = buf; + } + size_t len = log_msg(msg, LOG_BUFF_MAX - 1, fmt, ap); + log_set_lexstring(log_line_item_set(this->ll, LOG_ITEM_LOG_MESSAGE), msg, + len); + } +} + +inline LogEvent &LogEvent::message(const char *fmt, ...) { + va_list args; + va_start(args, fmt); + set_message(fmt, args); + va_end(args); + + return *this; +} + +// Methods initialize and de-initialize logging service for plugins. +#if defined(MYSQL_DYNAMIC_PLUGIN) + +/** + Method to de-initialize logging service in plugin. + + param[in,out] reg_srv Plugin registry service. + param[in,out] log_bi Error logging service. + param[in,out] log_bs String service for error logging. +*/ +inline void deinit_logging_service_for_plugin( + SERVICE_TYPE(registry) * *reg_srv, SERVICE_TYPE(log_builtins) * *log_bi, + SERVICE_TYPE(log_builtins_string) * *log_bs) { + using log_builtins_t = SERVICE_TYPE_NO_CONST(log_builtins); + using log_builtins_string_t = SERVICE_TYPE_NO_CONST(log_builtins_string); + if (*log_bi) + (*reg_srv)->release( + reinterpret_cast<my_h_service>(const_cast<log_builtins_t *>(*log_bi))); + if (*log_bs) + (*reg_srv)->release(reinterpret_cast<my_h_service>( + const_cast<log_builtins_string_t *>(*log_bs))); + mysql_plugin_registry_release(*reg_srv); + *log_bi = nullptr; + *log_bs = nullptr; + *reg_srv = nullptr; +} + +/** + Method to de-initialize logging service in plugin. + + param[in,out] reg_srv Plugin registry service. + param[in,out] log_bi Error logging service. + param[in,out] log_bs String service for error logging. + + @retval false Success. + @retval true Failed. +*/ +inline bool init_logging_service_for_plugin( + SERVICE_TYPE(registry) * *reg_srv, SERVICE_TYPE(log_builtins) * *log_bi, + SERVICE_TYPE(log_builtins_string) * *log_bs) { + my_h_service log_srv = nullptr; + my_h_service log_str_srv = nullptr; + *reg_srv = mysql_plugin_registry_acquire(); + if (!(*reg_srv)->acquire("log_builtins.mysql_server", &log_srv) && + !(*reg_srv)->acquire("log_builtins_string.mysql_server", &log_str_srv)) { + (*log_bi) = reinterpret_cast<SERVICE_TYPE(log_builtins) *>(log_srv); + (*log_bs) = + reinterpret_cast<SERVICE_TYPE(log_builtins_string) *>(log_str_srv); + } else { + deinit_logging_service_for_plugin(reg_srv, log_bi, log_bs); + return true; + } + return false; +} + +#elif defined(EXTRA_CODE_FOR_UNIT_TESTING) + +/** + Method is used by unit tests. + + param[in,out] reg_srv Plugin registry service. + param[in,out] log_bi Error logging service. + param[in,out] log_bs String service for error logging. + + @retval false Success. + @retval true Failed. +*/ +inline bool init_logging_service_for_plugin( + SERVICE_TYPE(registry) * *reg_srv MY_ATTRIBUTE((unused)), + SERVICE_TYPE(log_builtins) * *log_bi MY_ATTRIBUTE((unused)), + SERVICE_TYPE(log_builtins_string) * *log_bs MY_ATTRIBUTE((unused))) + +{ + return false; +} + +/** + Method is used by unit tests. + + param[in,out] reg_srv Plugin registry service. + param[in,out] log_bi Error logging service. + param[in,out] log_bs String service for error logging. +*/ +inline void deinit_logging_service_for_plugin( + SERVICE_TYPE(registry) * *reg_srv MY_ATTRIBUTE((unused)), + SERVICE_TYPE(log_builtins) * *log_bi MY_ATTRIBUTE((unused)), + SERVICE_TYPE(log_builtins_string) * *log_bs MY_ATTRIBUTE((unused))) {} + +#endif // MYSQL_DYNAMIC_PLUGIN + +#endif // __cplusplus + +#endif diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/log_shared.h b/contrib/libs/libmysql_r/include/mysql/components/services/log_shared.h new file mode 100644 index 0000000000..b5a18cf9ef --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/log_shared.h @@ -0,0 +1,234 @@ +/* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef LOG_SHARED_H +#define LOG_SHARED_H + +#include <mysql/mysql_lex_string.h> + +#include "my_basename.h" +#include "my_inttypes.h" +#include "my_loglevel.h" + +/** fallback: includer may not have set this to something sensible. */ +#ifndef LOG_SUBSYSTEM_TAG +#define LOG_SUBSYSTEM_TAG NULL +#endif + +/** + The logging sub-system internally uses the log_line structure to pass + data around. This header primarily the specifics and symbols of that + structure. + + Within the server, those interfaces may be used, but it is usually + preferable to use the fluent C++ convenience class LogErr() instead + where possible (and the variadic convenience function log_message() + where it is not). (see sql/log.h). + + (The legacy calls sql_print_(error|warning|information) have now + been defined to use log_message().) + + Finally, this header defines log types (error log etc.) as well + as log item types (timestamp, message, ...) used by the logging + components; these are shared between the variadic convenience + functions (log_message(), sql_print_*()) as well as the lower + level services using the log_line structure. +*/ + +/* + By historical convention in the lex context, + CSTRING means "constant lex string (char * + size_t)", + not "C-style string" (char *, \0 terminated)! +*/ +typedef struct MYSQL_LEX_CSTRING LEX_CSTRING; + +/** + log_type -- which log to send data to + check vs enum_log_table_type and LOG_FILE/LOG_TABLE/LOG_NONE +*/ +enum enum_log_type { + LOG_TYPE_UNDEF = 0, + LOG_TYPE_ERROR = 1, + LOG_TYPE_GENERAL = 2, + LOG_TYPE_SLOW = 4, + LOG_TYPE_AUDIT = 8, + LOG_TYPE_MISC = 16 +}; + +/** + item_type -- what to log + + + Used by variadic convenience interface + log_message(), legacy sql_print_*(), legacy my_plugin_log_message(). + Also available via the log_builtins service as message(). + + (Wherever possible, use the fluent C++ wrapper LogErr() (see + log_builtins.h) instead, though.) + + LOG_ITEM_GEN_CSTRING lets the caller submit a \0 terminated, + C-style string for convenience; it will be converted to + lex style (char *, size_t) on submission. + + LOG_ITEM_END should not be used in the variadic interface + as submitting a log line without an actual message is discouraged. + Instead LOG_ITEM_LOG_MESSAGE or LOG_ITEM_LOG_LOOKUP should be used + as the last LOG_ITEM_* key-value pairs: + + - LOG_ITEM_LOG_MESSAGE can be used to submit an ad hoc message + directly while debugging. + + - LOG_ITEM_LOG_LOOKUP asks for the given error number to be + replaced by the associated error message (i.e. the error message + for the error number will be looked up, and the LOOKUP item will + be replaced by a MESSAGE one). + + In variadic submission, both ad hoc and well-known error messages + are considered printf()-style format strings, and should be followed + by any arguments/variables required by that format string. + + In some situations, the variadic interface will automatically + generate some items ("If you cannot afford a timestamp, one will + be provided for you."). If an item of the required type already + exists, the submission interface should not generate another. + + Old-style plug-ins using my_plugin_log_message() will automatically + be tagged with a default LOG_ITEM_MSC_COMPONENT of their plug-in name. + + + + Non-variadic interface + + In non-variadic submission (i.e. all functions accepting a log_line), + LOG_ITEM_LOG_LOOKUP and LOG_ITEM_GEN_CSTRING are not valid item types, + while LOG_ITEM_LOG_MESSAGE must already be a string literal (i.e. any + substitutions must already have taken place). +*/ +typedef enum enum_log_item_type { + LOG_ITEM_END = 0, /**< end of list, see above */ + LOG_ITEM_LOG_TYPE = 1 << 0, /**< error log, etc. */ + LOG_ITEM_SQL_ERRCODE = 1 << 1, /**< mysql error code (numeric) */ + LOG_ITEM_SQL_ERRSYMBOL = 1 << 2, /**< mysql error code (symbolic) */ + LOG_ITEM_SQL_STATE = 1 << 3, /**< SQL state */ + LOG_ITEM_SYS_ERRNO = 1 << 4, /**< OS errno */ + LOG_ITEM_SYS_STRERROR = 1 << 5, /**< OS strerror() */ + LOG_ITEM_SRC_FILE = 1 << 6, /**< log called from file ... */ + LOG_ITEM_SRC_LINE = 1 << 7, /**< log called from line ... */ + LOG_ITEM_SRC_FUNC = 1 << 8, /**< log called from function ... */ + LOG_ITEM_SRV_SUBSYS = 1 << 9, /**< log called from subsystem ... */ + LOG_ITEM_SRV_COMPONENT = 1 << 10, /**< log called from component ... */ + LOG_ITEM_MSC_USER = 1 << 11, /**< offending thread owned by ... */ + LOG_ITEM_MSC_HOST = 1 << 12, /**< responsible user on host ... */ + LOG_ITEM_SRV_THREAD = 1 << 13, /**< connection ID */ + LOG_ITEM_SQL_QUERY_ID = 1 << 14, /**< query ID */ + LOG_ITEM_SQL_TABLE_NAME = 1 << 15, /**< table name */ + LOG_ITEM_LOG_PRIO = 1 << 16, /**< log priority (error, warn, ...) */ + LOG_ITEM_LOG_LABEL = 1 << 17, /**< label, unless auto-derived */ + LOG_ITEM_LOG_VERBATIM = 1 << 18, /**< the message, no % substitutions */ + LOG_ITEM_LOG_MESSAGE = 1 << 19, /**< the message, format string */ + LOG_ITEM_LOG_LOOKUP = 1 << 20, /**< insert message by error-code */ + LOG_ITEM_LOG_TIMESTAMP = 1 << 21, /**< ISO8601 timestamp */ + LOG_ITEM_LOG_BUFFERED = 1 << 22, /**< integer timestamp if/when buffered */ + LOG_ITEM_LOG_SUPPRESSED = 1 << 23, /**< "and ... more" throttled */ + LOG_ITEM_GEN_FLOAT = 1 << 24, /**< float not otherwise specified */ + LOG_ITEM_GEN_INTEGER = 1 << 25, /**< integer not otherwise specified */ + LOG_ITEM_GEN_LEX_STRING = 1 << 26, /**< lex string not otherwise specified */ + LOG_ITEM_GEN_CSTRING = 1 << 27 /**< C-string not otherwise specified */ +} log_item_type; + +/* some suggested keys for generic items */ + +/** DIAGNOSTICS: for da->message_text() */ +#define LOG_TAG_DIAG "DIAGNOSTICS" + +/** AUX: supplementary data not fitting any of the wellknown keys */ +#define LOG_TAG_AUX "AUX" + +/* data type */ +typedef enum enum_log_item_class { + LOG_UNTYPED = 0, /**< undefined */ + LOG_CSTRING = 1, /**< string (char * + \0; variadic API only) */ + LOG_INTEGER = 2, /**< integer (long long) */ + LOG_FLOAT = 3, /**< float (double) */ + LOG_LEX_STRING = 4 /**< string (char *, size_t) */ +} log_item_class; + +/* do we need to release any parts of the item after use? */ +enum enum_log_item_free { + LOG_ITEM_FREE_NONE = 0, + LOG_ITEM_FREE_KEY = 1, + LOG_ITEM_FREE_VALUE = 2 +}; + +/* union: payload */ +typedef union _log_item_data { + longlong data_integer; + double data_float; + LEX_CSTRING data_string; +} log_item_data; + +/* item key: for now, a C-string */ +typedef const char *log_item_key; + +/* log item: key/value */ +typedef struct _log_item { + log_item_type type; + log_item_class item_class; + log_item_key key; + log_item_data data; + uint32 alloc; +} log_item; + +/* service helpers */ +typedef enum enum_log_item_error { + LOG_ITEM_OK = 0, + LOG_ITEM_TYPE_NOT_FOUND = -1, + LOG_ITEM_TYPE_RESERVED = -2, + LOG_ITEM_CLASS_MISMATCH = -3, + LOG_ITEM_KEY_MISMATCH = -4, + LOG_ITEM_STRING_NULL = -5, + LOG_ITEM_KEY_NULL = -6 +} log_item_error; + +/** a bit mask of log_types. standardizing the width to 64 bit. */ +typedef uint64 log_item_type_mask; + +/** log line: a collection of log items */ +typedef struct _log_line log_line; + +/** log iter: an iterator over the collection of log items in a log line */ +typedef struct _log_item_iter log_item_iter; + +/** advisory. components must not rely on others using the same value. */ +#define LOG_BUFF_MAX 8192 + +/** 26 for regular timestamp, plus 7 (".123456") when using micro-seconds */ +static const int iso8601_size = 33; + +/** + index of first server error message: messages with this index or + higher are intended for the error log; messages below this index + are intended for the client +*/ +#define ER_SERVER_RANGE_START 10000 + +#endif diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/my_io_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/my_io_bits.h new file mode 100644 index 0000000000..10d862aaa8 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/my_io_bits.h @@ -0,0 +1,62 @@ +/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_MY_IO_BITS_H +#define COMPONENTS_SERVICES_MY_IO_BITS_H + +/** + @file mysql/components/services/my_io_bits.h + Types to make file and socket I/O compatible. +*/ + +#ifdef _WIN32 +/* Include common headers.*/ +#include <io.h> /* access(), chmod() */ +#ifdef WIN32_LEAN_AND_MEAN +#include <winsock2.h> +#include <ws2tcpip.h> /* SOCKET */ +#endif +#endif + +#ifndef MYSQL_ABI_CHECK +#if !defined(_WIN32) +#include <sys/socket.h> +#include <unistd.h> +#endif +#include <errno.h> +#include <limits.h> +#include <sys/types.h> // Needed for mode_t, so IWYU pragma: keep. +#endif + +typedef int File; /* File descriptor */ +#ifdef _WIN32 +typedef int MY_MODE; +typedef int mode_t; +typedef int socket_len_t; +typedef SOCKET my_socket; +#else +typedef mode_t MY_MODE; +typedef socklen_t socket_len_t; +typedef int my_socket; /* File descriptor for sockets */ +#endif /* _WIN32 */ + +#endif /* COMPONENTS_SERVICES_MY_IO_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/my_thread_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/my_thread_bits.h new file mode 100644 index 0000000000..992f9a39a1 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/my_thread_bits.h @@ -0,0 +1,58 @@ +/* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_MY_THREAD_BITS_H +#define COMPONENTS_SERVICES_MY_THREAD_BITS_H + +/** + @file mysql/components/services/my_thread_bits.h + Types to make different thread packages compatible. +*/ + +#ifndef MYSQL_ABI_CHECK +#if defined(_WIN32) +#include <windows.h> +#else +#include <pthread.h> // IWYU pragma: export +#include <sched.h> // IWYU pragma: export +#endif +#endif /* MYSQL_ABI_CHECK */ + +#ifdef _WIN32 +typedef DWORD my_thread_t; +typedef struct thread_attr { + DWORD dwStackSize; + int detachstate; +} my_thread_attr_t; +#else +typedef pthread_t my_thread_t; +typedef pthread_attr_t my_thread_attr_t; +#endif + +struct my_thread_handle { + my_thread_t thread{0}; +#ifdef _WIN32 + HANDLE handle{INVALID_HANDLE_VALUE}; +#endif +}; + +#endif /* COMPONENTS_SERVICES_MY_THREAD_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/mysql_cond_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/mysql_cond_bits.h new file mode 100644 index 0000000000..3c9e2dcc9b --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/mysql_cond_bits.h @@ -0,0 +1,62 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_MYSQL_COND_BITS_H +#define COMPONENTS_SERVICES_MYSQL_COND_BITS_H + +/** + @file + Instrumentation helpers for conditions. +*/ + +#include "mysql/components/services/thr_cond_bits.h" + +/** + @defgroup psi_api_cond Cond Instrumentation (API) + @ingroup psi_api + @{ +*/ + +/** + An instrumented cond structure. + @c mysql_cond_t is a drop-in replacement for @c native_cond_t. + @sa mysql_cond_init + @sa mysql_cond_wait + @sa mysql_cond_timedwait + @sa mysql_cond_signal + @sa mysql_cond_broadcast + @sa mysql_cond_destroy +*/ +struct mysql_cond_t { + /** The real condition */ + native_cond_t m_cond; + /** + The instrumentation hook. + Note that this hook is not conditionally defined, + for binary compatibility of the @c mysql_cond_t interface. + */ + struct PSI_cond *m_psi; +}; + +/** @} (end of group psi_api_cond) */ + +#endif /* COMPONENTS_SERVICES_MYSQL_COND_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/mysql_mutex_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/mysql_mutex_bits.h new file mode 100644 index 0000000000..bca8420d1f --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/mysql_mutex_bits.h @@ -0,0 +1,62 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_MYSQL_MUTEX_BITS_H +#define COMPONENTS_SERVICES_MYSQL_MUTEX_BITS_H + +/** + @file + ABI for instrumented mutexes. +*/ + +#include <mysql/components/services/thr_mutex_bits.h> + +/** + @defgroup psi_api_mutex Mutex Instrumentation (API) + @ingroup psi_api + @{ +*/ + +/** + An instrumented mutex structure. + @c mysql_mutex_t is a drop-in replacement for @c my_mutex_t. + @sa mysql_mutex_assert_owner + @sa mysql_mutex_assert_not_owner + @sa mysql_mutex_init + @sa mysql_mutex_lock + @sa mysql_mutex_unlock + @sa mysql_mutex_destroy +*/ +struct mysql_mutex_t { + /** The real mutex. */ + my_mutex_t m_mutex; + /** + The instrumentation hook. + Note that this hook is not conditionally defined, + for binary compatibility of the @c mysql_mutex_t interface. + */ + struct PSI_mutex *m_psi{nullptr}; +}; + +/** @} (end of group psi_api_mutex) */ + +#endif /* COMPONENTS_SERVICES_MYSQL_MUTEX_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/mysql_rwlock_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/mysql_rwlock_bits.h new file mode 100644 index 0000000000..80ea267206 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/mysql_rwlock_bits.h @@ -0,0 +1,84 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_MYSQL_RWLOCK_BITS_H +#define COMPONENTS_SERVICES_MYSQL_RWLOCK_BITS_H + +/** + @file + Instrumentation helpers for rwlock. +*/ + +#include "mysql/components/services/thr_rwlock_bits.h" + +/** + @defgroup psi_api_rwlock Rwlock Instrumentation (API) + @ingroup psi_api + @{ +*/ + +/** + An instrumented rwlock structure. + @c mysql_rwlock_t is a drop-in replacement for @c pthread_rwlock_t. + @sa mysql_rwlock_init + @sa mysql_rwlock_rdlock + @sa mysql_rwlock_tryrdlock + @sa mysql_rwlock_wrlock + @sa mysql_rwlock_trywrlock + @sa mysql_rwlock_unlock + @sa mysql_rwlock_destroy +*/ +struct mysql_rwlock_t { + /** The real rwlock */ + native_rw_lock_t m_rwlock; + /** + The instrumentation hook. + Note that this hook is not conditionally defined, + for binary compatibility of the @c mysql_rwlock_t interface. + */ + struct PSI_rwlock *m_psi; +}; + +/** + An instrumented prlock structure. + A prlock is a read write lock that 'prefers readers' (pr). + @c mysql_prlock_t is a drop-in replacement for @c rw_pr_lock_t. + @sa mysql_prlock_init + @sa mysql_prlock_rdlock + @sa mysql_prlock_wrlock + @sa mysql_prlock_unlock + @sa mysql_prlock_destroy +*/ +struct mysql_prlock_t { + /** The real prlock */ + rw_pr_lock_t m_prlock; + /** + The instrumentation hook. + Note that this hook is not conditionally defined, + for binary compatibility of the @c mysql_rwlock_t interface. + */ + struct PSI_rwlock *m_psi; +}; + +/** @} (end of group psi_api_rwlock) */ + +#endif /* COMPONENTS_SERVICES_MYSQL_RWLOCK_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/mysql_socket_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/mysql_socket_bits.h new file mode 100644 index 0000000000..2e3f4477e9 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/mysql_socket_bits.h @@ -0,0 +1,63 @@ +#ifndef COMPONENTS_SERVICES_MYSQL_SOCKET_BITS_H +#define COMPONENTS_SERVICES_MYSQL_SOCKET_BITS_H + +/* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "my_io.h" +#include "mysql/components/services/my_io_bits.h" + +/** + An instrumented socket. + @c MYSQL_SOCKET is a replacement for @c my_socket. +*/ +struct MYSQL_SOCKET { + /** The real socket descriptor. */ + my_socket fd; + + /** + The instrumentation hook. + Note that this hook is not conditionally defined, + for binary compatibility of the @c MYSQL_SOCKET interface. + */ + struct PSI_socket *m_psi; +}; + +/** + @def MYSQL_INVALID_SOCKET + MYSQL_SOCKET initial value. +*/ +// MYSQL_SOCKET MYSQL_INVALID_SOCKET= {INVALID_SOCKET, NULL}; +#define MYSQL_INVALID_SOCKET mysql_socket_invalid() + +/** + MYSQL_SOCKET helper. Initialize instrumented socket. + @sa mysql_socket_getfd + @sa mysql_socket_setfd +*/ +static inline MYSQL_SOCKET mysql_socket_invalid() { + MYSQL_SOCKET mysql_socket = {INVALID_SOCKET, NULL}; + return mysql_socket; +} + +#endif // COMPONENTS_SERVICES_MYSQL_SOCKET_BITS_H diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/page_track_service.h b/contrib/libs/libmysql_r/include/mysql/components/services/page_track_service.h new file mode 100644 index 0000000000..9e71b777f9 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/page_track_service.h @@ -0,0 +1,184 @@ +/* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + + This program 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; version 2 of the License. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +/** + @brief + + This defines the API used to call functions to the page tracking service. + When implementing such a service, refer to mysql_page_track.h instead! + +*/ + +#ifndef MYSQL_PAGE_TRACK_SERVICE_H +#define MYSQL_PAGE_TRACK_SERVICE_H + +#include <mysql/components/service.h> +#include <functional> + +#ifdef __cplusplus +class THD; +#define MYSQL_THD THD * +#else +#define MYSQL_THD void * +#endif + +/** + SE for the page tracking. Currently supports only in InnoDB. +*/ +typedef enum { PAGE_TRACK_SE_INNODB = 1 } Page_Track_SE; + +/** + Page tracking callback function. + + @param[in] thd Current thread context + @param[in] buffer buffer filled with 8 byte page ids; the format is + specific to SE. For InnoDB it is space_id (4 bytes) followed by page number + (4 bytes) + @param[in] buf_len length of buffer in bytes + @param[in] num_pages number of valid page IDs in buffer + @param[in,out] user_ctx user context passed to page tracking function + + @return Operation status. +*/ +typedef int (*Page_Track_Callback)(MYSQL_THD thd, const unsigned char *buffer, + size_t buf_len, int num_pages, + void *user_ctx); + +BEGIN_SERVICE_DEFINITION(mysql_page_track) + +/** + Service API to start page tracking + + @param[in] opaque_thd Current thread context. + @param[in] se_type SE for which to enable tracking + @param[out] start_id SE specific sequence number [LSN for InnoDB] + indicating when the tracking was started + + @return Operation status. + @retval 0 Success + @retval other ER_* mysql error. Get error details from THD. +*/ + +DECLARE_METHOD(int, start, + (MYSQL_THD opaque_thd, Page_Track_SE se_type, + uint64_t *start_id)); + +/** + Service API to stop page tracking + + @param[in] opaque_thd Current thread context. + @param[in] se_type SE for which to enable tracking + @param[out] stop_id SE specific sequence number [LSN for InnoDB] + indicating when the tracking was stopped + + @return Operation status. + @retval 0 Success + @retval other ER_* mysql error. Get error details from THD. +*/ + +DECLARE_METHOD(int, stop, + (MYSQL_THD opaque_thd, Page_Track_SE se_type, + uint64_t *stop_id)); + +/** + Service API to purge page tracking data. + + @param[in] opaque_thd Current thread context. + @param[in] se_type SE for which to enable tracking + @param[in,out] purge_id SE specific sequence number [LSN for InnoDB] + initially indicating till where the data needs to be purged and finally + updated to until where it was actually purged + + @return Operation status. + @retval 0 Success + @retval other ER_* mysql error. Get error details from THD. +*/ +DECLARE_METHOD(int, purge, + (MYSQL_THD opaque_thd, Page_Track_SE se_type, + uint64_t *purge_id)); + +/** + Service API to get tracked pages + + @param[in] opaque_thd Current thread context. + @param[in] se_type SE for which to enable tracking + @param[in,out] start_id SE specific sequence number [LSN for InnoDB] from + where the pages tracked would be returned. + @note The range might get expanded and the actual start_id used for the + querying will be updated. + @param[in,out] stop_id SE specific sequence number [LSN for InnoDB] + until where the pages tracked would be returned. + @note The range might get expanded and the actual stop_id used for the + querying will be updated. + @param[out] buffer allocated buffer to copy page IDs + @param[in] buffer_len length of buffer in bytes + @param[in] cbk_func callback function return page IDs + @param[in] cbk_ctx caller's context for callback + + @return Operation status. + @retval 0 Success + @retval other ER_* mysql error. Get error details from THD. +*/ + +DECLARE_METHOD(int, get_page_ids, + (MYSQL_THD opaque_thd, Page_Track_SE se_type, uint64_t *start_id, + uint64_t *stop_id, unsigned char *buffer, size_t buffer_len, + Page_Track_Callback cbk_func, void *cbk_ctx)); + +/** + Service API to get approximate number of pages tracked in the given range. + + @param[in] opaque_thd Current thread context. + @param[in] se_type SE for which to enable tracking + @param[in,out] start_id SE specific sequence number [LSN for InnoDB] from + where the pages tracked would be returned. + @note the range might get expanded and the actual start_id used for the + querying will be updated. + @param[in,out] stop_id SE specific sequence number [LSN for InnoDB] + until where the pages tracked would be returned. + @note the range might get expanded and the actual stop_id used for the + querying will be updated. + @param[out] num_pages number of pages tracked + + @return Operation status. + @retval 0 Success + @retval other ER_* mysql error. Get error details from THD. +*/ +DECLARE_METHOD(int, get_num_page_ids, + (MYSQL_THD opaque_thd, Page_Track_SE se_type, uint64_t *start_id, + uint64_t *stop_id, uint64_t *num_pages)); + +/** + API to check if the page tracking is active or not and to return start id if + it's active. + + @param[in] opaque_thd Current thread context. + @param[in] se_type SE for which to enable tracking + @param[out] initial_start_id SE specific sequence number [LSN for + InnoDB] which denotes the start id at which page tracking was started if it's + active + @param[out] last_start_id SE specific sequence number [LSN for + InnoDB] which denotes the start id the last time the start request was issued + @return if page tracking is active or not + @retval true if page tracking is active + @retval false if page tracking is not active +*/ +DECLARE_METHOD(int, get_status, + (MYSQL_THD opaque_thd, Page_Track_SE se_type, + uint64_t *initial_start_id, uint64_t *last_start_id)); + +END_SERVICE_DEFINITION(mysql_page_track) + +#endif diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_cond_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_cond_bits.h new file mode 100644 index 0000000000..68082c2f03 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_cond_bits.h @@ -0,0 +1,197 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_COND_BITS_H +#define COMPONENTS_SERVICES_PSI_COND_BITS_H + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_cond Cond Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Instrumented cond key. + To instrument a condition, a condition key must be obtained + using @c register_cond. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_cond_key; + +/** + @def PSI_COND_VERSION_1 + Performance Schema Cond Interface number for version 1. + This version is supported. +*/ +#define PSI_COND_VERSION_1 1 + +/** + @def PSI_CURRENT_COND_VERSION + Performance Schema Cond Interface number for the most recent version. + The most current version is @c PSI_COND_VERSION_1 +*/ +#define PSI_CURRENT_COND_VERSION 1 + +/** + Interface for an instrumented condition. + This is an opaque structure. +*/ +struct PSI_cond; +typedef struct PSI_cond PSI_cond; + +/** + Interface for an instrumented condition operation. + This is an opaque structure. +*/ +struct PSI_cond_locker; +typedef struct PSI_cond_locker PSI_cond_locker; + +/** Operation performed on an instrumented condition. */ +enum PSI_cond_operation { + /** Wait. */ + PSI_COND_WAIT = 0, + /** Wait, with timeout. */ + PSI_COND_TIMEDWAIT = 1 +}; +typedef enum PSI_cond_operation PSI_cond_operation; + +/** + Condition information. + @since PSI_COND_VERSION_1 + This structure is used to register an instrumented cond. +*/ +struct PSI_cond_info_v1 { + /** + Pointer to the key assigned to the registered cond. + */ + PSI_cond_key *m_key; + /** + The name of the cond to register. + */ + const char *m_name; + /** + The flags of the cond to register. + @sa PSI_FLAG_SINGLETON + */ + unsigned int m_flags; + /** Volatility index. */ + int m_volatility; + /** Documentation. */ + const char *m_documentation; +}; +typedef struct PSI_cond_info_v1 PSI_cond_info_v1; + +/** + State data storage for @c start_cond_wait_v1_t. + This structure provide temporary storage to a condition locker. + The content of this structure is considered opaque, + the fields are only hints of what an implementation + of the psi interface can use. + This memory is provided by the instrumented code for performance reasons. + @sa start_cond_wait_v1_t +*/ +struct PSI_cond_locker_state_v1 { + /** Internal state. */ + unsigned int m_flags; + /** Current operation. */ + enum PSI_cond_operation m_operation; + /** Current condition. */ + struct PSI_cond *m_cond; + /** Current mutex. */ + struct PSI_mutex *m_mutex; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Internal data. */ + void *m_wait; +}; +typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state_v1; + +/** + Cond registration API. + @param category a category name (typically a plugin name) + @param info an array of cond info to register + @param count the size of the info array +*/ +typedef void (*register_cond_v1_t)(const char *category, + struct PSI_cond_info_v1 *info, int count); + +/** + Cond instrumentation initialisation API. + @param key the registered key + @param identity the address of the cond itself + @return an instrumented cond +*/ +typedef struct PSI_cond *(*init_cond_v1_t)(PSI_cond_key key, + const void *identity); + +/** + Cond instrumentation destruction API. + @param cond the rcond to destroy +*/ +typedef void (*destroy_cond_v1_t)(struct PSI_cond *cond); + +/** + Record a condition instrumentation signal event. + @param cond the cond instrumentation +*/ +typedef void (*signal_cond_v1_t)(struct PSI_cond *cond); + +/** + Record a condition instrumentation broadcast event. + @param cond the cond instrumentation +*/ +typedef void (*broadcast_cond_v1_t)(struct PSI_cond *cond); + +/** + Record a condition instrumentation wait start event. + @param state data storage for the locker + @param cond the instrumented cond to lock + @param op the operation to perform + @param src_file the source file name + @param src_line the source line number + @return a cond locker, or NULL +*/ +typedef struct PSI_cond_locker *(*start_cond_wait_v1_t)( + struct PSI_cond_locker_state_v1 *state, struct PSI_cond *cond, + struct PSI_mutex *mutex, enum PSI_cond_operation op, const char *src_file, + unsigned int src_line); + +/** + Record a condition instrumentation wait end event. + @param locker a thread locker for the running thread + @param rc the wait operation return code +*/ +typedef void (*end_cond_wait_v1_t)(struct PSI_cond_locker *locker, int rc); + +typedef struct PSI_cond_info_v1 PSI_cond_info; +typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state; + +/** @} (end of group psi_abi_cond) */ + +#endif /* COMPONENTS_SERVICES_PSI_COND_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_error_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_error_bits.h new file mode 100644 index 0000000000..89d7e18a8a --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_error_bits.h @@ -0,0 +1,51 @@ +/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_ERROR_BITS_H +#define COMPONENTS_SERVICES_PSI_ERROR_BITS_H + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_error Error Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +enum PSI_error_operation { + PSI_ERROR_OPERATION_RAISED = 0, + PSI_ERROR_OPERATION_HANDLED +}; +typedef enum PSI_error_operation PSI_error_operation; + +/** + Log the error seen in Performance Schema buffers. + @param error_num MySQL error number + @param error_operation operation on error (PSI_ERROR_OPERATION_*) +*/ +typedef void (*log_error_v1_t)(unsigned int error_num, + PSI_error_operation error_operation); + +/** @} (end of group psi_abi_error) */ + +#endif /* COMPONENTS_SERVICES_PSI_ERROR_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_file_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_file_bits.h new file mode 100644 index 0000000000..da89b9bb6e --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_file_bits.h @@ -0,0 +1,318 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_FILE_BITS_H +#define COMPONENTS_SERVICES_PSI_FILE_BITS_H + +#ifndef MYSQL_ABI_CHECK +#include <stddef.h> /* size_t */ +#endif + +#include <mysql/components/services/my_io_bits.h> /* File */ + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_file File Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Instrumented file key. + To instrument a file, a file key must be obtained using @c register_file. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_file_key; + +/** + Interface for an instrumented file handle. + This is an opaque structure. +*/ +struct PSI_file; +typedef struct PSI_file PSI_file; + +/** + Interface for an instrumented file operation. + This is an opaque structure. +*/ +struct PSI_file_locker; +typedef struct PSI_file_locker PSI_file_locker; + +/** Operation performed on an instrumented file. */ +enum PSI_file_operation { + /** File creation, as in @c create(). */ + PSI_FILE_CREATE = 0, + /** Temporary file creation, as in @c create_temp_file(). */ + PSI_FILE_CREATE_TMP = 1, + /** File open, as in @c open(). */ + PSI_FILE_OPEN = 2, + /** File open, as in @c fopen(). */ + PSI_FILE_STREAM_OPEN = 3, + /** File close, as in @c close(). */ + PSI_FILE_CLOSE = 4, + /** File close, as in @c fclose(). */ + PSI_FILE_STREAM_CLOSE = 5, + /** + Generic file read, such as @c fgets(), @c fgetc(), @c fread(), @c read(), + @c pread(). + */ + PSI_FILE_READ = 6, + /** + Generic file write, such as @c fputs(), @c fputc(), @c fprintf(), + @c vfprintf(), @c fwrite(), @c write(), @c pwrite(). + */ + PSI_FILE_WRITE = 7, + /** Generic file seek, such as @c fseek() or @c seek(). */ + PSI_FILE_SEEK = 8, + /** Generic file tell, such as @c ftell() or @c tell(). */ + PSI_FILE_TELL = 9, + /** File flush, as in @c fflush(). */ + PSI_FILE_FLUSH = 10, + /** File stat, as in @c stat(). */ + PSI_FILE_STAT = 11, + /** File stat, as in @c fstat(). */ + PSI_FILE_FSTAT = 12, + /** File chsize, as in @c my_chsize(). */ + PSI_FILE_CHSIZE = 13, + /** File delete, such as @c my_delete() or @c my_delete_with_symlink(). */ + PSI_FILE_DELETE = 14, + /** File rename, such as @c my_rename() or @c my_rename_with_symlink(). */ + PSI_FILE_RENAME = 15, + /** File sync, as in @c fsync() or @c my_sync(). */ + PSI_FILE_SYNC = 16 +}; +typedef enum PSI_file_operation PSI_file_operation; + +/** + File instrument information. + @since PSI_FILE_VERSION_1 + This structure is used to register an instrumented file. +*/ +struct PSI_file_info_v1 { + /** + Pointer to the key assigned to the registered file. + */ + PSI_file_key *m_key; + /** + The name of the file instrument to register. + */ + const char *m_name; + /** + The flags of the file instrument to register. + @sa PSI_FLAG_SINGLETON + */ + unsigned int m_flags; + /** Volatility index. */ + int m_volatility; + /** Documentation. */ + const char *m_documentation; +}; +typedef struct PSI_file_info_v1 PSI_file_info_v1; + +/** + State data storage for @c get_thread_file_name_locker_v1_t. + This structure provide temporary storage to a file locker. + The content of this structure is considered opaque, + the fields are only hints of what an implementation + of the psi interface can use. + This memory is provided by the instrumented code for performance reasons. + @sa get_thread_file_name_locker_v1_t + @sa get_thread_file_stream_locker_v1_t + @sa get_thread_file_descriptor_locker_v1_t +*/ +struct PSI_file_locker_state_v1 { + /** Internal state. */ + unsigned int m_flags; + /** Current operation. */ + enum PSI_file_operation m_operation; + /** Current file. */ + struct PSI_file *m_file; + /** Current file name. */ + const char *m_name; + /** Current file class. */ + void *m_class; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Operation number of bytes. */ + size_t m_number_of_bytes; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Internal data. */ + void *m_wait; +}; +typedef struct PSI_file_locker_state_v1 PSI_file_locker_state_v1; + +/** + File registration API. + @param category a category name (typically a plugin name) + @param info an array of file info to register + @param count the size of the info array +*/ +typedef void (*register_file_v1_t)(const char *category, + struct PSI_file_info_v1 *info, int count); + +/** + Create a file instrumentation for a created file. + This method does not create the file itself, but is used to notify the + instrumentation interface that a file was just created. + @param key the file instrumentation key for this file + @param name the file name + @param file the file handle +*/ +typedef void (*create_file_v1_t)(PSI_file_key key, const char *name, File file); + +/** + Get a file instrumentation locker, for opening or creating a file. + @param state data storage for the locker + @param key the file instrumentation key + @param op the operation to perform + @param name the file name + @param identity a pointer representative of this file. + @return a file locker, or NULL +*/ +typedef struct PSI_file_locker *(*get_thread_file_name_locker_v1_t)( + struct PSI_file_locker_state_v1 *state, PSI_file_key key, + enum PSI_file_operation op, const char *name, const void *identity); + +/** + Get a file stream instrumentation locker. + @param state data storage for the locker + @param file the file stream to access + @param op the operation to perform + @return a file locker, or NULL +*/ +typedef struct PSI_file_locker *(*get_thread_file_stream_locker_v1_t)( + struct PSI_file_locker_state_v1 *state, struct PSI_file *file, + enum PSI_file_operation op); + +/** + Get a file instrumentation locker. + @param state data storage for the locker + @param file the file descriptor to access + @param op the operation to perform + @return a file locker, or NULL +*/ +typedef struct PSI_file_locker *(*get_thread_file_descriptor_locker_v1_t)( + struct PSI_file_locker_state_v1 *state, File file, + enum PSI_file_operation op); + +/** + Start a file instrumentation open operation. + @param locker the file locker + @param src_file the source file name + @param src_line the source line number +*/ +typedef void (*start_file_open_wait_v1_t)(struct PSI_file_locker *locker, + const char *src_file, + unsigned int src_line); + +/** + End a file instrumentation open operation, for file streams. + @param locker the file locker. + @param result the opened file (NULL indicates failure, non NULL success). + @return an instrumented file handle +*/ +typedef struct PSI_file *(*end_file_open_wait_v1_t)( + struct PSI_file_locker *locker, void *result); + +/** + End a file instrumentation open operation, for non stream files. + @param locker the file locker. + @param file the file number assigned by open() or create() for this file. +*/ +typedef void (*end_file_open_wait_and_bind_to_descriptor_v1_t)( + struct PSI_file_locker *locker, File file); + +/** + End a file instrumentation open operation, for non stream temporary files. + @param locker the file locker. + @param file the file number assigned by open() or create() for this file. + @param filename the file name generated during temporary file creation. +*/ +typedef void (*end_temp_file_open_wait_and_bind_to_descriptor_v1_t)( + struct PSI_file_locker *locker, File file, const char *filename); + +/** + Record a file instrumentation start event. + @param locker a file locker for the running thread + @param count the number of bytes requested, or 0 if not applicable + @param src_file the source file name + @param src_line the source line number +*/ +typedef void (*start_file_wait_v1_t)(struct PSI_file_locker *locker, + size_t count, const char *src_file, + unsigned int src_line); + +/** + Record a file instrumentation end event. + Note that for file close operations, the instrumented file handle + associated with the file (which was provided to obtain a locker) + is invalid after this call. + @param locker a file locker for the running thread + @param count the number of bytes actually used in the operation, + or 0 if not applicable, or -1 if the operation failed + @sa get_thread_file_name_locker + @sa get_thread_file_stream_locker + @sa get_thread_file_descriptor_locker +*/ +typedef void (*end_file_wait_v1_t)(struct PSI_file_locker *locker, + size_t count); + +/** + Start a file instrumentation close operation. + @param locker the file locker + @param src_file the source file name + @param src_line the source line number +*/ +typedef void (*start_file_close_wait_v1_t)(struct PSI_file_locker *locker, + const char *src_file, + unsigned int src_line); + +/** + End a file instrumentation close operation. + @param locker the file locker. + @param rc the close operation return code (0 for success). +*/ +typedef void (*end_file_close_wait_v1_t)(struct PSI_file_locker *locker, + int rc); + +/** + Rename a file instrumentation close operation. + @param locker the file locker. + @param old_name name of the file to be renamed. + @param new_name name of the file after rename. + @param rc the rename operation return code (0 for success). +*/ +typedef void (*end_file_rename_wait_v1_t)(struct PSI_file_locker *locker, + const char *old_name, + const char *new_name, int rc); + +typedef struct PSI_file_info_v1 PSI_file_info; +typedef struct PSI_file_locker_state_v1 PSI_file_locker_state; + +/** @} (end of group psi_abi_file) */ + +#endif /* COMPONENTS_SERVICES_PSI_FILE_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_idle_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_idle_bits.h new file mode 100644 index 0000000000..bf2074145a --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_idle_bits.h @@ -0,0 +1,86 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_IDLE_BITS_H +#define COMPONENTS_SERVICES_PSI_IDLE_BITS_H + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_idle Idle Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Interface for an instrumented idle operation. + This is an opaque structure. +*/ +struct PSI_idle_locker; +typedef struct PSI_idle_locker PSI_idle_locker; + +/** + State data storage for @c start_idle_wait_v1_t. + This structure provide temporary storage to an idle locker. + The content of this structure is considered opaque, + the fields are only hints of what an implementation + of the psi interface can use. + This memory is provided by the instrumented code for performance reasons. + @sa start_idle_wait_v1_t. +*/ +struct PSI_idle_locker_state_v1 { + /** Internal state. */ + unsigned int m_flags; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Internal data. */ + void *m_wait; +}; +typedef struct PSI_idle_locker_state_v1 PSI_idle_locker_state_v1; + +/** + Record an idle instrumentation wait start event. + @param state data storage for the locker + @param src_file the source file name + @param src_line the source line number + @return an idle locker, or NULL +*/ +typedef struct PSI_idle_locker *(*start_idle_wait_v1_t)( + struct PSI_idle_locker_state_v1 *state, const char *src_file, + unsigned int src_line); + +/** + Record an idle instrumentation wait end event. + @param locker a thread locker for the running thread +*/ +typedef void (*end_idle_wait_v1_t)(struct PSI_idle_locker *locker); + +typedef struct PSI_idle_locker_state_v1 PSI_idle_locker_state; + +/** @} (end of group psi_abi_idle) */ + +#endif /* COMPONENTS_SERVICES_PSI_IDLE_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_mdl_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_mdl_bits.h new file mode 100644 index 0000000000..01f95ebadf --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_mdl_bits.h @@ -0,0 +1,106 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_MDL_BITS_H +#define COMPONENTS_SERVICES_PSI_MDL_BITS_H + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_mdl Metadata Lock Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +struct MDL_key; + +/** @sa enum_mdl_type. */ +typedef int opaque_mdl_type; + +/** @sa enum_mdl_duration. */ +typedef int opaque_mdl_duration; + +/** @sa MDL_wait::enum_wait_status. */ +typedef int opaque_mdl_status; + +/** + Interface for an instrumented metadata lock. + This is an opaque structure. +*/ +struct PSI_metadata_lock; +typedef struct PSI_metadata_lock PSI_metadata_lock; + +/** + Interface for an instrumented MDL operation. + This is an opaque structure. +*/ +struct PSI_metadata_locker; +typedef struct PSI_metadata_locker PSI_metadata_locker; + +/** + State data storage for @c start_metadata_wait_v1_t. + This structure provide temporary storage to a metadata locker. + The content of this structure is considered opaque, + the fields are only hints of what an implementation + of the psi interface can use. + This memory is provided by the instrumented code for performance reasons. + @sa start_metadata_wait_v1_t +*/ +struct PSI_metadata_locker_state_v1 { + /** Internal state. */ + unsigned int m_flags; + /** Current metadata lock. */ + struct PSI_metadata_lock *m_metadata_lock; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Internal data. */ + void *m_wait; +}; +typedef struct PSI_metadata_locker_state_v1 PSI_metadata_locker_state_v1; + +typedef PSI_metadata_lock *(*create_metadata_lock_v1_t)( + void *identity, const struct MDL_key *key, opaque_mdl_type mdl_type, + opaque_mdl_duration mdl_duration, opaque_mdl_status mdl_status, + const char *src_file, unsigned int src_line); + +typedef void (*set_metadata_lock_status_v1_t)(PSI_metadata_lock *lock, + opaque_mdl_status mdl_status); + +typedef void (*destroy_metadata_lock_v1_t)(PSI_metadata_lock *lock); + +typedef struct PSI_metadata_locker *(*start_metadata_wait_v1_t)( + struct PSI_metadata_locker_state_v1 *state, struct PSI_metadata_lock *mdl, + const char *src_file, unsigned int src_line); + +typedef void (*end_metadata_wait_v1_t)(struct PSI_metadata_locker *locker, + int rc); + +typedef struct PSI_metadata_locker_state_v1 PSI_metadata_locker_state; + +/** @} (end of group psi_abi_mdl) */ + +#endif /* COMPONENTS_SERVICES_PSI_MDL_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_memory_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_memory_bits.h new file mode 100644 index 0000000000..a7b7f268ed --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_memory_bits.h @@ -0,0 +1,127 @@ +/* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_MEMORY_BITS_H +#define COMPONENTS_SERVICES_PSI_MEMORY_BITS_H + +#ifndef MYSQL_ABI_CHECK +#include <stddef.h> /* size_t */ +#endif + +/** + @file + Performance schema instrumentation interface. +*/ + +/** + @defgroup psi_abi_memory Memory Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Instrumented memory key. + To instrument memory, a memory key must be obtained using @c register_memory. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_memory_key; + +struct PSI_thread; + +/** + Memory instrument information. + @since PSI_MEMORY_VERSION_1 + This structure is used to register instrumented memory. +*/ +struct PSI_memory_info_v1 { + /** Pointer to the key assigned to the registered memory. */ + PSI_memory_key *m_key; + /** The name of the memory instrument to register. */ + const char *m_name; + /** + The flags of the memory instrument to register. + @sa PSI_FLAG_ONLY_GLOBAL_STAT + */ + unsigned int m_flags; + /** Volatility index. */ + int m_volatility; + /** Documentation. */ + const char *m_documentation; +}; +typedef struct PSI_memory_info_v1 PSI_memory_info_v1; + +/** + Memory registration API. + @param category a category name (typically a plugin name) + @param info an array of memory info to register + @param count the size of the info array +*/ +typedef void (*register_memory_v1_t)(const char *category, + struct PSI_memory_info_v1 *info, + int count); + +/** + Instrument memory allocation. + @param key the memory instrument key + @param size the size of memory allocated + @param[out] owner the memory owner + @return the effective memory instrument key +*/ +typedef PSI_memory_key (*memory_alloc_v1_t)(PSI_memory_key key, size_t size, + struct PSI_thread **owner); + +/** + Instrument memory re allocation. + @param key the memory instrument key + @param old_size the size of memory previously allocated + @param new_size the size of memory re allocated + @param[in, out] owner the memory owner + @return the effective memory instrument key +*/ +typedef PSI_memory_key (*memory_realloc_v1_t)(PSI_memory_key key, + size_t old_size, size_t new_size, + struct PSI_thread **owner); + +/** + Instrument memory claim. + @param key the memory instrument key + @param size the size of memory allocated + @param[in, out] owner the memory owner + @return the effective memory instrument key +*/ +typedef PSI_memory_key (*memory_claim_v1_t)(PSI_memory_key key, size_t size, + struct PSI_thread **owner); + +/** + Instrument memory free. + @param key the memory instrument key + @param size the size of memory allocated + @param owner the memory owner +*/ +typedef void (*memory_free_v1_t)(PSI_memory_key key, size_t size, + struct PSI_thread *owner); + +typedef struct PSI_memory_info_v1 PSI_memory_info; + +/** @} (end of group psi_abi_memory) */ + +#endif /* COMPONENTS_SERVICES_PSI_MEMORY_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_mutex_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_mutex_bits.h new file mode 100644 index 0000000000..7931746508 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_mutex_bits.h @@ -0,0 +1,196 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_MUTEX_BITS_H +#define COMPONENTS_SERVICES_PSI_MUTEX_BITS_H + +/** + @file + Instrumentation helpers for mutexes. + This header file provides the necessary declarations + to use the mutex API with the performance schema instrumentation. + In some compilers (SunStudio), 'static inline' functions, when declared + but not used, are not optimized away (because they are unused) by default, + so that including a static inline function from a header file does + create unwanted dependencies, causing unresolved symbols at link time. + Other compilers, like gcc, optimize these dependencies by default. +*/ + +/** + @defgroup psi_abi_mutex Mutex Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Instrumented mutex key. + To instrument a mutex, a mutex key must be obtained using @c register_mutex. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_mutex_key; + +/** + @def PSI_MUTEX_VERSION_1 + Performance Schema Mutex Interface number for version 1. + This version is supported. +*/ +#define PSI_MUTEX_VERSION_1 1 + +/** + @def PSI_CURRENT_MUTEX_VERSION + Performance Schema Mutex Interface number for the most recent version. + The most current version is @c PSI_MUTEX_VERSION_1 +*/ +#define PSI_CURRENT_MUTEX_VERSION 1 + +/** + Mutex information. + @since PSI_MUTEX_VERSION_1 + This structure is used to register an instrumented mutex. +*/ +struct PSI_mutex_info_v1 { + /** + Pointer to the key assigned to the registered mutex. + */ + PSI_mutex_key *m_key; + /** + The name of the mutex to register. + */ + const char *m_name; + /** + The flags of the mutex to register. + @sa PSI_FLAG_SINGLETON + */ + unsigned int m_flags; + /** Volatility index. */ + int m_volatility; + /** Documentation. */ + const char *m_documentation; +}; + +/** + Interface for an instrumented mutex. + This is an opaque structure. +*/ +struct PSI_mutex; +typedef struct PSI_mutex PSI_mutex; + +/** + Interface for an instrumented mutex operation. + This is an opaque structure. +*/ +struct PSI_mutex_locker; +typedef struct PSI_mutex_locker PSI_mutex_locker; + +/** Operation performed on an instrumented mutex. */ +enum PSI_mutex_operation { + /** Lock. */ + PSI_MUTEX_LOCK = 0, + /** Lock attempt. */ + PSI_MUTEX_TRYLOCK = 1 +}; +typedef enum PSI_mutex_operation PSI_mutex_operation; + +/** + State data storage for @c start_mutex_wait_v1_t. + This structure provide temporary storage to a mutex locker. + The content of this structure is considered opaque, + the fields are only hints of what an implementation + of the psi interface can use. + This memory is provided by the instrumented code for performance reasons. + @sa start_mutex_wait_v1_t +*/ +struct PSI_mutex_locker_state_v1 { + /** Internal state. */ + unsigned int m_flags; + /** Current operation. */ + enum PSI_mutex_operation m_operation; + /** Current mutex. */ + struct PSI_mutex *m_mutex; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Internal data. */ + void *m_wait; +}; +typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state_v1; + +/** + Mutex registration API. + @param category a category name (typically a plugin name) + @param info an array of mutex info to register + @param count the size of the info array +*/ +typedef void (*register_mutex_v1_t)(const char *category, + struct PSI_mutex_info_v1 *info, int count); + +/** + Mutex instrumentation initialization API. + @param key the registered mutex key + @param identity the address of the mutex itself + @return an instrumented mutex +*/ +typedef struct PSI_mutex *(*init_mutex_v1_t)(PSI_mutex_key key, + const void *identity); + +/** + Mutex instrumentation destruction API. + @param mutex the mutex to destroy +*/ +typedef void (*destroy_mutex_v1_t)(struct PSI_mutex *mutex); + +/** + Record a mutex instrumentation unlock event. + @param mutex the mutex instrumentation +*/ +typedef void (*unlock_mutex_v1_t)(struct PSI_mutex *mutex); + +/** + Record a mutex instrumentation wait start event. + @param state data storage for the locker + @param mutex the instrumented mutex to lock + @param op the operation to perform + @param src_file the source file name + @param src_line the source line number + @return a mutex locker, or NULL +*/ +typedef struct PSI_mutex_locker *(*start_mutex_wait_v1_t)( + struct PSI_mutex_locker_state_v1 *state, struct PSI_mutex *mutex, + enum PSI_mutex_operation op, const char *src_file, unsigned int src_line); + +/** + Record a mutex instrumentation wait end event. + @param locker a thread locker for the running thread + @param rc the wait operation return code +*/ +typedef void (*end_mutex_wait_v1_t)(struct PSI_mutex_locker *locker, int rc); + +typedef struct PSI_mutex_info_v1 PSI_mutex_info_v1; +typedef PSI_mutex_info_v1 PSI_mutex_info; +typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state; + +/** @} (end of group psi_abi_mutex) */ + +#endif /* COMPONENTS_SERVICES_PSI_MUTEX_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_rwlock_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_rwlock_bits.h new file mode 100644 index 0000000000..31a1a61655 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_rwlock_bits.h @@ -0,0 +1,295 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_RWLOCK_BITS_H +#define COMPONENTS_SERVICES_PSI_RWLOCK_BITS_H + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_rwlock Rwlock Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Instrumented rwlock key. + To instrument a rwlock, a rwlock key must be obtained + using @c register_rwlock. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_rwlock_key; + +/** + @def PSI_RWLOCK_VERSION_1 + Performance Schema Rwlock Interface number for version 1. + This version is obsolete. +*/ +#define PSI_RWLOCK_VERSION_1 1 + +/** + @def PSI_RWLOCK_VERSION_2 + Performance Schema Rwlock Interface number for version 2. + This version is supported. +*/ +#define PSI_RWLOCK_VERSION_2 2 + +/** + @def PSI_CURRENT_RWLOCK_VERSION + Performance Schema Rwlock Interface number for the most recent version. + The most current version is @c PSI_RWLOCK_VERSION_2 +*/ +#define PSI_CURRENT_RWLOCK_VERSION 2 + +/** + Interface for an instrumented rwlock. + This is an opaque structure. +*/ +struct PSI_rwlock; +typedef struct PSI_rwlock PSI_rwlock; + +/** + Interface for an instrumented rwlock operation. + This is an opaque structure. +*/ +struct PSI_rwlock_locker; +typedef struct PSI_rwlock_locker PSI_rwlock_locker; + +#if 0 +/* + Keeping the original version 1 definition in the source, + in case we ever need to provide support for version 1. +*/ + +/** + Operation performed on an instrumented rwlock. + For basic READ / WRITE lock, + operations are "READ" or "WRITE". + For SX-locks, operations are "SHARED", "SHARED-EXCLUSIVE" or "EXCLUSIVE". +*/ +enum PSI_rwlock_operation { + /** Read lock. */ + PSI_RWLOCK_READLOCK = 0, + /** Write lock. */ + PSI_RWLOCK_WRITELOCK = 1, + /** Read lock attempt. */ + PSI_RWLOCK_TRYREADLOCK = 2, + /** Write lock attempt. */ + PSI_RWLOCK_TRYWRITELOCK = 3, + + /** Shared lock. */ + PSI_RWLOCK_SHAREDLOCK = 4, + /** Shared Exclusive lock. */ + PSI_RWLOCK_SHAREDEXCLUSIVELOCK = 5, + /** Exclusive lock. */ + PSI_RWLOCK_EXCLUSIVELOCK = 6, + /** Shared lock attempt. */ + PSI_RWLOCK_TRYSHAREDLOCK = 7, + /** Shared Exclusive lock attempt. */ + PSI_RWLOCK_TRYSHAREDEXCLUSIVELOCK = 8, + /** Exclusive lock attempt. */ + PSI_RWLOCK_TRYEXCLUSIVELOCK = 9 +}; +#endif + +/** + Operation performed on an instrumented rwlock. + For basic READ / WRITE lock, + operations are "READ" or "WRITE". + For SX-locks, operations are "SHARED", "SHARED-EXCLUSIVE" or "EXCLUSIVE". +*/ +enum PSI_rwlock_operation { + /** Read lock. */ + PSI_RWLOCK_READLOCK = 0, + /** Write lock. */ + PSI_RWLOCK_WRITELOCK = 1, + /** Read lock attempt. */ + PSI_RWLOCK_TRYREADLOCK = 2, + /** Write lock attempt. */ + PSI_RWLOCK_TRYWRITELOCK = 3, + /** Unlock (Read or Write). */ + PSI_RWLOCK_UNLOCK = 4, + + /** Shared lock. */ + PSI_RWLOCK_SHAREDLOCK = 5, + /** Shared Exclusive lock. */ + PSI_RWLOCK_SHAREDEXCLUSIVELOCK = 6, + /** Exclusive lock. */ + PSI_RWLOCK_EXCLUSIVELOCK = 7, + /** Shared lock attempt. */ + PSI_RWLOCK_TRYSHAREDLOCK = 8, + /** Shared Exclusive lock attempt. */ + PSI_RWLOCK_TRYSHAREDEXCLUSIVELOCK = 9, + /** Exclusive lock attempt. */ + PSI_RWLOCK_TRYEXCLUSIVELOCK = 10, + /** Unlock a shared lock. */ + PSI_RWLOCK_SHAREDUNLOCK = 11, + /** Unlock a shared exclusive lock. */ + PSI_RWLOCK_SHAREDEXCLUSIVEUNLOCK = 12, + /** Unlock an exclusive lock. */ + PSI_RWLOCK_EXCLUSIVEUNLOCK = 13 +}; +typedef enum PSI_rwlock_operation PSI_rwlock_operation; + +/** + Rwlock information. + @since PSI_RWLOCK_VERSION_1 + This structure is used to register an instrumented rwlock. +*/ +struct PSI_rwlock_info_v1 { + /** + Pointer to the key assigned to the registered rwlock. + */ + PSI_rwlock_key *m_key; + /** + The name of the rwlock to register. + */ + const char *m_name; + /** + The flags of the rwlock to register. + @sa PSI_FLAG_SINGLETON + */ + unsigned int m_flags; + /** Volatility index. */ + int m_volatility; + /** Documentation. */ + const char *m_documentation; +}; +typedef struct PSI_rwlock_info_v1 PSI_rwlock_info_v1; + +/** + State data storage for @c start_rwlock_rdwait_v1_t, @c + start_rwlock_wrwait_v1_t. + This structure provide temporary storage to a rwlock locker. + The content of this structure is considered opaque, + the fields are only hints of what an implementation + of the psi interface can use. + This memory is provided by the instrumented code for performance reasons. + @sa start_rwlock_rdwait_v1_t + @sa start_rwlock_wrwait_v1_t +*/ +struct PSI_rwlock_locker_state_v1 { + /** Internal state. */ + unsigned int m_flags; + /** Current operation. */ + enum PSI_rwlock_operation m_operation; + /** Current rwlock. */ + struct PSI_rwlock *m_rwlock; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Internal data. */ + void *m_wait; +}; +typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state_v1; + +/** + Rwlock registration API. + @param category a category name (typically a plugin name) + @param info an array of rwlock info to register + @param count the size of the info array +*/ +typedef void (*register_rwlock_v1_t)(const char *category, + struct PSI_rwlock_info_v1 *info, + int count); + +/** + Rwlock instrumentation initialization API. + @param key the registered rwlock key + @param identity the address of the rwlock itself + @return an instrumented rwlock +*/ +typedef struct PSI_rwlock *(*init_rwlock_v1_t)(PSI_rwlock_key key, + const void *identity); + +/** + Rwlock instrumentation destruction API. + @param rwlock the rwlock to destroy +*/ +typedef void (*destroy_rwlock_v1_t)(struct PSI_rwlock *rwlock); + +/** + Record a rwlock instrumentation read wait start event. + @param state data storage for the locker + @param rwlock the instrumented rwlock to lock + @param op the operation to perform + @param src_file the source file name + @param src_line the source line number + @return a rwlock locker, or NULL +*/ +typedef struct PSI_rwlock_locker *(*start_rwlock_rdwait_v1_t)( + struct PSI_rwlock_locker_state_v1 *state, struct PSI_rwlock *rwlock, + enum PSI_rwlock_operation op, const char *src_file, unsigned int src_line); + +/** + Record a rwlock instrumentation read wait end event. + @param locker a thread locker for the running thread + @param rc the wait operation return code +*/ +typedef void (*end_rwlock_rdwait_v1_t)(struct PSI_rwlock_locker *locker, + int rc); + +/** + Record a rwlock instrumentation write wait start event. + @param state data storage for the locker + @param rwlock the instrumented rwlock to lock + @param op the operation to perform + @param src_file the source file name + @param src_line the source line number + @return a rwlock locker, or NULL +*/ +typedef struct PSI_rwlock_locker *(*start_rwlock_wrwait_v1_t)( + struct PSI_rwlock_locker_state_v1 *state, struct PSI_rwlock *rwlock, + enum PSI_rwlock_operation op, const char *src_file, unsigned int src_line); + +/** + Record a rwlock instrumentation write wait end event. + @param locker a thread locker for the running thread + @param rc the wait operation return code +*/ +typedef void (*end_rwlock_wrwait_v1_t)(struct PSI_rwlock_locker *locker, + int rc); + +/** + Record a rwlock instrumentation unlock event. + @param rwlock the rwlock instrumentation +*/ +typedef void (*unlock_rwlock_v1_t)(struct PSI_rwlock *rwlock); + +/** + Record a rwlock instrumentation unlock event. + @param rwlock the rwlock instrumentation + @param op the unlock operation performed +*/ +typedef void (*unlock_rwlock_v2_t)(struct PSI_rwlock *rwlock, + enum PSI_rwlock_operation op); + +typedef struct PSI_rwlock_info_v1 PSI_rwlock_info; +typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state; + +/** @} (end of group psi_abi_rwlock) */ + +#endif /* COMPONENTS_SERVICES_PSI_RWLOCK_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_socket_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_socket_bits.h new file mode 100644 index 0000000000..27c9ac220f --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_socket_bits.h @@ -0,0 +1,268 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_SOCKET_BITS_H +#define COMPONENTS_SERVICES_PSI_SOCKET_BITS_H + +#ifndef MYSQL_ABI_CHECK +#include <stddef.h> /* size_t */ +#endif + +#include <mysql/components/services/my_io_bits.h> /* socklen_t */ + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_socket Socket Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Instrumented socket key. + To instrument a socket, a socket key must be obtained using @c + register_socket. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_socket_key; + +/** + @def PSI_SOCKET_VERSION_1 + Performance Schema Socket Interface number for version 1. + This version is supported. +*/ +#define PSI_SOCKET_VERSION_1 1 + +/** + @def PSI_CURRENT_SOCKET_VERSION + Performance Schema Socket Interface number for the most recent version. + The most current version is @c PSI_SOCKET_VERSION_1 +*/ +#define PSI_CURRENT_SOCKET_VERSION 1 + +/** + Interface for an instrumented socket descriptor. + This is an opaque structure. +*/ +struct PSI_socket; +typedef struct PSI_socket PSI_socket; + +/** + Interface for an instrumented socket operation. + This is an opaque structure. +*/ +struct PSI_socket_locker; +typedef struct PSI_socket_locker PSI_socket_locker; + +/** State of an instrumented socket. */ +enum PSI_socket_state { + /** Idle, waiting for the next command. */ + PSI_SOCKET_STATE_IDLE = 1, + /** Active, executing a command. */ + PSI_SOCKET_STATE_ACTIVE = 2 +}; +typedef enum PSI_socket_state PSI_socket_state; + +/** Operation performed on an instrumented socket. */ +enum PSI_socket_operation { + /** Socket creation, as in @c socket() or @c socketpair(). */ + PSI_SOCKET_CREATE = 0, + /** Socket connection, as in @c connect(), @c listen() and @c accept(). */ + PSI_SOCKET_CONNECT = 1, + /** Socket bind, as in @c bind(), @c getsockname() and @c getpeername(). */ + PSI_SOCKET_BIND = 2, + /** Socket close, as in @c shutdown(). */ + PSI_SOCKET_CLOSE = 3, + /** Socket send, @c send(). */ + PSI_SOCKET_SEND = 4, + /** Socket receive, @c recv(). */ + PSI_SOCKET_RECV = 5, + /** Socket send, @c sendto(). */ + PSI_SOCKET_SENDTO = 6, + /** Socket receive, @c recvfrom). */ + PSI_SOCKET_RECVFROM = 7, + /** Socket send, @c sendmsg(). */ + PSI_SOCKET_SENDMSG = 8, + /** Socket receive, @c recvmsg(). */ + PSI_SOCKET_RECVMSG = 9, + /** Socket seek, such as @c fseek() or @c seek(). */ + PSI_SOCKET_SEEK = 10, + /** Socket options, as in @c getsockopt() and @c setsockopt(). */ + PSI_SOCKET_OPT = 11, + /** Socket status, as in @c sockatmark() and @c isfdtype(). */ + PSI_SOCKET_STAT = 12, + /** Socket shutdown, as in @c shutdown(). */ + PSI_SOCKET_SHUTDOWN = 13, + /** Socket select, as in @c select() and @c poll(). */ + PSI_SOCKET_SELECT = 14 +}; +typedef enum PSI_socket_operation PSI_socket_operation; + +/** + Socket instrument information. + @since PSI_SOCKET_VERSION_1 + This structure is used to register an instrumented socket. +*/ +struct PSI_socket_info_v1 { + /** + Pointer to the key assigned to the registered socket. + */ + PSI_socket_key *m_key; + /** + The name of the socket instrument to register. + */ + const char *m_name; + /** + The flags of the socket instrument to register. + @sa PSI_FLAG_SINGLETON + */ + unsigned int m_flags; + /** Volatility index. */ + int m_volatility; + /** Documentation. */ + const char *m_documentation; +}; +typedef struct PSI_socket_info_v1 PSI_socket_info_v1; + +/** + State data storage for @c start_socket_wait_v1_t. + This structure provide temporary storage to a socket locker. + The content of this structure is considered opaque, + the fields are only hints of what an implementation + of the psi interface can use. + This memory is provided by the instrumented code for performance reasons. + @sa start_socket_wait_v1_t +*/ +struct PSI_socket_locker_state_v1 { + /** Internal state. */ + unsigned int m_flags; + /** Current socket. */ + struct PSI_socket *m_socket; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Operation number of bytes. */ + size_t m_number_of_bytes; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Current operation. */ + enum PSI_socket_operation m_operation; + /** Source file. */ + const char *m_src_file; + /** Source line number. */ + int m_src_line; + /** Internal data. */ + void *m_wait; +}; +typedef struct PSI_socket_locker_state_v1 PSI_socket_locker_state_v1; + +/** + Socket registration API. + @param category a category name (typically a plugin name) + @param info an array of socket info to register + @param count the size of the info array +*/ +typedef void (*register_socket_v1_t)(const char *category, + struct PSI_socket_info_v1 *info, + int count); + +/** + Socket instrumentation initialisation API. + @param key the registered socket key + @param fd socket file descriptor + @param addr the socket ip address + @param addr_len length of socket ip address + @return an instrumented socket +*/ +typedef struct PSI_socket *(*init_socket_v1_t)(PSI_socket_key key, + const my_socket *fd, + const struct sockaddr *addr, + socklen_t addr_len); + +/** + socket instrumentation destruction API. + @param socket the socket to destroy +*/ +typedef void (*destroy_socket_v1_t)(struct PSI_socket *socket); + +/** + Record a socket instrumentation start event. + @param state data storage for the locker + @param socket the instrumented socket + @param op socket operation to be performed + @param count the number of bytes requested, or 0 if not applicable + @param src_file the source file name + @param src_line the source line number + @return a socket locker, or NULL +*/ +typedef struct PSI_socket_locker *(*start_socket_wait_v1_t)( + struct PSI_socket_locker_state_v1 *state, struct PSI_socket *socket, + enum PSI_socket_operation op, size_t count, const char *src_file, + unsigned int src_line); + +/** + Record a socket instrumentation end event. + Note that for socket close operations, the instrumented socket handle + associated with the socket (which was provided to obtain a locker) + is invalid after this call. + @param locker a socket locker for the running thread + @param count the number of bytes actually used in the operation, + or 0 if not applicable, or -1 if the operation failed + @sa get_thread_socket_locker +*/ +typedef void (*end_socket_wait_v1_t)(struct PSI_socket_locker *locker, + size_t count); + +/** + Set the socket state for an instrumented socket. + @param socket the instrumented socket + @param state socket state +*/ +typedef void (*set_socket_state_v1_t)(struct PSI_socket *socket, + enum PSI_socket_state state); + +/** + Set the socket info for an instrumented socket. + @param socket the instrumented socket + @param fd the socket descriptor + @param addr the socket ip address + @param addr_len length of socket ip address +*/ +typedef void (*set_socket_info_v1_t)(struct PSI_socket *socket, + const my_socket *fd, + const struct sockaddr *addr, + socklen_t addr_len); + +/** + Bind a socket to the thread that owns it. + @param socket instrumented socket +*/ +typedef void (*set_socket_thread_owner_v1_t)(struct PSI_socket *socket); + +typedef struct PSI_socket_info_v1 PSI_socket_info; +typedef struct PSI_socket_locker_state_v1 PSI_socket_locker_state; + +/** @} (end of group psi_abi_socket) */ + +#endif /* COMPONENTS_SERVICES_PSI_SOCKET_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_stage_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_stage_bits.h new file mode 100644 index 0000000000..5f1768e429 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_stage_bits.h @@ -0,0 +1,120 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_STAGE_BITS_H +#define COMPONENTS_SERVICES_PSI_STAGE_BITS_H + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_stage Stage Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Instrumented stage key. + To instrument a stage, a stage key must be obtained using @c register_stage. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_stage_key; + +/** + @def PSI_STAGE_VERSION_1 + Performance Schema Stage Interface number for version 1. + This version is supported. +*/ +#define PSI_STAGE_VERSION_1 1 + +/** + @def PSI_CURRENT_STAGE_VERSION + Performance Schema Stage Interface number for the most recent version. + The most current version is @c PSI_STAGE_VERSION_1 +*/ +#define PSI_CURRENT_STAGE_VERSION 1 + +/** + Interface for an instrumented stage progress. + This is a public structure, for efficiency. +*/ +struct PSI_stage_progress_v1 { + unsigned long long m_work_completed; + unsigned long long m_work_estimated; +}; +typedef struct PSI_stage_progress_v1 PSI_stage_progress_v1; + +/** + Stage instrument information. + @since PSI_STAGE_VERSION_1 + This structure is used to register an instrumented stage. +*/ +struct PSI_stage_info_v1 { + /** The registered stage key. */ + PSI_stage_key m_key{0}; + /** The name of the stage instrument to register. */ + const char *m_name{nullptr}; + /** + The flags of the stage instrument to register. + @sa PSI_FLAG_PROGRESS + */ + unsigned int m_flags{0}; + /** Documentation. */ + const char *m_documentation{nullptr}; +}; +typedef struct PSI_stage_info_v1 PSI_stage_info_v1; + +/** + Stage registration API. + @param category a category name + @param info an array of stage info to register + @param count the size of the info array +*/ +typedef void (*register_stage_v1_t)(const char *category, + struct PSI_stage_info_v1 **info, int count); + +/** + Start a new stage, and implicitly end the previous stage. + @param key the key of the new stage + @param src_file the source file name + @param src_line the source line number + @return the new stage progress +*/ +typedef PSI_stage_progress_v1 *(*start_stage_v1_t)(PSI_stage_key key, + const char *src_file, + int src_line); + +/** + Get the current stage progress. + @return the stage progress +*/ +typedef PSI_stage_progress_v1 *(*get_current_stage_progress_v1_t)(void); + +/** End the current stage. */ +typedef void (*end_stage_v1_t)(void); + +typedef struct PSI_stage_info_v1 PSI_stage_info; +typedef struct PSI_stage_progress_v1 PSI_stage_progress; + +/** @} (end of group psi_abi_stage) */ + +#endif /* COMPONENTS_SERVICES_PSI_STAGE_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_statement_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_statement_bits.h new file mode 100644 index 0000000000..d3f53e6fe6 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_statement_bits.h @@ -0,0 +1,508 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_STATEMENT_BITS_H +#define COMPONENTS_SERVICES_PSI_STATEMENT_BITS_H + +#ifndef MYSQL_ABI_CHECK +#include <stddef.h> /* size_t */ +#endif + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_statement Statement Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Instrumented statement key. + To instrument a statement, a statement key must be obtained using @c + register_statement. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_statement_key; + +/** + @def PSI_STATEMENT_VERSION_1 + Performance Schema Statement Interface number for version 1. + This version is deprecated. +*/ +#define PSI_STATEMENT_VERSION_1 1 + +/** + @def PSI_STATEMENT_VERSION_2 + Performance Schema Statement Interface number for version 2. + This version is supported. +*/ +#define PSI_STATEMENT_VERSION_2 2 + +/** + @def PSI_CURRENT_STATEMENT_VERSION + Performance Schema Statement Interface number for the most recent version. + The most current version is @c PSI_STATEMENT_VERSION_2 +*/ +#define PSI_CURRENT_STATEMENT_VERSION 2 + +/** + Interface for an instrumented statement. + This is an opaque structure. +*/ +struct PSI_statement_locker; +typedef struct PSI_statement_locker PSI_statement_locker; + +/** + Interface for an instrumented prepared statement. + This is an opaque structure. +*/ +struct PSI_prepared_stmt; +typedef struct PSI_prepared_stmt PSI_prepared_stmt; + +/** + Interface for an instrumented statement digest operation. + This is an opaque structure. +*/ +struct PSI_digest_locker; +typedef struct PSI_digest_locker PSI_digest_locker; + +/** + Interface for an instrumented stored procedure share. + This is an opaque structure. +*/ +struct PSI_sp_share; +typedef struct PSI_sp_share PSI_sp_share; + +/** + Interface for an instrumented stored program. + This is an opaque structure. +*/ +struct PSI_sp_locker; +typedef struct PSI_sp_locker PSI_sp_locker; + +/** + Statement instrument information. + @since PSI_STATEMENT_VERSION_1 + This structure is used to register an instrumented statement. +*/ +struct PSI_statement_info_v1 { + /** The registered statement key. */ + PSI_statement_key m_key; + /** The name of the statement instrument to register. */ + const char *m_name; + /** + The flags of the statement instrument to register. + @sa PSI_FLAG_MUTABLE + */ + unsigned int m_flags; + /** Documentation. */ + const char *m_documentation; +}; +typedef struct PSI_statement_info_v1 PSI_statement_info_v1; + +/* Duplicate of NAME_LEN, to avoid dependency on mysql_com.h */ +#define PSI_SCHEMA_NAME_LEN (64 * 3) + +/** + State data storage for @c get_thread_statement_locker_v1_t, + @c get_thread_statement_locker_v1_t. + This structure provide temporary storage to a statement locker. + The content of this structure is considered opaque, + the fields are only hints of what an implementation + of the psi interface can use. + This memory is provided by the instrumented code for performance reasons. + @sa get_thread_statement_locker_v1_t +*/ +struct PSI_statement_locker_state_v1 { + /** Discarded flag. */ + bool m_discarded; + /** In prepare flag. */ + bool m_in_prepare; + /** Metric, no index used flag. */ + unsigned char m_no_index_used; + /** Metric, no good index used flag. */ + unsigned char m_no_good_index_used; + /** Internal state. */ + unsigned int m_flags; + /** Instrumentation class. */ + void *m_class; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Internal data. */ + void *m_statement; + /** Locked time. */ + unsigned long long m_lock_time; + /** Rows sent. */ + unsigned long long m_rows_sent; + /** Rows examined. */ + unsigned long long m_rows_examined; + /** Metric, temporary tables created on disk. */ + unsigned long m_created_tmp_disk_tables; + /** Metric, temporary tables created. */ + unsigned long m_created_tmp_tables; + /** Metric, number of select full join. */ + unsigned long m_select_full_join; + /** Metric, number of select full range join. */ + unsigned long m_select_full_range_join; + /** Metric, number of select range. */ + unsigned long m_select_range; + /** Metric, number of select range check. */ + unsigned long m_select_range_check; + /** Metric, number of select scan. */ + unsigned long m_select_scan; + /** Metric, number of sort merge passes. */ + unsigned long m_sort_merge_passes; + /** Metric, number of sort merge. */ + unsigned long m_sort_range; + /** Metric, number of sort rows. */ + unsigned long m_sort_rows; + /** Metric, number of sort scans. */ + unsigned long m_sort_scan; + /** Statement digest. */ + const struct sql_digest_storage *m_digest; + /** Current schema name. */ + char m_schema_name[PSI_SCHEMA_NAME_LEN]; + /** Length in bytes of @c m_schema_name. */ + unsigned int m_schema_name_length; + /** Statement character set number. */ + unsigned int m_cs_number; + /** Statement query sample. */ + const char *m_query_sample; + /** Length in bytes of @c m_query_sample. */ + unsigned int m_query_sample_length; + /** True if @c m_query_sample was truncated. */ + bool m_query_sample_truncated; + + PSI_sp_share *m_parent_sp_share; + PSI_prepared_stmt *m_parent_prepared_stmt; +}; +typedef struct PSI_statement_locker_state_v1 PSI_statement_locker_state_v1; + +struct PSI_sp_locker_state_v1 { + /** Internal state. */ + unsigned int m_flags; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Stored Procedure share. */ + PSI_sp_share *m_sp_share; +}; +typedef struct PSI_sp_locker_state_v1 PSI_sp_locker_state_v1; + +/** + Statement registration API. + @param category a category name + @param info an array of statement info to register + @param count the size of the info array +*/ +typedef void (*register_statement_v1_t)(const char *category, + struct PSI_statement_info_v1 *info, + int count); + +/** + Get a statement instrumentation locker. + @param state data storage for the locker + @param key the statement instrumentation key + @param charset client character set + @return a statement locker, or NULL +*/ +typedef struct PSI_statement_locker *(*get_thread_statement_locker_v1_t)( + struct PSI_statement_locker_state_v1 *state, PSI_statement_key key, + const void *charset, PSI_sp_share *sp_share); + +/** + Refine a statement locker to a more specific key. + Note that only events declared mutable can be refined. + @param locker the statement locker for the current event + @param key the new key for the event + @sa PSI_FLAG_MUTABLE +*/ +typedef struct PSI_statement_locker *(*refine_statement_v1_t)( + struct PSI_statement_locker *locker, PSI_statement_key key); + +/** + Start a new statement event. + @param locker the statement locker for this event + @param db the active database name for this statement + @param db_length the active database name length for this statement + @param src_file source file name + @param src_line source line number +*/ +typedef void (*start_statement_v1_t)(struct PSI_statement_locker *locker, + const char *db, unsigned int db_length, + const char *src_file, + unsigned int src_line); + +/** + Set the statement text for a statement event. + Note that the statement text pointer must remain valid until end statement + is called. + @param locker the current statement locker + @param text the statement text + @param text_len the statement text length +*/ +typedef void (*set_statement_text_v1_t)(struct PSI_statement_locker *locker, + const char *text, + unsigned int text_len); + +/** + Set a statement query id. + Introduced in MySQL 8.0.14 + @param locker the statement locker + @param query_id the query id +*/ +typedef void (*set_statement_query_id_t)(struct PSI_statement_locker *locker, + unsigned long long query_id); + +/** + Set a statement event lock time. + @param locker the statement locker + @param lock_time the locked time, in microseconds +*/ +typedef void (*set_statement_lock_time_t)(struct PSI_statement_locker *locker, + unsigned long long lock_time); + +/** + Set a statement event rows sent metric. + @param locker the statement locker + @param count the number of rows sent +*/ +typedef void (*set_statement_rows_sent_t)(struct PSI_statement_locker *locker, + unsigned long long count); + +/** + Set a statement event rows examined metric. + @param locker the statement locker + @param count the number of rows examined +*/ +typedef void (*set_statement_rows_examined_t)( + struct PSI_statement_locker *locker, unsigned long long count); + +/** + Increment a statement event "created tmp disk tables" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_created_tmp_disk_tables_t)( + struct PSI_statement_locker *locker, unsigned long count); + +/** + Increment a statement event "created tmp tables" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_created_tmp_tables_t)( + struct PSI_statement_locker *locker, unsigned long count); + +/** + Increment a statement event "select full join" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_select_full_join_t)( + struct PSI_statement_locker *locker, unsigned long count); + +/** + Increment a statement event "select full range join" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_select_full_range_join_t)( + struct PSI_statement_locker *locker, unsigned long count); + +/** + Increment a statement event "select range join" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_select_range_t)( + struct PSI_statement_locker *locker, unsigned long count); + +/** + Increment a statement event "select range check" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_select_range_check_t)( + struct PSI_statement_locker *locker, unsigned long count); + +/** + Increment a statement event "select scan" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_select_scan_t)(struct PSI_statement_locker *locker, + unsigned long count); + +/** + Increment a statement event "sort merge passes" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_sort_merge_passes_t)( + struct PSI_statement_locker *locker, unsigned long count); + +/** + Increment a statement event "sort range" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_sort_range_t)(struct PSI_statement_locker *locker, + unsigned long count); + +/** + Increment a statement event "sort rows" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_sort_rows_t)(struct PSI_statement_locker *locker, + unsigned long count); + +/** + Increment a statement event "sort scan" metric. + @param locker the statement locker + @param count the metric increment value +*/ +typedef void (*inc_statement_sort_scan_t)(struct PSI_statement_locker *locker, + unsigned long count); + +/** + Set a statement event "no index used" metric. + @param locker the statement locker +*/ +typedef void (*set_statement_no_index_used_t)( + struct PSI_statement_locker *locker); + +/** + Set a statement event "no good index used" metric. + @param locker the statement locker +*/ +typedef void (*set_statement_no_good_index_used_t)( + struct PSI_statement_locker *locker); + +/** + End a statement event. + @param locker the statement locker + @param stmt_da the statement diagnostics area. + @sa Diagnostics_area +*/ +typedef void (*end_statement_v1_t)(struct PSI_statement_locker *locker, + void *stmt_da); + +/** + Get a prepare statement. + @param locker a statement locker for the running thread. +*/ +typedef PSI_prepared_stmt *(*create_prepared_stmt_v1_t)( + void *identity, unsigned int stmt_id, PSI_statement_locker *locker, + const char *stmt_name, size_t stmt_name_length, const char *name, + size_t length); + +/** + destroy a prepare statement. + @param prepared_stmt prepared statement. +*/ +typedef void (*destroy_prepared_stmt_v1_t)(PSI_prepared_stmt *prepared_stmt); + +/** + repreare a prepare statement. + @param prepared_stmt prepared statement. +*/ +typedef void (*reprepare_prepared_stmt_v1_t)(PSI_prepared_stmt *prepared_stmt); + +/** + Record a prepare statement instrumentation execute event. + @param locker a statement locker for the running thread. + @param prepared_stmt prepared statement. +*/ +typedef void (*execute_prepared_stmt_v1_t)(PSI_statement_locker *locker, + PSI_prepared_stmt *prepared_stmt); + +/** + Set the statement text for a prepared statment event. + @param prepared_stmt prepared statement. + @param text the prepared statement text + @param text_len the prepared statement text length +*/ +typedef void (*set_prepared_stmt_text_v1_t)(PSI_prepared_stmt *prepared_stmt, + const char *text, + unsigned int text_len); +/** + Get a digest locker for the current statement. + @param locker a statement locker for the running thread +*/ +typedef struct PSI_digest_locker *(*digest_start_v1_t)( + struct PSI_statement_locker *locker); + +/** + Add a computed digest to the current digest instrumentation. + @param locker a digest locker for the current statement + @param digest the computed digest +*/ +typedef void (*digest_end_v1_t)(struct PSI_digest_locker *locker, + const struct sql_digest_storage *digest); + +/** + Acquire a sp share instrumentation. + @param object_type type of stored program + @param schema_name schema name of stored program + @param schema_name_length length of schema_name + @param object_name object name of stored program + @param object_name_length length of object_name + @return a stored program share instrumentation, or NULL +*/ +typedef struct PSI_sp_share *(*get_sp_share_v1_t)( + unsigned int object_type, const char *schema_name, + unsigned int schema_name_length, const char *object_name, + unsigned int object_name_length); + +/** + Release a stored program share. + @param share the stored program share to release +*/ +typedef void (*release_sp_share_v1_t)(struct PSI_sp_share *share); + +typedef PSI_sp_locker *(*start_sp_v1_t)(struct PSI_sp_locker_state_v1 *state, + struct PSI_sp_share *sp_share); + +typedef void (*end_sp_v1_t)(struct PSI_sp_locker *locker); + +typedef void (*drop_sp_v1_t)(unsigned int object_type, const char *schema_name, + unsigned int schema_name_length, + const char *object_name, + unsigned int object_name_length); + +typedef struct PSI_statement_info_v1 PSI_statement_info; +typedef struct PSI_statement_locker_state_v1 PSI_statement_locker_state; +typedef struct PSI_sp_locker_state_v1 PSI_sp_locker_state; + +/** @} (end of group psi_abi_statement) */ + +#endif /* COMPONENTS_SERVICES_PSI_STATEMENT_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_system_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_system_bits.h new file mode 100644 index 0000000000..680910e0f2 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_system_bits.h @@ -0,0 +1,42 @@ +/* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_SYSTEM_BITS_H +#define COMPONENTS_SERVICES_PSI_SYSTEM_BITS_H + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_system System Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + System event - plugin unload event +*/ +typedef void (*unload_plugin_v1_t)(const char *plugin_name); + +/** @} (end of group psi_abi_system) */ + +#endif /* COMPONENTS_SERVICES_PSI_SYSTEM_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_table_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_table_bits.h new file mode 100644 index 0000000000..f9e09fe07d --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_table_bits.h @@ -0,0 +1,228 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_TABLE_BITS_H +#define COMPONENTS_SERVICES_PSI_TABLE_BITS_H + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_table Table Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +struct TABLE_SHARE; + +/** + Interface for an instrumented table operation. + This is an opaque structure. +*/ +struct PSI_table_locker; +typedef struct PSI_table_locker PSI_table_locker; + +/** IO operation performed on an instrumented table. */ +enum PSI_table_io_operation { + /** Row fetch. */ + PSI_TABLE_FETCH_ROW = 0, + /** Row write. */ + PSI_TABLE_WRITE_ROW = 1, + /** Row update. */ + PSI_TABLE_UPDATE_ROW = 2, + /** Row delete. */ + PSI_TABLE_DELETE_ROW = 3 +}; +typedef enum PSI_table_io_operation PSI_table_io_operation; + +/** + State data storage for @c start_table_io_wait_v1_t, + @c start_table_lock_wait_v1_t. + This structure provide temporary storage to a table locker. + The content of this structure is considered opaque, + the fields are only hints of what an implementation + of the psi interface can use. + This memory is provided by the instrumented code for performance reasons. + @sa start_table_io_wait_v1_t + @sa start_table_lock_wait_v1_t +*/ +struct PSI_table_locker_state { + /** Internal state. */ + unsigned int m_flags; + /** Current io operation. */ + enum PSI_table_io_operation m_io_operation; + /** Current table handle. */ + struct PSI_table *m_table; + /** Current table share. */ + struct PSI_table_share *m_table_share; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Internal data. */ + void *m_wait; + /** + Implementation specific. + For table io, the table io index. + For table lock, the lock type. + */ + unsigned int m_index; +}; +typedef struct PSI_table_locker_state PSI_table_locker_state; + +/** + Interface for an instrumented table share. + This is an opaque structure. +*/ +struct PSI_table_share; +typedef struct PSI_table_share PSI_table_share; + +/** + Interface for an instrumented table handle. + This is an opaque structure. +*/ +struct PSI_table; +typedef struct PSI_table PSI_table; + +/** Lock operation performed on an instrumented table. */ +enum PSI_table_lock_operation { + /** Table lock, in the server layer. */ + PSI_TABLE_LOCK = 0, + /** Table lock, in the storage engine layer. */ + PSI_TABLE_EXTERNAL_LOCK = 1 +}; +typedef enum PSI_table_lock_operation PSI_table_lock_operation; + +/** + Acquire a table share instrumentation. + @param temporary True for temporary tables + @param share The SQL layer table share + @return a table share instrumentation, or NULL +*/ +typedef struct PSI_table_share *(*get_table_share_v1_t)( + bool temporary, struct TABLE_SHARE *share); + +/** + Release a table share. + @param share the table share to release +*/ +typedef void (*release_table_share_v1_t)(struct PSI_table_share *share); + +/** + Drop a table share. + @param temporary True for temporary tables + @param schema_name the table schema name + @param schema_name_length the table schema name length + @param table_name the table name + @param table_name_length the table name length +*/ +typedef void (*drop_table_share_v1_t)(bool temporary, const char *schema_name, + int schema_name_length, + const char *table_name, + int table_name_length); + +/** + Open an instrumentation table handle. + @param share the table to open + @param identity table handle identity + @return a table handle, or NULL +*/ +typedef struct PSI_table *(*open_table_v1_t)(struct PSI_table_share *share, + const void *identity); + +/** + Unbind a table handle from the current thread. + This operation happens when an opened table is added to the open table cache. + @param table the table to unbind +*/ +typedef void (*unbind_table_v1_t)(struct PSI_table *table); + +/** + Rebind a table handle to the current thread. + This operation happens when a table from the open table cache + is reused for a thread. + @param table the table to unbind +*/ +typedef PSI_table *(*rebind_table_v1_t)(PSI_table_share *share, + const void *identity, PSI_table *table); + +/** + Close an instrumentation table handle. + Note that the table handle is invalid after this call. + @param table the table handle to close +*/ +typedef void (*close_table_v1_t)(struct TABLE_SHARE *server_share, + struct PSI_table *table); + +/** + Record a table instrumentation io wait start event. + @param state data storage for the locker + @param table the instrumented table + @param op the operation to perform + @param index the operation index + @param src_file the source file name + @param src_line the source line number +*/ +typedef struct PSI_table_locker *(*start_table_io_wait_v1_t)( + struct PSI_table_locker_state *state, struct PSI_table *table, + enum PSI_table_io_operation op, unsigned int index, const char *src_file, + unsigned int src_line); + +/** + Record a table instrumentation io wait end event. + @param locker a table locker for the running thread + @param numrows the number of rows involved in io +*/ +typedef void (*end_table_io_wait_v1_t)(struct PSI_table_locker *locker, + unsigned long long numrows); + +/** + Record a table instrumentation lock wait start event. + @param state data storage for the locker + @param table the instrumented table + @param op the operation to perform + @param flags the operation flags + @param src_file the source file name + @param src_line the source line number +*/ +typedef struct PSI_table_locker *(*start_table_lock_wait_v1_t)( + struct PSI_table_locker_state *state, struct PSI_table *table, + enum PSI_table_lock_operation op, unsigned long flags, const char *src_file, + unsigned int src_line); + +/** + Record a table instrumentation lock wait end event. + @param locker a table locker for the running thread +*/ +typedef void (*end_table_lock_wait_v1_t)(struct PSI_table_locker *locker); + +/** + Record a table unlock event. + @param table instrumentation for the table being unlocked +*/ +typedef void (*unlock_table_v1_t)(struct PSI_table *table); + +/** @} (end of group psi_abi_table) */ + +#endif /* COMPONENTS_SERVICES_PSI_TABLE_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_thread_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_thread_bits.h new file mode 100644 index 0000000000..21b5b4da04 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_thread_bits.h @@ -0,0 +1,468 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_THREAD_BITS_H +#define COMPONENTS_SERVICES_PSI_THREAD_BITS_H + +#ifndef MYSQL_ABI_CHECK +#include <stddef.h> /* size_t */ +#endif + +#include <mysql/components/services/my_io_bits.h> /* sockaddr_storage */ +#include <mysql/components/services/my_thread_bits.h> /* my_thread_handle */ + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_thread Thread Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Instrumented thread key. + To instrument a thread, a thread key must be obtained + using @c register_thread. + Using a zero key always disable the instrumentation. +*/ +typedef unsigned int PSI_thread_key; + +#ifdef __cplusplus +class THD; +#else +/* + Phony declaration when compiling C code. + This is ok, because the C code will never have a THD anyway. +*/ +struct opaque_THD { + int dummy; +}; +typedef struct opaque_THD THD; +#endif + +/** @sa enum_vio_type. */ +typedef int opaque_vio_type; + +/** + Interface for an instrumented thread. + This is an opaque structure. +*/ +struct PSI_thread; +typedef struct PSI_thread PSI_thread; + +/** + Thread instrument information. + @since PSI_THREAD_VERSION_1 + This structure is used to register an instrumented thread. +*/ +struct PSI_thread_info_v1 { + /** + Pointer to the key assigned to the registered thread. + */ + PSI_thread_key *m_key; + /** + The name of the thread instrument to register. + */ + const char *m_name; + /** + The flags of the thread to register. + @sa PSI_FLAG_SINGLETON + @sa PSI_FLAG_USER + */ + unsigned int m_flags; + /** Volatility index. */ + int m_volatility; + /** Documentation. */ + const char *m_documentation; +}; +typedef struct PSI_thread_info_v1 PSI_thread_info_v1; + +/** + Thread registration API. + @param category a category name (typically a plugin name) + @param info an array of thread info to register + @param count the size of the info array +*/ +typedef void (*register_thread_v1_t)(const char *category, + struct PSI_thread_info_v1 *info, + int count); + +/** + Spawn a thread. + This method creates a new thread, with instrumentation. + @param key the instrumentation key for this thread + @param thread the resulting thread + @param attr the thread attributes + @param start_routine the thread start routine + @param arg the thread start routine argument +*/ +typedef int (*spawn_thread_v1_t)(PSI_thread_key key, my_thread_handle *thread, + const my_thread_attr_t *attr, + void *(*start_routine)(void *), void *arg); + +/** + Create instrumentation for a thread. + @param key the registered key + @param identity an address typical of the thread + @param thread_id PROCESSLIST_ID of the thread + @return an instrumented thread +*/ +typedef struct PSI_thread *(*new_thread_v1_t)(PSI_thread_key key, + const void *identity, + unsigned long long thread_id); + +/** + Assign a THD to an instrumented thread. + @param thread the instrumented thread + @param thd the sql layer THD to assign +*/ +typedef void (*set_thread_THD_v1_t)(struct PSI_thread *thread, THD *thd); + +/** + Assign an id to an instrumented thread. + @param thread the instrumented thread + @param id the PROCESSLIST_ID to assign +*/ +typedef void (*set_thread_id_v1_t)(struct PSI_thread *thread, + unsigned long long id); +/** + Read the THREAD_ID of the current thread. + @return the id of the instrumented thread +*/ +typedef unsigned long long (*get_current_thread_internal_id_v2_t)(); + +/** + Read the THREAD_ID of an instrumented thread. + @param thread the instrumented thread + @return the id of the instrumented thread +*/ +typedef unsigned long long (*get_thread_internal_id_v2_t)( + struct PSI_thread *thread); + +/** + Get the instrumentation for the thread of given PROCESSLIST_ID. + @param processlist_id the thread id + @return the instrumented thread +*/ +typedef struct PSI_thread *(*get_thread_by_id_v2_t)( + unsigned long long processlist_id); + +/** + Assign the current operating system thread id to an instrumented thread. + The operating system task id is obtained from @c gettid() + @param thread the instrumented thread +*/ +typedef void (*set_thread_os_id_v1_t)(struct PSI_thread *thread); + +/** + Get the instrumentation for the running thread. + For this function to return a result, + the thread instrumentation must have been attached to the + running thread using @c set_thread() + @return the instrumentation for the running thread +*/ +typedef struct PSI_thread *(*get_thread_v1_t)(void); + +/** + Assign a user name to the instrumented thread. + @param user the user name + @param user_len the user name length +*/ +typedef void (*set_thread_user_v1_t)(const char *user, int user_len); + +/** + Assign a user name and host name to the instrumented thread. + @param user the user name + @param user_len the user name length + @param host the host name + @param host_len the host name length +*/ +typedef void (*set_thread_account_v1_t)(const char *user, int user_len, + const char *host, int host_len); + +/** + Assign a current database to the instrumented thread. + @param db the database name + @param db_len the database name length +*/ +typedef void (*set_thread_db_v1_t)(const char *db, int db_len); + +/** + Assign a current command to the instrumented thread. + @param command the current command +*/ +typedef void (*set_thread_command_v1_t)(int command); + +/** + Assign a connection type to the instrumented thread. + @param conn_type the connection type +*/ +typedef void (*set_connection_type_v1_t)(opaque_vio_type conn_type); + +/** + Assign a start time to the instrumented thread. + @param start_time the thread start time +*/ +typedef void (*set_thread_start_time_v1_t)(time_t start_time); + +/** + Assign a state to the instrumented thread. + @param state the thread state +*/ +typedef void (*set_thread_state_v1_t)(const char *state); + +/** + Assign a process info to the instrumented thread. + @param info the process into string + @param info_len the process into string length +*/ +typedef void (*set_thread_info_v1_t)(const char *info, unsigned int info_len); + +/** + Assign a resource group name to the current thread. + + @param group_name resource group name string + @param group_name_len resource group name string length + @param user_data user-defined data + return 0 if successful, 1 otherwise +*/ +typedef int (*set_thread_resource_group_v1_t)(const char *group_name, + int group_name_len, + void *user_data); + +/** + Assign a resource group name to an instrumented thread, identified either by + the thread instrumentation or Performance Schema thread id. + + @param thread pointer to the thread instrumentation. Ignored if NULL. + @param thread_id thread id of the target thread. Only used if thread is NULL. + @param group_name resource group name string + @param group_name_len resource group name string length + @param user_data user-defined data + return 0 if successful, 1 otherwise +*/ +typedef int (*set_thread_resource_group_by_id_v1_t)( + PSI_thread *thread, unsigned long long thread_id, const char *group_name, + int group_name_len, void *user_data); + +/** + Attach a thread instrumentation to the running thread. + In case of thread pools, this method should be called when + a worker thread picks a work item and runs it. + Also, this method should be called if the instrumented code does not + keep the pointer returned by @c new_thread() and relies on @c get_thread() + instead. + @param thread the thread instrumentation +*/ +typedef void (*set_thread_v1_t)(struct PSI_thread *thread); + +/** Aggregate the thread status variables. */ +typedef void (*aggregate_thread_status_v2_t)(struct PSI_thread *thread); + +/** Delete the current thread instrumentation. */ +typedef void (*delete_current_thread_v1_t)(void); + +/** Delete a thread instrumentation. */ +typedef void (*delete_thread_v1_t)(struct PSI_thread *thread); + +/** + Stores an array of connection attributes + @param buffer char array of length encoded connection attributes + in network format + @param length length of the data in buffer + @param from_cs charset in which @c buffer is encoded + @return state + @retval non_0 attributes truncated + @retval 0 stored the attribute +*/ +typedef int (*set_thread_connect_attrs_v1_t)(const char *buffer, + unsigned int length, + const void *from_cs); + +/** + Get the current thread current event. + @param [out] thread_internal_id The thread internal id + @param [out] event_id The per thread event id. +*/ +typedef void (*get_current_thread_event_id_v2_t)( + unsigned long long *thread_internal_id, unsigned long long *event_id); + +/** + Get the thread current event. + @deprecated + @param [out] thread_internal_id The thread internal id + @param [out] event_id The per thread event id. +*/ +typedef void (*get_thread_event_id_v1_t)(unsigned long long *thread_internal_id, + unsigned long long *event_id); + +/** + Get the thread current event. + @param thread the instrumented thread + @param [out] thread_internal_id The thread internal id + @param [out] event_id The per thread event id. +*/ +typedef void (*get_thread_event_id_v2_t)(struct PSI_thread *psi, + unsigned long long *thread_internal_id, + unsigned long long *event_id); + +/* Duplicate definitions to avoid dependency on mysql_com.h */ +#define PSI_USERNAME_LENGTH (32 * 3) +#define PSI_NAME_LEN (64 * 3) +#define PSI_HOSTNAME_LENGTH (255) + +/** + Performance Schema thread type: user/foreground or system/background. + @sa get_thread_system_attrs +*/ +struct PSI_thread_attrs_v3 { + /* PFS internal thread id, unique. */ + unsigned long long m_thread_internal_id; + + /* SHOW PROCESSLIST thread id, not unique. */ + unsigned long m_processlist_id; + + /* Operating system thread id, if any. */ + unsigned long long m_thread_os_id; + + /* User-defined data. */ + void *m_user_data; + + /* User name. */ + char m_username[PSI_USERNAME_LENGTH]; + + /* User name length. */ + size_t m_username_length; + + /* Host name. */ + char m_hostname[PSI_HOSTNAME_LENGTH]; + + /* Host name length. */ + size_t m_hostname_length; + + /* Resource group name. */ + char m_groupname[PSI_NAME_LEN]; + + /* Resource group name length. */ + size_t m_groupname_length; + + /** Raw socket address */ + struct sockaddr_storage m_sock_addr; + + /** Length of address */ + socklen_t m_sock_addr_length; + + /* True if system/background thread, false if user/foreground thread. */ + bool m_system_thread; +}; + +typedef struct PSI_thread_attrs_v3 PSI_thread_attrs; + +/** + Callback for the pfs_notification service. + @param thread_attrs system attributes of the current thread. +*/ +typedef void (*PSI_notification_cb_v3)(const PSI_thread_attrs_v3 *thread_attrs); + +/** + Registration structure for the pfs_notification service. + @sa register_notification_v3_t +*/ +struct PSI_notification_v3 { + PSI_notification_cb_v3 thread_create; + PSI_notification_cb_v3 thread_destroy; + PSI_notification_cb_v3 session_connect; + PSI_notification_cb_v3 session_disconnect; + PSI_notification_cb_v3 session_change_user; +}; + +typedef struct PSI_notification_v3 PSI_notification; + +/** + Get system attributes for the current thread. + + @param thread_attrs pointer to pfs_thread_attr struct + @return 0 if successful, 1 otherwise +*/ +typedef int (*get_thread_system_attrs_v3_t)(PSI_thread_attrs_v3 *thread_attrs); + +/** + Get system attributes for an instrumented thread, identified either by the + thread instrumentation or Performance Schema thread id. + + @param thread pointer to the thread instrumentation. Ignored if NULL. + @param thread_id thread id of the target thread. Only used if thread is NULL. + @param thread_attrs pointer to pfs_thread_attr struct + @return 0 if successful, 1 otherwise +*/ +typedef int (*get_thread_system_attrs_by_id_v3_t)( + PSI_thread *thread, unsigned long long thread_id, + PSI_thread_attrs_v3 *thread_attrs); + +/** + Register callback functions for the Notification service. + For best performance, set with_ref_count = false. + + @param callbacks structure of user-defined callback functions + @param with_ref_count true if callbacks can be unregistered + @sa unregister_notification + @return registration handle on success, 0 if failure +*/ +typedef int (*register_notification_v3_t)(const PSI_notification_v3 *callbacks, + bool with_ref_count); + +/** + Unregister callback functions for the Notification service. + + @param handle registration handle returned by register_notification() + @sa register_notification + @return 0 if successful, non-zero otherwise +*/ +typedef int (*unregister_notification_v1_t)(int handle); + +/** + Invoke the callback function registered for a session connect event. + + @param thread the thread instrumentation +*/ +typedef void (*notify_session_connect_v1_t)(PSI_thread *thread); + +/** + Invoke the callback function registered for a session disconnect event. + + @param thread the thread instrumentation +*/ +typedef void (*notify_session_disconnect_v1_t)(PSI_thread *thread); + +/** + Invoke the callback function registered for a changer user event. + + @param thread the thread instrumentation +*/ +typedef void (*notify_session_change_user_v1_t)(PSI_thread *thread); + +typedef struct PSI_thread_info_v1 PSI_thread_info; + +/** @} (end of group psi_abi_thread) */ + +#endif /* COMPONENTS_SERVICES_PSI_THREAD_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/psi_transaction_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/psi_transaction_bits.h new file mode 100644 index 0000000000..283faf8f44 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/psi_transaction_bits.h @@ -0,0 +1,176 @@ +/* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_PSI_TRANSACTION_BITS_H +#define COMPONENTS_SERVICES_PSI_TRANSACTION_BITS_H + +/** + @file + Performance schema instrumentation interface. + + @defgroup psi_abi_transaction Transaction Instrumentation (ABI) + @ingroup psi_abi + @{ +*/ + +/** + Interface for an instrumented transaction. + This is an opaque structure. +*/ +struct PSI_transaction_locker; +typedef struct PSI_transaction_locker PSI_transaction_locker; + +/** + State data storage for @c get_thread_transaction_locker_v1_t, + @c get_thread_transaction_locker_v1_t. + This structure provide temporary storage to a transaction locker. + The content of this structure is considered opaque, + the fields are only hints of what an implementation + of the psi interface can use. + This memory is provided by the instrumented code for performance reasons. + @sa get_thread_transaction_locker_v1_t +*/ +struct PSI_transaction_locker_state_v1 { + /** Internal state. */ + unsigned int m_flags; + /** Instrumentation class. */ + void *m_class; + /** Current thread. */ + struct PSI_thread *m_thread; + /** Timer start. */ + unsigned long long m_timer_start; + /** Timer function. */ + unsigned long long (*m_timer)(void); + /** Internal data. */ + void *m_transaction; + /** True if read-only transaction, false if read-write. */ + bool m_read_only; + /** True if transaction is autocommit. */ + bool m_autocommit; + /** Number of statements. */ + unsigned long m_statement_count; + /** Total number of savepoints. */ + unsigned long m_savepoint_count; + /** Number of rollback_to_savepoint. */ + unsigned long m_rollback_to_savepoint_count; + /** Number of release_savepoint. */ + unsigned long m_release_savepoint_count; +}; +typedef struct PSI_transaction_locker_state_v1 PSI_transaction_locker_state_v1; + +/** + Get a transaction instrumentation locker. + @param state data storage for the locker + @param xid the xid for this transaction + @param trxid the InnoDB transaction id + @param isolation_level isolation level for this transaction + @param read_only true if transaction access mode is read-only + @param autocommit true if transaction is autocommit + @return a transaction locker, or NULL +*/ +typedef struct PSI_transaction_locker *(*get_thread_transaction_locker_v1_t)( + struct PSI_transaction_locker_state_v1 *state, const void *xid, + const unsigned long long *trxid, int isolation_level, bool read_only, + bool autocommit); + +/** + Start a new transaction event. + @param locker the transaction locker for this event + @param src_file source file name + @param src_line source line number +*/ +typedef void (*start_transaction_v1_t)(struct PSI_transaction_locker *locker, + const char *src_file, + unsigned int src_line); + +/** + Set the transaction xid. + @param locker the transaction locker for this event + @param xid the id of the XA transaction + @param xa_state the state of the XA transaction +*/ +typedef void (*set_transaction_xid_v1_t)(struct PSI_transaction_locker *locker, + const void *xid, int xa_state); + +/** + Set the state of the XA transaction. + @param locker the transaction locker for this event + @param xa_state the new state of the xa transaction +*/ +typedef void (*set_transaction_xa_state_v1_t)( + struct PSI_transaction_locker *locker, int xa_state); + +/** + Set the transaction gtid. + @param locker the transaction locker for this event + @param sid the source id for the transaction, mapped from sidno + @param gtid_spec the gtid specifier for the transaction +*/ +typedef void (*set_transaction_gtid_v1_t)(struct PSI_transaction_locker *locker, + const void *sid, + const void *gtid_spec); + +/** + Set the transaction trx_id. + @param locker the transaction locker for this event + @param trxid the storage engine transaction ID +*/ +typedef void (*set_transaction_trxid_v1_t)( + struct PSI_transaction_locker *locker, const unsigned long long *trxid); + +/** + Increment a transaction event savepoint count. + @param locker the transaction locker + @param count the increment value +*/ +typedef void (*inc_transaction_savepoints_v1_t)( + struct PSI_transaction_locker *locker, unsigned long count); + +/** + Increment a transaction event rollback to savepoint count. + @param locker the transaction locker + @param count the increment value +*/ +typedef void (*inc_transaction_rollback_to_savepoint_v1_t)( + struct PSI_transaction_locker *locker, unsigned long count); + +/** + Increment a transaction event release savepoint count. + @param locker the transaction locker + @param count the increment value +*/ +typedef void (*inc_transaction_release_savepoint_v1_t)( + struct PSI_transaction_locker *locker, unsigned long count); + +/** + Commit or rollback the transaction. + @param locker the transaction locker for this event + @param commit true if transaction was committed, false if rolled back +*/ +typedef void (*end_transaction_v1_t)(struct PSI_transaction_locker *locker, + bool commit); + +typedef struct PSI_transaction_locker_state_v1 PSI_transaction_locker_state; + +/** @} (end of group psi_abi_transaction) */ + +#endif /* COMPONENTS_SERVICES_PSI_TRANSACTION_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/registry.h b/contrib/libs/libmysql_r/include/mysql/components/services/registry.h new file mode 100644 index 0000000000..fc86666273 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/registry.h @@ -0,0 +1,296 @@ +/* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License, version 2.0, +as published by the Free Software Foundation. + +This program is also distributed with certain software (including +but not limited to OpenSSL) that is licensed under separate terms, +as designated in a particular file or component or in included license +documentation. The authors of MySQL hereby grant you an additional +permission to link the program and your derivative works with the +separately licensed software that they have included with MySQL. + +This program 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, version 2.0, for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef MYSQL_REGISTRY_H +#define MYSQL_REGISTRY_H + +#include <mysql/components/service.h> +#include <stdint.h> + +/** + A handle type for acquired Service. +*/ +DEFINE_SERVICE_HANDLE(my_h_service); + +/** + A handle type for a iterator to a Service Implementation. +*/ +DEFINE_SERVICE_HANDLE(my_h_service_iterator); +/** + A handle type for a iterator to metadata of some Service Implementation. +*/ +DEFINE_SERVICE_HANDLE(my_h_service_metadata_iterator); + +/** + Service for acquiring and releasing references to all registered Service + Implementations. +*/ +BEGIN_SERVICE_DEFINITION(registry) +/** + Finds and acquires a Service by name. A name of the Service or the Service + Implementation can be specified. In case of the Service name, the default + Service Implementation for Service specified will be returned. + + @param service_name Name of Service or Service Implementation to acquire. + @param [out] out_service Pointer to Service handle to set acquired Service. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(acquire, + (const char *service_name, my_h_service *out_service)); +/** + Finds a Service by name. If there is a Service Implementation with the same + Component part of name as the input Service then the found Service is + returned. Otherwise the default Service Implementation for specified + Service is returned. + + @param service_name Name of Service or Service Implementation to acquire. + @param service Service handle already acquired Service Implementation. + @param [out] out_service Pointer to Service Implementation handle to set + acquired Service Implementation. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(acquire_related, + (const char *service_name, my_h_service service, + my_h_service *out_service)); +/** + Releases the Service Implementation previously acquired. After the call to + this method the usage of the Service Implementation handle will lead to + unpredicted results. + + @param service Service Implementation handle of already acquired Service. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(release, (my_h_service service)); +END_SERVICE_DEFINITION(registry) + +/** + Service for managing list of registered Service Implementations. +*/ +BEGIN_SERVICE_DEFINITION(registry_registration) +/** + Registers a new Service Implementation. If it is the first Service + Implementation for the specified Service then it is made a default one. + + @param service_implementation_name Name of the Service Implementation to + register. + @param ptr Pointer to the Service Implementation structure. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(register_service, (const char *service_implementation_name, + my_h_service ptr)); +/** + Removes previously registered Service Implementation from registry. If it is + the default one for specified Service then any one still registered is made + default. If there is no other, the default entry is removed from the + Registry too. + + @param service_implementation_name Name of the Service Implementation to + unregister. + @return Status of performed operation + @retval false success + @retval true Failure. May happen when Service is still being referenced. +*/ +DECLARE_BOOL_METHOD(unregister, (const char *service_implementation_name)); +/** + Sets new default Service Implementation for corresponding Service name. + + @param service_implementation_name Name of the Service Implementation to + set as default one. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(set_default, (const char *service_implementation_name)); +END_SERVICE_DEFINITION(registry_registration) + +/** + Service for listing all Service Implementations by iterator. +*/ +BEGIN_SERVICE_DEFINITION(registry_query) +/** + Creates iterator that iterates through all registered Service + Implementations. If successful it leaves read lock on the Registry until + iterator is released. The starting point of iteration may be specified + to be on one particular Service Implementation. The iterator will move + through all Service Implementations and additionally through all default + Service Implementation additionally, i.e. the default Service Implementation + will be returned twice. If no name is specified for search, iterator will be + positioned on the first Service Implementation. + + @param service_name_pattern Name of Service or Service Implementation to + start iteration from. May be empty string or NULL pointer, in which case + iteration starts from the first Service Implementation. + @param [out] out_iterator Pointer to the Service Implementation iterator + handle. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(create, (const char *service_name_pattern, + my_h_service_iterator *out_iterator)); +/** + Gets name of Service pointed to by iterator. The pointer returned will last + at least up to the moment of call to the release() method on the iterator. + + @param iterator Service Implementation iterator handle. + @param [out] out_name Pointer to string with name to set result pointer to. + @return Status of performed operation + @retval false success + @retval true Failure, may be caused when called on iterator that went + through all values already. +*/ +DECLARE_BOOL_METHOD(get, (my_h_service_iterator iter, const char **out_name)); +/** + Advances specified iterator to next element. Will succeed but return true if + it reaches one-past-last element. + + @param iterator Service Implementation iterator handle. + @return Status of performed operation and validity of iterator after + operation. + @retval false success + @retval true Failure or called on iterator that was on last element. +*/ +DECLARE_BOOL_METHOD(next, (my_h_service_iterator iter)); +/** + Checks if specified iterator is valid, i.e. have not reached one-past-last + element. + + @param iterator Service Implementation iterator handle. + @return Validity of iterator + @retval false Valid + @retval true Invalid or reached one-past-last element. +*/ +DECLARE_BOOL_METHOD(is_valid, (my_h_service_iterator iter)); +/** + Releases the Service Implementations iterator. Releases read lock on the + Registry. + + @param iterator Service Implementation iterator handle. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_METHOD(void, release, (my_h_service_iterator iter)); +END_SERVICE_DEFINITION(registry_query) + +/** + Service for listing all metadata for a Service Implementation specified by + the given iterator. +*/ +BEGIN_SERVICE_DEFINITION(registry_metadata_enumerate) +/** + Creates a iterator that iterates through all metadata for the object pointed + by the specified iterator. If successful it leaves read lock on the registry + until the iterator is released. + + @param iterator A iterator that points to object to get the metadata + iterator for. + @param [out] out_iterator Pointer to metadata iterator handle. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_BOOL_METHOD(create, (my_h_service_iterator iterator, + my_h_service_metadata_iterator *out_iterator)); +/** + Gets the key and value of the metadata pointed to by the specified iterator. + The pointers returned will last at least up to the moment of call to the + release() method on the iterator. + + @param iterator Metadata iterator handle. + @param [out] out_name A pointer to the string with the key to set the result + pointer to. + @param [out] out_value A pointer to the string with the metadata value to + set the result pointer to. + @return Status of performed operation + @retval false success + @retval true Failure, may be caused when called on the iterator that went + through all values already. +*/ +DECLARE_BOOL_METHOD(get, (my_h_service_metadata_iterator iterator, + const char **name, const char **value)); +/** + Advances specified iterator to next element. Will fail if it reaches + one-past-last element. + + @param iterator Metadata iterator handle. + @return Status of performed operation + @retval false success + @retval true Failure, may be caused when called on iterator that was on last + element. +*/ +DECLARE_BOOL_METHOD(next, (my_h_service_metadata_iterator iterator)); +/** + Checks if specified iterator is valid, i.e. have not reached one-past-last + element. + + @param iterator Metadata iterator handle. + @return Validity of iterator + @retval false Valid + @retval true Invalid or reached one-past-last element. +*/ +DECLARE_BOOL_METHOD(is_valid, (my_h_service_metadata_iterator iterator)); +/** + Releases the specified iterator. Releases read lock on the registry. + + @param iterator Metadata iterator handle. + @return Status of performed operation + @retval false success + @retval true failure +*/ +DECLARE_METHOD(void, release, (my_h_service_metadata_iterator iterator)); +END_SERVICE_DEFINITION(registry_metadata_enumerate) + +/** + Service to query specified metadata key directly for the specified Service + Implementation by iterator to it. +*/ +BEGIN_SERVICE_DEFINITION(registry_metadata_query) +/** + Gets the key and value of the metadata pointed to by the specified object + iterator. The pointer returned will last at least up to the moment of call + to the release() method on the iterator. + + @param iterator A iterator that points to object to get the metadata + iterator for. + @param name A pointer to the string with the key to set the result + pointer to. + @param [out] out_value A pointer to the string with the metadata value to + set the result pointer to. + @return Status of performed operation + @retval false success + @retval true Failure, may be caused when called on the iterator that went + through all values already. +*/ +DECLARE_BOOL_METHOD(get_value, (my_h_service_iterator iterator, + const char *name, const char **value)); +END_SERVICE_DEFINITION(registry_metadata_query) + +#endif /* MYSQL_REGISTRY_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/system_variable_source_type.h b/contrib/libs/libmysql_r/include/mysql/components/services/system_variable_source_type.h new file mode 100644 index 0000000000..449bcdd126 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/system_variable_source_type.h @@ -0,0 +1,45 @@ +/* + Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef SYSTEM_VARIABLE_SOURCE_TYPE_H +#define SYSTEM_VARIABLE_SOURCE_TYPE_H +/** + This enum values define how system variables are set. For example if a + variable is set by global option file /etc/my.cnf then source will be + set to GLOBAL, or if a variable is set from command line then source + will hold value as COMMAND_LINE. +*/ +enum enum_variable_source { + COMPILED = 1, + GLOBAL, + SERVER, + EXPLICIT, + EXTRA, + MYSQL_USER, + LOGIN, + COMMAND_LINE, + PERSISTED, + DYNAMIC +}; + +#endif /* SYSTEM_VARIABLE_SOURCE_TYPE_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/thr_cond_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/thr_cond_bits.h new file mode 100644 index 0000000000..f77f40236f --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/thr_cond_bits.h @@ -0,0 +1,48 @@ +/* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_THR_COND_BITS_H +#define COMPONENTS_SERVICES_THR_COND_BITS_H + +/** + @file + MySQL condition variable implementation. + + native_cond_t + Windows - ConditionVariable + Other OSes - pthread +*/ + +#include <stddef.h> +#include <sys/types.h> +#ifdef _WIN32 +#include <time.h> +#include "my_systime.h" +#endif + +#ifdef _WIN32 +typedef CONDITION_VARIABLE native_cond_t; +#else +typedef pthread_cond_t native_cond_t; +#endif + +#endif /* COMPONENTS_SERVICES_THR_COND_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/thr_mutex_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/thr_mutex_bits.h new file mode 100644 index 0000000000..84add7f443 --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/thr_mutex_bits.h @@ -0,0 +1,68 @@ +/* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_THR_MUTEX_BITS_H +#define COMPONENTS_SERVICES_THR_MUTEX_BITS_H + +#if defined(_WIN32) +#include <windows.h> +#else +#include <pthread.h> // IWYU pragma: export +#include <sched.h> // IWYU pragma: export +#endif + +/** + @file + ABI for thd_mutex + + There are three "layers": + 1) native_mutex_*() + Functions that map directly down to OS primitives. + Windows - CriticalSection + Other OSes - pthread + 2) my_mutex_*() + Functions that implement SAFE_MUTEX (default for debug), + Otherwise native_mutex_*() is used. + 3) mysql_mutex_*() + Functions that include Performance Schema instrumentation. + See include/mysql/psi/mysql_thread.h +*/ + +#ifdef _WIN32 +typedef CRITICAL_SECTION native_mutex_t; +typedef int native_mutexattr_t; +#else +typedef pthread_mutex_t native_mutex_t; +typedef pthread_mutexattr_t native_mutexattr_t; +#endif + +struct safe_mutex_t; + +struct my_mutex_t { + union u { + native_mutex_t m_native; + safe_mutex_t *m_safe_ptr; + } m_u; +}; +typedef struct my_mutex_t my_mutex_t; + +#endif /* COMPONENTS_SERVICES_THR_MUTEX_BITS_H */ diff --git a/contrib/libs/libmysql_r/include/mysql/components/services/thr_rwlock_bits.h b/contrib/libs/libmysql_r/include/mysql/components/services/thr_rwlock_bits.h new file mode 100644 index 0000000000..8cd066d5bf --- /dev/null +++ b/contrib/libs/libmysql_r/include/mysql/components/services/thr_rwlock_bits.h @@ -0,0 +1,115 @@ +/* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2.0, + as published by the Free Software Foundation. + + This program is also distributed with certain software (including + but not limited to OpenSSL) that is licensed under separate terms, + as designated in a particular file or component or in included license + documentation. The authors of MySQL hereby grant you an additional + permission to link the program and your derivative works with the + separately licensed software that they have included with MySQL. + + This program 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, version 2.0, for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef COMPONENTS_SERVICES_THR_RWLOCK_BITS_H +#define COMPONENTS_SERVICES_THR_RWLOCK_BITS_H + +/** + @file + MySQL rwlock ABI. + + There are two "layers": + 1) native_rw_*() + Functions that map directly down to OS primitives. + Windows - SRWLock + Other OSes - pthread + 2) mysql_rw*() + Functions that include Performance Schema instrumentation. + See include/mysql/psi/mysql_thread.h + + This file also includes rw_pr_*(), which implements a special + version of rwlocks that prefer readers. The P_S version of these + are mysql_prlock_*() - see include/mysql/psi/mysql_thread.h +*/ + +#include <stddef.h> +#include <sys/types.h> +#ifdef _WIN32 +#include <windows.h> +#endif + +#include <mysql/components/services/my_thread_bits.h> +#include <mysql/components/services/thr_cond_bits.h> +#include <mysql/components/services/thr_mutex_bits.h> + +#ifdef _WIN32 +struct native_rw_lock_t { + SRWLOCK srwlock; /* native reader writer lock */ + BOOL have_exclusive_srwlock; /* used for unlock */ +}; +#else +typedef pthread_rwlock_t native_rw_lock_t; +#endif + +/** + Portable implementation of special type of read-write locks. + + These locks have two properties which are unusual for rwlocks: + 1) They "prefer readers" in the sense that they do not allow + situations in which rwlock is rd-locked and there is a + pending rd-lock which is blocked (e.g. due to pending + request for wr-lock). + This is a stronger guarantee than one which is provided for + PTHREAD_RWLOCK_PREFER_READER_NP rwlocks in Linux. + MDL subsystem deadlock detector relies on this property for + its correctness. + 2) They are optimized for uncontended wr-lock/unlock case. + This is scenario in which they are most oftenly used + within MDL subsystem. Optimizing for it gives significant + performance improvements in some of tests involving many + connections. + + Another important requirement imposed on this type of rwlock + by the MDL subsystem is that it should be OK to destroy rwlock + object which is in unlocked state even though some threads might + have not yet fully left unlock operation for it (of course there + is an external guarantee that no thread will try to lock rwlock + which is destroyed). + Putting it another way the unlock operation should not access + rwlock data after changing its state to unlocked. + + TODO/FIXME: We should consider alleviating this requirement as + it blocks us from doing certain performance optimizations. +*/ + +struct rw_pr_lock_t { + /** + Lock which protects the structure. + Also held for the duration of wr-lock. + */ + native_mutex_t lock; + /** + Condition variable which is used to wake-up + writers waiting for readers to go away. + */ + native_cond_t no_active_readers; + /** Number of active readers. */ + unsigned int active_readers; + /** Number of writers waiting for readers to go away. */ + unsigned int writers_waiting_readers; + /** Indicates whether there is an active writer. */ + bool active_writer; + /** Thread holding wr-lock (for debug purposes only). */ + my_thread_t writer_thread; +}; + +#endif /* COMPONENTS_SERVICES_THR_RWLOCK_BITS_H */ |