Fix postgresql database creation failures from prepare func

postgresql needs to restart during the bootstrap, but the postgres
driver still reports the healthy status.

this commit resets the healthy_counts when status is not healthy,
and make state_healthy_counts configurable.

Change-Id: I746b86326790dbc667f4f0d6dabcd1a656502273
This commit is contained in:
wu.chunyang 2023-08-01 07:30:52 +00:00
parent 3ed6d3f5b1
commit 8cd982be5c
3 changed files with 11 additions and 4 deletions

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Fix potential PostgreSQL database creation failures from the instance create API

View File

@ -201,6 +201,8 @@ common_opts = [
'change.'),
cfg.IntOpt('state_change_poll_time', default=3,
help='Interval between state change poll requests (seconds).'),
cfg.IntOpt('state_healthy_counts', default=5,
help='consecutive success db connections for status HEALTHY'),
cfg.IntOpt('agent_heartbeat_time', default=10,
help='Maximum time (in seconds) for the Guest Agent to reply '
'to a heartbeat request.'),

View File

@ -290,15 +290,15 @@ class BaseDbStatus(object):
# outside.
loop = True
# We need 3 (by default) consecutive success db connections for status
# We need 5 (by default) consecutive success db connections for status
# 'HEALTHY'
healthy_count = 0
state_healthy_counts = CONF.state_healthy_counts - 1
while loop:
self.status = self.get_actual_db_status()
if self.status == status:
if (status == service_status.ServiceStatuses.HEALTHY and
healthy_count < 2):
healthy_count < state_healthy_counts):
healthy_count += 1
time.sleep(CONF.state_change_poll_time)
continue
@ -310,7 +310,8 @@ class BaseDbStatus(object):
# should we remain in this loop? this is the thing
# that emulates the do-while construct.
loop = (time.time() < end_time)
# reset the healthy_count
healthy_count = 0
# no point waiting if our time is up and we're
# just going to error out anyway.
if loop: