From 4667c80b90ff686c6dd16ae6c109753a55b90a4e Mon Sep 17 00:00:00 2001
From: Damian Dabrowski <damian@dabrowski.cloud>
Date: Thu, 2 Dec 2021 19:19:33 +0100
Subject: [PATCH] Database connection pooling improvements

- Implemented new variable ``connection_recycle_time`` responsible for SQLAlchemy's connection recycling
- Set new default values for db pooling variables which are inherited from the global ones.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible/+/819424
Change-Id: I28c64b44eadfd726e07cb7159e5d3d94fde106ed
---
 defaults/main.yml           | 4 ++++
 templates/designate.conf.j2 | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/defaults/main.yml b/defaults/main.yml
index 63e6da9..246ec08 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -68,6 +68,10 @@ designate_galera_database: designate
 designate_galera_use_ssl: "{{ galera_use_ssl | default(False) }}"
 designate_galera_ssl_ca_cert: "{{ galera_ssl_ca_cert | default('') }}"
 designate_galera_port: "{{ galera_port | default('3306') }}"
+designate_db_max_overflow: "{{ openstack_db_max_overflow | default('50') }}"
+designate_db_max_pool_size: "{{ openstack_db_max_pool_size | default('5') }}"
+designate_db_pool_timeout: "{{ openstack_db_pool_timeout | default('30') }}"
+designate_db_connection_recycle_time: "{{ openstack_db_connection_recycle_time | default('600') }}"
 
 ## Oslo Messaging
 # RPC
diff --git a/templates/designate.conf.j2 b/templates/designate.conf.j2
index af3d4d1..387c4c2 100644
--- a/templates/designate.conf.j2
+++ b/templates/designate.conf.j2
@@ -373,7 +373,11 @@ endpoint_type = internalURL
 # SQLAlchemy Storage
 #-----------------------
 [storage:sqlalchemy]
-connection = mysql+pymysql://{{ designate_galera_user }}:{{ designate_galera_password }}@{{ designate_galera_address }}/{{ designate_galera_database }}?charset=utf8{% if designate_galera_use_ssl | bool %}&ssl_verify_cert=true{% if designate_galera_ssl_ca_cert | length > 0 %}&ssl_ca={{ designate_galera_ssl_ca_cert }}{% endif %}{% endif %}
+connection = mysql+pymysql://{{ designate_galera_user }}:{{ designate_galera_password }}@{{ designate_galera_address }}/{{ designate_galera_database }}?charset=utf8{% if designate_galera_use_ssl | bool %}&ssl_verify_cert=true{% if designate_galera_ssl_ca_cert | length > 0 %}&ssl_ca={{ designate_galera_ssl_ca_cert }}{% endif %}{% endif +%}
+max_overflow = {{ designate_db_max_overflow }}
+max_pool_size = {{ designate_db_max_pool_size }}
+pool_timeout = {{ designate_db_pool_timeout }}
+connection_recycle_time = {{ designate_db_connection_recycle_time }}
 
 #connection_debug = 0
 #connection_trace = False