24#ifndef PLUGIN_UTILS_INCLUDED
25#define PLUGIN_UTILS_INCLUDED
144 virtual bool push(
const T &value) = 0;
154 virtual bool pop(T *out) = 0;
200 bool push(
const T &value)
override {
209 bool pop(T *out)
override {
212 while (
queue.empty())
214 *out =
queue.front();
223 while (
queue.empty())
235 *out =
queue.front();
244 qsize =
queue.size();
253 std::queue<T, std::list<T, Malloc_allocator<T>>>
queue;
279 bool push(
const T &value)
override {
285 this->
queue.push(value);
302 bool pop(T *out)
override {
309 *out = this->
queue.front();
355 *out = this->
queue.front();
374 while (this->
queue.size()) {
376 elem = this->
queue.front();
378 if (delete_elements) {
427 ulong time_lapsed = 0;
428 struct timespec abstime;
519 for (
typename std::map<K, CountDownLatch *>::iterator it =
map.begin();
520 it !=
map.end(); ++it)
559 typename std::map<K, CountDownLatch *>::iterator it =
map.find(
key);
560 if (it !=
map.end()) {
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) {
598 typename std::map<K, CountDownLatch *>::iterator it =
map.find(
key);
605 if (cdl !=
nullptr) {
637 typename std::map<K, CountDownLatch *>::iterator it =
map.find(
key);
641 if (release_due_to_error) {
642 it->second->set_error();
644 it->second->countDown();
658 for (
typename std::map<K, CountDownLatch *>::iterator iter =
map.begin();
659 iter !=
map.end(); ++iter) {
661 key_list.push_back(
key);
680 while (!
map.empty()) {
681 struct timespec abstime;
690 }
else if (!
map.empty()) {
705 std::map<K, CountDownLatch *>
map;
716 assert(arg !=
nullptr);
747 DBUG_EXECUTE_IF(
"group_replication_continue_kill_pending_transaction", {
748 const char act[] =
"now SIGNAL signal.gr_applier_early_failure";
851 DBUG_PRINT(
"sleep", (
"Waiting in Plugin_waitlock::start_waitlock()"));
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)));
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: 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