From: halil.cakal Date: Tue, 13 May 2025 10:19:54 +0000 (+0100) Subject: Increase startup delay from 1 sec to 2 sec X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=cf5371790ad3ddf82fee5037e71508fba32833f6;p=cps.git Increase startup delay from 1 sec to 2 sec - if cps-ncmp-1 got a head start before cps-ncmp-0, and spin-off faster than cps-ncmp-0 the current delay '1 sec' is not enough to prevent race condition between liquibase instances Issue-ID: CPS-2807 Change-Id: I9ed5780daea4b95e6a2026e46427c7f4e464818e Signed-off-by: halil.cakal --- diff --git a/cps-application/src/main/java/org/onap/cps/startup/InstanceStartupDelayManager.java b/cps-application/src/main/java/org/onap/cps/startup/InstanceStartupDelayManager.java index d7baec7c08..4ce94225e7 100644 --- a/cps-application/src/main/java/org/onap/cps/startup/InstanceStartupDelayManager.java +++ b/cps-application/src/main/java/org/onap/cps/startup/InstanceStartupDelayManager.java @@ -36,7 +36,7 @@ public class InstanceStartupDelayManager { * This method is useful in environments with multiple instances. * (e.g., Docker Compose, Kubernetes), where simultaneous Liquibase executions might result in conflicts. * Delay calculation: - * - For host names that match {host-name}-{sequence-number} the delay wil be 1 second times the sequence number. + * - For host names that match {host-name}-{sequence-number} the delay will be 2 second times the sequence number. * - please note, the sequence number can be 2 digits at most. * - For other names the delay is calculated as the hash code of that name modulus 10,000 ms i.e. up to 10,000 ms. */ @@ -47,7 +47,7 @@ public class InstanceStartupDelayManager { final Matcher matcher = HOST_NAME_WITH_SEQUENCE_PATTERN.matcher(hostName); final long startupDelayInMillis; if (matcher.matches()) { - startupDelayInMillis = Integer.valueOf(matcher.group(1)) * 1_000L; + startupDelayInMillis = Integer.valueOf(matcher.group(1)) * 2_000L; log.info("Sequenced host name detected, calculated delay = {} ms", startupDelayInMillis); } else { startupDelayInMillis = Math.abs(hostName.hashCode() % 10_000L); diff --git a/cps-application/src/test/groovy/org/onap/cps/startup/InstanceStartupDelayManagerSpec.groovy b/cps-application/src/test/groovy/org/onap/cps/startup/InstanceStartupDelayManagerSpec.groovy index ad92322eb1..8ac87cb2c2 100644 --- a/cps-application/src/test/groovy/org/onap/cps/startup/InstanceStartupDelayManagerSpec.groovy +++ b/cps-application/src/test/groovy/org/onap/cps/startup/InstanceStartupDelayManagerSpec.groovy @@ -38,10 +38,10 @@ class InstanceStartupDelayManagerSpec extends Specification { where: ' following sequenced host names are used' scenario | hostName || expectedDelayInSeconds 'our usual host-name' | 'cps-and-ncmp-0' || 0 - 'dash and 1 digit at end' | 'host-1' || 1 - 'dash and 2 digits at end' | 'host-23' || 23 - 'digits in name' | 'host-2-34' || 34 - 'weird name ending in digits' | 't@st : - { " -56' || 56 + 'dash and 1 digit at end' | 'host-1' || 2 + 'dash and 2 digits at end' | 'host-23' || 46 + 'digits in name' | 'host-2-34' || 68 + 'weird name ending in digits' | 't@st : - { " -56' || 112 } def 'Startup delay with un-sequenced host name.'() {