* must be separated. This avoids the need to re-launch lot
* of connections together.
*/
- if (cf_server_lifetime > 0 && pool->db->pool_size > 0)
+ if (pool->db->pool_size > 0)
lifetime_kill_gap = cf_server_lifetime / pool->db->pool_size;
/* disconnect idle servers if needed */
disconnect_server(server, true, "SV_USED server got dirty");
} else if (cf_server_idle_timeout > 0 && idle > cf_server_idle_timeout) {
disconnect_server(server, true, "server idle timeout");
- } else if (cf_server_lifetime > 0 && age > cf_server_lifetime) {
+ } else if (age >= cf_server_lifetime) {
if (pool->last_lifetime_disconnect + lifetime_kill_gap <= now) {
disconnect_server(server, true, "server lifetime over");
pool->last_lifetime_disconnect = now;
return res;
}
+static bool life_over(PgSocket *server)
+{
+ PgPool *pool = server->pool;
+ usec_t lifetime_kill_gap = 0;
+ usec_t now = get_cached_time();
+ usec_t age = now - server->connect_time;
+ usec_t last_kill = now - pool->last_lifetime_disconnect;
+
+ if (age < cf_server_lifetime)
+ return false;
+
+ if (pool->db->pool_size > 0)
+ lifetime_kill_gap = cf_server_lifetime / pool->db->pool_size;
+
+ if (last_kill >= lifetime_kill_gap)
+ return true;
+
+ return false;
+}
+
/* connecting/active -> idle, unlink if needed */
bool release_server(PgSocket *server)
{
fatal("bad server state in release_server");
}
+ /* enforce lifetime immidiately on release */
+ if (server->state != SV_LOGIN && life_over(server)) {
+ disconnect_server(server, true, "server_lifetime");
+ return false;
+ }
+
Assert(server->link == NULL);
slog_noise(server, "release_server: new state=%d", newstate);
change_server_state(server, newstate);