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
85dd0684
Commit
85dd0684
authored
Nov 20, 2018
by
Alex Suraci
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extract and document serialization failure check
parent
587081a6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
4 deletions
+17
-4
sql.go
storage/sql/sql.go
+17
-4
No files found.
storage/sql/sql.go
View file @
85dd0684
...
...
@@ -40,6 +40,21 @@ func matchLiteral(s string) *regexp.Regexp {
return
regexp
.
MustCompile
(
`\b`
+
regexp
.
QuoteMeta
(
s
)
+
`\b`
)
}
// Detect a serialization failure, which should trigger retrying the
// transaction according to PostgreSQL docs:
//
// https://www.postgresql.org/docs/current/transaction-iso.html#XACT-SERIALIZABLE
//
// "applications using this level must be prepared to retry transactions due to
// serialization failures"
func
isRetryableSerializationFailure
(
err
error
)
bool
{
if
pqErr
,
ok
:=
err
.
(
*
pq
.
Error
);
ok
{
return
pqErr
.
Code
.
Name
()
==
"serialization_failure"
}
return
false
}
var
(
// The "github.com/lib/pq" driver is the default flavor. All others are
// translations of this.
...
...
@@ -67,8 +82,7 @@ var (
}
if
err
:=
fn
(
tx
);
err
!=
nil
{
if
pqErr
,
ok
:=
err
.
(
*
pq
.
Error
);
ok
&&
pqErr
.
Code
.
Name
()
==
"serialization_failure"
{
// serialization error; retry
if
isRetryableSerializationFailure
(
err
)
{
continue
}
...
...
@@ -77,8 +91,7 @@ var (
err
=
tx
.
Commit
()
if
err
!=
nil
{
if
pqErr
,
ok
:=
err
.
(
*
pq
.
Error
);
ok
&&
pqErr
.
Code
.
Name
()
==
"serialization_failure"
{
// serialization error; retry
if
isRetryableSerializationFailure
(
err
)
{
continue
}
...
...
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