Skip to content

feat(common): #RBACK-205, vertx lock on startup scripts#958

Open
pb-jo wants to merge 1 commit intodevfrom
feat-RBACK-205-vertx-lock-on-startup-scripts
Open

feat(common): #RBACK-205, vertx lock on startup scripts#958
pb-jo wants to merge 1 commit intodevfrom
feat-RBACK-205-vertx-lock-on-startup-scripts

Conversation

@pb-jo
Copy link
Contributor

@pb-jo pb-jo commented Feb 4, 2026

Description

Add a vertx lock on startup scripts (migrations...).

Fixes

#RBACK-205

Type of change

Please check options that are relevant.

  • Chore (PATCH)
  • Doc (PATCH)
  • Bug fix (PATCH)
  • New feature (MINOR)

Which packages changed?

Please check the name of the package you changed

  • admin
  • app-registry
  • archive
  • auth
  • cas
  • common
  • communication
  • conversation
  • directory
  • feeder
  • infra
  • portal
  • session
  • test
  • tests
  • timeline
  • workspace

Tests

  1. Describe here the tests you performed
  2. Step by step
  3. With expected results

Reminder

  • Security flaws

  • Performance impacts (think bulk !)

  • Unit tests were replayed

  • Unit tests were added and/or changed

  • I have updated the reminder for the version including my modifications

  • All done ! 😃

@pb-jo pb-jo requested review from Copilot and juniorode February 4, 2026 16:08
@pb-jo pb-jo self-assigned this Feb 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a distributed locking mechanism using Vert.x shared data to prevent concurrent execution of SQL migration scripts during application startup. This ensures that only one instance processes database migrations at a time in a clustered environment.

Changes:

  • Added configurable timeout and delay constants for SQL lock management
  • Wrapped SQL migration execution with a Vert.x distributed lock acquisition and release mechanism
  • Enhanced error handling and logging for lock acquisition failures

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +343 to +344
sharedData.releaseLockAfterDelay(lock, SQL_LOCK_RELEASE_DELAY);
if (result.failed()) {
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lock is released even when migration fails. If a migration fails partway through, releasing the lock allows another instance to potentially run migrations on a database in an inconsistent state. Consider only releasing the lock on successful completion, or implementing a retry mechanism with appropriate failure handling.

Suggested change
sharedData.releaseLockAfterDelay(lock, SQL_LOCK_RELEASE_DELAY);
if (result.failed()) {
if (result.succeeded()) {
sharedData.releaseLockAfterDelay(lock, SQL_LOCK_RELEASE_DELAY);
} else {

Copilot uses AI. Check for mistakes.
final SharedDataHelper sharedData = SharedDataHelper.getInstance();
final String lockName = "sql_migration_" + schema;
sharedData.getLock(lockName, SQL_LOCK_TIMEOUT)
.onFailure(th -> log.debug("Lock '" + lockName + "' unavailable, another instance is processing SQL scripts", th))
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When lock acquisition fails, the application continues without running migrations, which could lead to the application starting with an outdated database schema. This should either fail the startup process or implement a retry mechanism to ensure migrations are eventually executed.

Copilot uses AI. Check for mistakes.
final SharedDataHelper sharedData = SharedDataHelper.getInstance();
final String lockName = "sql_migration_" + schema;
sharedData.getLock(lockName, SQL_LOCK_TIMEOUT)
.onFailure(th -> log.debug("Lock '" + lockName + "' unavailable, another instance is processing SQL scripts", th))
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lock acquisition failure is logged at debug level, making it easy to miss in production environments. This should be logged at a higher level (warn or error) since it represents a significant operational event that affects application startup behavior.

Suggested change
.onFailure(th -> log.debug("Lock '" + lockName + "' unavailable, another instance is processing SQL scripts", th))
.onFailure(th -> log.warn("Lock '" + lockName + "' unavailable, another instance is processing SQL scripts", th))

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants