Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
f697f819
Commit
f697f819
authored
May 15, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sqlite: fixed database table looked handling, now retries up to 5 times, fixes #7992
parent
fd969bf6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
pkg/services/sqlstore/shared.go
+17
-0
No files found.
pkg/services/sqlstore/shared.go
View file @
f697f819
package
sqlstore
import
(
"time"
"github.com/go-xorm/xorm"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
sqlite3
"github.com/mattn/go-sqlite3"
)
type
dbTransactionFunc
func
(
sess
*
xorm
.
Session
)
error
...
...
@@ -19,6 +22,10 @@ func (sess *session) publishAfterCommit(msg interface{}) {
}
func
inTransaction
(
callback
dbTransactionFunc
)
error
{
return
inTransactionWithRetry
(
callback
,
0
)
}
func
inTransactionWithRetry
(
callback
dbTransactionFunc
,
retry
int
)
error
{
var
err
error
sess
:=
x
.
NewSession
()
...
...
@@ -30,6 +37,16 @@ func inTransaction(callback dbTransactionFunc) error {
err
=
callback
(
sess
)
// special handling of database locked errors for sqlite, then we can retry 3 times
if
sqlError
,
ok
:=
err
.
(
sqlite3
.
Error
);
ok
&&
retry
<
5
{
if
sqlError
.
Code
==
sqlite3
.
ErrLocked
{
sess
.
Rollback
()
time
.
Sleep
(
time
.
Millisecond
*
time
.
Duration
(
10
))
sqlog
.
Info
(
"Database table locked, sleeping then retrying"
,
"retry"
,
retry
)
return
inTransactionWithRetry
(
callback
,
retry
+
1
)
}
}
if
err
!=
nil
{
sess
.
Rollback
()
return
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment