MySQL 8.4.2
Source Code Documentation
plugin_utils.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2024, Oracle and/or its affiliates.
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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef PLUGIN_UTILS_INCLUDED
25#define PLUGIN_UTILS_INCLUDED
26
27#include <errno.h>
29#include <stddef.h>
30#include <algorithm>
31#include <chrono>
32#include <map>
33#include <queue>
34#include <random>
35#include <string>
36#include <vector>
37
38#include "my_dbug.h"
39#include "my_systime.h"
42#include "string_with_len.h"
43
45
46void abort_plugin_process(const char *message);
47
49 /**
50 * @enum thread_state_enum
51 * @brief Maintains thread status
52 */
54 THREAD_NONE = 0, /**< THREAD_NOT_CREATED */
55 THREAD_CREATED, /**< THREAD_CREATED */
56 THREAD_INIT, /**< THREAD_INIT */
57
58 THREAD_RUNNING, /**< THREAD_RUNNING */
59
60 THREAD_TERMINATED, /**< THREAD_EXIT */
61 THREAD_END /**< END OF ENUM */
62 };
63
64 private:
66
67 public:
69
70 void set_running() { thread_state_var = thread_state_enum::THREAD_RUNNING; }
71
73 thread_state_var = thread_state_enum::THREAD_TERMINATED;
74 }
75
76 void set_initialized() { thread_state_var = thread_state_enum::THREAD_INIT; }
77
78 void set_created() { thread_state_var = thread_state_enum::THREAD_CREATED; }
79
80 bool is_initialized() const {
81 return ((thread_state_var >= thread_state_enum::THREAD_INIT) &&
82 (thread_state_var < thread_state_enum::THREAD_TERMINATED));
83 }
84
85 bool is_running() const {
86 return thread_state_var == thread_state_enum::THREAD_RUNNING;
87 }
88
89 bool is_alive_not_running() const {
90 return thread_state_var < thread_state_enum::THREAD_RUNNING;
91 }
92
93 bool is_thread_alive() const {
94 return ((thread_state_var >= thread_state_enum::THREAD_CREATED) &&
95 (thread_state_var < thread_state_enum::THREAD_TERMINATED));
96 }
97
98 bool is_thread_dead() const { return !is_thread_alive(); }
99};
100
102 public:
105
106 /**
107 This method instructs all local transactions to rollback when certification
108 is no longer possible.
109 */
111
112 private:
113 /* The lock that disallows concurrent method executions */
115};
116
117/**
118 @class Synchronized_queue_interface
119
120 Interface that defines a queue protected against multi thread access.
121
122 */
123
124template <typename T>
126 public:
127 virtual ~Synchronized_queue_interface() = default;
128
129 /**
130 Checks if the queue is empty
131 @return if is empty
132 @retval true empty
133 @retval false not empty
134 */
135 virtual bool empty() = 0;
136
137 /**
138 Inserts an element in the queue.
139 Alerts any other thread lock on pop() or front()
140 @param value The value to insert
141
142 @return false, operation always succeeded
143 */
144 virtual bool push(const T &value) = 0;
145
146 /**
147 Fetches the front of the queue and removes it.
148 @note The method will block if the queue is empty until a element is pushed
149
150 @param out The fetched reference.
151
152 @return false, operation always succeeded
153 */
154 virtual bool pop(T *out) = 0;
155
156 /**
157 Pops the front of the queue removing it.
158 @note The method will block if the queue is empty until a element is pushed
159
160 @return true if method was aborted, false otherwise
161 */
162 virtual bool pop() = 0;
163
164 /**
165 Fetches the front of the queue but does not remove it.
166 @note The method will block if the queue is empty until a element is pushed
167
168 @param out The fetched reference.
169
170 @return false, operation always succeeded
171 */
172 virtual bool front(T *out) = 0;
173
174 /**
175 Checks the queue size
176 @return the size of the queue
177 */
178 virtual size_t size() = 0;
179};
180
181template <typename T>
183 public:
187 }
188
190
191 bool empty() override {
192 bool res = true;
194 res = queue.empty();
196
197 return res;
198 }
199
200 bool push(const T &value) override {
202 queue.push(value);
205
206 return false;
207 }
208
209 bool pop(T *out) override {
210 *out = nullptr;
212 while (queue.empty())
213 mysql_cond_wait(&cond, &lock); /* purecov: inspected */
214 *out = queue.front();
215 queue.pop();
217
218 return false;
219 }
220
221 bool pop() override {
223 while (queue.empty())
224 mysql_cond_wait(&cond, &lock); /* purecov: inspected */
225 queue.pop();
227
228 return false;
229 }
230
231 bool front(T *out) override {
232 *out = nullptr;
234 while (queue.empty()) mysql_cond_wait(&cond, &lock);
235 *out = queue.front();
237
238 return false;
239 }
240
241 size_t size() override {
242 size_t qsize = 0;
244 qsize = queue.size();
246
247 return qsize;
248 }
249
250 protected:
253 std::queue<T, std::list<T, Malloc_allocator<T>>> queue;
254};
255
256/**
257 Abortable synchronized queue extends synchronized queue allowing to
258 abort methods waiting for elements on queue.
259*/
260
261template <typename T>
263 public:
265 : Synchronized_queue<T>(key), m_abort(false) {}
266
267 ~Abortable_synchronized_queue() override = default;
268
269 /**
270 Inserts an element in the queue.
271 Alerts any other thread lock on pop() or front()
272 @note The method will not push if abort was executed.
273
274 @param value The value to insert
275
276 @return false, operation always succeeded
277 */
278
279 bool push(const T &value) override {
280 bool res = false;
281 mysql_mutex_lock(&this->lock);
282 if (m_abort) {
283 res = true;
284 } else {
285 this->queue.push(value);
287 }
288
289 mysql_mutex_unlock(&this->lock);
290 return res;
291 }
292
293 /**
294 Fetches the front of the queue and removes it.
295 @note The method will block if the queue is empty until a element is pushed
296 or abort is executed
297
298 @param out The fetched reference.
299
300 @return true if method was aborted, false otherwise
301 */
302 bool pop(T *out) override {
303 *out = nullptr;
304 mysql_mutex_lock(&this->lock);
305 while (this->queue.empty() && !m_abort)
306 mysql_cond_wait(&this->cond, &this->lock); /* purecov: inspected */
307
308 if (!m_abort) {
309 *out = this->queue.front();
310 this->queue.pop();
311 }
312
313 const bool result = m_abort;
314 mysql_mutex_unlock(&this->lock);
315 return result;
316 }
317
318 /**
319 Pops the front of the queue removing it.
320 @note The method will block if the queue is empty until a element is pushed
321 or abort is executed
322
323 @return false, operation always succeeded
324 */
325 bool pop() override {
326 mysql_mutex_lock(&this->lock);
327 while (this->queue.empty() && !m_abort)
328 mysql_cond_wait(&this->cond, &this->lock);
329
330 if (!m_abort) {
331 this->queue.pop();
332 }
333
334 const bool result = m_abort;
335 mysql_mutex_unlock(&this->lock);
336 return result;
337 }
338
339 /**
340 Fetches the front of the queue but does not remove it.
341 @note The method will block if the queue is empty until a element is pushed
342 or abort is executed
343
344 @param out The fetched reference.
345
346 @return true if method was aborted, false otherwise
347 */
348 bool front(T *out) override {
349 *out = nullptr;
350 mysql_mutex_lock(&this->lock);
351 while (this->queue.empty() && !m_abort)
352 mysql_cond_wait(&this->cond, &this->lock);
353
354 if (!m_abort) {
355 *out = this->queue.front();
356 }
357
358 const bool result = m_abort;
359 mysql_mutex_unlock(&this->lock);
360 return result;
361 }
362
363 /**
364 Remove all elements, abort current and future waits on retrieving elements
365 from queue.
366
367 @param delete_elements When true, apart from emptying the queue, it also
368 delete each element.
369 When false, the delete (memory release) responsibility
370 belongs to the `push()` caller.
371 */
372 void abort(bool delete_elements) {
373 mysql_mutex_lock(&this->lock);
374 while (this->queue.size()) {
375 T elem;
376 elem = this->queue.front();
377 this->queue.pop();
378 if (delete_elements) {
379 delete elem;
380 }
381 }
382 m_abort = true;
384 mysql_mutex_unlock(&this->lock);
385 }
386
387 private:
389};
390
391/**
392 Synchronization auxiliary class that allows one or more threads
393 to wait on a given number of requirements.
394
395 Usage:
396 CountDownLatch(count):
397 Create the latch with the number of requirements to wait.
398 wait():
399 Block until the number of requirements reaches zero.
400 countDown():
401 Decrease the number of requirements by one.
402*/
404 public:
405 /**
406 Create the latch with the number of requirements to wait.
407
408 @param count The number of requirements to wait
409 */
413 }
414
415 virtual ~CountDownLatch() {
418 }
419
420 /**
421 Block until the number of requirements reaches zero.
422 */
423 void wait(ulong timeout = 0) {
425
426 if (timeout > 0) {
427 ulong time_lapsed = 0;
428 struct timespec abstime;
429
430 while (count > 0 && timeout > time_lapsed) {
431 set_timespec(&abstime, 1);
432 mysql_cond_timedwait(&cond, &lock, &abstime);
433 time_lapsed++;
434 }
435
436 if (count > 0 && timeout == time_lapsed) {
437 error = true;
438 }
439 } else {
440 while (count > 0) mysql_cond_wait(&cond, &lock);
441 }
442
444 }
445
446 /**
447 Decrease the number of requirements by one.
448 */
449 void countDown() {
451 --count;
452 if (count == 0) mysql_cond_broadcast(&cond);
454 }
455
456 /**
457 Get current number requirements.
458
459 @return the number of requirements
460 */
461 uint getCount() {
462 uint res = 0;
464 res = count;
466 return res;
467 }
468
469 /**
470 Set error flag, once this latch is release the waiter can check
471 if it was due to a error or due to correct termination.
472 */
473 void set_error() { error = true; }
474
475 /**
476 Get latch release reason.
477
478 @return true the latch was released due to a error
479 false the latch was released on correct termination
480 */
481 bool get_error() { return error; }
482
483 private:
486 int count;
487 bool error;
488};
489
490/**
491 Ticket register/wait auxiliary class.
492 Usage:
493 registerTicket(k):
494 create a ticket with key k with status ongoing.
495 releaseTicket(k):
496 set ticket with key k status to done.
497 waitTicket(k):
498 wait until ticket with key k status is changed to done.
499*/
500template <typename K>
502 public:
503 Wait_ticket() : blocked(false), waiting(false) {
506 }
507
508 virtual ~Wait_ticket() {
509 clear();
512 }
513
514 void clear() {
516 assert(false == blocked);
517 assert(false == waiting);
518
519 for (typename std::map<K, CountDownLatch *>::iterator it = map.begin();
520 it != map.end(); ++it)
521 delete it->second; /* purecov: inspected */
522 map.clear();
524 }
525
526 /**
527 Check if there are waiting tickets.
528
529 @retval true empty
530 @retval false otherwise
531 */
532 bool empty() {
533 bool result = false;
534
536 result = map.empty();
538
539 return result;
540 }
541
542 /**
543 Register ticker with status ongoing.
544
545 @param key The key that identifies the ticket
546 @retval 0 success
547 @retval !=0 key already exists, error on insert or it is blocked
548 */
549 int registerTicket(const K &key) {
550 int error = 0;
551
553
554 if (blocked) {
555 mysql_mutex_unlock(&lock); /* purecov: inspected */
556 return 1; /* purecov: inspected */
557 }
558
559 typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
560 if (it != map.end()) {
561 mysql_mutex_unlock(&lock); /* purecov: inspected */
562 return 1; /* purecov: inspected */
563 }
564
565 CountDownLatch *cdl = new CountDownLatch(1);
566 std::pair<typename std::map<K, CountDownLatch *>::iterator, bool> ret;
567 ret = map.insert(std::pair<K, CountDownLatch *>(key, cdl));
568 if (ret.second == false) {
569 error = 1; /* purecov: inspected */
570 delete cdl; /* purecov: inspected */
571 }
572
574 return error;
575 }
576
577 /**
578 Wait until ticket status is done.
579 @note The ticket is removed after the wait.
580
581 @param key The key that identifies the ticket
582 @param timeout maximum time in seconds to wait
583 by default is 0, which means no timeout
584 @retval 0 success
585 @retval !=0 key doesn't exist, or the Ticket is blocked
586 */
587 int waitTicket(const K &key, ulong timeout = 0) {
588 int error = 0;
589 CountDownLatch *cdl = nullptr;
590
592
593 if (blocked) {
594 mysql_mutex_unlock(&lock); /* purecov: inspected */
595 return 1; /* purecov: inspected */
596 }
597
598 typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
599 if (it == map.end())
600 error = 1;
601 else
602 cdl = it->second;
604
605 if (cdl != nullptr) {
606 cdl->wait(timeout);
607 error = cdl->get_error() ? 1 : 0;
608
610 delete cdl;
611 map.erase(it);
612
613 if (waiting) {
614 if (map.empty()) {
616 }
617 }
619 }
620
621 return error;
622 }
623
624 /**
625 Set ticket status to done.
626
627 @param key The key that identifies the ticket
628 @param release_due_to_error Inform the thread waiting that the
629 release is due to a error
630 @retval 0 success
631 @retval !=0 (key doesn't exist)
632 */
633 int releaseTicket(const K &key, bool release_due_to_error = false) {
634 int error = 0;
635
637 typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
638 if (it == map.end())
639 error = 1;
640 else {
641 if (release_due_to_error) {
642 it->second->set_error();
643 }
644 it->second->countDown();
645 }
647
648 return error;
649 }
650
651 /**
652 Gets all the waiting keys.
653
654 @param[out] key_list all the keys to return
655 */
656 void get_all_waiting_keys(std::vector<K> &key_list) {
658 for (typename std::map<K, CountDownLatch *>::iterator iter = map.begin();
659 iter != map.end(); ++iter) {
660 K key = iter->first;
661 key_list.push_back(key);
662 }
664 }
665
666 /**
667 Blocks or unblocks the class from receiving waiting requests.
668
669 @param[in] blocked_flag if the class should block or not
670 */
671 void set_blocked_status(bool blocked_flag) {
673 blocked = blocked_flag;
675 }
676
679 waiting = true;
680 while (!map.empty()) {
681 struct timespec abstime;
682 set_timespec(&abstime, 1);
683#ifndef NDEBUG
684 int error =
685#endif
686 mysql_cond_timedwait(&cond, &lock, &abstime);
687 assert(error == ETIMEDOUT || error == 0);
688 if (timeout >= 1) {
689 timeout = timeout - 1;
690 } else if (!map.empty()) {
691 // time out
692 waiting = false;
694 return 1;
695 }
696 }
697 waiting = false;
699 return 0;
700 }
701
702 private:
705 std::map<K, CountDownLatch *> map;
708};
709
711 public:
713 : shared_write_lock(arg), write_lock_in_use(false) {
715
716 assert(arg != nullptr);
717
721
722 return;
723 }
724
728 }
729
731 int res = 0;
733
735 res = 1; /* purecov: inspected */
736 else {
738 write_lock_in_use = true;
739 }
740
742 return res;
743 }
744
747 DBUG_EXECUTE_IF("group_replication_continue_kill_pending_transaction", {
748 const char act[] = "now SIGNAL signal.gr_applier_early_failure";
749 assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
750 };);
751 while (write_lock_in_use == true)
753
755 write_lock_in_use = true;
757 }
758
762 write_lock_in_use = false;
765 }
766
767 /**
768 Grab a read lock only if there is no write lock acquired.
769
770 @retval 0 read lock acquired
771 @retval !=0 there is a write lock acquired
772 */
774 int res = 0;
776
778 res = 1;
779 else
781
783 return res;
784 }
785
787
789
790 private:
795};
796
798 public:
799 /**
800 Constructor.
801 Instantiate the mutex lock, mutex condition,
802 mutex and condition key.
803
804 @param lock the mutex lock for access to class and condition variables
805 @param cond the condition variable calling thread will wait on
806 @param lock_key mutex instrumentation key
807 @param cond_key cond instrumentation key
808 */
810 PSI_mutex_key lock_key, PSI_cond_key cond_key)
811 : wait_lock(lock),
812 wait_cond(cond),
813 key_lock(lock_key),
814 key_cond(cond_key),
815 wait_status(false) {
817
820
821 return;
822 }
823
824 /**
825 Destructor.
826 Destroys the mutex and condition objects.
827 */
831 }
832
833 /**
834 Set condition to block or unblock the calling threads
835
836 @param[in] status if the thread should be blocked or not
837 */
842 }
843
844 /**
845 Blocks the calling thread
846 */
850 while (wait_status) {
851 DBUG_PRINT("sleep", ("Waiting in Plugin_waitlock::start_waitlock()"));
853 }
855 return;
856 }
857
858 /**
859 Release the blocked thread
860 */
863 wait_status = false;
866 }
867
868 /**
869 Checks whether thread should be blocked
870
871 @retval true thread should be blocked
872 @retval false thread should not be blocked
873 */
874 bool is_waiting() {
876 bool result = wait_status;
878 return result;
879 }
880
881 private:
882 /** the mutex lock for access to class and condition variables */
884 /** the condition variable calling thread will wait on */
886 /** mutex instrumentation key */
888 /** cond instrumentation key */
890 /** determine whether calling thread should be blocked or not */
892};
893
894/**
895 Simple method to escape character on a string
896
897 @note based on escape_string_for_mysql
898 @note the result is stored in the parameter string
899
900 @param[in,out] string_to_escape the string to escape
901*/
902void plugin_escape_string(std::string &string_to_escape);
903
904/**
905 Rearranges the given vector elements randomly.
906 @param[in,out] v the vector to shuffle
907*/
908template <typename T>
910 auto seed{std::chrono::system_clock::now().time_since_epoch().count()};
911 std::shuffle(v->begin(), v->end(),
912 std::default_random_engine(
913 static_cast<std::default_random_engine::result_type>(seed)));
914}
915
916#endif /* PLUGIN_UTILS_INCLUDED */
Abortable synchronized queue extends synchronized queue allowing to abort methods waiting for element...
Definition: plugin_utils.h:262
void abort(bool delete_elements)
Remove all elements, abort current and future waits on retrieving elements from queue.
Definition: plugin_utils.h:372
bool pop() override
Pops the front of the queue removing it.
Definition: plugin_utils.h:325
bool push(const T &value) override
Inserts an element in the queue.
Definition: plugin_utils.h:279
bool m_abort
Definition: plugin_utils.h:388
bool front(T *out) override
Fetches the front of the queue but does not remove it.
Definition: plugin_utils.h:348
Abortable_synchronized_queue(PSI_memory_key key)
Definition: plugin_utils.h:264
bool pop(T *out) override
Fetches the front of the queue and removes it.
Definition: plugin_utils.h:302
~Abortable_synchronized_queue() override=default
Definition: plugin_utils.h:101
mysql_mutex_t unblocking_process_lock
Definition: plugin_utils.h:114
Blocked_transaction_handler()
Definition: plugin_utils.cc:33
virtual ~Blocked_transaction_handler()
Definition: plugin_utils.cc:38
void unblock_waiting_transactions()
This method instructs all local transactions to rollback when certification is no longer possible.
Definition: plugin_utils.cc:42
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:324
void rdlock()
Acquire the read lock.
Definition: rpl_gtid.h:485
void wrlock()
Acquire the write lock.
Definition: rpl_gtid.h:494
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_gtid.h:505
Synchronization auxiliary class that allows one or more threads to wait on a given number of requirem...
Definition: plugin_utils.h:403
uint getCount()
Get current number requirements.
Definition: plugin_utils.h:461
void wait(ulong timeout=0)
Block until the number of requirements reaches zero.
Definition: plugin_utils.h:423
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:473
mysql_cond_t cond
Definition: plugin_utils.h:485
void countDown()
Decrease the number of requirements by one.
Definition: plugin_utils.h:449
virtual ~CountDownLatch()
Definition: plugin_utils.h:415
int count
Definition: plugin_utils.h:486
bool error
Definition: plugin_utils.h:487
mysql_mutex_t lock
Definition: plugin_utils.h:484
bool get_error()
Get latch release reason.
Definition: plugin_utils.h:481
CountDownLatch(uint count)
Create the latch with the number of requirements to wait.
Definition: plugin_utils.h:410
Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
Definition: malloc_allocator.h:63
Definition: plugin_utils.h:797
bool is_waiting()
Checks whether thread should be blocked.
Definition: plugin_utils.h:874
PSI_cond_key key_cond
cond instrumentation key
Definition: plugin_utils.h:889
PSI_mutex_key key_lock
mutex instrumentation key
Definition: plugin_utils.h:887
bool wait_status
determine whether calling thread should be blocked or not
Definition: plugin_utils.h:891
void start_waitlock()
Blocks the calling thread.
Definition: plugin_utils.h:847
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:809
void set_wait_lock(bool status)
Set condition to block or unblock the calling threads.
Definition: plugin_utils.h:838
void end_wait_lock()
Release the blocked thread.
Definition: plugin_utils.h:861
virtual ~Plugin_waitlock()
Destructor.
Definition: plugin_utils.h:828
mysql_mutex_t * wait_lock
the mutex lock for access to class and condition variables
Definition: plugin_utils.h:883
mysql_cond_t * wait_cond
the condition variable calling thread will wait on
Definition: plugin_utils.h:885
Definition: plugin_utils.h:710
Shared_writelock(Checkable_rwlock *arg)
Definition: plugin_utils.h:712
mysql_mutex_t write_lock
Definition: plugin_utils.h:792
void release_read_lock()
Definition: plugin_utils.h:788
virtual ~Shared_writelock()
Definition: plugin_utils.h:725
Checkable_rwlock * shared_write_lock
Definition: plugin_utils.h:791
bool write_lock_in_use
Definition: plugin_utils.h:794
void release_write_lock()
Definition: plugin_utils.h:759
void grab_read_lock()
Definition: plugin_utils.h:786
void grab_write_lock()
Definition: plugin_utils.h:745
mysql_cond_t write_lock_protection
Definition: plugin_utils.h:793
int try_grab_write_lock()
Definition: plugin_utils.h:730
int try_grab_read_lock()
Grab a read lock only if there is no write lock acquired.
Definition: plugin_utils.h:773
Interface that defines a queue protected against multi thread access.
Definition: plugin_utils.h:125
virtual size_t size()=0
Checks the queue size.
virtual bool pop(T *out)=0
Fetches the front of the queue and removes it.
virtual bool front(T *out)=0
Fetches the front of the queue but does not remove it.
virtual bool pop()=0
Pops the front of the queue removing it.
virtual ~Synchronized_queue_interface()=default
virtual bool push(const T &value)=0
Inserts an element in the queue.
virtual bool empty()=0
Checks if the queue is empty.
Definition: plugin_utils.h:182
bool front(T *out) override
Fetches the front of the queue but does not remove it.
Definition: plugin_utils.h:231
bool pop() override
Pops the front of the queue removing it.
Definition: plugin_utils.h:221
Synchronized_queue(PSI_memory_key key)
Definition: plugin_utils.h:184
size_t size() override
Checks the queue size.
Definition: plugin_utils.h:241
bool pop(T *out) override
Fetches the front of the queue and removes it.
Definition: plugin_utils.h:209
bool empty() override
Checks if the queue is empty.
Definition: plugin_utils.h:191
mysql_cond_t cond
Definition: plugin_utils.h:252
std::queue< T, std::list< T, Malloc_allocator< T > > > queue
Definition: plugin_utils.h:253
bool push(const T &value) override
Inserts an element in the queue.
Definition: plugin_utils.h:200
~Synchronized_queue() override
Definition: plugin_utils.h:189
mysql_mutex_t lock
Definition: plugin_utils.h:251
Ticket register/wait auxiliary class.
Definition: plugin_utils.h:501
void clear()
Definition: plugin_utils.h:514
int waitTicket(const K &key, ulong timeout=0)
Wait until ticket status is done.
Definition: plugin_utils.h:587
bool empty()
Check if there are waiting tickets.
Definition: plugin_utils.h:532
Wait_ticket()
Definition: plugin_utils.h:503
void set_blocked_status(bool blocked_flag)
Blocks or unblocks the class from receiving waiting requests.
Definition: plugin_utils.h:671
int registerTicket(const K &key)
Register ticker with status ongoing.
Definition: plugin_utils.h:549
void get_all_waiting_keys(std::vector< K > &key_list)
Gets all the waiting keys.
Definition: plugin_utils.h:656
bool waiting
Definition: plugin_utils.h:707
virtual ~Wait_ticket()
Definition: plugin_utils.h:508
mysql_mutex_t lock
Definition: plugin_utils.h:703
std::map< K, CountDownLatch * > map
Definition: plugin_utils.h:705
mysql_cond_t cond
Definition: plugin_utils.h:704
bool blocked
Definition: plugin_utils.h:706
int releaseTicket(const K &key, bool release_due_to_error=false)
Set ticket status to done.
Definition: plugin_utils.h:633
int block_until_empty(int timeout)
Definition: plugin_utils.h:677
#define mysql_cond_wait(C, M)
Definition: mysql_cond.h:48
#define mysql_cond_destroy(C)
Definition: mysql_cond.h:45
#define mysql_cond_init(K, C)
Definition: mysql_cond.h:42
#define mysql_cond_timedwait(C, M, T)
Definition: mysql_cond.h:51
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_destroy(M)
Definition: mysql_mutex.h:46
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
#define mysql_mutex_init(K, M, A)
Definition: mysql_mutex.h:41
thread_local THD * current_thd
Definition: current_thd.cc:26
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:44
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:52
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:171
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
#define DBUG_TRACE
Definition: my_dbug.h:146
Defines for getting and processing the current system type programmatically.
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:84
#define ETIMEDOUT
Definition: my_thread.h:48
int(* mysql_cond_broadcast)(mysql_cond_t *that, const char *src_file, unsigned int src_line)
Definition: mysql_cond_service.h:52
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2874
struct result result
Definition: result.h:34
PSI_cond_key key_GR_COND_synchronized_queue
Definition: plugin_psi.h:168
PSI_cond_key key_GR_COND_count_down_latch
Definition: plugin_psi.h:146
PSI_mutex_key key_GR_LOCK_count_down_latch
Definition: plugin_psi.h:90
PSI_cond_key key_GR_COND_wait_ticket
Definition: plugin_psi.h:171
PSI_cond_key key_GR_COND_write_lock_protection
Definition: plugin_psi.h:172
PSI_mutex_key key_GR_LOCK_write_lock_protection
Definition: plugin_psi.h:129
PSI_mutex_key key_GR_LOCK_wait_ticket
Definition: plugin_psi.h:128
PSI_mutex_key key_GR_LOCK_synchronized_queue
Definition: plugin_psi.h:122
void vector_random_shuffle(std::vector< T, Malloc_allocator< T > > *v)
Rearranges the given vector elements randomly.
Definition: plugin_utils.h:909
void plugin_escape_string(std::string &string_to_escape)
Simple method to escape character on a string.
Definition: plugin_utils.cc:99
void abort_plugin_process(const char *message)
Definition: plugin_utils.cc:91
void log_primary_member_details()
Definition: plugin_utils.cc:74
required string key
Definition: replication_asynchronous_connection_failover.proto:60
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:61
#define STRING_WITH_LEN(X)
Definition: string_with_len.h:29
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: result.h:30
Definition: plugin_utils.h:48
bool is_thread_alive() const
Definition: plugin_utils.h:93
thread_state()
Definition: plugin_utils.h:68
bool is_initialized() const
Definition: plugin_utils.h:80
void set_initialized()
Definition: plugin_utils.h:76
bool is_thread_dead() const
Definition: plugin_utils.h:98
thread_state_enum
Maintains thread status.
Definition: plugin_utils.h:53
@ THREAD_NONE
THREAD_NOT_CREATED.
Definition: plugin_utils.h:54
@ THREAD_RUNNING
THREAD_RUNNING.
Definition: plugin_utils.h:58
@ THREAD_TERMINATED
THREAD_EXIT.
Definition: plugin_utils.h:60
@ THREAD_INIT
THREAD_INIT.
Definition: plugin_utils.h:56
@ THREAD_END
END OF ENUM.
Definition: plugin_utils.h:61
@ THREAD_CREATED
THREAD_CREATED.
Definition: plugin_utils.h:55
void set_running()
Definition: plugin_utils.h:70
bool is_running() const
Definition: plugin_utils.h:85
void set_created()
Definition: plugin_utils.h:78
thread_state_enum thread_state_var
Definition: plugin_utils.h:65
bool is_alive_not_running() const
Definition: plugin_utils.h:89
void set_terminated()
Definition: plugin_utils.h:72
#define MY_MUTEX_INIT_FAST
Definition: thr_mutex.h:68