Skip to content

feat: batch staging files for creating upload_v2 notifier jobs - #5765

Merged
shekhar-rudder merged 8 commits into
masterfrom
war-462-batching-algorithm
Apr 30, 2025
Merged

shekhar-rudder merged 8 commits into
masterfrom
war-462-batching-algorithm

Conversation

@shekhar-rudder

@shekhar-rudder shekhar-rudder commented Apr 24, 2025 •

Copy link
Copy Markdown
Member

Description

  • Renamed prepareBaseJobRequest to generateBaseRequest and added computing StagingDestinationConfig and LoadFilePrefix instead of doing it in publishJobs
  • Renamed publishJobs to publishToNotifier which now accepts messages as argument instead of computing it using chunk
  • In createUploadV2Jobs, added GroupStagingFiles to group files based on size and other characteristics

Security

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

@codecov

codecov Bot commented Apr 29, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 91.59664% with 10 lines in your changes missing coverage. Please review.

Project coverage is 76.86%. Comparing base (dbc830f) to head (a2e1cc5).
Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
warehouse/internal/loadfiles/loadfiles.go 91.59% 7 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5765      +/-   ##
==========================================
- Coverage   76.96%   76.86%   -0.11%     
==========================================
  Files         488      491       +3     
  Lines       66617    67150     +533     
==========================================
+ Hits        51273    51614     +341     
- Misses      12554    12713     +159     
- Partials     2790     2823      +33     

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

}

// splits a group of staging files based on size constraints
func (lf *LoadFileGenerator) groupBySize(files []*fileWithMaxSize, maxSizeMB int) [][]*model.StagingFile {

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.

offline discussion:

  1. []*fileWithMaxSize has a file and largest table byte size in each file. Largest table byte size could be of tracks for one file and identifies for another. This won't give optimal batching in case if one file has more tracks, other file has less tracks. Ideally, we want large table size belonging to only one table per each file.

  2. why move last item in slice to the current file index? Last file is going to have lesser table size

                files[i] = files[len(files)-1]
				files = files[:len(files)-1]

@RanjeetMishra RanjeetMishra Apr 29, 2025 •

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.

@vyeshwanth

  1. As far as I understood, this is First Fit Decreasing (FFD) algorithm? At our scale we can look for other bin packing algo later as well. Unless you are recommending any other algo?
  2. I see, instead of current index it should be a full shift according to algo. Did not catch this in review. To avoid shift or changing slice, we can use indexes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  1. Fixed the code, to check for the only the table with max size across all files
  2. Updated the element removal logic to avoid any changes in sorting order

@RanjeetMishra RanjeetMishra 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
I actually understood @vyeshwanth's comment better while reviewing this change. 🙏 Good catch!

Comment on lines +626 to +637
tableSizes := lo.Reduce(files, func(acc map[string]int64, file *model.StagingFile, _ int) map[string]int64 {
for tableName, size := range file.BytesPerTable {
acc[tableName] += size
}
return acc
}, make(map[string]int64))

maxTable, maxTableSize := lo.FindKeyBy(tableSizes, func(tableName string, size int64) bool {
return size == lo.MaxBy(lo.Values(tableSizes), func(a, b int64) bool {
return a > b
})
})

@vyeshwanth vyeshwanth Apr 30, 2025 •

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.

Suggested change
tableSizes := lo.Reduce(files, func(acc map[string]int64, file *model.StagingFile, _ int) map[string]int64 {
for tableName, size := range file.BytesPerTable {
acc[tableName] += size
}
return acc
}, make(map[string]int64))
maxTable, maxTableSize := lo.FindKeyBy(tableSizes, func(tableName string, size int64) bool {
return size == lo.MaxBy(lo.Values(tableSizes), func(a, b int64) bool {
return a > b
})
})
var (
maxTableName string
maxTableSize int64
)
tableSizes := lo.Reduce(files, func(acc map[string]int64, file *model.StagingFile, _ int) map[string]int64 {
for tableName, size := range file.BytesPerTable {
acc[tableName] += size
if acc[tableName] > maxTableSize {
maxTableName = tableName
maxTableSize = acc[tableName]
}
}
return acc
}, make(map[string]int64))

this should work?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done with slight modification (Here output of reduce tableSizes is unused)

batchTableSizes := make(map[string]int64)

// Try to add files to the current batch
for i := 0; i < len(files); i++ {

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.

nit:

Suggested change
for i := 0; i < len(files); i++ {
for i, file := range files {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

@shekhar-rudder
shekhar-rudder merged commit 7dc3a45 into master Apr 30, 2025
@shekhar-rudder
shekhar-rudder deleted the war-462-batching-algorithm branch April 30, 2025 11:14
satishrudderstack pushed a commit that referenced this pull request May 12, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.49.0-rc.1](v1.48.0...v1.49.0-rc.1)
(2025-05-12)


### Features

* add support for processing of upload_v2 job type by slave
([#5796](#5796))
([67988d1](67988d1))
* batch staging files for creating upload_v2 notifier jobs
([#5765](#5765))
([7dc3a45](7dc3a45))
* enable worker-based kafka client batching
([#5788](#5788))
([66dc19f](66dc19f))
* support claim renewal in notifier jobs
([#5818](#5818))
([a499d9c](a499d9c))
* support new consent resolution strategy values
([#5798](#5798))
([181b95b](181b95b))
* update config to add account details with destination in
workspaceConfig
([#5753](#5753))
([dbd46bf](dbd46bf))
* update contract for account and accountDefinition
([#5830](#5830))
([c704b07](c704b07))
* use account to decide oauth type of a destination
([#5810](#5810))
([9165e8c](9165e8c))


### Bug Fixes

* add check for nil secret on oauthv2
([#5807](#5807))
([fbc4abe](fbc4abe))
* convert bad request errors to 500 errors in oauth interceptor to
prevent panics
([#5813](#5813))
([3a08ec4](3a08ec4))
* **jobsdb:** completed datasets don't get deleted without a pair
([#5793](#5793))
([54aee71](54aee71))
* reporting common client path with query
([#5842](#5842))
([c068920](c068920))
* transformer client recycle ttl bound to connection idle timeout
([#5800](#5800))
([b13f92c](b13f92c))
* update account type to remove id which we are getting as map key
([#5835](#5835))
([bc52242](bc52242))
* ut mirroring race condition
([#5824](#5824))
([a4d579f](a4d579f))
* warehouse cached schema mismatch
([#5805](#5805))
([4656247](4656247))
* warehouse transformations mismatches
([#5779](#5779))
([01a7b83](01a7b83))


### Miscellaneous

* **deps:** bump github.com/snowflakedb/gosnowflake from 1.13.2 to
1.13.3 in the go_modules group
([#5787](#5787))
([41db33e](41db33e))
* **deps:** bump golangci/golangci-lint-action from 7 to 8
([#5815](#5815))
([bf3e808](bf3e808))
* **jobsdb:** cache distinct parameters query result for all datasets
except last
([#5752](#5752))
([e85811e](e85811e))
* migrate from denisenkom/go-mssqldb to microsoft/go-mssqldb
([#5776](#5776))
([dbd46bf](dbd46bf))
* revert synapse staging table with max varchar length
([#5817](#5817))
([2418329](2418329))
* **router:** support destination-specific configuration overrides for
all options
([#5841](#5841))
([695cf53](695cf53))
* synapse staging table with max varchar length
([#5775](#5775))
([2fc5384](2fc5384))
* update accountDefination type with authenticationType
([#5791](#5791))
([2a24e59](2a24e59))
* update rudder-go-kit to 0.49.2
([#5832](#5832))
([01a7b83](01a7b83))
* upload embedded dt response difference samples to s3
([#5792](#5792))
([c81001f](c81001f))
* warehouse transformer migration to embedded destination transformer
package
([#5827](#5827))
([e124bb0](e124bb0))
* warehouse transformer sample diff
([#5837](#5837))
([8af55de](8af55de))
* warehouse transformer uploader
([#5828](#5828))
([fc640bf](fc640bf))
* webhook integration test module upgrade
([#5665](#5665))
([f4130d1](f4130d1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
This was referenced May 13, 2025
satishrudderstack pushed a commit that referenced this pull request May 13, 2025
🤖 I have created a release *beep* *boop*
---


##
[1.49.0](v1.48.0...v1.49.0)
(2025-05-13)


### Features

* add dynamic config existence flag for destinations
([#5821](#5821))
([1b4ea06](1b4ea06))
* add support for processing of upload_v2 job type by slave
([#5796](#5796))
([67988d1](67988d1))
* batch staging files for creating upload_v2 notifier jobs
([#5765](#5765))
([7dc3a45](7dc3a45))
* enable worker-based kafka client batching
([#5788](#5788))
([66dc19f](66dc19f))
* support claim renewal in notifier jobs
([#5818](#5818))
([a499d9c](a499d9c))
* support new consent resolution strategy values
([#5798](#5798))
([181b95b](181b95b))
* update config to add account details with destination in
workspaceConfig
([#5753](#5753))
([dbd46bf](dbd46bf))
* update contract for account and accountDefinition
([#5830](#5830))
([c704b07](c704b07))
* use account to decide oauth type of a destination
([#5810](#5810))
([9165e8c](9165e8c))


### Bug Fixes

* add check for nil secret on oauthv2
([#5807](#5807))
([fbc4abe](fbc4abe))
* convert bad request errors to 500 errors in oauth interceptor to
prevent panics
([#5813](#5813))
([3a08ec4](3a08ec4))
* embedded transformations upload
([#5848](#5848))
([0b19968](0b19968))
* **jobsdb:** completed datasets don't get deleted without a pair
([#5793](#5793))
([54aee71](54aee71))
* reporting common client path with query
([#5842](#5842))
([c068920](c068920))
* transformer client recycle ttl bound to connection idle timeout
([#5800](#5800))
([b13f92c](b13f92c))
* update account type to remove id which we are getting as map key
([#5835](#5835))
([bc52242](bc52242))
* ut mirroring race condition
([#5824](#5824))
([a4d579f](a4d579f))
* warehouse cached schema mismatch
([#5805](#5805))
([4656247](4656247))
* warehouse transformations mismatches
([#5779](#5779))
([01a7b83](01a7b83))


### Miscellaneous

* **deps:** bump github.com/snowflakedb/gosnowflake from 1.13.2 to
1.13.3 in the go_modules group
([#5787](#5787))
([41db33e](41db33e))
* **deps:** bump golangci/golangci-lint-action from 7 to 8
([#5815](#5815))
([bf3e808](bf3e808))
* enrich event with bot details
([#5836](#5836))
([6035658](6035658))
* **jobsdb:** cache distinct parameters query result for all datasets
except last
([#5752](#5752))
([e85811e](e85811e))
* migrate from denisenkom/go-mssqldb to microsoft/go-mssqldb
([#5776](#5776))
([dbd46bf](dbd46bf))
* revert synapse staging table with max varchar length
([#5817](#5817))
([2418329](2418329))
* **router:** support destination-specific configuration overrides for
all options
([#5841](#5841))
([695cf53](695cf53))
* synapse staging table with max varchar length
([#5775](#5775))
([2fc5384](2fc5384))
* update accountDefination type with authenticationType
([#5791](#5791))
([2a24e59](2a24e59))
* update rudder-go-kit to 0.49.2
([#5832](#5832))
([01a7b83](01a7b83))
* upload embedded dt response difference samples to s3
([#5792](#5792))
([c81001f](c81001f))
* warehouse transformer migration to embedded destination transformer
package
([#5827](#5827))
([e124bb0](e124bb0))
* warehouse transformer sample diff
([#5837](#5837))
([8af55de](8af55de))
* warehouse transformer uploader
([#5828](#5828))
([fc640bf](fc640bf))
* webhook integration test module upgrade
([#5665](#5665))
([f4130d1](f4130d1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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