Skip to content

Commit cbcb500

Browse files
committed
Optimize refreshing global memory info
1 parent 0b03c08 commit cbcb500

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

tc_mysql_module.c

+31-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
typedef struct {
1616
time_t last_refresh_time;
17+
uint32_t seq_after_ps;
1718
uint32_t sec_auth_checked:1;
1819
uint32_t sec_auth_not_yet_done:1;
1920
uint32_t first_auth_sent:1;
@@ -389,6 +390,13 @@ check_pack_needed_for_recons(tc_sess_t *s, tc_iph_t *ip, tc_tcph_t *tcp)
389390
tc_mysql_session *mysql_sess;
390391
mysql_table_item_t *item;
391392

393+
mysql_sess = s->data;
394+
395+
if (s->sm.fake_syn) {
396+
if (before(ntohl(tcp->seq), mysql_sess->seq_after_ps)) {
397+
return false;
398+
}
399+
}
392400

393401
if (s->cur_pack.cont_len > 0) {
394402

@@ -402,8 +410,6 @@ check_pack_needed_for_recons(tc_sess_t *s, tc_iph_t *ip, tc_tcph_t *tcp)
402410

403411
if (command != COM_STMT_PREPARE) {
404412

405-
mysql_sess = s->data;
406-
407413
diff = tc_time() - mysql_sess->last_refresh_time;
408414

409415
if (diff >= MAX_RETHRESH_TIME) {
@@ -495,16 +501,26 @@ mysql_dispose_auth(tc_sess_t *s, tc_iph_t *ip, tc_tcph_t *tcp)
495501

496502
mysql_sess->first_auth_sent = 1;
497503

498-
release_resources(s->hash_key);
499-
500-
value = (void *) cp_fr_ip_pack(ctx.fir_auth_pool, ip);
501-
hash_add(ctx.fir_auth_table, ctx.fir_auth_pool, s->hash_key, value);
502-
mysql_sess->last_refresh_time = tc_time();
504+
if (!s->sm.fake_syn) {
505+
release_resources(s->hash_key);
506+
507+
value = (void *) cp_fr_ip_pack(ctx.fir_auth_pool, ip);
508+
hash_add(ctx.fir_auth_table, ctx.fir_auth_pool, s->hash_key, value);
509+
mysql_sess->last_refresh_time = tc_time();
503510

504511
#if (TC_DETECT_MEMORY)
505-
tc_log_info(LOG_INFO, 0, "s:%p,hash add fir auth:%llu,value:%p, p:%u",
506-
s, s->hash_key, value, ntohs(s->src_port));
512+
tc_log_info(LOG_INFO, 0, "s:%p,hash add fir auth:%llu,value:%p, p:%u",
513+
s, s->hash_key, value, ntohs(s->src_port));
507514
#endif
515+
} else {
516+
hash_node *hn = hash_find_node(ctx.fir_auth_table, s->hash_key);
517+
if (hn != NULL) {
518+
mysql_sess->last_refresh_time = hn->create_time;
519+
} else {
520+
tc_log_info(LOG_WARN, 0, "hash node for key:%llu is nil",
521+
s->hash_key);
522+
}
523+
}
508524

509525
} else if (mysql_sess->first_auth_sent && mysql_sess->sec_auth_not_yet_done)
510526
{
@@ -519,8 +535,10 @@ mysql_dispose_auth(tc_sess_t *s, tc_iph_t *ip, tc_tcph_t *tcp)
519535
change_clt_second_auth_content(payload, cont_len, encryption);
520536
mysql_sess->sec_auth_not_yet_done = 0;
521537

522-
value = (void *) cp_fr_ip_pack(ctx.sec_auth_pool, ip);
523-
hash_add(ctx.sec_auth_table, ctx.sec_auth_pool, s->hash_key, value);
538+
if (!s->sm.fake_syn) {
539+
value = (void *) cp_fr_ip_pack(ctx.sec_auth_pool, ip);
540+
hash_add(ctx.sec_auth_table, ctx.sec_auth_pool, s->hash_key, value);
541+
}
524542
}
525543

526544
return TC_OK;
@@ -588,6 +606,8 @@ prepare_for_renew_session(tc_sess_t *s, tc_iph_t *ip, tc_tcph_t *tcp)
588606
tc_log_debug2(LOG_INFO, 0, "total len subtracted:%u,p:%u", tot_clen,
589607
ntohs(s->src_port));
590608

609+
mysql_sess->seq_after_ps = ntohl(tcp->seq);
610+
591611
tcp->seq = htonl(ntohl(tcp->seq) - tot_clen);
592612
fir_tcp->seq = htonl(ntohl(tcp->seq) + 1);
593613
tc_save_pack(s, s->slide_win_packs, fir_ip, fir_tcp);

0 commit comments

Comments
 (0)