Browse Source

ckdb - allow and ckpool message to create workerstatus and workers

master
kanoi 10 years ago
parent
commit
42beeeb1b7
  1. 2
      src/ckdb.h
  2. 53
      src/ckdb_data.c

2
src/ckdb.h

@ -55,7 +55,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.0" #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 " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__

53
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 /* Worker loading/creation calls this with create = true
* All others with create = false since the workerstatus should exist * 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 * 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, K_ITEM *_find_create_workerstatus(int64_t userid, char *workername,
bool create, const char *file2, bool create, const char *file2,
@ -718,32 +720,55 @@ K_ITEM *_find_create_workerstatus(int64_t userid, char *workername,
WHERE_FFL_ARGS) WHERE_FFL_ARGS)
{ {
WORKERSTATUS *row; 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); ws_item = get_workerstatus(userid, workername);
if (!item) { if (!ws_item) {
if (!create) { if (!create) {
LOGEMERG("%s(): Missing workerstatus %"PRId64"/%s" ws_err = true;
WHERE_FFL WHERE_FFL,
__func__, userid, workername, w_item = find_workers(userid, workername);
file2, func2, line2, WHERE_FFL_PASS); if (!w_item) {
return NULL; 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); 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)); bzero(row, sizeof(*row));
row->userid = userid; row->userid = userid;
STRNCPY(row->workername, workername); STRNCPY(row->workername, workername);
workerstatus_root = add_to_ktree(workerstatus_root, item, cmp_workerstatus); workerstatus_root = add_to_ktree(workerstatus_root, ws_item, cmp_workerstatus);
k_add_head(workerstatus_store, item); k_add_head(workerstatus_store, ws_item);
K_WUNLOCK(workerstatus_free); 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 /* All data is loaded, now update workerstatus fields

Loading…
Cancel
Save