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

SQLStore: Fix SQLite error propagation if query retries are disabled #64904

Merged
merged 4 commits into from Mar 17, 2023

Conversation

papagian
Copy link
Contributor

@papagian papagian commented Mar 16, 2023

What is this feature?

The following condition (introduced in #58559) used to fail if the query retries are disabled (equal to zero) (default behaviour):

if retry == ss.dbCfg.QueryRetries {

As a result due to retryer behaviour:
if retries >= maxRetries {
return nil
}

the sqlite3.ErrLocked and sqlite3.ErrBusy were not propagated

This fix changes the above condition to check for greater or equal instead

Why do we need this feature?

[Add a description of the problem the feature is trying to solve.]

Who is this feature for?

[Add information on what kind of user the feature is for.]

Which issue(s) does this PR fix?:

Fixes #

Special notes for your reviewer:

@papagian papagian added type/bug no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes labels Mar 16, 2023
@papagian papagian added this to the 9.5.0 milestone Mar 16, 2023
@papagian papagian requested a review from a team as a code owner March 16, 2023 13:59
@papagian papagian requested review from sakjur, zserge and suntala and removed request for a team March 16, 2023 13:59
@papagian papagian added add to changelog and removed no-changelog Skip including change in changelog/release notes labels Mar 16, 2023
Copy link
Contributor

@suntala suntala left a comment

Choose a reason for hiding this comment

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

Looks good to me overall! Just one small suggestion.

i := 0
callback := func(sess *DBSession) error {
i++
return sqlite3.Error{Code: sqlite3.ErrBusy}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also have a test case for the error being sqlite3.ErrLocked?

@papagian papagian enabled auto-merge (squash) March 17, 2023 09:49
@@ -44,6 +44,19 @@ func TestRetryingDisabled(t *testing.T) {
require.Equal(t, 1, i)
})

t.Run(fmt.Sprintf("%s should return the sqlite3.Error immediately", name), func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Might be nice to change sqlite3.Error to sqlite3.ErrBusy/sqlite3.ErrLocked depending on the test case.

@papagian papagian disabled auto-merge March 17, 2023 10:12
@papagian papagian added backport v9.3.x backport v9.4.x Mark PR for automatic backport to v9.4.x and removed no-backport Skip backport of PR labels Mar 17, 2023
@papagian papagian enabled auto-merge (squash) March 17, 2023 10:30
@papagian papagian merged commit 4184346 into main Mar 17, 2023
4 checks passed
@papagian papagian deleted the papagian/fix-query-no-retrying branch March 17, 2023 10:57
@grafanabot
Copy link
Contributor

The backport to v9.3.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-64904-to-v9.3.x origin/v9.3.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x 41843464d17df3800df447af4eec1ebfcc54d42b
# Push it to GitHub
git push --set-upstream origin backport-64904-to-v9.3.x
git switch main
# Remove the local backport branch
git branch -D backport-64904-to-v9.3.x

Then, create a pull request where the base branch is v9.3.x and the compare/head branch is backport-64904-to-v9.3.x.

@grafanabot grafanabot added the backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. label Mar 17, 2023
grafanabot pushed a commit that referenced this pull request Mar 17, 2023
…64904)

* SQLStore: Add test when query retrying is disabled

* Fix condition

* Add test cases for sqlite3.ErrLocked

(cherry picked from commit 4184346)
@papagian
Copy link
Contributor Author

the bug was introduced in 9.4.0-beta1 (#58559) so no need to be backported to 9.3.x

@papagian papagian modified the milestones: 9.5.0, 9.4.8 Mar 17, 2023
papagian added a commit that referenced this pull request Mar 17, 2023
…disabled (#64948)

SQLStore: Fix SQLite error propagation if query retries are disabled (#64904)

* SQLStore: Add test when query retrying is disabled

* Fix condition

* Add test cases for sqlite3.ErrLocked

(cherry picked from commit 4184346)

Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
@zerok zerok modified the milestones: 9.4.x, 9.4.8, 9.5.0 Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/backend backport v9.4.x Mark PR for automatic backport to v9.4.x backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants