Skip to content

feat: add configurable batch size for bulk inserting failed rsources records - #6873

Merged
mihir20 merged 7 commits into
masterfrom
mihir/bulk-insert-failed-records
Apr 22, 2026
Merged

mihir20 merged 7 commits into
masterfrom
mihir/bulk-insert-failed-records

Conversation

@mihir20

@mihir20 mihir20 commented Apr 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

Txn Inserting into rsources_failed_keys_v2_records is taking too much time. The core bottleneck is AddFailedRecords() for rsources_stats. It uses tx.Prepare + a loop of individual stmt.ExecContext calls. Each ExecContext is a separate network round-trip to Postgres. If a batch
has 1,000 aborted jobs with record_ids, that's 1,000 sequential INSERT round-trips all within one transaction.

  • Introduced batch processing for inserting failed records in rsources_failed_keys_v2_records
  • Added FailedRecordsInsertBatchSize configuration to control batch size
  • Implemented batch insert SQL statement with unnest
  • Updated unit tests to cover multi-batch scenarios
  • Ensured default batch size is set when configuration is invalid

We could have used the COPY command, but the insert needs ON CONFLICT (id, record_id) DO UPDATE SET ts = NOW(), and COPY doesn't support ON CONFLICT

Linear Ticket

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@mihir20
mihir20 force-pushed the mihir/bulk-insert-failed-records branch from a0bc0ea to d838708 Compare April 12, 2026 08:09
@codecov

codecov Bot commented Apr 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.50%. Comparing base (c5b2927) to head (205de23).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6873      +/-   ##
==========================================
+ Coverage   78.49%   78.50%   +0.01%     
==========================================
  Files         565      565              
  Lines       75105    75117      +12     
==========================================
+ Hits        58951    58969      +18     
+ Misses      13149    13143       -6     
  Partials     3005     3005              

☔ 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.

@mihir20
mihir20 force-pushed the mihir/bulk-insert-failed-records branch from d838708 to 91e7652 Compare April 12, 2026 08:59
@mihir20
mihir20 requested a review from atzoum April 12, 2026 08:59
@mihir20
mihir20 force-pushed the mihir/bulk-insert-failed-records branch from 91e7652 to 94718f8 Compare April 12, 2026 13:03
Comment thread services/rsources/handler.go Resolved
…records

🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 force-pushed the mihir/bulk-insert-failed-records branch from 94718f8 to 3da64f6 Compare April 13, 2026 05:55
🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 requested review from atzoum and ktgowtham April 13, 2026 05:58

@ktgowtham ktgowtham left a comment

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.

LGTM

Comment thread services/rsources/handler.go Resolved
… failed records

🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 requested a review from atzoum April 21, 2026 09:16
Comment thread app/apphandlers/setup.go Resolved
@mihir20
mihir20 requested a review from atzoum April 21, 2026 11:25
🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 force-pushed the mihir/bulk-insert-failed-records branch from 87b77c5 to 94b0716 Compare April 21, 2026 11:45
Comment thread services/rsources/handler.go Resolved
…ch size for failed records

🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 requested a review from atzoum April 22, 2026 07:12
@mihir20
mihir20 enabled auto-merge (squash) April 22, 2026 09:28
@mihir20
mihir20 merged commit d8f6ea0 into master Apr 22, 2026
71 checks passed
@mihir20
mihir20 deleted the mihir/bulk-insert-failed-records branch April 22, 2026 09:55
mihir20 pushed a commit that referenced this pull request Apr 27, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.74.0-rc.1](v1.73.0...v1.74.0-rc.1)
(2026-04-27)


### Features

* add configurable batch size for bulk inserting failed rsources records
([#6873](#6873))
([d8f6ea0](d8f6ea0))
* add native deletion support for identity removal in gzip files
([#6896](#6896))
([c1e27d0](c1e27d0))
* deep job pickups when no results cache is cold
([#6850](#6850))
([03e9d88](03e9d88))
* **jobsdb:** improve migration compaction
([#6844](#6844))
([b7f2b9f](b7f2b9f))


### Bug Fixes

* add correct host for salesforceBU destination
([#6906](#6906))
([2430cb4](2430cb4))
* batch router drained events metrics
([#6898](#6898))
([c5b2927](c5b2927))
* build action failing
([#6899](#6899))
([691a812](691a812))
* snowpipe struck scenarios
([#6895](#6895))
([35b07a8](35b07a8))
* use tid instead of vid
([#6908](#6908))
([954dcf7](954dcf7))


### Miscellaneous

* avoid marshalling proc error job payloads
([#6872](#6872))
([145826b](145826b))
* bump build-scan-push-action from v2.1.0 to v2.2.0
([#6903](#6903))
([e917f9b](e917f9b))
* contract tests for dns regressions and overrides
([#6864](#6864))
([b105678](b105678))
* pin and bump action refs (SEC-171)
([#6863](#6863))
([8089953](8089953))
* pytransformer pooling contract tests
([#6883](#6883))
([0530c8c](0530c8c))
* scope workflow permissions to least privilege (SEC-167)
([#6911](#6911))
([5600dbe](5600dbe))
* update Slack notification method in scheduled release workflow
([#6879](#6879))
([3b67dcb](3b67dcb))
* **vuln:** zizmor --fix=all findings (SEC-199)
([#6905](#6905))
([d8cc34f](d8cc34f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
mihir20 pushed a commit that referenced this pull request Apr 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.74.0](v1.73.0...v1.74.0)
(2026-04-27)


### Features

* add configurable batch size for bulk inserting failed rsources records
([#6873](#6873))
([d8f6ea0](d8f6ea0))
* add native deletion support for identity removal in gzip files
([#6896](#6896))
([c1e27d0](c1e27d0))
* deep job pickups when no results cache is cold
([#6850](#6850))
([03e9d88](03e9d88))
* **jobsdb:** improve migration compaction
([#6844](#6844))
([b7f2b9f](b7f2b9f))


### Bug Fixes

* add correct host for salesforceBU destination
([#6906](#6906))
([2430cb4](2430cb4))
* batch router drained events metrics
([#6898](#6898))
([c5b2927](c5b2927))
* build action failing
([#6899](#6899))
([691a812](691a812))
* snowpipe struck scenarios
([#6895](#6895))
([35b07a8](35b07a8))
* use tid instead of vid
([#6908](#6908))
([954dcf7](954dcf7))


### Miscellaneous

* avoid marshalling proc error job payloads
([#6872](#6872))
([145826b](145826b))
* bump build-scan-push-action from v2.1.0 to v2.2.0
([#6903](#6903))
([e917f9b](e917f9b))
* contract tests for dns regressions and overrides
([#6864](#6864))
([b105678](b105678))
* pin and bump action refs (SEC-171)
([#6863](#6863))
([8089953](8089953))
* pytransformer pooling contract tests
([#6883](#6883))
([0530c8c](0530c8c))
* scope workflow permissions to least privilege (SEC-167)
([#6911](#6911))
([5600dbe](5600dbe))
* update Slack notification method in scheduled release workflow
([#6879](#6879))
([3b67dcb](3b67dcb))
* **vuln:** zizmor --fix=all findings (SEC-199)
([#6905](#6905))
([d8cc34f](d8cc34f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
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.

3 participants