Skip to content

Commit ae500cc

Browse files
authored
#53 Fixed issue with multi-database configuration (#54)
* #53 Fixed issue with multi-database configuration * #53 Added short-circuit if system is in trouble
1 parent 3bb1a1a commit ae500cc

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
[markdownlint](https://dlaa.me/markdownlint/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [1.0.10] - 2023-10-05
10+
11+
### Changed in 1.0.10
12+
13+
- Fix issue with calculating wait time in multi-database configuration
14+
915
## [1.0.9] - 2023-02-09
1016

1117
### Changed in 1.0.9

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
psycopg2-binary==2.9.9
2-

senzing_governor.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
# Metadata
4242

4343
__all__ = []
44-
__version__ = "1.0.9" # See https://www.python.org/dev/peps/pep-0396/
44+
__version__ = "1.0.10" # See https://www.python.org/dev/peps/pep-0396/
4545
__date__ = '2020-08-26'
46-
__updated__ = '2023-02-09'
46+
__updated__ = '2023-10-05'
4747

4848
# See https://github.com/Senzing/knowledge-base/blob/main/lists/senzing-product-ids.md
4949
SENZING_PRODUCT_ID = "5017"
@@ -370,9 +370,10 @@ def govern(self, *args, **kwargs):
370370

371371
if (self.counter % self.interval == 0) or (time.time() > self.next_check_time):
372372

373-
# Reset timer.
373+
# Reset timer and calculated wait time.
374374

375375
self.next_check_time = time.time() + self.check_time_interval_in_seconds
376+
self.old_wait_time = 0.0
376377

377378
# Go through each database connection to determine if watermark is above high_watermark.
378379

@@ -391,21 +392,27 @@ def govern(self, *args, **kwargs):
391392
SENZING_PRODUCT_ID, database_host, database_name, watermark, oid_name, self.high_watermark))
392393
self.last_log_time = current_log_time
393394

394-
# When we get above the low water mark, use our wait time
395-
# function to start to slow down.
395+
# When we get above the low water mark, use our wait time function to start to slow down.
396396

397397
if watermark > self.low_watermark: # This all needs to be done based on the worst XID if all DBs
398398
wait_time = self.get_wait_time(watermark)
399+
400+
# Short-circuit if the the system is in trouble.
401+
402+
if wait_time < 0:
403+
return -1.0
404+
405+
# Calculate largest wait time.
406+
399407
current_log_time = time.time()
400-
# log a message when the wait_time changes OR if the log interval has passed
401-
if (wait_time != self.old_wait_time) or ((current_log_time - self.last_log_time) > self.log_interval_in_seconds):
402-
logging.info("senzing-{0}0005I Governor waiting {1} seconds for {2} database age(XID) to go from current value of {3} ({4}) to low watermark of {5}.".format(
408+
409+
# Log a message when the wait_time changes OR if the log interval has passed
410+
411+
if (wait_time > self.old_wait_time) or ((current_log_time - self.last_log_time) > self.log_interval_in_seconds):
412+
logging.info("senzing-{0}0005I Governor suggests waiting {1} seconds for {2} database age(XID) to go from current value of {3} ({4}) to low watermark of {5}.".format(
403413
SENZING_PRODUCT_ID, wait_time, database_name, watermark, oid_name, self.low_watermark))
404-
self.old_wait_time = wait_time
414+
self.old_wait_time = max(self.old_wait_time, wait_time)
405415
self.last_log_time = current_log_time
406-
elif self.old_wait_time != 0.0:
407-
logging.info("senzing-{0}0006I Governor delay ended. Returning to no wait.".format(SENZING_PRODUCT_ID))
408-
self.old_wait_time = 0.0
409416
return self.old_wait_time
410417

411418
def close(self, *args, **kwargs):

0 commit comments

Comments
 (0)