MySQL  8.0.19
Source Code Documentation
plugin_utils.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef PLUGIN_UTILS_INCLUDED
24 #define PLUGIN_UTILS_INCLUDED
25 
26 #include <errno.h>
28 #include <stddef.h>
29 #include <map>
30 #include <queue>
31 #include <string>
32 #include <vector>
33 
34 #include "my_dbug.h"
35 #include "my_systime.h"
37 
39 
40 void abort_plugin_process(const char *message);
41 
42 struct thread_state {
43  /**
44  * @enum thread_state_enum
45  * @brief Maintains thread status
46  */
48  THREAD_NONE = 0, /**< THREAD_NOT_CREATED */
49  THREAD_CREATED, /**< THREAD_CREATED */
50  THREAD_INIT, /**< THREAD_INIT */
51 
52  THREAD_RUNNING, /**< THREAD_RUNNING */
53 
54  THREAD_TERMINATED, /**< THREAD_EXIT */
55  THREAD_END /**< END OF ENUM */
56  };
57 
58  private:
60 
61  public:
63 
64  void set_running() { thread_state_var = thread_state_enum::THREAD_RUNNING; }
65 
66  void set_terminated() {
67  thread_state_var = thread_state_enum::THREAD_TERMINATED;
68  }
69 
70  void set_initialized() { thread_state_var = thread_state_enum::THREAD_INIT; }
71 
72  void set_created() { thread_state_var = thread_state_enum::THREAD_CREATED; }
73 
74  bool is_initialized() const {
75  return ((thread_state_var >= thread_state_enum::THREAD_INIT) &&
76  (thread_state_var < thread_state_enum::THREAD_TERMINATED));
77  }
78 
79  bool is_running() const {
80  return thread_state_var == thread_state_enum::THREAD_RUNNING;
81  }
82 
83  bool is_alive_not_running() const {
84  return thread_state_var < thread_state_enum::THREAD_RUNNING;
85  }
86 
87  bool is_thread_alive() const {
88  return ((thread_state_var >= thread_state_enum::THREAD_CREATED) &&
89  (thread_state_var < thread_state_enum::THREAD_TERMINATED));
90  }
91 
92  bool is_thread_dead() const { return !is_thread_alive(); }
93 };
94 
96  public:
99 
100  /**
101  This method instructs all local transactions to rollback when certification
102  is no longer possible.
103  */
105 
106  private:
107  /* The lock that disallows concurrent method executions */
109 };
110 
111 /**
112  @class Synchronized_queue_interface
113 
114  Interface that defines a queue protected against multi thread access.
115 
116  */
117 
118 template <typename T>
120  public:
122 
123  /**
124  Checks if the queue is empty
125  @return if is empty
126  @retval true empty
127  @retval false not empty
128  */
129  virtual bool empty() = 0;
130 
131  /**
132  Inserts an element in the queue.
133  Alerts any other thread lock on pop() or front()
134  @param value The value to insert
135 
136  @return false, operation always succeeded
137  */
138  virtual bool push(const T &value) = 0;
139 
140  /**
141  Fetches the front of the queue and removes it.
142  @note The method will block if the queue is empty until a element is pushed
143 
144  @param out The fetched reference.
145 
146  @return false, operation always succeeded
147  */
148  virtual bool pop(T *out) = 0;
149 
150  /**
151  Pops the front of the queue removing it.
152  @note The method will block if the queue is empty until a element is pushed
153 
154  @return true if method was aborted, false otherwise
155  */
156  virtual bool pop() = 0;
157 
158  /**
159  Fetches the front of the queue but does not remove it.
160  @note The method will block if the queue is empty until a element is pushed
161 
162  @param out The fetched reference.
163 
164  @return false, operation always succeeded
165  */
166  virtual bool front(T *out) = 0;
167 
168  /**
169  Checks the queue size
170  @return the size of the queue
171  */
172  virtual size_t size() = 0;
173 };
174 
175 template <typename T>
177  public:
181  }
182 
184 
185  bool empty() {
186  bool res = true;
188  res = queue.empty();
190 
191  return res;
192  }
193 
194  virtual bool push(const T &value) {
196  queue.push(value);
199 
200  return false;
201  }
202 
203  virtual bool pop(T *out) {
204  *out = NULL;
206  while (queue.empty())
207  mysql_cond_wait(&cond, &lock); /* purecov: inspected */
208  *out = queue.front();
209  queue.pop();
211 
212  return false;
213  }
214 
215  virtual bool pop() {
217  while (queue.empty())
218  mysql_cond_wait(&cond, &lock); /* purecov: inspected */
219  queue.pop();
221 
222  return false;
223  }
224 
225  virtual bool front(T *out) {
226  *out = NULL;
228  while (queue.empty()) mysql_cond_wait(&cond, &lock);
229  *out = queue.front();
231 
232  return false;
233  }
234 
235  size_t size() {
236  size_t qsize = 0;
238  qsize = queue.size();
240 
241  return qsize;
242  }
243 
244  protected:
247  std::queue<T> queue;
248 };
249 
250 /**
251  Abortable synchronized queue extends synchronized queue allowing to
252  abort methods waiting for elements on queue.
253 */
254 
255 template <typename T>
257  public:
259 
261 
262  /**
263  Inserts an element in the queue.
264  Alerts any other thread lock on pop() or front()
265  @note The method will not push if abort was executed.
266 
267  @param value The value to insert
268 
269  @return false, operation always succeeded
270  */
271 
272  bool push(const T &value) {
273  bool res = false;
274  mysql_mutex_lock(&this->lock);
275  if (m_abort) {
276  res = true;
277  } else {
278  this->queue.push(value);
279  mysql_cond_broadcast(&this->cond);
280  }
281 
282  mysql_mutex_unlock(&this->lock);
283  return res;
284  }
285 
286  /**
287  Fetches the front of the queue and removes it.
288  @note The method will block if the queue is empty until a element is pushed
289  or abort is executed
290 
291  @param out The fetched reference.
292 
293  @return true if method was aborted, false otherwise
294  */
295  bool pop(T *out) {
296  *out = nullptr;
297  mysql_mutex_lock(&this->lock);
298  while (this->queue.empty() && !m_abort)
299  mysql_cond_wait(&this->cond, &this->lock); /* purecov: inspected */
300 
301  if (!m_abort) {
302  *out = this->queue.front();
303  this->queue.pop();
304  }
305 
306  const bool result = m_abort;
307  mysql_mutex_unlock(&this->lock);
308  return result;
309  }
310 
311  /**
312  Pops the front of the queue removing it.
313  @note The method will block if the queue is empty until a element is pushed
314  or abort is executed
315 
316  @return false, operation always succeeded
317  */
318  bool pop() {
319  mysql_mutex_lock(&this->lock);
320  while (this->queue.empty() && !m_abort)
321  mysql_cond_wait(&this->cond, &this->lock);
322 
323  if (!m_abort) {
324  this->queue.pop();
325  }
326 
327  const bool result = m_abort;
328  mysql_mutex_unlock(&this->lock);
329  return result;
330  }
331 
332  /**
333  Fetches the front of the queue but does not remove it.
334  @note The method will block if the queue is empty until a element is pushed
335  or abort is executed
336 
337  @param out The fetched reference.
338 
339  @return true if method was aborted, false otherwise
340  */
341  bool front(T *out) {
342  *out = nullptr;
343  mysql_mutex_lock(&this->lock);
344  while (this->queue.empty() && !m_abort)
345  mysql_cond_wait(&this->cond, &this->lock);
346 
347  if (!m_abort) {
348  *out = this->queue.front();
349  }
350 
351  const bool result = m_abort;
352  mysql_mutex_unlock(&this->lock);
353  return result;
354  }
355 
356  /**
357  Remove all elements, abort current and future waits on retrieving elements
358  from queue.
359  */
360  void abort() {
361  mysql_mutex_lock(&this->lock);
362  while (this->queue.size()) {
363  T elem;
364  elem = this->queue.front();
365  this->queue.pop();
366  delete elem;
367  }
368  m_abort = true;
369  mysql_cond_broadcast(&this->cond);
370  mysql_mutex_unlock(&this->lock);
371  }
372 
373  private:
374  bool m_abort;
375 };
376 
377 /**
378  Synchronization auxiliary class that allows one or more threads
379  to wait on a given number of requirements.
380 
381  Usage:
382  CountDownLatch(count):
383  Create the latch with the number of requirements to wait.
384  wait():
385  Block until the number of requirements reaches zero.
386  countDown():
387  Decrease the number of requirements by one.
388 */
390  public:
391  /**
392  Create the latch with the number of requirements to wait.
393 
394  @param count The number of requirements to wait
395  */
399  }
400 
401  virtual ~CountDownLatch() {
404  }
405 
406  /**
407  Block until the number of requirements reaches zero.
408  */
409  void wait(ulong timeout = 0) {
411 
412  if (timeout > 0) {
413  ulong time_lapsed = 0;
414  struct timespec abstime;
415 
416  while (count > 0 && timeout > time_lapsed) {
417  set_timespec(&abstime, 1);
419  time_lapsed++;
420  }
421 
422  if (count > 0 && timeout == time_lapsed) {
423  error = true;
424  }
425  } else {
426  while (count > 0) mysql_cond_wait(&cond, &lock);
427  }
428 
430  }
431 
432  /**
433  Decrease the number of requirements by one.
434  */
435  void countDown() {
437  --count;
438  if (count == 0) mysql_cond_broadcast(&cond);
440  }
441 
442  /**
443  Get current number requirements.
444 
445  @return the number of requirements
446  */
448  uint res = 0;
450  res = count;
452  return res;
453  }
454 
455  /**
456  Set error flag, once this latch is release the waiter can check
457  if it was due to a error or due to correct termination.
458  */
459  void set_error() { error = true; }
460 
461  /**
462  Get latch release reason.
463 
464  @return true the latch was released due to a error
465  false the latch was released on correct termination
466  */
467  bool get_error() { return error; }
468 
469  private:
472  int count;
473  bool error;
474 };
475 
476 /**
477  Ticket register/wait auxiliary class.
478  Usage:
479  registerTicket(k):
480  create a ticket with key k with status ongoing.
481  releaseTicket(k):
482  set ticket with key k status to done.
483  waitTicket(k):
484  wait until ticket with key k status is changed to done.
485 */
486 template <typename K>
487 class Wait_ticket {
488  public:
492  }
493 
494  virtual ~Wait_ticket() {
495  clear();
498  }
499 
500  void clear() {
502  DBUG_ASSERT(false == blocked);
503  DBUG_ASSERT(false == waiting);
504 
505  for (typename std::map<K, CountDownLatch *>::iterator it = map.begin();
506  it != map.end(); ++it)
507  delete it->second; /* purecov: inspected */
508  map.clear();
510  }
511 
512  /**
513  Check if there are waiting tickets.
514  @return
515  @retval true empty
516  @retval false otherwise
517  */
518  bool empty() {
519  bool result = false;
520 
522  result = map.empty();
524 
525  return result;
526  }
527 
528  /**
529  Register ticker with status ongoing.
530 
531  @param key The key that identifies the ticket
532  @return
533  @retval 0 success
534  @retval !=0 key already exists, error on insert or it is blocked
535  */
536  int registerTicket(const K &key) {
537  int error = 0;
538 
540 
541  if (blocked) {
542  mysql_mutex_unlock(&lock); /* purecov: inspected */
543  return 1; /* purecov: inspected */
544  }
545 
546  typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
547  if (it != map.end()) {
548  mysql_mutex_unlock(&lock); /* purecov: inspected */
549  return 1; /* purecov: inspected */
550  }
551 
552  CountDownLatch *cdl = new CountDownLatch(1);
553  std::pair<typename std::map<K, CountDownLatch *>::iterator, bool> ret;
554  ret = map.insert(std::pair<K, CountDownLatch *>(key, cdl));
555  if (ret.second == false) {
556  error = 1; /* purecov: inspected */
557  delete cdl; /* purecov: inspected */
558  }
559 
561  return error;
562  }
563 
564  /**
565  Wait until ticket status is done.
566  @note The ticket is removed after the wait.
567 
568  @param key The key that identifies the ticket
569  @param timeout maximum time in seconds to wait
570  by default is 0, which means no timeout
571  @return
572  @retval 0 success
573  @retval !=0 key doesn't exist, or the Ticket is blocked
574  */
575  int waitTicket(const K &key, ulong timeout = 0) {
576  int error = 0;
577  CountDownLatch *cdl = NULL;
578 
580 
581  if (blocked) {
582  mysql_mutex_unlock(&lock); /* purecov: inspected */
583  return 1; /* purecov: inspected */
584  }
585 
586  typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
587  if (it == map.end())
588  error = 1;
589  else
590  cdl = it->second;
592 
593  if (cdl != NULL) {
594  cdl->wait(timeout);
595  error = cdl->get_error() ? 1 : 0;
596 
598  delete cdl;
599  map.erase(it);
600 
601  if (waiting) {
602  if (map.empty()) {
604  }
605  }
607  }
608 
609  return error;
610  }
611 
612  /**
613  Set ticket status to done.
614 
615  @param key The key that identifies the ticket
616  @param release_due_to_error Inform the thread waiting that the
617  release is due to a error
618  @return
619  @retval 0 success
620  @retval !=0 (key doesn't exist)
621  */
622  int releaseTicket(const K &key, bool release_due_to_error = false) {
623  int error = 0;
624 
626  typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
627  if (it == map.end())
628  error = 1;
629  else {
630  if (release_due_to_error) {
631  it->second->set_error();
632  }
633  it->second->countDown();
634  }
636 
637  return error;
638  }
639 
640  /**
641  Gets all the waiting keys.
642 
643  @param[out] key_list all the keys to return
644  */
645  void get_all_waiting_keys(std::vector<K> &key_list) {
647  for (typename std::map<K, CountDownLatch *>::iterator iter = map.begin();
648  iter != map.end(); ++iter) {
649  K key = iter->first;
650  key_list.push_back(key);
651  }
653  }
654 
655  /**
656  Blocks or unblocks the class from receiving waiting requests.
657 
658  @param[in] blocked_flag if the class should block or not
659  */
660  void set_blocked_status(bool blocked_flag) {
662  blocked = blocked_flag;
664  }
665 
666  int block_until_empty(int timeout) {
668  waiting = true;
669  while (!map.empty()) {
670  struct timespec abstime;
671  set_timespec(&abstime, 1);
672 #ifndef DBUG_OFF
673  int error =
674 #endif
676  DBUG_ASSERT(error == ETIMEDOUT || error == 0);
677  if (timeout >= 1) {
678  timeout = timeout - 1;
679  } else if (!map.empty()) {
680  // time out
681  waiting = false;
683  return 1;
684  }
685  }
686  waiting = false;
688  return 0;
689  }
690 
691  private:
694  std::map<K, CountDownLatch *> map;
695  bool blocked;
696  bool waiting;
697 };
698 
700  public:
703  DBUG_TRACE;
704 
705  DBUG_ASSERT(arg != NULL);
706 
710 
711  return;
712  }
713 
714  virtual ~Shared_writelock() {
717  }
718 
720  int res = 0;
722 
723  if (write_lock_in_use)
724  res = 1; /* purecov: inspected */
725  else {
727  write_lock_in_use = true;
728  }
729 
731  return res;
732  }
733 
736  DBUG_EXECUTE_IF("group_replication_continue_kill_pending_transaction", {
737  const char act[] = "now SIGNAL signal.gr_applier_early_failure";
738  DBUG_ASSERT(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
739  };);
740  while (write_lock_in_use == true)
742 
744  write_lock_in_use = true;
746  }
747 
751  write_lock_in_use = false;
754  }
755 
756  /**
757  Grab a read lock only if there is no write lock acquired.
758 
759  @return
760  @retval 0 read lock acquired
761  @retval !=0 there is a write lock acquired
762  */
764  int res = 0;
766 
767  if (write_lock_in_use)
768  res = 1;
769  else
771 
773  return res;
774  }
775 
777 
779 
780  private:
785 };
786 
788  public:
789  /**
790  Constructor.
791  Instatiate the mutex lock, mutex condition,
792  mutex and condition key.
793 
794  @param lock the mutex lock for access to class and condition variables
795  @param cond the condition variable calling thread will wait on
796  @param lock_key mutex instrumentation key
797  @param cond_key cond instrumentation key
798  */
800  PSI_mutex_key lock_key, PSI_cond_key cond_key)
801  : wait_lock(lock),
802  wait_cond(cond),
803  key_lock(lock_key),
804  key_cond(cond_key),
805  wait_status(false) {
806  DBUG_TRACE;
807 
810 
811  return;
812  }
813 
814  /**
815  Destructor.
816  Destroys the mutex and condition objects.
817  */
818  virtual ~Plugin_waitlock() {
821  }
822 
823  /**
824  Set condition to block or unblock the calling threads
825 
826  @param[in] status if the thread should be blocked or not
827  */
828  void set_wait_lock(bool status) {
832  }
833 
834  /**
835  Blocks the calling thread
836  */
837  void start_waitlock() {
838  DBUG_TRACE;
840  while (wait_status) {
841  DBUG_PRINT("sleep", ("Waiting in Plugin_waitlock::start_waitlock()"));
843  }
845  return;
846  }
847 
848  /**
849  Release the blocked thread
850  */
851  void end_wait_lock() {
853  wait_status = false;
856  }
857 
858  /**
859  Checks whether thread should be blocked
860 
861  @return
862  @retval true thread should be blocked
863  @retval false thread should not be blocked
864  */
865  bool is_waiting() {
867  bool result = wait_status;
869  return result;
870  }
871 
872  private:
873  /** the mutex lock for access to class and condition variables */
875  /** the condition variable calling thread will wait on */
877  /** mutex instrumentation key */
879  /** cond instrumentation key */
881  /** determine whether calling thread should be blocked or not */
883 };
884 
885 /**
886  Simple method to escape character on a string
887 
888  @note based on escape_string_for_mysql
889  @note the result is stored in the parameter string
890 
891  @param[in,out] string_to_escape the string to escape
892 */
893 void plugin_escape_string(std::string &string_to_escape);
894 
895 #endif /* PLUGIN_UTILS_INCLUDED */
Shared_writelock
Definition: plugin_utils.h:699
mysql_mutex_init
#define mysql_mutex_init(K, M, A)
Definition: mysql_mutex.h:34
Wait_ticket::releaseTicket
int releaseTicket(const K &key, bool release_due_to_error=false)
Set ticket status to done.
Definition: plugin_utils.h:622
Wait_ticket::waiting
bool waiting
Definition: plugin_utils.h:696
thread_state::THREAD_INIT
@ THREAD_INIT
THREAD_INIT.
Definition: plugin_utils.h:50
PSI_mutex_key
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:49
Shared_writelock::Shared_writelock
Shared_writelock(Checkable_rwlock *arg)
Definition: plugin_utils.h:701
DBUG_TRACE
DBUG_TRACE
Definition: do_ctype.cc:46
DBUG_PRINT
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:179
CountDownLatch::CountDownLatch
CountDownLatch(uint count)
Create the latch with the number of requirements to wait.
Definition: plugin_utils.h:396
Plugin_waitlock::key_cond
PSI_cond_key key_cond
cond instrumentation key
Definition: plugin_utils.h:880
CountDownLatch::~CountDownLatch
virtual ~CountDownLatch()
Definition: plugin_utils.h:401
Synchronized_queue_interface::size
virtual size_t size()=0
Checks the queue size.
Shared_writelock::~Shared_writelock
virtual ~Shared_writelock()
Definition: plugin_utils.h:714
mysql_mutex_lock
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:44
NULL
#define NULL
Definition: types.h:55
Checkable_rwlock::rdlock
void rdlock()
Acquire the read lock.
Definition: rpl_gtid.h:454
Shared_writelock::grab_read_lock
void grab_read_lock()
Definition: plugin_utils.h:776
thread_state::THREAD_CREATED
@ THREAD_CREATED
THREAD_CREATED.
Definition: plugin_utils.h:49
Synchronized_queue
Definition: plugin_utils.h:176
log_primary_member_details
void log_primary_member_details()
Definition: plugin_utils.cc:73
Wait_ticket::set_blocked_status
void set_blocked_status(bool blocked_flag)
Blocks or unblocks the class from receiving waiting requests.
Definition: plugin_utils.h:660
thread_state::THREAD_END
@ THREAD_END
END OF ENUM.
Definition: plugin_utils.h:55
Plugin_waitlock::start_waitlock
void start_waitlock()
Blocks the calling thread.
Definition: plugin_utils.h:837
Shared_writelock::write_lock_in_use
bool write_lock_in_use
Definition: plugin_utils.h:784
Plugin_waitlock::set_wait_lock
void set_wait_lock(bool status)
Set condition to block or unblock the calling threads.
Definition: plugin_utils.h:828
DBUG_EXECUTE_IF
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:169
Synchronized_queue::~Synchronized_queue
virtual ~Synchronized_queue()
Definition: plugin_utils.h:183
CountDownLatch
Synchronization auxiliary class that allows one or more threads to wait on a given number of requirem...
Definition: plugin_utils.h:389
thread_state::is_alive_not_running
bool is_alive_not_running() const
Definition: plugin_utils.h:83
Wait_ticket::blocked
bool blocked
Definition: plugin_utils.h:695
Shared_writelock::write_lock_protection
mysql_cond_t write_lock_protection
Definition: plugin_utils.h:783
my_dbug.h
key_GR_COND_wait_ticket
PSI_cond_key key_GR_COND_wait_ticket
Definition: plugin_psi.h:159
mysql_mutex_t
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
CountDownLatch::cond
mysql_cond_t cond
Definition: plugin_utils.h:471
thread_state::thread_state_var
thread_state_enum thread_state_var
Definition: plugin_utils.h:59
Synchronized_queue_interface::push
virtual bool push(const T &value)=0
Inserts an element in the queue.
result
Definition: result.h:33
plugin_escape_string
void plugin_escape_string(std::string &string_to_escape)
Simple method to escape character on a string.
Definition: plugin_utils.cc:99
Synchronized_queue_interface::pop
virtual bool pop()=0
Pops the front of the queue removing it.
value
const string value("\"Value\"")
Wait_ticket::lock
mysql_mutex_t lock
Definition: plugin_utils.h:692
Plugin_waitlock::key_lock
PSI_mutex_key key_lock
mutex instrumentation key
Definition: plugin_utils.h:878
Abortable_synchronized_queue::~Abortable_synchronized_queue
~Abortable_synchronized_queue()
Definition: plugin_utils.h:260
mysql_cond_broadcast
int(* mysql_cond_broadcast)(mysql_cond_t *that, const char *src_file, unsigned int src_line)
Definition: mysql_cond_service.h:51
Synchronized_queue::empty
bool empty()
Checks if the queue is empty.
Definition: plugin_utils.h:185
key
static const char * key
Definition: suite_stubs.c:14
Plugin_waitlock::wait_cond
mysql_cond_t * wait_cond
the condition variable calling thread will wait on
Definition: plugin_utils.h:876
CountDownLatch::set_error
void set_error()
Set error flag, once this latch is release the waiter can check if it was due to a error or due to co...
Definition: plugin_utils.h:459
Abortable_synchronized_queue::Abortable_synchronized_queue
Abortable_synchronized_queue()
Definition: plugin_utils.h:258
CountDownLatch::countDown
void countDown()
Decrease the number of requirements by one.
Definition: plugin_utils.h:435
key_GR_COND_count_down_latch
PSI_cond_key key_GR_COND_count_down_latch
Definition: plugin_psi.h:136
Wait_ticket::~Wait_ticket
virtual ~Wait_ticket()
Definition: plugin_utils.h:494
thread_state::thread_state_enum
thread_state_enum
Maintains thread status.
Definition: plugin_utils.h:47
CountDownLatch::count
int count
Definition: plugin_utils.h:472
Blocked_transaction_handler::~Blocked_transaction_handler
virtual ~Blocked_transaction_handler()
Definition: plugin_utils.cc:37
STRING_WITH_LEN
#define STRING_WITH_LEN(X)
Definition: m_string.h:306
Checkable_rwlock::wrlock
void wrlock()
Acquire the write lock.
Definition: rpl_gtid.h:463
key_GR_COND_write_lock_protection
PSI_cond_key key_GR_COND_write_lock_protection
Definition: plugin_psi.h:160
key_GR_LOCK_count_down_latch
PSI_mutex_key key_GR_LOCK_count_down_latch
Definition: plugin_psi.h:89
Plugin_waitlock::is_waiting
bool is_waiting()
Checks whether thread should be blocked.
Definition: plugin_utils.h:865
status
static STATUS status
Definition: mysql.cc:197
CountDownLatch::get_error
bool get_error()
Get latch release reason.
Definition: plugin_utils.h:467
plugin_psi.h
thread_state::is_thread_dead
bool is_thread_dead() const
Definition: plugin_utils.h:92
abstime
static time_t abstime(const rel_time_t exptime)
Convert the relative time to an absolute time (relative to EPOC ;) )
Definition: memcached.c:271
thread_state::THREAD_RUNNING
@ THREAD_RUNNING
THREAD_RUNNING.
Definition: plugin_utils.h:52
Synchronized_queue::lock
mysql_mutex_t lock
Definition: plugin_utils.h:245
mysql_cond_wait
#define mysql_cond_wait(C, M)
Definition: mysql_cond.h:43
key_GR_LOCK_synchronized_queue
PSI_mutex_key key_GR_LOCK_synchronized_queue
Definition: plugin_psi.h:120
PSI_cond_key
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:41
mysql_cond_timedwait
#define mysql_cond_timedwait(C, M, T)
Definition: mysql_cond.h:47
CountDownLatch::wait
void wait(ulong timeout=0)
Block until the number of requirements reaches zero.
Definition: plugin_utils.h:409
Shared_writelock::write_lock
mysql_mutex_t write_lock
Definition: plugin_utils.h:782
thread_state::set_running
void set_running()
Definition: plugin_utils.h:64
set_timespec
void set_timespec(struct timespec *abstime, Timeout_type sec)
Set the value of a timespec object to the current time plus a number of seconds using seconds.
Definition: my_systime.cc:82
Blocked_transaction_handler::unblock_waiting_transactions
void unblock_waiting_transactions()
This method instructs all local transactions to rollback when certification is no longer possible.
Definition: plugin_utils.cc:41
mysql_cond_init
#define mysql_cond_init(K, C)
Definition: mysql_cond.h:35
Synchronized_queue::Synchronized_queue
Synchronized_queue()
Definition: plugin_utils.h:178
uint
unsigned int uint
Definition: uca-dump.cc:29
Synchronized_queue::queue
std::queue< T > queue
Definition: plugin_utils.h:247
Synchronized_queue::pop
virtual bool pop(T *out)
Fetches the front of the queue and removes it.
Definition: plugin_utils.h:203
Wait_ticket::clear
void clear()
Definition: plugin_utils.h:500
Shared_writelock::release_write_lock
void release_write_lock()
Definition: plugin_utils.h:748
Blocked_transaction_handler::Blocked_transaction_handler
Blocked_transaction_handler()
Definition: plugin_utils.cc:32
Synchronized_queue_interface
Definition: plugin_utils.h:119
mysql_mutex_unlock
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:53
Wait_ticket::waitTicket
int waitTicket(const K &key, ulong timeout=0)
Wait until ticket status is done.
Definition: plugin_utils.h:575
Synchronized_queue::front
virtual bool front(T *out)
Fetches the front of the queue but does not remove it.
Definition: plugin_utils.h:225
key_GR_COND_synchronized_queue
PSI_cond_key key_GR_COND_synchronized_queue
Definition: plugin_psi.h:157
thread_state::thread_state
thread_state()
Definition: plugin_utils.h:62
thread_state
Definition: plugin_utils.h:42
Abortable_synchronized_queue::push
bool push(const T &value)
Inserts an element in the queue.
Definition: plugin_utils.h:272
Checkable_rwlock::unlock
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_gtid.h:474
Wait_ticket::cond
mysql_cond_t cond
Definition: plugin_utils.h:693
thread_state::is_thread_alive
bool is_thread_alive() const
Definition: plugin_utils.h:87
thread_state::set_created
void set_created()
Definition: plugin_utils.h:72
MY_MUTEX_INIT_FAST
#define MY_MUTEX_INIT_FAST
Definition: thr_mutex.h:66
Shared_writelock::try_grab_read_lock
int try_grab_read_lock()
Grab a read lock only if there is no write lock acquired.
Definition: plugin_utils.h:763
thread_state::set_initialized
void set_initialized()
Definition: plugin_utils.h:70
thread_state::set_terminated
void set_terminated()
Definition: plugin_utils.h:66
Synchronized_queue_interface::~Synchronized_queue_interface
virtual ~Synchronized_queue_interface()
Definition: plugin_utils.h:121
Wait_ticket::registerTicket
int registerTicket(const K &key)
Register ticker with status ongoing.
Definition: plugin_utils.h:536
thread_state::is_initialized
bool is_initialized() const
Definition: plugin_utils.h:74
Wait_ticket::block_until_empty
int block_until_empty(int timeout)
Definition: plugin_utils.h:666
Synchronized_queue_interface::front
virtual bool front(T *out)=0
Fetches the front of the queue but does not remove it.
Plugin_waitlock::wait_lock
mysql_mutex_t * wait_lock
the mutex lock for access to class and condition variables
Definition: plugin_utils.h:874
Plugin_waitlock::Plugin_waitlock
Plugin_waitlock(mysql_mutex_t *lock, mysql_cond_t *cond, PSI_mutex_key lock_key, PSI_cond_key cond_key)
Constructor.
Definition: plugin_utils.h:799
Synchronized_queue::push
virtual bool push(const T &value)
Inserts an element in the queue.
Definition: plugin_utils.h:194
DBUG_ASSERT
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
CountDownLatch::getCount
uint getCount()
Get current number requirements.
Definition: plugin_utils.h:447
Checkable_rwlock
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:430
key_GR_LOCK_wait_ticket
PSI_mutex_key key_GR_LOCK_wait_ticket
Definition: plugin_psi.h:125
Abortable_synchronized_queue
Abortable synchronized queue extends synchronized queue allowing to abort methods waiting for element...
Definition: plugin_utils.h:256
Shared_writelock::grab_write_lock
void grab_write_lock()
Definition: plugin_utils.h:734
Abortable_synchronized_queue::m_abort
bool m_abort
Definition: plugin_utils.h:374
mysql_cond_destroy
#define mysql_cond_destroy(C)
Definition: mysql_cond.h:39
Shared_writelock::try_grab_write_lock
int try_grab_write_lock()
Definition: plugin_utils.h:719
Wait_ticket::empty
bool empty()
Check if there are waiting tickets.
Definition: plugin_utils.h:518
Wait_ticket::get_all_waiting_keys
void get_all_waiting_keys(std::vector< K > &key_list)
Gets all the waiting keys.
Definition: plugin_utils.h:645
Synchronized_queue::cond
mysql_cond_t cond
Definition: plugin_utils.h:246
key_GR_LOCK_write_lock_protection
PSI_mutex_key key_GR_LOCK_write_lock_protection
Definition: plugin_psi.h:126
Synchronized_queue::size
size_t size()
Checks the queue size.
Definition: plugin_utils.h:235
Blocked_transaction_handler
Definition: plugin_utils.h:95
Wait_ticket::Wait_ticket
Wait_ticket()
Definition: plugin_utils.h:489
ulong
unsigned long ulong
Definition: my_inttypes.h:48
Shared_writelock::shared_write_lock
Checkable_rwlock * shared_write_lock
Definition: plugin_utils.h:781
thread_state::THREAD_NONE
@ THREAD_NONE
THREAD_NOT_CREATED.
Definition: plugin_utils.h:48
CountDownLatch::lock
mysql_mutex_t lock
Definition: plugin_utils.h:470
Plugin_waitlock::wait_status
bool wait_status
determine whether calling thread should be blocked or not
Definition: plugin_utils.h:882
Abortable_synchronized_queue::pop
bool pop()
Pops the front of the queue removing it.
Definition: plugin_utils.h:318
mysql_cond_t
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
Wait_ticket
Ticket register/wait auxiliary class.
Definition: plugin_utils.h:487
mysql_mutex_destroy
#define mysql_mutex_destroy(M)
Definition: mysql_mutex.h:39
Abortable_synchronized_queue::abort
void abort()
Remove all elements, abort current and future waits on retrieving elements from queue.
Definition: plugin_utils.h:360
privilege_status::error
@ error
Shared_writelock::release_read_lock
void release_read_lock()
Definition: plugin_utils.h:778
Synchronized_queue::pop
virtual bool pop()
Pops the front of the queue removing it.
Definition: plugin_utils.h:215
ETIMEDOUT
#define ETIMEDOUT
Definition: my_thread.h:47
Plugin_waitlock
Definition: plugin_utils.h:787
result
struct result result
Definition: result.h:37
my_systime.h
CountDownLatch::error
bool error
Definition: plugin_utils.h:473
Abortable_synchronized_queue::pop
bool pop(T *out)
Fetches the front of the queue and removes it.
Definition: plugin_utils.h:295
current_thd
thread_local THD * current_thd
Definition: current_thd.cc:25
Blocked_transaction_handler::unblocking_process_lock
mysql_mutex_t unblocking_process_lock
Definition: plugin_utils.h:108
Wait_ticket::map
std::map< K, CountDownLatch * > map
Definition: plugin_utils.h:694
Abortable_synchronized_queue::front
bool front(T *out)
Fetches the front of the queue but does not remove it.
Definition: plugin_utils.h:341
Synchronized_queue_interface::empty
virtual bool empty()=0
Checks if the queue is empty.
abort_plugin_process
void abort_plugin_process(const char *message)
Definition: plugin_utils.cc:91
thread_state::THREAD_TERMINATED
@ THREAD_TERMINATED
THREAD_EXIT.
Definition: plugin_utils.h:54
thread_state::is_running
bool is_running() const
Definition: plugin_utils.h:79
Plugin_waitlock::end_wait_lock
void end_wait_lock()
Release the blocked thread.
Definition: plugin_utils.h:851
group_replication_priv.h
Plugin_waitlock::~Plugin_waitlock
virtual ~Plugin_waitlock()
Destructor.
Definition: plugin_utils.h:818
false
#define false
Definition: config_static.h:43