summaryrefslogtreecommitdiff
path: root/sql/sql_class.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r--sql/sql_class.cc66
1 files changed, 58 insertions, 8 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index c10eedaadfb..c7e5f5e6dc2 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -683,7 +683,8 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
m_stmt_da(&main_da),
tdc_hash_pins(0),
xid_hash_pins(0),
- m_tmp_tables_locked(false)
+ m_tmp_tables_locked(false),
+ async_state()
#ifdef HAVE_REPLICATION
,
current_linfo(0),
@@ -4917,6 +4918,56 @@ void reset_thd(MYSQL_THD thd)
free_root(thd->mem_root, MYF(MY_KEEP_PREALLOC));
}
+/**
+ This function can be used by storage engine
+ to indicate a start of an async operation.
+
+ This asynchronous is such operation needs to be
+ finished before we write response to the client
+.
+ An example of this operation is Innodb's asynchronous
+ group commit. Server needs to wait for the end of it
+ before writing response to client, to provide durability
+ guarantees, in other words, server can't send OK packet
+ before modified data is durable in redo log.
+*/
+extern "C" MYSQL_THD thd_increment_pending_ops(void)
+{
+ THD *thd = current_thd;
+ if (!thd)
+ return NULL;
+ thd->async_state.inc_pending_ops();
+ return thd;
+}
+
+/**
+ This function can be used by plugin/engine to indicate
+ end of async operation (such as end of group commit
+ write flush)
+
+ @param thd THD
+*/
+extern "C" void thd_decrement_pending_ops(MYSQL_THD thd)
+{
+ DBUG_ASSERT(thd);
+ thd_async_state::enum_async_state state;
+ if (thd->async_state.dec_pending_ops(&state) == 0)
+ {
+ switch(state)
+ {
+ case thd_async_state::enum_async_state::SUSPENDED:
+ DBUG_ASSERT(thd->scheduler->thd_resume);
+ thd->scheduler->thd_resume(thd);
+ break;
+ case thd_async_state::enum_async_state::NONE:
+ break;
+ default:
+ DBUG_ASSERT(0);
+ }
+ }
+}
+
+
unsigned long long thd_get_query_id(const MYSQL_THD thd)
{
return((unsigned long long)thd->query_id);
@@ -5032,14 +5083,13 @@ extern "C" enum enum_server_command thd_current_command(MYSQL_THD thd)
return thd->get_command();
}
-
-extern "C" int thd_slave_thread(const MYSQL_THD thd)
+#ifdef HAVE_REPLICATION /* Working around MDEV-24622 */
+/** @return whether the current thread is for applying binlog in a replica */
+extern "C" int thd_is_slave(const MYSQL_THD thd)
{
- return(thd->slave_thread);
+ return thd && thd->slave_thread;
}
-
-
-
+#endif /* HAVE_REPLICATION */
/* Returns high resolution timestamp for the start
of the current query. */
@@ -5078,7 +5128,7 @@ thd_need_wait_reports(const MYSQL_THD thd)
}
/*
- Used by storage engines (currently TokuDB and InnoDB) to report that
+ Used by storage engines (currently InnoDB) to report that
one transaction THD is about to go to wait for a transactional lock held by
another transactions OTHER_THD.