From 7072135a72de3f965e39e0144e7bb2315195209a Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 26 Mar 2015 15:19:29 +1100 Subject: [PATCH] ckdb - fix old worker lastshare in workerstatus --- src/ckdb.h | 3 +- src/ckdb_data.c | 92 ++++++++++++++++++++++--------------------------- 2 files changed, 44 insertions(+), 51 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index a0fdb2a1..862ddc07 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.040" +#define CKDB_VERSION DB_VERSION"-1.041" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1808,6 +1808,7 @@ extern cmp_t cmp_sharesummary_workinfoid(K_ITEM *a, K_ITEM *b); extern void zero_sharesummary(SHARESUMMARY *row, tv_t *cd, double diff); extern K_ITEM *find_sharesummary(int64_t userid, char *workername, int64_t workinfoid); +extern K_ITEM *find_last_sharesummary(int64_t userid, char *workername); extern void auto_age_older(PGconn *conn, int64_t workinfoid, char *poolinstance, char *by, char *code, char *inet, tv_t *cd); #define dbhash2btchash(_hash, _buf, _siz) \ diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 13641b8d..a6171049 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -750,58 +750,28 @@ K_ITEM *_find_create_workerstatus(int64_t userid, char *workername, TODO: combine set_block_share_counters() with this? */ void workerstatus_ready() { - K_TREE_CTX ws_ctx[1], ss_ctx[1], ms_ctx[1]; - K_ITEM *ws_item, us_look, ss_look, *us_item, *ss_item; - K_ITEM *ms_item, ms_look, *wm_item; - USERSTATS *userstats; - SHARESUMMARY looksharesummary, *sharesummary; - MARKERSUMMARY *markersummary; + K_TREE_CTX ws_ctx[1]; + K_ITEM *ws_item, *ms_item, *ss_item; WORKERSTATUS *workerstatus; + MARKERSUMMARY *markersummary; + SHARESUMMARY *sharesummary; LOGWARNING("%s(): Updating workerstatus...", __func__); - INIT_USERSTATS(&us_look); - INIT_MARKERSUMMARY(&ms_look); - INIT_SHARESUMMARY(&ss_look); ws_item = first_in_ktree(workerstatus_root, ws_ctx); while (ws_item) { DATA_WORKERSTATUS(workerstatus, ws_item); - // Zero or one - K_RLOCK(userstats_free); - us_item = find_userstats(workerstatus->userid, - workerstatus->workername); - K_RUNLOCK(userstats_free); - if (us_item) { - DATA_USERSTATS(userstats, us_item); - if (userstats->idle) { - if (tv_newer(&(workerstatus->last_idle), - &(userstats->statsdate))) { - copy_tv(&(workerstatus->last_idle), - &(userstats->statsdate)); - } - } else { - if (tv_newer(&(workerstatus->last_stats), - &(userstats->statsdate))) { - copy_tv(&(workerstatus->last_stats), - &(userstats->statsdate)); - } - } - } - K_RLOCK(markersummary_free); - // This is the last one + // This is the last share datestamp ms_item = find_markersummary_userid(workerstatus->userid, - workerstatus->workername, ms_ctx); + workerstatus->workername, + NULL); K_RUNLOCK(markersummary_free); if (ms_item) { DATA_MARKERSUMMARY(markersummary, ms_item); - K_RLOCK(workmarkers_free); - wm_item = find_workmarkerid(markersummary->markerid, - false, MARKER_PROCESSED); - K_RUNLOCK(workmarkers_free); - if (wm_item && - tv_newer(&(workerstatus->last_share), &(markersummary->lastshare))) { + if (tv_newer(&(workerstatus->last_share), + &(markersummary->lastshare))) { copy_tv(&(workerstatus->last_share), &(markersummary->lastshare)); workerstatus->last_diff = @@ -809,14 +779,9 @@ void workerstatus_ready() } } - // The last one - looksharesummary.userid = workerstatus->userid; - looksharesummary.workername = workerstatus->workername; - looksharesummary.workinfoid = MAXID; - ss_look.data = (void *)(&looksharesummary); K_RLOCK(sharesummary_free); - ss_item = find_before_in_ktree(sharesummary_root, &ss_look, - cmp_sharesummary, ss_ctx); + ss_item = find_last_sharesummary(workerstatus->userid, + workerstatus->workername); K_RUNLOCK(sharesummary_free); if (ss_item) { DATA_SHARESUMMARY(sharesummary, ss_item); @@ -1931,6 +1896,28 @@ K_ITEM *find_sharesummary(int64_t userid, char *workername, int64_t workinfoid) return find_in_ktree(sharesummary_root, &look, cmp_sharesummary, ctx); } +K_ITEM *find_last_sharesummary(int64_t userid, char *workername) +{ + SHARESUMMARY look_sharesummary, *sharesummary; + K_TREE_CTX ctx[1]; + K_ITEM look, *item; + + look_sharesummary.userid = userid; + look_sharesummary.workername = workername; + look_sharesummary.workinfoid = MAXID; + + INIT_SHARESUMMARY(&look); + look.data = (void *)(&look_sharesummary); + item = find_before_in_ktree(sharesummary_root, &look, cmp_sharesummary, ctx); + if (item) { + DATA_SHARESUMMARY(sharesummary, item); + if (sharesummary->userid != userid || + strcmp(sharesummary->workername, workername) != 0) + item = NULL; + } + return item; +} + /* TODO: markersummary checking? * However, there should be no issues since the sharesummaries are removed */ void auto_age_older(PGconn *conn, int64_t workinfoid, char *poolinstance, @@ -3577,7 +3564,7 @@ void dsp_markersummary(K_ITEM *item, FILE *stream) } } -// order by markerid asc,userid asc,workername asc +// order by markerid asc,userid asc,workername asc (has no expirydate) cmp_t cmp_markersummary(K_ITEM *a, K_ITEM *b) { MARKERSUMMARY *ma, *mb; @@ -3592,7 +3579,7 @@ cmp_t cmp_markersummary(K_ITEM *a, K_ITEM *b) return c; } -// order by userid asc,workername asc,lastshare asc +// order by userid asc,workername asc,lastshare asc (has no expirydate) cmp_t cmp_markersummary_userid(K_ITEM *a, K_ITEM *b) { MARKERSUMMARY *ma, *mb; @@ -3607,12 +3594,17 @@ cmp_t cmp_markersummary_userid(K_ITEM *a, K_ITEM *b) return c; } -// Finds the last markersummary for the worker but also returns the CTX -K_ITEM *find_markersummary_userid(int64_t userid, char *workername, K_TREE_CTX *ctx) +// Finds the last markersummary for the worker and optionally return the CTX +K_ITEM *find_markersummary_userid(int64_t userid, char *workername, + K_TREE_CTX *ctx) { + K_TREE_CTX ctx0[1]; K_ITEM look, *ms_item = NULL; MARKERSUMMARY markersummary, *ms; + if (ctx == NULL) + ctx = ctx0; + markersummary.userid = userid; markersummary.workername = workername; markersummary.lastshare.tv_sec = DATE_S_EOT;