Lines 477-487
Link Here
|
477 |
} |
477 |
} |
478 |
|
478 |
|
|
|
479 |
static void kill_database(PgDatabase *db); |
480 |
static void cleanup_inactive_autodatabases(void) |
481 |
{ |
482 |
List *item, *tmp; |
483 |
PgDatabase *db; |
484 |
usec_t age; |
485 |
usec_t now = get_cached_time(); |
486 |
|
487 |
if (cf_autodb_idle_timeout <= 0) |
488 |
return; |
489 |
|
490 |
statlist_for_each_safe(item, &autodatabase_idle_list, tmp) { |
491 |
db = container_of(item, PgDatabase, head); |
492 |
age = now - db->inactive_time; |
493 |
if (age > cf_autodb_idle_timeout) |
494 |
kill_database(db); |
495 |
else |
496 |
break; |
497 |
} |
498 |
} |
499 |
|
479 |
/* full-scale maintenance, done only occasionally */ |
500 |
/* full-scale maintenance, done only occasionally */ |
480 |
static void do_full_maint(int sock, short flags, void *arg) |
501 |
static void do_full_maint(int sock, short flags, void *arg) |
481 |
{ |
502 |
{ |
482 |
List *item; |
503 |
List *item, *tmp; |
483 |
PgPool *pool; |
504 |
PgPool *pool; |
484 |
|
505 |
|
485 |
statlist_for_each(item, &pool_list) { |
506 |
statlist_for_each_safe(item, &pool_list, tmp) { |
486 |
pool = container_of(item, PgPool, head); |
507 |
pool = container_of(item, PgPool, head); |
487 |
if (pool->db->admin) |
508 |
if (pool->db->admin) |
Lines 489-494
Link Here
|
489 |
pool_server_maint(pool); |
510 |
pool_server_maint(pool); |
490 |
pool_client_maint(pool); |
511 |
pool_client_maint(pool); |
|
|
512 |
if (pool->db->db_auto && pool->db->inactive_time == 0 && |
513 |
pool_client_count(pool) == 0 && pool_server_count(pool) == 0 ) { |
514 |
pool->db->inactive_time = get_cached_time(); |
515 |
statlist_remove(&pool->db->head, &database_list); |
516 |
statlist_append(&pool->db->head, &autodatabase_idle_list); |
517 |
} |
491 |
} |
518 |
} |
492 |
|
519 |
|
|
|
520 |
cleanup_inactive_autodatabases(); |
521 |
|
493 |
cleanup_client_logins(); |
522 |
cleanup_client_logins(); |
494 |
|
523 |
|
Lines 536-540
Link Here
|
536 |
List *item, *tmp; |
565 |
List *item, *tmp; |
537 |
|
566 |
|
538 |
log_warning("dropping database '%s' as it does not exist anymore", db->name); |
567 |
log_warning("dropping database '%s' as it does not exist anymore or inactive auto-database", db->name); |
539 |
|
568 |
|
540 |
statlist_for_each_safe(item, &pool_list, tmp) { |
569 |
statlist_for_each_safe(item, &pool_list, tmp) { |
Lines 547-551
Link Here
|
547 |
if (db->connect_query) |
576 |
if (db->connect_query) |
548 |
free((void *)db->connect_query); |
577 |
free((void *)db->connect_query); |
549 |
statlist_remove(&db->head, &database_list); |
578 |
if (db->inactive_time) |
|
|
579 |
statlist_remove(&db->head, &autodatabase_idle_list); |
580 |
else |
581 |
statlist_remove(&db->head, &database_list); |
550 |
obj_free(db_cache, db); |
582 |
obj_free(db_cache, db); |
551 |
} |
583 |
} |