* 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.
*/
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);
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.'() {