extern StatList login_client_list;
extern ObjectCache *client_cache;
extern ObjectCache *server_cache;
+extern ObjectCache *db_cache;
+extern ObjectCache *pool_cache;
+extern ObjectCache *user_cache;
PgDatabase *find_database(const char *name);
PgUser *find_user(const char *name);
list_del(&pool->map_head);
statlist_remove(&pool->head, &pool_list);
- free(pool);
+ obj_free(pool_cache, pool);
}
static void kill_database(PgDatabase *db)
kill_pool(pool);
}
if (db->forced_user)
- free(db->forced_user);
+ obj_free(user_cache, db->forced_user);
statlist_remove(&db->head, &database_list);
- free(db);
+ obj_free(db_cache, db);
}
/* as [pgbouncer] section can be loaded after databases,
ObjectCache *server_cache;
ObjectCache *client_cache;
+ObjectCache *db_cache;
+ObjectCache *pool_cache;
+ObjectCache *user_cache;
/*
* libevent may still report events when event_del()
void init_objects(void)
{
tree_init(&user_tree, user_node_cmp, NULL);
+ user_cache = objcache_create("user_cache", sizeof(PgUser), 0, NULL, NULL);
+ db_cache = objcache_create("db_cache", sizeof(PgDatabase), 0, NULL, NULL);
+ pool_cache = objcache_create("pool_cache", sizeof(PgPool), 0, NULL, NULL);
+
+ if (!user_cache || !db_cache || !pool_cache)
+ fatal("cannot create initial caches");
}
/* initialization after config loading */
/* create new object if needed */
if (db == NULL) {
- db = zmalloc(sizeof(*db));
+ db = obj_alloc(db_cache);
if (!db)
return NULL;
PgUser *user = find_user(name);
if (user == NULL) {
- user = zmalloc(sizeof(*user));
+ user = obj_alloc(user_cache);
if (!user)
return NULL;
{
PgUser *user = db->forced_user;
if (!user) {
- user = zmalloc(sizeof(*user));
+ user = obj_alloc(user_cache);
if (!user)
return NULL;
list_init(&user->head);
{
PgPool *pool;
- pool = zmalloc(sizeof(*pool));
+ pool = obj_alloc(pool_cache);
if (!pool)
return NULL;