Browse Source

ckdb - update workerstatus when loading sharesummaries

master
kanoi 11 years ago
parent
commit
bd3aab8f68
  1. 21
      src/ckdb.c

21
src/ckdb.c

@ -1647,7 +1647,8 @@ static K_ITEM *_find_create_workerstatus(int64_t userid, char *workername, bool
#define find_create_workerstatus(_u, _w) _find_create_workerstatus(_u, _w, true) #define find_create_workerstatus(_u, _w) _find_create_workerstatus(_u, _w, true)
#define find_workerstatus(_u, _w) _find_create_workerstatus(_u, _w, false) #define find_workerstatus(_u, _w) _find_create_workerstatus(_u, _w, false)
static void workerstatus_update(AUTHS *auths, SHARES *shares, USERSTATS *userstats) static void workerstatus_update(AUTHS *auths, SHARES *shares, USERSTATS *userstats,
SHARESUMMARY *sharesummary)
{ {
WORKERSTATUS *row; WORKERSTATUS *row;
K_ITEM *item; K_ITEM *item;
@ -1679,6 +1680,13 @@ static void workerstatus_update(AUTHS *auths, SHARES *shares, USERSTATS *usersta
memcpy(&(row->stats), &(userstats->statsdate), sizeof(row->idle)); memcpy(&(row->stats), &(userstats->statsdate), sizeof(row->idle));
} }
} }
if (sharesummary) {
item = find_create_workerstatus(sharesummary->userid, sharesummary->workername);
row = DATA_WORKERSTATUS(item);
if (tv_newer(&(row->share), &(sharesummary->lastshare)))
memcpy(&(row->share), &(sharesummary->lastshare), sizeof(row->share));
}
} }
// default tree order by username asc,expirydate desc // default tree order by username asc,expirydate desc
@ -2964,7 +2972,7 @@ static bool shares_add(char *workinfoid, char *username, char *workername, char
if (!w_item) if (!w_item)
goto unitem; goto unitem;
workerstatus_update(NULL, shares, NULL); workerstatus_update(NULL, shares, NULL, NULL);
sharesummary_update(NULL, shares, NULL, NULL, now, by, code, inet); sharesummary_update(NULL, shares, NULL, NULL, now, by, code, inet);
@ -3584,6 +3592,8 @@ static bool sharesummary_fill(PGconn *conn)
sharesummary_root = add_to_ktree(sharesummary_root, item, cmp_sharesummary); sharesummary_root = add_to_ktree(sharesummary_root, item, cmp_sharesummary);
sharesummary_workinfoid_root = add_to_ktree(sharesummary_workinfoid_root, item, cmp_sharesummary_workinfoid); sharesummary_workinfoid_root = add_to_ktree(sharesummary_workinfoid_root, item, cmp_sharesummary_workinfoid);
k_add_head(sharesummary_store, item); k_add_head(sharesummary_store, item);
workerstatus_update(NULL, NULL, NULL, row);
} }
if (!ok) if (!ok)
k_add_head(sharesummary_list, item); k_add_head(sharesummary_list, item);
@ -3992,7 +4002,7 @@ static char *auths_add(PGconn *conn, char *poolinstance, char *username,
HISTORYDATETRANSFER(row); HISTORYDATETRANSFER(row);
// Update even if DB fails // Update even if DB fails
workerstatus_update(row, NULL, NULL); workerstatus_update(row, NULL, NULL, NULL);
row->authid = nextid(conn, "authid", (int64_t)1, now, by, code, inet); row->authid = nextid(conn, "authid", (int64_t)1, now, by, code, inet);
if (row->authid == 0) if (row->authid == 0)
@ -4123,6 +4133,7 @@ static bool auths_fill(PGconn *conn)
auths_root = add_to_ktree(auths_root, item, cmp_auths); auths_root = add_to_ktree(auths_root, item, cmp_auths);
k_add_head(auths_store, item); k_add_head(auths_store, item);
workerstatus_update(row, NULL, NULL, NULL);
} }
if (!ok) if (!ok)
k_add_head(auths_list, item); k_add_head(auths_list, item);
@ -4506,7 +4517,7 @@ static bool userstats_add(char *poolinstance, char *elapsed, char *username,
createdate.tv_usec = row->createdate.tv_usec; createdate.tv_usec = row->createdate.tv_usec;
} }
workerstatus_update(NULL, NULL, row); workerstatus_update(NULL, NULL, row, NULL);
/* group at full key: userid,createdate,poolinstance,workername /* group at full key: userid,createdate,poolinstance,workername
i.e. ignore instance and group together down at workername */ i.e. ignore instance and group together down at workername */
@ -4664,7 +4675,7 @@ static bool userstats_fill(PGconn *conn)
userstats_root = add_to_ktree(userstats_root, item, cmp_userstats); userstats_root = add_to_ktree(userstats_root, item, cmp_userstats);
k_add_head(userstats_store, item); k_add_head(userstats_store, item);
workerstatus_update(NULL, NULL, DATA_USERSTATS(item)); workerstatus_update(NULL, NULL, row, NULL);
} }
if (!ok) if (!ok)
k_add_head(userstats_list, item); k_add_head(userstats_list, item);

Loading…
Cancel
Save