Skip to content

Conversation

@JasonWildMe
Copy link
Collaborator

@JasonWildMe JasonWildMe commented Dec 27, 2025

Prevents request stampede and blocked queueing when Wildbook IA very active and constantly checking WBIA for its queue size.

Key Changes to WbiaQueueUtil.java

  1. Cache Stampede Prevention with AtomicBoolean

private static final AtomicBoolean isReloading = new AtomicBoolean(false);

  • Uses compareAndSet(false, true) to ensure only ONE thread performs the refresh
  • Other threads immediately return with stale (but valid) cached values
  • Lock is released in finally block to prevent deadlocks
  1. Removed synchronized from all methods
  • Original: All methods were synchronized, causing threads to queue and wait
  • Now: Uses volatile for thread-safe reads without blocking
  1. Made all static fields volatile
  • Ensures visibility across threads without synchronization
  • Threads always see the latest written values
  1. Fixed double-call bug
  • Original had a strange pattern calling reloadIfNeeded twice (in try AND finally)
  • Now each getter calls it exactly once
  1. Atomic value updates
  • Uses temporary variables to calculate all values first
  • Then assigns them all at once, preventing partially-updated state

Prevent request stampede
@JasonWildMe JasonWildMe self-assigned this Dec 27, 2025
@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2025

Codecov Report

❌ Patch coverage is 0% with 94 lines in your changes missing coverage. Please review.
✅ Project coverage is 11.54%. Comparing base (505e91f) to head (ef3e3cc).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/main/java/org/ecocean/ia/WbiaQueueUtil.java 0.00% 94 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1358      +/-   ##
============================================
- Coverage     11.55%   11.54%   -0.01%     
  Complexity     1307     1307              
============================================
  Files           710      710              
  Lines         72933    72953      +20     
  Branches      13954    13957       +3     
============================================
  Hits           8425     8425              
- Misses        63597    63617      +20     
  Partials        911      911              
Flag Coverage Δ
backend 11.54% <0.00%> (-0.01%) ⬇️
frontend 11.54% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JasonWildMe JasonWildMe marked this pull request as ready for review December 28, 2025 21:26
@JasonWildMe JasonWildMe requested a review from naknomum December 28, 2025 21:26
Copy link
Member

@naknomum naknomum left a comment

Choose a reason for hiding this comment

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

going to say it looks good, as much as i can say i can following threading code entirely in my head.

@JasonWildMe JasonWildMe merged commit 1553c7f into main Jan 1, 2026
1 check passed
@JasonWildMe JasonWildMe deleted the wbiaqueueutil_optimization branch January 1, 2026 19:02
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.

4 participants