Increase startup delay from 1 sec to 2 sec 72/140872/2
authorhalil.cakal <halil.cakal@est.tech>
Tue, 13 May 2025 10:19:54 +0000 (11:19 +0100)
committerhalil.cakal <halil.cakal@est.tech>
Tue, 13 May 2025 14:13:03 +0000 (15:13 +0100)
- 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 <halil.cakal@est.tech>
cps-application/src/main/java/org/onap/cps/startup/InstanceStartupDelayManager.java
cps-application/src/test/groovy/org/onap/cps/startup/InstanceStartupDelayManagerSpec.groovy

index d7baec7..4ce9422 100644 (file)
@@ -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);
index ad92322..8ac87cb 100644 (file)
@@ -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.'() {