Replace rand() with lock-free Xoshiro128++ PRNG

v3.0_refactor_prepared_statement_cache_design_5211
Rahim Kanji 3 months ago
parent 1251e4d539
commit 9c0e14a5d1

@ -820,7 +820,7 @@ PgSQL_HostGroups_Manager::PgSQL_HostGroups_Manager() {
static const char alphanum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
rand_del[0] = '-';
for (int i = 1; i < 6; i++) {
rand_del[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
rand_del[i] = alphanum[rand_fast() % (sizeof(alphanum) - 1)];
}
rand_del[6] = '-';
rand_del[7] = 0;
@ -2208,11 +2208,12 @@ PgSQL_SrvC *PgSQL_HGC::get_random_MySrvC(char * gtid_uuid, uint64_t gtid_trxid,
unsigned int k;
if (New_sum > 32768) {
k=rand()%New_sum;
} else {
k=fastrand()%New_sum;
}
//if (New_sum > 32768) {
// k=rand()%New_sum;
//} else {
// k=fastrand()%New_sum;
//}
k = rand_fast() % New_sum;
k++;
New_sum=0;
@ -2341,11 +2342,12 @@ PgSQL_Connection * PgSQL_SrvConnList::get_random_MyConn(PgSQL_Session *sess, boo
}
}
if (l && ff==false && needs_warming==false) {
if (l>32768) {
i=rand()%l;
} else {
i=fastrand()%l;
}
//if (l>32768) {
// i=rand()%l;
//} else {
// i=fastrand()%l;
//}
i = rand_fast() % l;
if (sess && sess->client_myds && sess->client_myds->myconn && sess->client_myds->myconn->userinfo) {
PgSQL_Connection * client_conn = sess->client_myds->myconn;
get_random_MyConn_inner_search(i, l, conn_found_idx, connection_quality_level, number_of_matching_session_variables, client_conn);

@ -404,7 +404,7 @@ bool PgSQL_Protocol::generate_pkt_initial_handshake(bool send, void** _ptr, unsi
// Fallback method: using a basic pseudo-random generator
srand((unsigned int)time(NULL));
for (size_t i = 0; i < sizeof((*myds)->tmp_login_salt); i++) {
(*myds)->tmp_login_salt[i] = rand() % 256;
(*myds)->tmp_login_salt[i] = rand_fast() % 256;
}
}
pgpkt.write_generic(type, "ib", PG_PKT_AUTH_MD5, (*myds)->tmp_login_salt, sizeof((*myds)->tmp_login_salt));

@ -2943,7 +2943,7 @@ void PgSQL_Thread::run() {
#ifdef IDLE_THREADS
if (GloVars.global.idle_threads) {
if (idle_maintenance_thread == false) {
int r = rand() % (GloPTH->num_threads);
int r = rand_fast() % (GloPTH->num_threads);
PgSQL_Thread* thr = GloPTH->pgsql_threads_idles[r].worker;
worker_thread_assigns_sessions_to_idle_thread(thr);
worker_thread_gets_sessions_from_idle_thread();
@ -2967,7 +2967,7 @@ void PgSQL_Thread::run() {
// The delay for the active-wait is a fraction of 'poll_timeout'. Since other
// threads may be waiting on poll for further operations, checks are meaningless
// until that timeout expires (other workers make progress).
usleep(std::min(std::max(pgsql_thread___poll_timeout/20, 10000), 40000) + (rand() % 2000));
usleep(std::min(std::max(pgsql_thread___poll_timeout/20, 10000), 40000) + (rand_fast() % 2000));
}
proxy_debug(PROXY_DEBUG_NET, 7, "poll_timeout=%u\n", mypolls.poll_timeout);
@ -3124,7 +3124,7 @@ void PgSQL_Thread::run() {
__run_skip_2 :
if (GloVars.global.idle_threads && idle_maintenance_thread) {
// this is an idle thread
unsigned int w = rand() % (GloPTH->num_threads);
unsigned int w = rand_fast() % (GloPTH->num_threads);
PgSQL_Thread* thr = GloPTH->pgsql_threads[w].worker;
if (resume_mysql_sessions->len) {
idle_thread_assigns_sessions_to_worker_thread(thr);

@ -228,7 +228,7 @@ Query_Processor<QP_DERIVED>::Query_Processor(int _query_rules_fast_routing_algor
rand_del[1] = '-';
rand_del[2] = '-';
for (int i = 3; i < 11; i++) {
rand_del[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
rand_del[i] = alphanum[rand_fast() % (sizeof(alphanum) - 1)];
}
rand_del[11] = '-';
rand_del[12] = '-';
@ -1878,9 +1878,9 @@ void Query_Processor<QP_DERIVED>::update_query_digest(uint64_t digest_total, uin
TypeConnInfo* ui, unsigned long long t, unsigned long long n, const char* client_addr, unsigned long long rows_affected,
unsigned long long rows_sent) {
QP_query_digest_stats* qds;
pthread_rwlock_wrlock(&digest_rwlock);
std::unordered_map<uint64_t, void*>::iterator it;
std::unordered_map<uint64_t, void *>::iterator it;
pthread_rwlock_wrlock(&digest_rwlock);
it=digest_umap.find(digest_total);
if (it != digest_umap.end()) {
// found

Loading…
Cancel
Save