Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DynamoDB getAllRecords logic when 1MB query limit is reached #10726

Merged
merged 11 commits into from
Mar 4, 2022

Conversation

smallinsky
Copy link
Contributor

No description provided.

Copy link
Contributor

@greedy52 greedy52 left a comment

Choose a reason for hiding this comment

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

Fix looks good. I think an alternative is to keep a running limit like

for i := 0; i < backend.DefaultRangeLimit/100; i++ {
	limitRemaining := 0
	if limit > 0 {
		limitRemaining = limit - len(results.records)
	}
	re, err := b.getRecords(ctx, prependPrefix(startKey), prependPrefix(endKey), limitRemaining, result.lastEvaluatedKey)

...
}

This can make sure we WONT fetch more than what we need. Also maybe no need to do len(result.records) >= limit check i believe.

@smallinsky smallinsky force-pushed the smallinsky/fix_dynamodb_1mb_issue branch 3 times, most recently from 2af8078 to c89f568 Compare March 2, 2022 17:46
@smallinsky smallinsky marked this pull request as ready for review March 2, 2022 17:47
@github-actions github-actions bot requested a review from hatched March 2, 2022 17:47
@smallinsky smallinsky requested review from greedy52 and removed request for hatched March 2, 2022 17:48
@smallinsky smallinsky force-pushed the smallinsky/fix_dynamodb_1mb_issue branch from c89f568 to 554e636 Compare March 2, 2022 17:51
lib/backend/test/suite.go Outdated Show resolved Hide resolved
lib/backend/test/suite.go Outdated Show resolved Hide resolved
@smallinsky smallinsky requested a review from greedy52 March 2, 2022 20:42
@smallinsky smallinsky force-pushed the smallinsky/fix_dynamodb_1mb_issue branch from c9959c5 to 0644652 Compare March 2, 2022 20:43
lib/backend/test/suite.go Outdated Show resolved Hide resolved
@smallinsky smallinsky force-pushed the smallinsky/fix_dynamodb_1mb_issue branch from 0644652 to 673d3ca Compare March 2, 2022 20:47
@r0mant r0mant requested a review from fspmarshall March 2, 2022 23:59
Copy link
Contributor

@fspmarshall fspmarshall left a comment

Choose a reason for hiding this comment

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

Fix for the 1mb issue looks good. It seems like we're just mishandling limits here generally tho.

The backend should return at most limit, and should default to using backend.DefaultRangeLimit if no limit is specified. I think we should change getAllRecords to set the limit to backend.DefaultRangeLimit if no limit is specified. Also, instead of passing in the same limit for each subsequent call to getRecords, we should pass in limit - len(result.records), so that we get at most exactly limit worth of items.

If you have the time, can you make those changes here b4 merging?

@smallinsky
Copy link
Contributor Author

@fspmarshall

we should pass in limit - len(result.records), so that we get at most exactly limit worth of items.

This approach will have main drawback. Namely the limit is a applied before filtering in dynamoDB case so if there are 1000x elements that doesn't match filtering rule and there is only one element that matches it will means tha in case of limit set to 1 the dynamoDB API in worst case will be called 1001x times.

Regarding:

The backend should return at most limit, and should default to using backend.DefaultRangeLimit if no limit is specified

Agree, I will change this.

@smallinsky smallinsky force-pushed the smallinsky/fix_dynamodb_1mb_issue branch from 27e6472 to a726ab5 Compare March 3, 2022 10:10
@smallinsky smallinsky merged commit c77711e into master Mar 4, 2022
@smallinsky smallinsky deleted the smallinsky/fix_dynamodb_1mb_issue branch March 4, 2022 12:53
@webvictim webvictim mentioned this pull request Mar 4, 2022
@webvictim webvictim mentioned this pull request Apr 19, 2022
@webvictim webvictim mentioned this pull request Jun 8, 2022
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.

None yet

4 participants