24#ifndef PLUGIN_UTILS_INCLUDED
25#define PLUGIN_UTILS_INCLUDED
143 virtual bool push(
const T &value) = 0;
153 virtual bool pop(T *out) = 0;
199 bool push(
const T &value)
override {
208 bool pop(T *out)
override {
211 while (
queue.empty())
213 *out =
queue.front();
222 while (
queue.empty())
234 *out =
queue.front();
243 qsize =
queue.size();
252 std::queue<T, std::list<T, Malloc_allocator<T>>>
queue;
278 bool push(
const T &value)
override {
284 this->
queue.push(value);
301 bool pop(T *out)
override {
308 *out = this->
queue.front();
354 *out = this->
queue.front();
373 while (this->
queue.size()) {
375 elem = this->
queue.front();
377 if (delete_elements) {
426 ulong time_lapsed = 0;
427 struct timespec abstime;
518 for (
typename std::map<K, CountDownLatch *>::iterator it =
map.begin();
519 it !=
map.end(); ++it)
558 typename std::map<K, CountDownLatch *>::iterator it =
map.find(
key);
559 if (it !=
map.end()) {
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) {
597 typename std::map<K, CountDownLatch *>::iterator it =
map.find(
key);
604 if (cdl !=
nullptr) {
636 typename std::map<K, CountDownLatch *>::iterator it =
map.find(
key);
640 if (release_due_to_error) {
641 it->second->set_error();
643 it->second->countDown();
657 for (
typename std::map<K, CountDownLatch *>::iterator iter =
map.begin();
658 iter !=
map.end(); ++iter) {
660 key_list.push_back(
key);
679 while (!
map.empty()) {
680 struct timespec abstime;
689 }
else if (!
map.empty()) {
704 std::map<K, CountDownLatch *>
map;
715 assert(arg !=
nullptr);
746 DBUG_EXECUTE_IF(
"group_replication_continue_kill_pending_transaction", {
747 const char act[] =
"now SIGNAL signal.gr_applier_early_failure";
850 DBUG_PRINT(
"sleep", (
"Waiting in Plugin_waitlock::start_waitlock()"));
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)));
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:2875
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: 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