Skip to content

Commit

Permalink
Merge branch 'mysql-8.0' into mysql-trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
gkodinov committed Jan 13, 2022
2 parents 48202be + 8b7c326 commit 4581efd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
38 changes: 37 additions & 1 deletion components/test/table_access/test_table_access.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2020, 2021, Oracle and/or its affiliates.
/* Copyright (c) 2020, 2022, Oracle and/or its affiliates.
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,
Expand Down Expand Up @@ -31,6 +31,7 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <thread>

REQUIRES_SERVICE_PLACEHOLDER_AS(mysql_current_thread_reader, current_thd_srv);
REQUIRES_SERVICE_PLACEHOLDER_AS(udf_registration, udf_srv);
Expand Down Expand Up @@ -822,6 +823,40 @@ static char *test_table_access_driver(UDF_INIT *, UDF_ARGS *args, char *result,
return nullptr;
}

#define CONST_STR_AND_LEN(x) x, sizeof(x) - 1

/**
@param [out] status: true for failure, false otherwise
*/
static void thd_function(bool *ret) {
TA_table tb = nullptr;
Table_access ta = nullptr;
size_t ticket = 0;
bool txn_started = false;
*ret = true;

ta = ta_factory_srv->create(nullptr, 1);
if (!ta) goto cleanup;
ticket = ta_srv->add(ta, CONST_STR_AND_LEN("mysql"), CONST_STR_AND_LEN("db"),
TA_READ);
if (ta_srv->begin(ta)) goto cleanup;
txn_started = true;
tb = ta_srv->get(ta, ticket);
if (!tb) goto cleanup;

*ret = false;
cleanup:
if (txn_started) ta_srv->rollback(ta);
if (ta) ta_factory_srv->destroy(ta);
}

static bool test_native_thread() {
bool retval = true;
std::thread thd(thd_function, &retval);
thd.join();
return retval;
}

mysql_service_status_t test_table_access_init() {
if (udf_srv->udf_register(udf_name, Item_result::STRING_RESULT,
(Udf_func_any)test_table_access_driver, udf_init,
Expand All @@ -836,6 +871,7 @@ mysql_service_status_t test_table_access_init() {
*/
(void)test_math_insert_utf8mb3(nullptr);
(void)test_math_insert_utf8mb4(nullptr);
if (test_native_thread()) return 1;

return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion include/mysql/components/services/bits/table_access_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ DEFINE_SERVICE_HANDLE(TA_key);
Create a table access object.
@sa destroy_table_access_v1_t
@param thd The current session.
@param thd The current session. Pass a null ptr if running from a non-MySQLd
thread
@param count The maximum number of tables to access.
@note The table access service will create a child session
Expand Down
18 changes: 14 additions & 4 deletions sql/server_component/table_access_service.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2020, 2021, Oracle and/or its affiliates.
/* Copyright (c) 2020, 2022, Oracle and/or its affiliates.
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,
Expand Down Expand Up @@ -580,12 +580,20 @@ void TA_key_impl::key_copy(uchar *record) {

Table_access_impl::Table_access_impl(THD *thd, size_t count)
: m_current_count(0), m_max_count(count), m_write(false), m_in_tx(false) {
assert(thd != nullptr);
m_parent_thd = thd;

m_child_thd = new THD(true);

m_child_thd->copy_table_access_properties(m_parent_thd);
if (m_parent_thd)
m_child_thd->copy_table_access_properties(m_parent_thd);
else {
void *dummy_p = nullptr;
m_child_thd->thread_stack = (char *)&dummy_p;
m_child_thd->security_context()->assign_user(
STRING_WITH_LEN("table_access"));
m_child_thd->security_context()->skip_grants("", "");
my_thread_init();
}

m_child_thd->real_id = my_thread_self();
m_child_thd->set_new_thread_id();
Expand Down Expand Up @@ -616,7 +624,7 @@ Table_access_impl::~Table_access_impl() {
m_child_thd->release_resources();
m_child_thd->restore_globals();

m_parent_thd->store_globals();
if (m_parent_thd) m_parent_thd->store_globals();

Global_THD_manager::get_instance()->remove_thd(m_child_thd);

Expand All @@ -625,6 +633,8 @@ Table_access_impl::~Table_access_impl() {
delete[] m_table_array;
delete[] m_table_state_array;

if (!m_parent_thd) my_thread_end();

// FIXME : kill flag ?
// FIXME : nested THD status variables ?
}
Expand Down

0 comments on commit 4581efd

Please sign in to comment.