summaryrefslogtreecommitdiff
path: root/src/mintdb/plugin_mintdb_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-09-21 14:36:18 +0200
committerChristian Grothoff <christian@grothoff.org>2015-09-21 14:36:18 +0200
commit93a84d5e5aee9df869ac9e78a88c294d6311a9ef (patch)
tree060813cef751493abfa6c6417ed15031aec4842b /src/mintdb/plugin_mintdb_postgres.c
parent70c28e53d0615bc6694ea2339a739d387f8d8691 (diff)
downloadexchange-93a84d5e5aee9df869ac9e78a88c294d6311a9ef.tar.gz
exchange-93a84d5e5aee9df869ac9e78a88c294d6311a9ef.tar.bz2
exchange-93a84d5e5aee9df869ac9e78a88c294d6311a9ef.zip
retry transactions on serialization/dead-lock failures (#3990)
Diffstat (limited to 'src/mintdb/plugin_mintdb_postgres.c')
-rw-r--r--src/mintdb/plugin_mintdb_postgres.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c
index 42aac19f1..621108026 100644
--- a/src/mintdb/plugin_mintdb_postgres.c
+++ b/src/mintdb/plugin_mintdb_postgres.c
@@ -1095,7 +1095,31 @@ postgres_commit (void *cls,
if (PGRES_COMMAND_OK !=
PQresultStatus (result))
{
- GNUNET_break (0);
+ const char *sqlstate;
+
+ sqlstate = PQresultErrorField (result,
+ PG_DIAG_SQLSTATE);
+ if (NULL == sqlstate)
+ {
+ /* very unexpected... */
+ GNUNET_break (0);
+ PQclear (result);
+ return GNUNET_SYSERR;
+ }
+ /* 40P01: deadlock, 40001: serialization failure */
+ if ( (0 == strcmp (sqlstate,
+ "40P01")) ||
+ (0 == strcmp (sqlstate,
+ "40001")) )
+ {
+ /* These two can be retried and have a fair chance of working
+ the next time */
+ PQclear (result);
+ return GNUNET_NO;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database commit failure: %s\n",
+ sqlstate);
PQclear (result);
return GNUNET_SYSERR;
}