MySQL 8.0.37
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
44
45void abort_plugin_process(const char *message);
46
48 /**
49 * @enum thread_state_enum
50 * @brief Maintains thread status
51 */
53 THREAD_NONE = 0, /**< THREAD_NOT_CREATED */
54 THREAD_CREATED, /**< THREAD_CREATED */
55 THREAD_INIT, /**< THREAD_INIT */
56
57 THREAD_RUNNING, /**< THREAD_RUNNING */
58
59 THREAD_TERMINATED, /**< THREAD_EXIT */
60 THREAD_END /**< END OF ENUM */
61 };
62
63 private:
65
66 public:
68
69 void set_running() { thread_state_var = thread_state_enum::THREAD_RUNNING; }
70
72 thread_state_var = thread_state_enum::THREAD_TERMINATED;
73 }
74
75 void set_initialized() { thread_state_var = thread_state_enum::THREAD_INIT; }
76
77 void set_created() { thread_state_var = thread_state_enum::THREAD_CREATED; }
78
79 bool is_initialized() const {
80 return ((thread_state_var >= thread_state_enum::THREAD_INIT) &&
81 (thread_state_var < thread_state_enum::THREAD_TERMINATED));
82 }
83
84 bool is_running() const {
85 return thread_state_var == thread_state_enum::THREAD_RUNNING;
86 }
87
88 bool is_alive_not_running() const {
89 return thread_state_var < thread_state_enum::THREAD_RUNNING;
90 }
91
92 bool is_thread_alive() const {
93 return ((thread_state_var >= thread_state_enum::THREAD_CREATED) &&
94 (thread_state_var < thread_state_enum::THREAD_TERMINATED));
95 }
96
97 bool is_thread_dead() const { return !is_thread_alive(); }
98};
99
101 public:
104
105 /**
106 This method instructs all local transactions to rollback when certification
107 is no longer possible.
108 */
110
111 private:
112 /* The lock that disallows concurrent method executions */
114};
115
116/**
117 @class Synchronized_queue_interface
118
119 Interface that defines a queue protected against multi thread access.
120
121 */
122
123template <typename T>
125 public:
126 virtual ~Synchronized_queue_interface() = default;
127
128 /**
129 Checks if the queue is empty
130 @return if is empty
131 @retval true empty
132 @retval false not empty
133 */
134 virtual bool empty() = 0;
135
136 /**
137 Inserts an element in the queue.
138 Alerts any other thread lock on pop() or front()
139 @param value The value to insert
140
141 @return false, operation always succeeded
142 */
143 virtual bool push(const T &value) = 0;
144
145 /**
146 Fetches the front of the queue and removes it.
147 @note The method will block if the queue is empty until a element is pushed
148
149 @param out The fetched reference.
150
151 @return false, operation always succeeded
152 */
153 virtual bool pop(T *out) = 0;
154
155 /**
156 Pops the front of the queue removing it.
157 @note The method will block if the queue is empty until a element is pushed
158
159 @return true if method was aborted, false otherwise
160 */
161 virtual bool pop() = 0;
162
163 /**
164 Fetches the front of the queue but does not remove it.
165 @note The method will block if the queue is empty until a element is pushed
166
167 @param out The fetched reference.
168
169 @return false, operation always succeeded
170 */
171 virtual bool front(T *out) = 0;
172
173 /**
174 Checks the queue size
175 @return the size of the queue
176 */
177 virtual size_t size() = 0;
178};
179
180template <typename T>
182 public:
186 }
187
189
190 bool empty() override {
191 bool res = true;
193 res = queue.empty();
195
196 return res;
197 }
198
199 bool push(const T &value) override {
201 queue.push(value);
204
205 return false;
206 }
207
208 bool pop(T *out) override {
209 *out = NULL;
211 while (queue.empty())
212 mysql_cond_wait(&cond, &lock); /* purecov: inspected */
213 *out = queue.front();
214 queue.pop();
216
217 return false;
218 }
219
220 bool pop() override {
222 while (queue.empty())
223 mysql_cond_wait(&cond, &lock); /* purecov: inspected */
224 queue.pop();
226
227 return false;
228 }
229
230 bool front(T *out) override {
231 *out = NULL;
233 while (queue.empty()) mysql_cond_wait(&cond, &lock);
234 *out = queue.front();
236
237 return false;
238 }
239
240 size_t size() override {
241 size_t qsize = 0;
243 qsize = queue.size();
245
246 return qsize;
247 }
248
249 protected:
252 std::queue<T, std::list<T, Malloc_allocator<T>>> queue;
253};
254
255/**
256 Abortable synchronized queue extends synchronized queue allowing to
257 abort methods waiting for elements on queue.
258*/
259
260template <typename T>
262 public:
264 : Synchronized_queue<T>(key), m_abort(false) {}
265
266 ~Abortable_synchronized_queue() override = default;
267
268 /**
269 Inserts an element in the queue.
270 Alerts any other thread lock on pop() or front()
271 @note The method will not push if abort was executed.
272
273 @param value The value to insert
274
275 @return false, operation always succeeded
276 */
277
278 bool push(const T &value) override {
279 bool res = false;
280 mysql_mutex_lock(&this->lock);
281 if (m_abort) {
282 res = true;
283 } else {
284 this->queue.push(value);
286 }
287
288 mysql_mutex_unlock(&this->lock);
289 return res;
290 }
291
292 /**
293 Fetches the front of the queue and removes it.
294 @note The method will block if the queue is empty until a element is pushed
295 or abort is executed
296
297 @param out The fetched reference.
298
299 @return true if method was aborted, false otherwise
300 */
301 bool pop(T *out) override {
302 *out = nullptr;
303 mysql_mutex_lock(&this->lock);
304 while (this->queue.empty() && !m_abort)
305 mysql_cond_wait(&this->cond, &this->lock); /* purecov: inspected */
306
307 if (!m_abort) {
308 *out = this->queue.front();
309 this->queue.pop();
310 }
311
312 const bool result = m_abort;
313 mysql_mutex_unlock(&this->lock);
314 return result;
315 }
316
317 /**
318 Pops the front of the queue removing it.
319 @note The method will block if the queue is empty until a element is pushed
320 or abort is executed
321
322 @return false, operation always succeeded
323 */
324 bool pop() override {
325 mysql_mutex_lock(&this->lock);
326 while (this->queue.empty() && !m_abort)
327 mysql_cond_wait(&this->cond, &this->lock);
328
329 if (!m_abort) {
330 this->queue.pop();
331 }
332
333 const bool result = m_abort;
334 mysql_mutex_unlock(&this->lock);
335 return result;
336 }
337
338 /**
339 Fetches the front of the queue but does not remove it.
340 @note The method will block if the queue is empty until a element is pushed
341 or abort is executed
342
343 @param out The fetched reference.
344
345 @return true if method was aborted, false otherwise
346 */
347 bool front(T *out) override {
348 *out = nullptr;
349 mysql_mutex_lock(&this->lock);
350 while (this->queue.empty() && !m_abort)
351 mysql_cond_wait(&this->cond, &this->lock);
352
353 if (!m_abort) {
354 *out = this->queue.front();
355 }
356
357 const bool result = m_abort;
358 mysql_mutex_unlock(&this->lock);
359 return result;
360 }
361
362 /**
363 Remove all elements, abort current and future waits on retrieving elements
364 from queue.
365
366 @param delete_elements When true, apart from emptying the queue, it also
367 delete each element.
368 When false, the delete (memory release) responsibility
369 belongs to the `push()` caller.
370 */
371 void abort(bool delete_elements) {
372 mysql_mutex_lock(&this->lock);
373 while (this->queue.size()) {
374 T elem;
375 elem = this->queue.front();
376 this->queue.pop();
377 if (delete_elements) {
378 delete elem;
379 }
380 }
381 m_abort = true;
383 mysql_mutex_unlock(&this->lock);
384 }
385
386 private:
388};
389
390/**
391 Synchronization auxiliary class that allows one or more threads
392 to wait on a given number of requirements.
393
394 Usage:
395 CountDownLatch(count):
396 Create the latch with the number of requirements to wait.
397 wait():
398 Block until the number of requirements reaches zero.
399 countDown():
400 Decrease the number of requirements by one.
401*/
403 public:
404 /**
405 Create the latch with the number of requirements to wait.
406
407 @param count The number of requirements to wait
408 */
412 }
413
414 virtual ~CountDownLatch() {
417 }
418
419 /**
420 Block until the number of requirements reaches zero.
421 */
422 void wait(ulong timeout = 0) {
424
425 if (timeout > 0) {
426 ulong time_lapsed = 0;
427 struct timespec abstime;
428
429 while (count > 0 && timeout > time_lapsed) {
430 set_timespec(&abstime, 1);
431 mysql_cond_timedwait(&cond, &lock, &abstime);
432 time_lapsed++;
433 }
434
435 if (count > 0 && timeout == time_lapsed) {
436 error = true;
437 }
438 } else {
439 while (count > 0) mysql_cond_wait(&cond, &lock);
440 }
441
443 }
444
445 /**
446 Decrease the number of requirements by one.
447 */
448 void countDown() {
450 --count;
451 if (count == 0) mysql_cond_broadcast(&cond);
453 }
454
455 /**
456 Get current number requirements.
457
458 @return the number of requirements
459 */
461 uint res = 0;
463 res = count;
465 return res;
466 }
467
468 /**
469 Set error flag, once this latch is release the waiter can check
470 if it was due to a error or due to correct termination.
471 */
472 void set_error() { error = true; }
473
474 /**
475 Get latch release reason.
476
477 @return true the latch was released due to a error
478 false the latch was released on correct termination
479 */
480 bool get_error() { return error; }
481
482 private:
485 int count;
486 bool error;
487};
488
489/**
490 Ticket register/wait auxiliary class.
491 Usage:
492 registerTicket(k):
493 create a ticket with key k with status ongoing.
494 releaseTicket(k):
495 set ticket with key k status to done.
496 waitTicket(k):
497 wait until ticket with key k status is changed to done.
498*/
499template <typename K>
501 public:
502 Wait_ticket() : blocked(false), waiting(false) {
505 }
506
507 virtual ~Wait_ticket() {
508 clear();
511 }
512
513 void clear() {
515 assert(false == blocked);
516 assert(false == waiting);
517
518 for (typename std::map<K, CountDownLatch *>::iterator it = map.begin();
519 it != map.end(); ++it)
520 delete it->second; /* purecov: inspected */
521 map.clear();
523 }
524
525 /**
526 Check if there are waiting tickets.
527
528 @retval true empty
529 @retval false otherwise
530 */
531 bool empty() {
532 bool result = false;
533
535 result = map.empty();
537
538 return result;
539 }
540
541 /**
542 Register ticker with status ongoing.
543
544 @param key The key that identifies the ticket
545 @retval 0 success
546 @retval !=0 key already exists, error on insert or it is blocked
547 */
548 int registerTicket(const K &key) {
549 int error = 0;
550
552
553 if (blocked) {
554 mysql_mutex_unlock(&lock); /* purecov: inspected */
555 return 1; /* purecov: inspected */
556 }
557
558 typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
559 if (it != map.end()) {
560 mysql_mutex_unlock(&lock); /* purecov: inspected */
561 return 1; /* purecov: inspected */
562 }
563
564 CountDownLatch *cdl = new CountDownLatch(1);
565 std::pair<typename std::map<K, CountDownLatch *>::iterator, bool> ret;
566 ret = map.insert(std::pair<K, CountDownLatch *>(key, cdl));
567 if (ret.second == false) {
568 error = 1; /* purecov: inspected */
569 delete cdl; /* purecov: inspected */
570 }
571
573 return error;
574 }
575
576 /**
577 Wait until ticket status is done.
578 @note The ticket is removed after the wait.
579
580 @param key The key that identifies the ticket
581 @param timeout maximum time in seconds to wait
582 by default is 0, which means no timeout
583 @retval 0 success
584 @retval !=0 key doesn't exist, or the Ticket is blocked
585 */
586 int waitTicket(const K &key, ulong timeout = 0) {
587 int error = 0;
588 CountDownLatch *cdl = nullptr;
589
591
592 if (blocked) {
593 mysql_mutex_unlock(&lock); /* purecov: inspected */
594 return 1; /* purecov: inspected */
595 }
596
597 typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
598 if (it == map.end())
599 error = 1;
600 else
601 cdl = it->second;
603
604 if (cdl != nullptr) {
605 cdl->wait(timeout);
606 error = cdl->get_error() ? 1 : 0;
607
609 delete cdl;
610 map.erase(it);
611
612 if (waiting) {
613 if (map.empty()) {
615 }
616 }
618 }
619
620 return error;
621 }
622
623 /**
624 Set ticket status to done.
625
626 @param key The key that identifies the ticket
627 @param release_due_to_error Inform the thread waiting that the
628 release is due to a error
629 @retval 0 success
630 @retval !=0 (key doesn't exist)
631 */
632 int releaseTicket(const K &key, bool release_due_to_error = false) {
633 int error = 0;
634
636 typename std::map<K, CountDownLatch *>::iterator it = map.find(key);
637 if (it == map.end())
638 error = 1;
639 else {
640 if (release_due_to_error) {
641 it->second->set_error();
642 }
643 it->second->countDown();
644 }
646
647 return error;
648 }
649
650 /**
651 Gets all the waiting keys.
652
653 @param[out] key_list all the keys to return
654 */
655 void get_all_waiting_keys(std::vector<K> &key_list) {
657 for (typename std::map<K, CountDownLatch *>::iterator iter = map.begin();
658 iter != map.end(); ++iter) {
659 K key = iter->first;
660 key_list.push_back(key);
661 }
663 }
664
665 /**
666 Blocks or unblocks the class from receiving waiting requests.
667
668 @param[in] blocked_flag if the class should block or not
669 */
670 void set_blocked_status(bool blocked_flag) {
672 blocked = blocked_flag;
674 }
675
678 waiting = true;
679 while (!map.empty()) {
680 struct timespec abstime;
681 set_timespec(&abstime, 1);
682#ifndef NDEBUG
683 int error =
684#endif
685 mysql_cond_timedwait(&cond, &lock, &abstime);
686 assert(error == ETIMEDOUT || error == 0);
687 if (timeout >= 1) {
688 timeout = timeout - 1;
689 } else if (!map.empty()) {
690 // time out
691 waiting = false;
693 return 1;
694 }
695 }
696 waiting = false;
698 return 0;
699 }
700
701 private:
704 std::map<K, CountDownLatch *> map;
707};
708
710 public:
712 : shared_write_lock(arg), write_lock_in_use(false) {
714
715 assert(arg != nullptr);
716
720
721 return;
722 }
723
727 }
728
730 int res = 0;
732
734 res = 1; /* purecov: inspected */
735 else {
737 write_lock_in_use = true;
738 }
739
741 return res;
742 }
743
746 DBUG_EXECUTE_IF("group_replication_continue_kill_pending_transaction", {
747 const char act[] = "now SIGNAL signal.gr_applier_early_failure";
748 assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
749 };);
750 while (write_lock_in_use == true)
752
754 write_lock_in_use = true;
756 }
757
761 write_lock_in_use = false;
764 }
765
766 /**
767 Grab a read lock only if there is no write lock acquired.
768
769 @retval 0 read lock acquired
770 @retval !=0 there is a write lock acquired
771 */
773 int res = 0;
775
777 res = 1;
778 else
780
782 return res;
783 }
784
786
788
789 private:
794};
795
797 public:
798 /**
799 Constructor.
800 Instantiate the mutex lock, mutex condition,
801 mutex and condition key.
802
803 @param lock the mutex lock for access to class and condition variables
804 @param cond the condition variable calling thread will wait on
805 @param lock_key mutex instrumentation key
806 @param cond_key cond instrumentation key
807 */
809 PSI_mutex_key lock_key, PSI_cond_key cond_key)
810 : wait_lock(lock),
811 wait_cond(cond),
812 key_lock(lock_key),
813 key_cond(cond_key),
814 wait_status(false) {
816
819
820 return;
821 }
822
823 /**
824 Destructor.
825 Destroys the mutex and condition objects.
826 */
830 }
831
832 /**
833 Set condition to block or unblock the calling threads
834
835 @param[in] status if the thread should be blocked or not
836 */
841 }
842
843 /**
844 Blocks the calling thread
845 */
849 while (wait_status) {
850 DBUG_PRINT("sleep", ("Waiting in Plugin_waitlock::start_waitlock()"));
852 }
854 return;
855 }
856
857 /**
858 Release the blocked thread
859 */
862 wait_status = false;
865 }
866
867 /**
868 Checks whether thread should be blocked
869
870 @retval true thread should be blocked
871 @retval false thread should not be blocked
872 */
873 bool is_waiting() {
875 bool result = wait_status;
877 return result;
878 }
879
880 private:
881 /** the mutex lock for access to class and condition variables */
883 /** the condition variable calling thread will wait on */
885 /** mutex instrumentation key */
887 /** cond instrumentation key */
889 /** determine whether calling thread should be blocked or not */
891};
892
893/**
894 Simple method to escape character on a string
895
896 @note based on escape_string_for_mysql
897 @note the result is stored in the parameter string
898
899 @param[in,out] string_to_escape the string to escape
900*/
901void plugin_escape_string(std::string &string_to_escape);
902
903/**
904 Rearranges the given vector elements randomly.
905 @param[in,out] v the vector to shuffle
906*/
907template <typename T>
909 auto seed{std::chrono::system_clock::now().time_since_epoch().count()};
910 std::shuffle(v->begin(), v->end(),
911 std::default_random_engine(
912 static_cast<std::default_random_engine::result_type>(seed)));
913}
914
915#endif /* PLUGIN_UTILS_INCLUDED */
Abortable synchronized queue extends synchronized queue allowing to abort methods waiting for element...
Definition: plugin_utils.h:261
void abort(bool delete_elements)
Remove all elements, abort current and future waits on retrieving elements from queue.
Definition: plugin_utils.h:371
bool pop() override
Pops the front of the queue removing it.
Definition: plugin_utils.h:324
bool push(const T &value) override
Inserts an element in the queue.
Definition: plugin_utils.h:278
bool m_abort
Definition: plugin_utils.h:387
bool front(T *out) override
Fetches the front of the queue but does not remove it.
Definition: plugin_utils.h:347
Abortable_synchronized_queue(PSI_memory_key key)
Definition: plugin_utils.h:263
bool pop(T *out) override
Fetches the front of the queue and removes it.
Definition: plugin_utils.h:301
~Abortable_synchronized_queue() override=default
Definition: plugin_utils.h:100
mysql_mutex_t unblocking_process_lock
Definition: plugin_utils.h:113
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:309
void rdlock()
Acquire the read lock.
Definition: rpl_gtid.h:460
void wrlock()
Acquire the write lock.
Definition: rpl_gtid.h:469
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_gtid.h:480
Synchronization auxiliary class that allows one or more threads to wait on a given number of requirem...
Definition: plugin_utils.h:402
uint getCount()
Get current number requirements.
Definition: plugin_utils.h:460
void wait(ulong timeout=0)
Block until the number of requirements reaches zero.
Definition: plugin_utils.h:422
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:472
mysql_cond_t cond
Definition: plugin_utils.h:484
void countDown()
Decrease the number of requirements by one.
Definition: plugin_utils.h:448
virtual ~CountDownLatch()
Definition: plugin_utils.h:414
int count
Definition: plugin_utils.h:485
bool error
Definition: plugin_utils.h:486
mysql_mutex_t lock
Definition: plugin_utils.h:483
bool get_error()
Get latch release reason.
Definition: plugin_utils.h:480
CountDownLatch(uint count)
Create the latch with the number of requirements to wait.
Definition: plugin_utils.h:409
Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
Definition: malloc_allocator.h:63
Definition: plugin_utils.h:796
bool is_waiting()
Checks whether thread should be blocked.
Definition: plugin_utils.h:873
PSI_cond_key key_cond
cond instrumentation key
Definition: plugin_utils.h:888
PSI_mutex_key key_lock
mutex instrumentation key
Definition: plugin_utils.h:886
bool wait_status
determine whether calling thread should be blocked or not
Definition: plugin_utils.h:890
void start_waitlock()
Blocks the calling thread.
Definition: plugin_utils.h:846
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:808
void set_wait_lock(bool status)
Set condition to block or unblock the calling threads.
Definition: plugin_utils.h:837
void end_wait_lock()
Release the blocked thread.
Definition: plugin_utils.h:860
virtual ~Plugin_waitlock()
Destructor.
Definition: plugin_utils.h:827
mysql_mutex_t * wait_lock
the mutex lock for access to class and condition variables
Definition: plugin_utils.h:882
mysql_cond_t * wait_cond
the condition variable calling thread will wait on
Definition: plugin_utils.h:884
Definition: plugin_utils.h:709
Shared_writelock(Checkable_rwlock *arg)
Definition: plugin_utils.h:711
mysql_mutex_t write_lock
Definition: plugin_utils.h:791
void release_read_lock()
Definition: plugin_utils.h:787
virtual ~Shared_writelock()
Definition: plugin_utils.h:724
Checkable_rwlock * shared_write_lock
Definition: plugin_utils.h:790
bool write_lock_in_use
Definition: plugin_utils.h:793
void release_write_lock()
Definition: plugin_utils.h:758
void grab_read_lock()
Definition: plugin_utils.h:785
void grab_write_lock()
Definition: plugin_utils.h:744
mysql_cond_t write_lock_protection
Definition: plugin_utils.h:792
int try_grab_write_lock()
Definition: plugin_utils.h:729
int try_grab_read_lock()
Grab a read lock only if there is no write lock acquired.
Definition: plugin_utils.h:772
Interface that defines a queue protected against multi thread access.
Definition: plugin_utils.h:124
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:181
bool front(T *out) override
Fetches the front of the queue but does not remove it.
Definition: plugin_utils.h:230
bool pop() override
Pops the front of the queue removing it.
Definition: plugin_utils.h:220
Synchronized_queue(PSI_memory_key key)
Definition: plugin_utils.h:183
size_t size() override
Checks the queue size.
Definition: plugin_utils.h:240
bool pop(T *out) override
Fetches the front of the queue and removes it.
Definition: plugin_utils.h:208
bool empty() override
Checks if the queue is empty.
Definition: plugin_utils.h:190
mysql_cond_t cond
Definition: plugin_utils.h:251
std::queue< T, std::list< T, Malloc_allocator< T > > > queue
Definition: plugin_utils.h:252
bool push(const T &value) override
Inserts an element in the queue.
Definition: plugin_utils.h:199
~Synchronized_queue() override
Definition: plugin_utils.h:188
mysql_mutex_t lock
Definition: plugin_utils.h:250
Ticket register/wait auxiliary class.
Definition: plugin_utils.h:500
void clear()
Definition: plugin_utils.h:513
int waitTicket(const K &key, ulong timeout=0)
Wait until ticket status is done.
Definition: plugin_utils.h:586
bool empty()
Check if there are waiting tickets.
Definition: plugin_utils.h:531
Wait_ticket()
Definition: plugin_utils.h:502
void set_blocked_status(bool blocked_flag)
Blocks or unblocks the class from receiving waiting requests.
Definition: plugin_utils.h:670
int registerTicket(const K &key)
Register ticker with status ongoing.
Definition: plugin_utils.h:548
void get_all_waiting_keys(std::vector< K > &key_list)
Gets all the waiting keys.
Definition: plugin_utils.h:655
bool waiting
Definition: plugin_utils.h:706
virtual ~Wait_ticket()
Definition: plugin_utils.h:507
mysql_mutex_t lock
Definition: plugin_utils.h:702
std::map< K, CountDownLatch * > map
Definition: plugin_utils.h:704
mysql_cond_t cond
Definition: plugin_utils.h:703
bool blocked
Definition: plugin_utils.h:705
int releaseTicket(const K &key, bool release_due_to_error=false)
Set ticket status to done.
Definition: plugin_utils.h:632
int block_until_empty(int timeout)
Definition: plugin_utils.h:676
#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 STRING_WITH_LEN(X)
Definition: m_string.h:315
#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:496
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:166
PSI_cond_key key_GR_COND_count_down_latch
Definition: plugin_psi.h:145
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:169
PSI_cond_key key_GR_COND_write_lock_protection
Definition: plugin_psi.h:170
PSI_mutex_key key_GR_LOCK_write_lock_protection
Definition: plugin_psi.h:128
PSI_mutex_key key_GR_LOCK_wait_ticket
Definition: plugin_psi.h:127
PSI_mutex_key key_GR_LOCK_synchronized_queue
Definition: plugin_psi.h:121
void vector_random_shuffle(std::vector< T, Malloc_allocator< T > > *v)
Rearranges the given vector elements randomly.
Definition: plugin_utils.h:908
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
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:47
bool is_thread_alive() const
Definition: plugin_utils.h:92
thread_state()
Definition: plugin_utils.h:67
bool is_initialized() const
Definition: plugin_utils.h:79
void set_initialized()
Definition: plugin_utils.h:75
bool is_thread_dead() const
Definition: plugin_utils.h:97
thread_state_enum
Maintains thread status.
Definition: plugin_utils.h:52
@ THREAD_NONE
THREAD_NOT_CREATED.
Definition: plugin_utils.h:53
@ THREAD_RUNNING
THREAD_RUNNING.
Definition: plugin_utils.h:57
@ THREAD_TERMINATED
THREAD_EXIT.
Definition: plugin_utils.h:59
@ THREAD_INIT
THREAD_INIT.
Definition: plugin_utils.h:55
@ THREAD_END
END OF ENUM.
Definition: plugin_utils.h:60
@ THREAD_CREATED
THREAD_CREATED.
Definition: plugin_utils.h:54
void set_running()
Definition: plugin_utils.h:69
bool is_running() const
Definition: plugin_utils.h:84
void set_created()
Definition: plugin_utils.h:77
thread_state_enum thread_state_var
Definition: plugin_utils.h:64
bool is_alive_not_running() const
Definition: plugin_utils.h:88
void set_terminated()
Definition: plugin_utils.h:71
#define MY_MUTEX_INIT_FAST
Definition: thr_mutex.h:68
#define NULL
Definition: types.h:55
unsigned int uint
Definition: uca9-dump.cc:75