From 09a40a4607e67889ad145ea93ae4fa90eb4d13cd Mon Sep 17 00:00:00 2001 From: kanoi Date: Wed, 10 Feb 2016 23:05:07 +1100 Subject: [PATCH] ckdb - add some table level locking to speed up large loads --- src/ckdb.h | 2 +- src/ckdb_dbio.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index 419dc45c..827b99ea 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -51,7 +51,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.4" -#define CKDB_VERSION DB_VERSION"-1.930" +#define CKDB_VERSION DB_VERSION"-1.940" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index eed647f2..9c827785 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -2943,6 +2943,14 @@ bool workinfo_fill(PGconn *conn) return false; } + res = PQexec(conn, "Lock table workinfo in access exclusive mode", CKPQ_READ); + rescode = PQresultStatus(res); + PQclear(res); + if (!PGOK(rescode)) { + PGLOGERR("Lock", rescode, conn); + goto flail; + } + res = PQexecParams(conn, sel, par, NULL, (const char **)params, NULL, NULL, 0, CKPQ_READ); rescode = PQresultStatus(res); PQclear(res); @@ -5468,6 +5476,14 @@ bool miningpayouts_fill(PGconn *conn) return false; } + res = PQexec(conn, "Lock table miningpayouts in access exclusive mode", CKPQ_READ); + rescode = PQresultStatus(res); + PQclear(res); + if (!PGOK(rescode)) { + PGLOGERR("Lock", rescode, conn); + goto flail; + } + res = PQexec(conn, sel, CKPQ_READ); rescode = PQresultStatus(res); PQclear(res); @@ -6967,9 +6983,6 @@ bool markersummary_fill(PGconn *conn) LOGDEBUG("%s(): select", __func__); - printf(TICK_PREFIX"ms 0\r"); - fflush(stdout); - // TODO: limit how far back sel = "declare ws cursor for select " "markerid,userid,workername,diffacc,diffsta,diffdup,diffhi," @@ -6987,6 +7000,9 @@ bool markersummary_fill(PGconn *conn) LOGWARNING("%s(): loading from markerid>=%s", __func__, params[0]); + printf(TICK_PREFIX"ms 0\r"); + fflush(stdout); + res = PQexec(conn, "Begin", CKPQ_READ); rescode = PQresultStatus(res); PQclear(res); @@ -6995,6 +7011,14 @@ bool markersummary_fill(PGconn *conn) return false; } + res = PQexec(conn, "Lock table markersummary in access exclusive mode", CKPQ_READ); + rescode = PQresultStatus(res); + PQclear(res); + if (!PGOK(rescode)) { + PGLOGERR("Lock", rescode, conn); + goto flail; + } + res = PQexecParams(conn, sel, par, NULL, (const char **)params, NULL, NULL, 0, CKPQ_READ); rescode = PQresultStatus(res); PQclear(res);