Browse Source

ckdb - fix old worker lastshare in workerstatus

master
kanoi 10 years ago
parent
commit
7072135a72
  1. 3
      src/ckdb.h
  2. 92
      src/ckdb_data.c

3
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.040" #define CKDB_VERSION DB_VERSION"-1.041"
#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__
@ -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 void zero_sharesummary(SHARESUMMARY *row, tv_t *cd, double diff);
extern K_ITEM *find_sharesummary(int64_t userid, char *workername, extern K_ITEM *find_sharesummary(int64_t userid, char *workername,
int64_t workinfoid); 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, extern void auto_age_older(PGconn *conn, int64_t workinfoid, char *poolinstance,
char *by, char *code, char *inet, tv_t *cd); char *by, char *code, char *inet, tv_t *cd);
#define dbhash2btchash(_hash, _buf, _siz) \ #define dbhash2btchash(_hash, _buf, _siz) \

92
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? */ TODO: combine set_block_share_counters() with this? */
void workerstatus_ready() void workerstatus_ready()
{ {
K_TREE_CTX ws_ctx[1], ss_ctx[1], ms_ctx[1]; K_TREE_CTX ws_ctx[1];
K_ITEM *ws_item, us_look, ss_look, *us_item, *ss_item; K_ITEM *ws_item, *ms_item, *ss_item;
K_ITEM *ms_item, ms_look, *wm_item;
USERSTATS *userstats;
SHARESUMMARY looksharesummary, *sharesummary;
MARKERSUMMARY *markersummary;
WORKERSTATUS *workerstatus; WORKERSTATUS *workerstatus;
MARKERSUMMARY *markersummary;
SHARESUMMARY *sharesummary;
LOGWARNING("%s(): Updating workerstatus...", __func__); 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); ws_item = first_in_ktree(workerstatus_root, ws_ctx);
while (ws_item) { while (ws_item) {
DATA_WORKERSTATUS(workerstatus, 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); K_RLOCK(markersummary_free);
// This is the last one // This is the last share datestamp
ms_item = find_markersummary_userid(workerstatus->userid, ms_item = find_markersummary_userid(workerstatus->userid,
workerstatus->workername, ms_ctx); workerstatus->workername,
NULL);
K_RUNLOCK(markersummary_free); K_RUNLOCK(markersummary_free);
if (ms_item) { if (ms_item) {
DATA_MARKERSUMMARY(markersummary, ms_item); DATA_MARKERSUMMARY(markersummary, ms_item);
K_RLOCK(workmarkers_free); if (tv_newer(&(workerstatus->last_share),
wm_item = find_workmarkerid(markersummary->markerid, &(markersummary->lastshare))) {
false, MARKER_PROCESSED);
K_RUNLOCK(workmarkers_free);
if (wm_item &&
tv_newer(&(workerstatus->last_share), &(markersummary->lastshare))) {
copy_tv(&(workerstatus->last_share), copy_tv(&(workerstatus->last_share),
&(markersummary->lastshare)); &(markersummary->lastshare));
workerstatus->last_diff = 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); K_RLOCK(sharesummary_free);
ss_item = find_before_in_ktree(sharesummary_root, &ss_look, ss_item = find_last_sharesummary(workerstatus->userid,
cmp_sharesummary, ss_ctx); workerstatus->workername);
K_RUNLOCK(sharesummary_free); K_RUNLOCK(sharesummary_free);
if (ss_item) { if (ss_item) {
DATA_SHARESUMMARY(sharesummary, 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); 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? /* TODO: markersummary checking?
* However, there should be no issues since the sharesummaries are removed */ * However, there should be no issues since the sharesummaries are removed */
void auto_age_older(PGconn *conn, int64_t workinfoid, char *poolinstance, 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) cmp_t cmp_markersummary(K_ITEM *a, K_ITEM *b)
{ {
MARKERSUMMARY *ma, *mb; MARKERSUMMARY *ma, *mb;
@ -3592,7 +3579,7 @@ cmp_t cmp_markersummary(K_ITEM *a, K_ITEM *b)
return c; 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) cmp_t cmp_markersummary_userid(K_ITEM *a, K_ITEM *b)
{ {
MARKERSUMMARY *ma, *mb; MARKERSUMMARY *ma, *mb;
@ -3607,12 +3594,17 @@ cmp_t cmp_markersummary_userid(K_ITEM *a, K_ITEM *b)
return c; return c;
} }
// Finds the last markersummary for the worker but also returns the 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_ITEM *find_markersummary_userid(int64_t userid, char *workername,
K_TREE_CTX *ctx)
{ {
K_TREE_CTX ctx0[1];
K_ITEM look, *ms_item = NULL; K_ITEM look, *ms_item = NULL;
MARKERSUMMARY markersummary, *ms; MARKERSUMMARY markersummary, *ms;
if (ctx == NULL)
ctx = ctx0;
markersummary.userid = userid; markersummary.userid = userid;
markersummary.workername = workername; markersummary.workername = workername;
markersummary.lastshare.tv_sec = DATE_S_EOT; markersummary.lastshare.tv_sec = DATE_S_EOT;

Loading…
Cancel
Save