@@ -34,7 +34,7 @@ static int
3434init_mysql_module ()
3535{
3636
37- ctx .pool = tc_create_pool (TC_DEFAULT_POOL_SIZE , 0 , 0 );
37+ ctx .pool = tc_create_pool (TC_PLUGIN_POOL_SIZE , 0 , 0 );
3838
3939 if (ctx .pool ) {
4040
@@ -49,9 +49,57 @@ init_mysql_module()
4949}
5050
5151
52+ static void
53+ remove_obsolete_resources (int is_full )
54+ {
55+ time_t thresh_access_tme ;
56+ uint32_t i , cnt = 0 ;
57+ link_list * l ;
58+ hash_node * hn ;
59+ p_link_node ln , next_ln ;
60+
61+ if (ctx .table == NULL || ctx .table -> total == 0 ) {
62+ return ;
63+ }
64+
65+ if (is_full ) {
66+ thresh_access_tme = tc_time () + 1 ;
67+ } else {
68+ thresh_access_tme = tc_time () - MAX_IDLE_TIME ;
69+ }
70+
71+ for (i = 0 ; i < ctx .table -> size ; i ++ ) {
72+ l = get_link_list (ctx .table , i );
73+ if (l -> size > 0 ) {
74+ ln = link_list_first (l );
75+ while (ln ) {
76+ hn = (hash_node * ) ln -> data ;
77+ next_ln = link_list_get_next (l , ln );
78+ if (hn -> access_time < thresh_access_tme ) {
79+ ctx .table -> total -- ;
80+ link_list_remove (l , ln );
81+ tc_pfree (ctx .pool , hn -> data );
82+ tc_pfree (ctx .pool , ln -> data );
83+ tc_pfree (ctx .pool , ln );
84+ }
85+ ln = next_ln ;
86+ }
87+
88+ cnt += l -> size ;
89+
90+ if (ctx .table -> total == cnt ) {
91+ break ;
92+ }
93+ }
94+ }
95+ }
96+
97+
5298static void
5399exit_mysql_module ()
54100{
101+ tc_log_info (LOG_INFO , 0 , "call exit_mysql_module" );
102+ remove_obsolete_resources (1 );
55103 if (ctx .pool != NULL ) {
56104 tc_destroy_pool (ctx .pool );
57105 ctx .table = NULL ;
@@ -268,6 +316,7 @@ proc_when_sess_destroyed(tc_sess_t *s)
268316 tc_pfree (ctx .pool , tln );
269317 }
270318
319+ tc_pfree (ctx .pool , item );
271320 tc_pfree (ctx .pool , list );
272321
273322 hash_del (ctx .table , ctx .pool , s -> hash_key );
@@ -349,6 +398,7 @@ tc_module_t tc_mysql_module = {
349398 NULL ,
350399 init_mysql_module ,
351400 exit_mysql_module ,
401+ remove_obsolete_resources ,
352402 check_renew_session ,
353403 prepare_for_renew_session ,
354404 check_pack_needed_for_recons ,
0 commit comments