Skip to content

CIRC-2697 Add request queue locking - #1702

Open
alexanderkurash wants to merge 3 commits into
masterfrom
CIRC-2697
Open

alexanderkurash wants to merge 3 commits into
masterfrom
CIRC-2697

Conversation

@alexanderkurash

Copy link
Copy Markdown
Contributor

Purpose

Prevent race conditions when concurrent operations recalculate positions in the same request queue.

Previously, simultaneous request creation or other queue-changing operations could read the same queue state and persist duplicate or inconsistent positions.

https://folio-org.atlassian.net/browse/CIRC-2697

Approach

  • Introduced a database-backed request queue lock using the request-queue-lock-storage interface.
  • Identified the effective queue by:
    • instance ID when TLR is enabled;
    • item ID when TLR is disabled.
  • Limited the critical section to:
    1. acquiring the effective queue lock;
    2. retrieving a fresh lightweight queue;
    3. recalculating and persisting queue changes;
    4. releasing the lock.
  • Applied locking to every flow that changes request positions:
    • request creation;
    • check-in and check-out;
    • cancellation and deletion;
    • moving requests between items;
    • manual queue reordering.
  • Added configurable lock TTL, retry interval, maximum wait time, and feature enablement through mod-settings.
  • Added retry with jitter for lock contention and a 503 Service Unavailable response when lock acquisition times out.
  • Ensured locks are released after both successful and failed operations.
  • Added unit and integration coverage, including concurrent item-level and title-level request creation.

This change requires the corresponding request-queue-lock-storage implementation from CIRCSTORE-684.

TODOS and Open Questions

  • Check logging — lock acquisition, release, timeout, failure, wait time, and hold time are logged.
  • Run the full test suite — 3,884 tests passed with no failures or errors.

@sonarqubecloud

Copy link
Copy Markdown


boolean allCreatorsReady = ready.await(5, TimeUnit.SECONDS);
start.countDown();
Assertions.assertTrue(allCreatorsReady);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

static import?

RequestQueueKey key = RequestQueueKey.from(records);
String message = "Request queue positions are not sequential for "
+ key.queueType() + ":" + key.queueId();
log.error(message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add method name to log message?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants