Skip to content

Commit 9832482

Browse files
committed
Bug#31048451 RECOVERY FRAMEWORK IS UNABLE TO DETECT FAILURE OF RECOVERY JOBS
Problem ======= Recovery Framework in RAPID plugin issues 'ALTER TABLE <table-name> SECONDARY_LOAD' commands to automatically load tables. Framework uses MySQL service to issue these queries in local sessions. Specifically command_service_run_command() is called, and it's return value is checked to know if load successfully happened or not. Along with the return value, the error value set in thd variable of the session is also checked. Understanding is that return value does not account all runtime errors. Analysis ======== WL#13357 introduced a modification in the session service query execution method that clears THD's Diagnostic Area at the end. Query execution failures could not be detected anymore. Fix === Modificaion in the command_service_run_command function was rolled back. The X plugin was modified not to rely on the Diagnostic Area when generating connection message audit event on authentication error. RB: 24103 Reviewed-by: Georgi 'Joro' Kodinov <[email protected]> Reviewed-by: Łukasz Kotula <[email protected]>
1 parent d3d78c7 commit 9832482

16 files changed

+140
-270
lines changed

include/mysql/components/services/audit_api_connection_service.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,45 @@ DECLARE_METHOD(int, emit, (void *thd, mysql_event_connection_subclass_t type));
5757

5858
END_SERVICE_DEFINITION(mysql_audit_api_connection)
5959

60+
/**
61+
@ingroup group_components_services_inventory
62+
63+
A service to generate Audit API events of the connection class
64+
(MYSQL_AUDIT_CONNECTION_CLASS) with the explicitly specified error code
65+
value.
66+
67+
This service should ONLY be used if we cannot set the THD's Statement
68+
Diagnostic Area result code, which is passed along the audit notification
69+
chain. The preferred way of generating the event is to rely on THD's internal
70+
data as much as possible (mysql_audit_api_connection service)
71+
72+
The emit method generates the event in the synchronous way, causing
73+
all subscribers to receive it.
74+
75+
@sa @ref mysql_audit_api_connection_imp
76+
*/
77+
BEGIN_SERVICE_DEFINITION(mysql_audit_api_connection_with_error)
78+
79+
/**
80+
Method that emits event of the MYSQL_AUDIT_CONNECTION_CLASS class
81+
and the specified type with the explicitly specified error code value.
82+
83+
@sa mysql_event_connection_subclass_t
84+
85+
@param thd Session THD that generates connection event.
86+
@param type Connection event type.
87+
@param errcode Error code that replaces Statement Diagnostic Area result
88+
value, which is simply bypassed by calling this method.
89+
90+
@return Plugin that receives Audit API event can return event processing
91+
value. The code that generates the event can take custom action
92+
based on the returned value. 0 value is returned if no action is
93+
required on the event generation side.
94+
`*/
95+
DECLARE_METHOD(int, emit,
96+
(void *thd, mysql_event_connection_subclass_t type,
97+
int errcode));
98+
99+
END_SERVICE_DEFINITION(mysql_audit_api_connection_with_error)
100+
60101
#endif /* AUDIT_API_CONNECTION_H */

plugin/x/source_files.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ SET(xplugin_SRC
8282
src/services/service_registry_registration.cc
8383
src/services/service_sys_variables.cc
8484
src/services/service_audit_api_connection.cc
85-
src/services/service_runtime_error.cc
8685
src/services/services.cc
8786
src/services/service_udf_registration.cc
8887
src/xpl_plugin.cc

plugin/x/src/interface/service_audit_api_connection.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ class Service_audit_api_connection {
5252
*/
5353
virtual int emit(void *thd, mysql_event_connection_subclass_t type) = 0;
5454

55+
/*
56+
Generate audit event of the connection class.
57+
58+
@param[in] thd THD used for error reporting.
59+
@param[in] type Connection event subtype.
60+
@param[in] errcode Error code that replaces Diagnostic Area result code.
61+
62+
@return Value returned by the Audit API handling mechanism.
63+
*/
64+
virtual int emit_with_errorcode(void *thd,
65+
mysql_event_connection_subclass_t type,
66+
int errcode) = 0;
67+
5568
/*
5669
Check validity of the object.
5770

plugin/x/src/interface/service_runtime_error.h

Lines changed: 0 additions & 68 deletions
This file was deleted.

plugin/x/src/services/service_audit_api_connection.cc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,36 @@ Service_audit_api_connection::Service_audit_api_connection(
3333
m_audit_api =
3434
reinterpret_cast<SERVICE_TYPE_NO_CONST(mysql_audit_api_connection) *>(
3535
m_registry->acquire("mysql_audit_api_connection"));
36+
37+
if (m_audit_api == nullptr) return;
38+
39+
m_audit_api_error = reinterpret_cast<SERVICE_TYPE_NO_CONST(
40+
mysql_audit_api_connection_with_error) *>(
41+
m_registry->acquire("mysql_audit_api_connection_with_error"));
42+
43+
if (m_audit_api_error == nullptr) {
44+
m_registry->release(reinterpret_cast<my_h_service>(m_audit_api));
45+
m_audit_api = nullptr;
46+
}
3647
}
3748

3849
Service_audit_api_connection::~Service_audit_api_connection() {
3950
m_registry->release(reinterpret_cast<my_h_service>(m_audit_api));
51+
m_registry->release(reinterpret_cast<my_h_service>(m_audit_api_error));
4052
}
4153

4254
int Service_audit_api_connection::emit(void *thd,
4355
mysql_event_connection_subclass_t type) {
4456
return m_audit_api->emit(thd, type);
4557
}
4658

59+
int Service_audit_api_connection::emit_with_errorcode(
60+
void *thd, mysql_event_connection_subclass_t type, int errcode) {
61+
return m_audit_api_error->emit(thd, type, errcode);
62+
}
63+
4764
bool Service_audit_api_connection::is_valid() const {
48-
return nullptr != m_audit_api;
65+
return nullptr != m_audit_api && nullptr != m_audit_api_error;
4966
}
5067

5168
} // namespace xpl

plugin/x/src/services/service_audit_api_connection.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,23 @@ class Service_audit_api_connection
5050
/*
5151
Generate audit event of the connection class using the service.
5252
53-
@param[in] thd THD used for error reporting.
54-
@param[in] type Connection event subtype.
53+
@param[in] thd THD used for error reporting.
54+
@param[in] type Connection event subtype.
5555
5656
@return Value returned by the Audit API handling mechanism.
5757
*/
5858
int emit(void *thd, mysql_event_connection_subclass_t type) override;
59+
/*
60+
Generate audit event of the connection class using the service.
5961
62+
@param[in] thd THD used for error reporting.
63+
@param[in] type Connection event subtype.
64+
@param[in] errcode Error code.
65+
66+
@return Value returned by the Audit API handling mechanism.
67+
*/
68+
int emit_with_errorcode(void *thd, mysql_event_connection_subclass_t type,
69+
int errcode) override;
6070
/*
6171
Check validity of the object.
6272
@@ -74,6 +84,11 @@ class Service_audit_api_connection
7484
Audit API service pointer acquired during the object construction.
7585
*/
7686
SERVICE_TYPE_NO_CONST(mysql_audit_api_connection) * m_audit_api;
87+
/*
88+
Audit API service pointer acquired during the object construction.
89+
*/
90+
SERVICE_TYPE_NO_CONST(mysql_audit_api_connection_with_error) *
91+
m_audit_api_error;
7792
};
7893

7994
} // namespace xpl

plugin/x/src/services/service_runtime_error.cc

Lines changed: 0 additions & 48 deletions
This file was deleted.

plugin/x/src/services/service_runtime_error.h

Lines changed: 0 additions & 78 deletions
This file was deleted.

plugin/x/src/services/services.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2323
#include "plugin/x/src/services/services.h"
2424

2525
#include "plugin/x/src/services/service_audit_api_connection.h"
26-
#include "plugin/x/src/services/service_runtime_error.h"
2726
#include "plugin/x/src/services/service_sys_variables.h"
2827

2928
namespace xpl {
3029

3130
Services::Services() {
3231
m_system_variable_register.reset(new Service_sys_variables(&m_registry));
3332
m_audit_api.reset(new Service_audit_api_connection(&m_registry));
34-
m_runtime_error.reset(new Service_runtime_error(&m_registry));
3533
}
3634

3735
} // namespace xpl

plugin/x/src/services/services.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2626
#include <memory>
2727

2828
#include "plugin/x/src/interface/service_audit_api_connection.h"
29-
#include "plugin/x/src/interface/service_runtime_error.h"
3029
#include "plugin/x/src/interface/service_sys_variables.h"
3130
#include "plugin/x/src/services/service_registry.h"
3231

@@ -41,7 +40,6 @@ class Services {
4140
public:
4241
using Sys_variables_ptr = std::unique_ptr<iface::Service_sys_variables>;
4342
using Audit_api_ptr = std::unique_ptr<iface::Service_audit_api_connection>;
44-
using Runtime_error_ptr = std::unique_ptr<iface::Service_runtime_error>;
4543

4644
public:
4745
/*
@@ -53,8 +51,7 @@ class Services {
5351
Check, whether all services has been correctly acquired.
5452
*/
5553
bool is_valid() const {
56-
return m_system_variable_register->is_valid() && m_audit_api->is_valid() &&
57-
m_runtime_error->is_valid();
54+
return m_system_variable_register->is_valid() && m_audit_api->is_valid();
5855
}
5956

6057
/*
@@ -69,10 +66,6 @@ class Services {
6966
Audit API service pointer.
7067
*/
7168
Audit_api_ptr m_audit_api;
72-
/*
73-
Runtime error service pointer.
74-
*/
75-
Runtime_error_ptr m_runtime_error;
7669
};
7770

7871
} // namespace xpl

0 commit comments

Comments
 (0)