From 3ae5e9d2b742970f58440d09b129af123c59e56c Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 15 Jan 2015 21:16:36 +1100 Subject: [PATCH] ckdb - allow setting workmarkers as processed via marks command --- src/ckdb.h | 2 +- src/ckdb_cmd.c | 37 +++++++++++++++++++++++++++++++++++-- src/ckdb_dbio.c | 4 +++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index 341ced0c..03184147 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -52,7 +52,7 @@ #define DB_VLOCK "1" #define DB_VERSION "0.9.6" -#define CKDB_VERSION DB_VERSION"-0.830" +#define CKDB_VERSION DB_VERSION"-0.831" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 233b36bf..5ece47c8 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -4105,13 +4105,13 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id, char msg[1024] = ""; K_ITEM *i_action, *i_workinfoid, *i_marktype, *i_description; K_ITEM *i_height, *i_status, *i_extra, *m_item, *b_item, *w_item; - K_ITEM *wm_item, *wm_item_prev; + K_ITEM *wm_item, *wm_item_prev, *i_markerid; WORKMARKERS *workmarkers; K_TREE_CTX ctx[1]; BLOCKS *blocks; MARKS *marks; char *action; - int64_t workinfoid = -1; + int64_t workinfoid = -1, markerid = -1; char *marktype; int32_t height = 0; char description[TXT_BIG+1] = { '\0' }; @@ -4401,6 +4401,39 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id, LOGERR("%s.%s", id, reply); return strdup(reply); } + } else if (strcasecmp(action, "processed") == 0) { + /* Mark a workmarker as processed + * Requires markerid */ + i_markerid = require_name(trf_root, "markerid", 1, (char *)intpatt, reply, siz); + if (!i_markerid) + return strdup(reply); + TXT_TO_BIGINT("markerid", transfer_data(i_markerid), markerid); + K_RLOCK(workmarkers_free); + wm_item = find_workmarkerid(markerid, true, '\0'); + K_RUNLOCK(workmarkers_free); + if (!wm_item) { + snprintf(reply, siz, + "unknown workmarkers with markerid %"PRId64, markerid); + return strdup(reply); + } + DATA_WORKMARKERS(workmarkers, wm_item); + if (WMPROCESSED(workmarkers->status)) { + snprintf(reply, siz, + "already processed markerid %"PRId64, markerid); + return strdup(reply); + } + ok = workmarkers_process(NULL, false, true, markerid, + workmarkers->poolinstance, + workmarkers->workinfoidend, + workmarkers->workinfoidstart, + workmarkers->description, + MARKER_PROCESSED_STR, + by, code, inet, cd, trf_root); + if (!ok) { + snprintf(reply, siz, "%s failed", action); + LOGERR("%s.%s", id, reply); + return strdup(reply); + } } else { snprintf(reply, siz, "unknown action '%s'", action); LOGERR("%s.%s", id, reply); diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index c4385982..74877f58 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -5756,7 +5756,9 @@ bool markersummary_fill(PGconn *conn) return ok; } -/* Add means create a new one and expire the old one if it exists, +/* Already means there is a transaction already in progress + * so don't begin or commit/rollback + * Add means create a new one and expire the old one if it exists, * otherwise we only expire the old one if it exists * Add requires all db fields except markerid, however if markerid * is non-zero, it will be used instead of getting a new one