MySQL 9.0.0
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 struct timespec abstime;
214 set_timespec(&abstime, 1);
215 mysql_cond_timedwait(&cond, &lock, &abstime);
216 }
217 *out = queue.front();
218 queue.pop();
220
221 return false;
222 }
223
224 bool pop() override {
226 while (queue.empty()) {
227 struct timespec abstime;
228 set_timespec(&abstime, 1);
229 mysql_cond_timedwait(&cond, &lock, &abstime);
230 }
231 queue.pop();
233
234 return false;
235 }
236
237 bool front(T *out) override {
238 *out = nullptr;
240 while (queue.empty()) {
241 struct timespec abstime;
242 set_timespec(&abstime, 1);
243 mysql_cond_timedwait(&cond, &lock, &abstime);
244 }
245 *out = queue.front();
247
248 return false;
249 }
250
251 size_t size() override {
252 size_t qsize = 0;
254 qsize = queue.size();
256
257 return qsize;
258 }
259
260 protected:
263 std::queue<T, std::list<T, Malloc_allocator<T>>> queue;
264};
265
266/**
267 Abortable synchronized queue extends synchronized queue allowing to
268 abort methods waiting for elements on queue.
269*/
270
271template <typename T>
273 public:
275 : Synchronized_queue<T>(key), m_abort(false) {}
276
277 ~Abortable_synchronized_queue() override = default;
278
279 /**
280 Inserts an element in the queue.
281 Alerts any other thread lock on pop() or front()
282 @note The method will not push if abort was executed.
283
284 @param value The value to insert
285
286 @return false, operation always succeeded
287 */
288
289 bool push(const T &value) override {
290 bool res = false;
291 mysql_mutex_lock(&this->lock);
292 if (m_abort) {
293 res = true;
294 } else {
295 this->queue.push(value);
297 }
298
299 mysql_mutex_unlock(&this->lock);
300 return res;
301 }
302
303 /**
304 Fetches the front of the queue and removes it.
305 @note The method will block if the queue is empty until a element is pushed
306 or abort is executed
307
308 @param out The fetched reference.
309
310 @return true if method was aborted, false otherwise
311 */
312 bool pop(T *out) override {
313 *out = nullptr;
314 mysql_mutex_lock(&this->lock);
315 while (this->queue.empty() && !m_abort) {
316 struct timespec abstime;
317 set_timespec(&abstime, 1);
318 mysql_cond_timedwait(&this->cond, &this->lock, &abstime);
319 }
320
321 if (!m_abort) {
322 *out = this->queue.front();
323 this->queue.pop();
324 }
325
326 const bool result = m_abort;
327 mysql_mutex_unlock(&this->lock);
328 return result;
329 }
330
331 /**
332 Pops the front of the queue removing it.
333 @note The method will block if the queue is empty until a element is pushed
334 or abort is executed
335
336 @return false, operation always succeeded
337 */
338 bool pop() override {
339 mysql_mutex_lock(&this->lock);
340 while (this->queue.empty() && !m_abort) {
341 struct timespec abstime;
342 set_timespec(&abstime, 1);
343 mysql_cond_timedwait(&this->cond, &this->lock, &abstime);
344 }
345
346 if (!m_abort) {
347 this->queue.pop();
348 }
349
350 const bool result = m_abort;
351 mysql_mutex_unlock(&this->lock);
352 return result;
353 }
354
355 /**
356 Fetches the front of the queue but does not remove it.
357 @note The method will block if the queue is empty until a element is pushed
358 or abort is executed
359
360 @param out The fetched reference.
361
362 @return true if method was aborted, false otherwise
363 */
364 bool front(T *out) override {
365 *out = nullptr;
366 mysql_mutex_lock(&this->lock);
367 while (this->queue.empty() && !m_abort) {
368 struct timespec abstime;
369 set_timespec(&abstime, 1);
370 mysql_cond_timedwait(&this->cond, &this->lock, &abstime);
371 }
372
373 if (!m_abort) {
374 *out = this->queue.front();
375 }
376
377 const bool result = m_abort;
378 mysql_mutex_unlock(&this->lock);
379 return result;
380 }
381
382 /**
383 Remove all elements, abort current and future waits on retrieving elements
384 from queue.
385
386 @param delete_elements When true, apart from emptying the queue, it also
387 delete each element.
388 When false, the delete (memory release) responsibility
389 belongs to the `push()` caller.
390 */
391 void abort(bool delete_elements) {
392 mysql_mutex_lock(&this->lock);
393 while (this->queue.size()) {
394 T elem;
395 elem = this->queue.front();
396 this->queue.pop();
397 if (delete_elements) {
398 delete elem;
399 }
400 }
401 m_abort = true;
403 mysql_mutex_unlock(&this->lock);
404 }
405
406 private:
408};
409
410/**
411 Synchronization auxiliary class that allows one or more threads
412 to wait on a given number of requirements.
413
414 Usage:
415 CountDownLatch(count):
416 Create the latch with the number of requirements to wait.
417 wait():
418 Block until the number of requirements reaches zero.
419 countDown():
420 Decrease the number of requirements by one.
421*/
423 public:
424 /**
425 Create the latch with the number of requirements to wait.
426
427 @param count The number of requirements to wait
428 */
432 }
433
434 virtual ~CountDownLatch() {
437 }
438
439 /**
440 Block until the number of requirements reaches zero.
441 */
442 void wait(ulong timeout = 0) {
444
445 if (timeout > 0) {
446 ulong time_lapsed = 0;
447 struct timespec abstime;
448
449 while (count > 0 && timeout > time_lapsed) {
450 set_timespec(&abstime, 1);
451 mysql_cond_timedwait(&cond, &lock, &abstime);
452 time_lapsed++;
453 }
454
455 if (count > 0 && timeout == time_lapsed) {
456 error = true;
457 }
458 } else {
459 while (count > 0) {
460 struct timespec abstime;
461 set_timespec(&abstime, 1);
462 mysql_cond_timedwait(&cond, &lock, &abstime);
463 }
464 }
465
467 }
468
469 /**
470 Decrease the number of requirements by one.
471 */
472 void countDown() {
474 --count;
475 if (count == 0) mysql_cond_broadcast(&cond);
477 }
478
479 /**
480 Get current number requirements.
481
482 @return the number of requirements
483 */
484 uint getCount() {
485 uint res = 0;
487 res = count;
489 return res;
490 }
491
492 /**
493 Set error flag, once this latch is release the waiter can check
494 if it was due to a error or due to correct termination.
495 */
496 void set_error() { error = true; }
497
498 /**
499 Get latch release reason.
500
501 @return true the latch was released due to a error
502 false the latch was released on correct termination
503 */
504 bool get_error() { return error; }
505
506 private:
509 int count;
510 bool error;
511};
512
513/**
514 Ticket register/wait auxiliary class.
515 Usage:
516 registerTicket(k):
517 create a ticket with key k with status ongoing.
518 releaseTicket(k):
519 set ticket with key k status to done.
520 waitTicket(k):
521 wait until ticket with key k status is changed to done.
522*/
523template <typename K>
525 public:
526 Wait_ticket() : blocked(false), waiting(false) {
529 }
530
531 virtual ~Wait_ticket() {
532 clear();
535 }
536
537 void clear() {
539 assert(false == blocked);
540 assert(false == waiting);
541
542 for (typename std::map<K, CountDownLatch *>::iterator it = map.begin();
543 it != map.end(); ++it)
544 delete it->second; /* purecov: inspected */
545 map.clear();
547 }
548
549 /**
550 Check if there are waiting tickets.
551
552 @retval true empty
553 @retval false otherwise
554 */
555 bool empty() {
556 bool result = false;
557
559 result = map.empty();
561
562 return result;
563 }
564
565 /**
566 Register ticker with status ongoing.
567
568 @param key The key that identifies the ticket
569 @retval 0 success
570 @retval !=0 key already exists, error on insert or it is blocked
571 */
572 int registerTicket(const K &key) {
573 int error = 0;
574
576
577 if (blocked) {
578 mysql_mutex_unlock(&lock); /* purecov: inspected */
579 return 1; /* purecov: inspected */
580 }
581
582 typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
583 if (it != map.end()) {
584 mysql_mutex_unlock(&lock); /* purecov: inspected */
585 return 1; /* purecov: inspected */
586 }
587
588 CountDownLatch *cdl = new CountDownLatch(1);
589 std::pair<typename std::map<K, CountDownLatch *>::iterator, bool> ret;
590 ret = map.insert(std::pair<K, CountDownLatch *>(key, cdl));
591 if (ret.second == false) {
592 error = 1; /* purecov: inspected */
593 delete cdl; /* purecov: inspected */
594 }
595
597 return error;
598 }
599
600 /**
601 Wait until ticket status is done.
602 @note The ticket is removed after the wait.
603
604 @param key The key that identifies the ticket
605 @param timeout maximum time in seconds to wait
606 by default is 0, which means no timeout
607 @retval 0 success
608 @retval !=0 key doesn't exist, or the Ticket is blocked
609 */
610 int waitTicket(const K &key, ulong timeout = 0) {
611 int error = 0;
612 CountDownLatch *cdl = nullptr;
613
615
616 if (blocked) {
617 mysql_mutex_unlock(&lock); /* purecov: inspected */
618 return 1; /* purecov: inspected */
619 }
620
621 typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
622 if (it == map.end())
623 error = 1;
624 else
625 cdl = it->second;
627
628 if (cdl != nullptr) {
629 cdl->wait(timeout);
630 error = cdl->get_error() ? 1 : 0;
631
633 delete cdl;
634 map.erase(it);
635
636 if (waiting) {
637 if (map.empty()) {
639 }
640 }
642 }
643
644 return error;
645 }
646
647 /**
648 Set ticket status to done.
649
650 @param key The key that identifies the ticket
651 @param release_due_to_error Inform the thread waiting that the
652 release is due to a error
653 @retval 0 success
654 @retval !=0 (key doesn't exist)
655 */
656 int releaseTicket(const K &key, bool release_due_to_error = false) {
657 int error = 0;
658
660 typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
661 if (it == map.end())
662 error = 1;
663 else {
664 if (release_due_to_error) {
665 it->second->set_error();
666 }
667 it->second->countDown();
668 }
670
671 return error;
672 }
673
674 /**
675 Gets all the waiting keys.
676
677 @param[out] key_list all the keys to return
678 */
679 void get_all_waiting_keys(std::vector<K> &key_list) {
681 for (typename std::map<K, CountDownLatch *>::iterator iter = map.begin();
682 iter != map.end(); ++iter) {
683 K key = iter->first;
684 key_list.push_back(key);
685 }
687 }
688
689 /**
690 Blocks or unblocks the class from receiving waiting requests.
691
692 @param[in] blocked_flag if the class should block or not
693 */
694 void set_blocked_status(bool blocked_flag) {
696 blocked = blocked_flag;
698 }
699
702 waiting = true;
703 while (!map.empty()) {
704 struct timespec abstime;
705 set_timespec(&abstime, 1);
706#ifndef NDEBUG
707 int error =
708#endif
709 mysql_cond_timedwait(&cond, &lock, &abstime);
710 assert(error == ETIMEDOUT || error == 0);
711 if (timeout >= 1) {
712 timeout = timeout - 1;
713 } else if (!map.empty()) {
714 // time out
715 waiting = false;
717 return 1;
718 }
719 }
720 waiting = false;
722 return 0;
723 }
724
725 private:
728 std::map<K, CountDownLatch *> map;
731};
732
734 public:
736 : shared_write_lock(arg), write_lock_in_use(false) {
738
739 assert(arg != nullptr);
740
744
745 return;
746 }
747
751 }
752
754 int res = 0;
756
758 res = 1; /* purecov: inspected */
759 else {
761 write_lock_in_use = true;
762 }
763
765 return res;
766 }
767
770 DBUG_EXECUTE_IF("group_replication_continue_kill_pending_transaction", {
771 const char act[] = "now SIGNAL signal.gr_applier_early_failure";
772 assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
773 };);
774 while (write_lock_in_use == true) {
775 struct timespec abstime;
776 set_timespec(&abstime, 1);
778 }
779
781 write_lock_in_use = true;
783 }
784
788 write_lock_in_use = false;
791 }
792
793 /**
794 Grab a read lock only if there is no write lock acquired.
795
796 @retval 0 read lock acquired
797 @retval !=0 there is a write lock acquired
798 */
800 int res = 0;
802
804 res = 1;
805 else
807
809 return res;
810 }
811
813
815
816 private:
821};
822
824 public:
825 /**
826 Constructor.
827 Instantiate the mutex lock, mutex condition,
828 mutex and condition key.
829
830 @param lock the mutex lock for access to class and condition variables
831 @param cond the condition variable calling thread will wait on
832 @param lock_key mutex instrumentation key
833 @param cond_key cond instrumentation key
834 */
836 PSI_mutex_key lock_key, PSI_cond_key cond_key)
837 : wait_lock(lock),
838 wait_cond(cond),
839 key_lock(lock_key),
840 key_cond(cond_key),
841 wait_status(false) {
843
846
847 return;
848 }
849
850 /**
851 Destructor.
852 Destroys the mutex and condition objects.
853 */
857 }
858
859 /**
860 Set condition to block or unblock the calling threads
861
862 @param[in] status if the thread should be blocked or not
863 */
868 }
869
870 /**
871 Blocks the calling thread
872 */
876 while (wait_status) {
877 DBUG_PRINT("sleep", ("Waiting in Plugin_waitlock::start_waitlock()"));
878 struct timespec abstime;
879 set_timespec(&abstime, 1);
881 }
883 return;
884 }
885
886 /**
887 Release the blocked thread
888 */
891 wait_status = false;
894 }
895
896 /**
897 Checks whether thread should be blocked
898
899 @retval true thread should be blocked
900 @retval false thread should not be blocked
901 */
902 bool is_waiting() {
904 bool result = wait_status;
906 return result;
907 }
908
909 private:
910 /** the mutex lock for access to class and condition variables */
912 /** the condition variable calling thread will wait on */
914 /** mutex instrumentation key */
916 /** cond instrumentation key */
918 /** determine whether calling thread should be blocked or not */
920};
921
922/**
923 Simple method to escape character on a string
924
925 @note based on escape_string_for_mysql
926 @note the result is stored in the parameter string
927
928 @param[in,out] string_to_escape the string to escape
929*/
930void plugin_escape_string(std::string &string_to_escape);
931
932/**
933 Rearranges the given vector elements randomly.
934 @param[in,out] v the vector to shuffle
935*/
936template <typename T>
938 auto seed{std::chrono::system_clock::now().time_since_epoch().count()};
939 std::shuffle(v->begin(), v->end(),
940 std::default_random_engine(
941 static_cast<std::default_random_engine::result_type>(seed)));
942}
943
944#endif /* PLUGIN_UTILS_INCLUDED */
Abortable synchronized queue extends synchronized queue allowing to abort methods waiting for element...
Definition: plugin_utils.h:272
void abort(bool delete_elements)
Remove all elements, abort current and future waits on retrieving elements from queue.
Definition: plugin_utils.h:391
bool pop() override
Pops the front of the queue removing it.
Definition: plugin_utils.h:338
bool push(const T &value) override
Inserts an element in the queue.
Definition: plugin_utils.h:289
bool m_abort
Definition: plugin_utils.h:407
bool front(T *out) override
Fetches the front of the queue but does not remove it.
Definition: plugin_utils.h:364
Abortable_synchronized_queue(PSI_memory_key key)
Definition: plugin_utils.h:274
bool pop(T *out) override
Fetches the front of the queue and removes it.
Definition: plugin_utils.h:312
~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:422
uint getCount()
Get current number requirements.
Definition: plugin_utils.h:484
void wait(ulong timeout=0)
Block until the number of requirements reaches zero.
Definition: plugin_utils.h:442
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:496
mysql_cond_t cond
Definition: plugin_utils.h:508
void countDown()
Decrease the number of requirements by one.
Definition: plugin_utils.h:472
virtual ~CountDownLatch()
Definition: plugin_utils.h:434
int count
Definition: plugin_utils.h:509
bool error
Definition: plugin_utils.h:510
mysql_mutex_t lock
Definition: plugin_utils.h:507
bool get_error()
Get latch release reason.
Definition: plugin_utils.h:504
CountDownLatch(uint count)
Create the latch with the number of requirements to wait.
Definition: plugin_utils.h:429
Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
Definition: malloc_allocator.h:63
Definition: plugin_utils.h:823
bool is_waiting()
Checks whether thread should be blocked.
Definition: plugin_utils.h:902
PSI_cond_key key_cond
cond instrumentation key
Definition: plugin_utils.h:917
PSI_mutex_key key_lock
mutex instrumentation key
Definition: plugin_utils.h:915
bool wait_status
determine whether calling thread should be blocked or not
Definition: plugin_utils.h:919
void start_waitlock()
Blocks the calling thread.
Definition: plugin_utils.h:873
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:835
void set_wait_lock(bool status)
Set condition to block or unblock the calling threads.
Definition: plugin_utils.h:864
void end_wait_lock()
Release the blocked thread.
Definition: plugin_utils.h:889
virtual ~Plugin_waitlock()
Destructor.
Definition: plugin_utils.h:854
mysql_mutex_t * wait_lock
the mutex lock for access to class and condition variables
Definition: plugin_utils.h:911
mysql_cond_t * wait_cond
the condition variable calling thread will wait on
Definition: plugin_utils.h:913
Definition: plugin_utils.h:733
Shared_writelock(Checkable_rwlock *arg)
Definition: plugin_utils.h:735
mysql_mutex_t write_lock
Definition: plugin_utils.h:818
void release_read_lock()
Definition: plugin_utils.h:814
virtual ~Shared_writelock()
Definition: plugin_utils.h:748
Checkable_rwlock * shared_write_lock
Definition: plugin_utils.h:817
bool write_lock_in_use
Definition: plugin_utils.h:820
void release_write_lock()
Definition: plugin_utils.h:785
void grab_read_lock()
Definition: plugin_utils.h:812
void grab_write_lock()
Definition: plugin_utils.h:768
mysql_cond_t write_lock_protection
Definition: plugin_utils.h:819
int try_grab_write_lock()
Definition: plugin_utils.h:753
int try_grab_read_lock()
Grab a read lock only if there is no write lock acquired.
Definition: plugin_utils.h:799
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:237
bool pop() override
Pops the front of the queue removing it.
Definition: plugin_utils.h:224
Synchronized_queue(PSI_memory_key key)
Definition: plugin_utils.h:184
size_t size() override
Checks the queue size.
Definition: plugin_utils.h:251
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:262
std::queue< T, std::list< T, Malloc_allocator< T > > > queue
Definition: plugin_utils.h:263
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:261
Ticket register/wait auxiliary class.
Definition: plugin_utils.h:524
void clear()
Definition: plugin_utils.h:537
int waitTicket(const K &key, ulong timeout=0)
Wait until ticket status is done.
Definition: plugin_utils.h:610
bool empty()
Check if there are waiting tickets.
Definition: plugin_utils.h:555
Wait_ticket()
Definition: plugin_utils.h:526
void set_blocked_status(bool blocked_flag)
Blocks or unblocks the class from receiving waiting requests.
Definition: plugin_utils.h:694
int registerTicket(const K &key)
Register ticker with status ongoing.
Definition: plugin_utils.h:572
void get_all_waiting_keys(std::vector< K > &key_list)
Gets all the waiting keys.
Definition: plugin_utils.h:679
bool waiting
Definition: plugin_utils.h:730
virtual ~Wait_ticket()
Definition: plugin_utils.h:531
mysql_mutex_t lock
Definition: plugin_utils.h:726
std::map< K, CountDownLatch * > map
Definition: plugin_utils.h:728
mysql_cond_t cond
Definition: plugin_utils.h:727
bool blocked
Definition: plugin_utils.h:729
int releaseTicket(const K &key, bool release_due_to_error=false)
Set ticket status to done.
Definition: plugin_utils.h:656
int block_until_empty(int timeout)
Definition: plugin_utils.h:700
#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:2875
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:937
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