From 42beeeb1b7263999b6f6d44bd4d30a3e61002177 Mon Sep 17 00:00:00 2001 From: kanoi Date: Fri, 27 Mar 2015 19:44:44 +1100 Subject: [PATCH] ckdb - allow and ckpool message to create workerstatus and workers --- src/ckdb.h | 2 +- src/ckdb_data.c | 53 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index dc3acb3c..8804ad10 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -55,7 +55,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.0" -#define CKDB_VERSION DB_VERSION"-1.043" +#define CKDB_VERSION DB_VERSION"-1.044" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_data.c b/src/ckdb_data.c index a6171049..4bf9355d 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -709,8 +709,10 @@ K_ITEM *get_workerstatus(int64_t userid, char *workername) /* Worker loading/creation calls this with create = true * All others with create = false since the workerstatus should exist - * Failure is a code bug and a reported error, but handled anyway + * If it is missing, it will check for and create the worker if needed + * and create a new workerstatus and return it * This has 2 sets of file/func/line to allow 2 levels of traceback + * to see why it happened */ K_ITEM *_find_create_workerstatus(int64_t userid, char *workername, bool create, const char *file2, @@ -718,32 +720,55 @@ K_ITEM *_find_create_workerstatus(int64_t userid, char *workername, WHERE_FFL_ARGS) { WORKERSTATUS *row; - K_ITEM *item; + K_ITEM *ws_item, *w_item = NULL; + bool ws_err = false, w_err = false; + tv_t now; - item = get_workerstatus(userid, workername); - if (!item) { + ws_item = get_workerstatus(userid, workername); + if (!ws_item) { if (!create) { - LOGEMERG("%s(): Missing workerstatus %"PRId64"/%s" - WHERE_FFL WHERE_FFL, - __func__, userid, workername, - file2, func2, line2, WHERE_FFL_PASS); - return NULL; + ws_err = true; + + w_item = find_workers(userid, workername); + if (!w_item) { + w_err = true; + setnow(&now); + w_item = workers_add(NULL, userid, workername, + NULL, NULL, NULL, + by_default, + (char *)__func__, + (char *)inet_default, + &now, NULL); + } } K_WLOCK(workerstatus_free); - item = k_unlink_head(workerstatus_free); + ws_item = k_unlink_head(workerstatus_free); - DATA_WORKERSTATUS(row, item); + DATA_WORKERSTATUS(row, ws_item); bzero(row, sizeof(*row)); row->userid = userid; STRNCPY(row->workername, workername); - workerstatus_root = add_to_ktree(workerstatus_root, item, cmp_workerstatus); - k_add_head(workerstatus_store, item); + workerstatus_root = add_to_ktree(workerstatus_root, ws_item, cmp_workerstatus); + k_add_head(workerstatus_store, ws_item); K_WUNLOCK(workerstatus_free); + + if (ws_err) { + LOGERR("%s(): CREATED Missing workerstatus %"PRId64"/%s" + WHERE_FFL WHERE_FFL, + __func__, userid, workername, + file2, func2, line2, WHERE_FFL_PASS); + if (w_err) { + LOGERR("%s(): %s Missing worker %"PRId64"/%s", + __func__, + w_item ? "CREATED" : "FAILED TO CREATE", + userid, workername); + } + } } - return item; + return ws_item; } /* All data is loaded, now update workerstatus fields