From 93a84d5e5aee9df869ac9e78a88c294d6311a9ef Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 21 Sep 2015 14:36:18 +0200 Subject: retry transactions on serialization/dead-lock failures (#3990) --- src/mintdb/plugin_mintdb_postgres.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/mintdb/plugin_mintdb_postgres.c') 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; } -- cgit v1.2.3