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()) {
213 struct timespec abstime;
217 *out =
queue.front();
226 while (
queue.empty()) {
227 struct timespec abstime;
240 while (
queue.empty()) {
241 struct timespec abstime;
245 *out =
queue.front();
254 qsize =
queue.size();
263 std::queue<T, std::list<T, Malloc_allocator<T>>>
queue;
289 bool push(
const T &value)
override {
295 this->
queue.push(value);
312 bool pop(T *out)
override {
316 struct timespec abstime;
322 *out = this->
queue.front();
341 struct timespec abstime;
368 struct timespec abstime;
374 *out = this->
queue.front();
393 while (this->
queue.size()) {
395 elem = this->
queue.front();
397 if (delete_elements) {
446 ulong time_lapsed = 0;
447 struct timespec abstime;
460 struct timespec abstime;
542 for (
typename std::map<K, CountDownLatch *>::iterator it =
map.begin();
543 it !=
map.end(); ++it)
582 typename std::map<K, CountDownLatch *>::iterator it =
map.find(
key);
583 if (it !=
map.end()) {
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) {
621 typename std::map<K, CountDownLatch *>::iterator it =
map.find(
key);
628 if (cdl !=
nullptr) {
660 typename std::map<K, CountDownLatch *>::iterator it =
map.find(
key);
664 if (release_due_to_error) {
665 it->second->set_error();
667 it->second->countDown();
681 for (
typename std::map<K, CountDownLatch *>::iterator iter =
map.begin();
682 iter !=
map.end(); ++iter) {
684 key_list.push_back(
key);
703 while (!
map.empty()) {
704 struct timespec abstime;
713 }
else if (!
map.empty()) {
728 std::map<K, CountDownLatch *>
map;
739 assert(arg !=
nullptr);
770 DBUG_EXECUTE_IF(
"group_replication_continue_kill_pending_transaction", {
771 const char act[] =
"now SIGNAL signal.gr_applier_early_failure";
775 struct timespec abstime;
877 DBUG_PRINT(
"sleep", (
"Waiting in Plugin_waitlock::start_waitlock()"));
878 struct timespec abstime;
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)));
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:325
void rdlock()
Acquire the read lock.
Definition: rpl_gtid.h:486
void wrlock()
Acquire the write lock.
Definition: rpl_gtid.h:495
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_gtid.h:506
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:2876
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: 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