Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
7e960214
Commit
7e960214
authored
Nov 15, 2018
by
Alex Suraci
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
retry on serialization errors
parent
efb15205
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
2 deletions
+17
-2
sql.go
storage/sql/sql.go
+17
-2
No files found.
storage/sql/sql.go
View file @
7e960214
...
@@ -6,10 +6,10 @@ import (
...
@@ -6,10 +6,10 @@ import (
"regexp"
"regexp"
"time"
"time"
"github.com/lib/pq"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
// import third party drivers
// import third party drivers
_
"github.com/lib/pq"
_
"github.com/mattn/go-sqlite3"
_
"github.com/mattn/go-sqlite3"
)
)
...
@@ -51,19 +51,34 @@ var (
...
@@ -51,19 +51,34 @@ var (
// NOTE(ericchiang): For some reason using `SET SESSION CHARACTERISTICS AS TRANSACTION` at a
// NOTE(ericchiang): For some reason using `SET SESSION CHARACTERISTICS AS TRANSACTION` at a
// session level didn't work for some edge cases. Might be something worth exploring.
// session level didn't work for some edge cases. Might be something worth exploring.
executeTx
:
func
(
db
*
sql
.
DB
,
fn
func
(
sqlTx
*
sql
.
Tx
)
error
)
error
{
executeTx
:
func
(
db
*
sql
.
DB
,
fn
func
(
sqlTx
*
sql
.
Tx
)
error
)
error
{
for
{
tx
,
err
:=
db
.
Begin
()
tx
,
err
:=
db
.
Begin
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
defer
tx
.
Rollback
()
defer
tx
.
Rollback
()
if
_
,
err
:=
tx
.
Exec
(
`SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;`
);
err
!=
nil
{
if
_
,
err
:=
tx
.
Exec
(
`SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;`
);
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
fn
(
tx
);
err
!=
nil
{
if
err
:=
fn
(
tx
);
err
!=
nil
{
return
err
return
err
}
}
return
tx
.
Commit
()
err
=
tx
.
Commit
()
if
err
!=
nil
{
if
pqErr
,
ok
:=
err
.
(
*
pq
.
Error
);
ok
&&
pqErr
.
Code
==
"40001"
{
// serialization error; retry
continue
}
return
err
}
return
nil
}
},
},
supportsTimezones
:
true
,
supportsTimezones
:
true
,
...
...
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