Add throttling mechanism to Elasticsearch migration backfill helper
What does this MR do?
This MR adds a throttling mechanism to the Elasticsearch migration backfill helper to prevent overwhelming the indexing queue during large migrations.
Why was this MR needed?
Elasticsearch migrations can produce a very large number of documents to index in a short period, which can overwhelm the Elasticsearch indexing queue and cause performance issues. This change adds an automatic throttling mechanism that pauses migrations when the queue size exceeds a threshold, allowing the system to catch up before continuing.
Technical details
- Added a
QUEUE_TRESHOLDconstant set to 50,000 items - Added a check in the
migratemethod that pauses processing when queue is full - Added a
queue_full?private method to check if bookkeeping service queue size exceeds threshold - Refactored service access through a
bookkeeping_servicemethod:- Makes the code more flexible for testing
- Allows for potential extension in subclasses
- Updated specs to test the throttling mechanism and service method
Testing
- Added tests to verify throttling behavior when queue is full
- Added tests for the bookkeeping service method
- Ran existing tests to ensure backward compatibility