|
|
|
@ -1819,7 +1819,8 @@ bool payments_fill(PGconn *conn)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool idcontrol_add(PGconn *conn, char *idname, char *idvalue, char *by, |
|
|
|
|
char *code, char *inet, tv_t *cd, K_TREE *trf_root) |
|
|
|
|
char *code, char *inet, tv_t *cd, |
|
|
|
|
__maybe_unused K_TREE *trf_root) |
|
|
|
|
{ |
|
|
|
|
K_ITEM *look; |
|
|
|
|
IDCONTROL *row; |
|
|
|
@ -2287,169 +2288,6 @@ unparam:
|
|
|
|
|
return workinfoid; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool workinfo_age(PGconn *conn, int64_t workinfoid, char *poolinstance, |
|
|
|
|
char *by, char *code, char *inet, tv_t *cd, |
|
|
|
|
tv_t *ss_first, tv_t *ss_last, int64_t *ss_count, |
|
|
|
|
int64_t *s_count, int64_t *s_diff) |
|
|
|
|
{ |
|
|
|
|
K_ITEM *wi_item, ss_look, *ss_item, s_look, *s_item, *tmp_item; |
|
|
|
|
K_TREE_CTX ss_ctx[1], s_ctx[1], tmp_ctx[1]; |
|
|
|
|
char cd_buf[DATE_BUFSIZ]; |
|
|
|
|
int64_t ss_tot, ss_already, ss_failed, shares_tot, shares_dumped; |
|
|
|
|
SHARESUMMARY looksharesummary, *sharesummary; |
|
|
|
|
WORKINFO *workinfo; |
|
|
|
|
SHARES lookshares, *shares; |
|
|
|
|
bool ok = false, conned = false, skipupdate; |
|
|
|
|
char error[1024]; |
|
|
|
|
|
|
|
|
|
LOGDEBUG("%s(): age", __func__); |
|
|
|
|
|
|
|
|
|
ss_first->tv_sec = ss_first->tv_usec = |
|
|
|
|
ss_last->tv_sec = ss_last->tv_usec = 0; |
|
|
|
|
*ss_count = *s_count = *s_diff = 0; |
|
|
|
|
|
|
|
|
|
wi_item = find_workinfo(workinfoid); |
|
|
|
|
if (!wi_item) { |
|
|
|
|
tv_to_buf(cd, cd_buf, sizeof(cd_buf)); |
|
|
|
|
LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s no workinfo! Age discarded!", |
|
|
|
|
__func__, workinfoid, poolinstance, |
|
|
|
|
cd->tv_sec, cd->tv_usec, cd_buf); |
|
|
|
|
goto bye; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DATA_WORKINFO(workinfo, wi_item); |
|
|
|
|
if (strcmp(poolinstance, workinfo->poolinstance) != 0) { |
|
|
|
|
tv_to_buf(cd, cd_buf, sizeof(cd_buf)); |
|
|
|
|
LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s Poolinstance changed " |
|
|
|
|
"(from %s)! Age discarded!", |
|
|
|
|
__func__, workinfoid, poolinstance, |
|
|
|
|
cd->tv_sec, cd->tv_usec, cd_buf, |
|
|
|
|
workinfo->poolinstance); |
|
|
|
|
goto bye; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
INIT_SHARESUMMARY(&ss_look); |
|
|
|
|
INIT_SHARES(&s_look); |
|
|
|
|
|
|
|
|
|
// Find the first matching sharesummary
|
|
|
|
|
looksharesummary.workinfoid = workinfoid; |
|
|
|
|
looksharesummary.userid = -1; |
|
|
|
|
looksharesummary.workername[0] = '\0'; |
|
|
|
|
|
|
|
|
|
ok = true; |
|
|
|
|
ss_tot = ss_already = ss_failed = shares_tot = shares_dumped = 0; |
|
|
|
|
ss_look.data = (void *)(&looksharesummary); |
|
|
|
|
K_RLOCK(sharesummary_free); |
|
|
|
|
ss_item = find_after_in_ktree(sharesummary_workinfoid_root, &ss_look, cmp_sharesummary_workinfoid, ss_ctx); |
|
|
|
|
K_RUNLOCK(sharesummary_free); |
|
|
|
|
DATA_SHARESUMMARY_NULL(sharesummary, ss_item); |
|
|
|
|
while (ss_item && sharesummary->workinfoid == workinfoid) { |
|
|
|
|
ss_tot++; |
|
|
|
|
error[0] = '\0'; |
|
|
|
|
skipupdate = false; |
|
|
|
|
/* Reloading during a confirm will not have any old data
|
|
|
|
|
* so finding an aged sharesummary here is an error */ |
|
|
|
|
if (reloading) { |
|
|
|
|
if (sharesummary->complete[0] == SUMMARY_COMPLETE) { |
|
|
|
|
ss_already++; |
|
|
|
|
skipupdate = true; |
|
|
|
|
if (confirm_sharesummary) { |
|
|
|
|
LOGERR("%s(): Duplicate %s found during confirm %"PRId64"/%s/%"PRId64, |
|
|
|
|
__func__, __func__, |
|
|
|
|
sharesummary->userid, |
|
|
|
|
sharesummary->workername, |
|
|
|
|
sharesummary->workinfoid); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!skipupdate) { |
|
|
|
|
if (conn == NULL && !confirm_sharesummary) { |
|
|
|
|
conn = dbconnect(); |
|
|
|
|
conned = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!sharesummary_update(conn, NULL, NULL, ss_item, by, code, inet, cd)) { |
|
|
|
|
ss_failed++; |
|
|
|
|
LOGERR("%s(): Failed to age share summary %"PRId64"/%s/%"PRId64, |
|
|
|
|
__func__, sharesummary->userid, |
|
|
|
|
sharesummary->workername, |
|
|
|
|
sharesummary->workinfoid); |
|
|
|
|
ok = false; |
|
|
|
|
} else { |
|
|
|
|
(*ss_count)++; |
|
|
|
|
*s_count += sharesummary->sharecount; |
|
|
|
|
*s_diff += sharesummary->diffacc; |
|
|
|
|
if (ss_first->tv_sec == 0 || |
|
|
|
|
!tv_newer(ss_first, &(sharesummary->firstshare))) |
|
|
|
|
copy_tv(ss_first, &(sharesummary->firstshare)); |
|
|
|
|
if (tv_newer(ss_last, &(sharesummary->lastshare))) |
|
|
|
|
copy_tv(ss_last, &(sharesummary->lastshare)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Discard the shares either way
|
|
|
|
|
lookshares.workinfoid = workinfoid; |
|
|
|
|
lookshares.userid = sharesummary->userid; |
|
|
|
|
strcpy(lookshares.workername, sharesummary->workername); |
|
|
|
|
lookshares.createdate.tv_sec = 0; |
|
|
|
|
lookshares.createdate.tv_usec = 0; |
|
|
|
|
|
|
|
|
|
s_look.data = (void *)(&lookshares); |
|
|
|
|
K_WLOCK(shares_free); |
|
|
|
|
s_item = find_after_in_ktree(shares_root, &s_look, cmp_shares, s_ctx); |
|
|
|
|
while (s_item) { |
|
|
|
|
DATA_SHARES(shares, s_item); |
|
|
|
|
if (shares->workinfoid != workinfoid || |
|
|
|
|
shares->userid != lookshares.userid || |
|
|
|
|
strcmp(shares->workername, lookshares.workername) != 0) |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
shares_tot++; |
|
|
|
|
tmp_item = next_in_ktree(s_ctx); |
|
|
|
|
shares_root = remove_from_ktree(shares_root, s_item, cmp_shares, tmp_ctx); |
|
|
|
|
k_unlink_item(shares_store, s_item); |
|
|
|
|
if (reloading && skipupdate) |
|
|
|
|
shares_dumped++; |
|
|
|
|
if (reloading && skipupdate && !error[0]) { |
|
|
|
|
snprintf(error, sizeof(error), |
|
|
|
|
"reload found aged shares: %"PRId64"/%"PRId64"/%s", |
|
|
|
|
shares->workinfoid, |
|
|
|
|
shares->userid, |
|
|
|
|
shares->workername); |
|
|
|
|
} |
|
|
|
|
k_add_head(shares_free, s_item); |
|
|
|
|
s_item = tmp_item; |
|
|
|
|
} |
|
|
|
|
K_WUNLOCK(shares_free); |
|
|
|
|
K_RLOCK(sharesummary_free); |
|
|
|
|
ss_item = next_in_ktree(ss_ctx); |
|
|
|
|
K_RUNLOCK(sharesummary_free); |
|
|
|
|
DATA_SHARESUMMARY_NULL(sharesummary, ss_item); |
|
|
|
|
|
|
|
|
|
if (error[0]) |
|
|
|
|
LOGERR("%s(): %s", __func__, error); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (conned) |
|
|
|
|
PQfinish(conn); |
|
|
|
|
|
|
|
|
|
if (ss_already || ss_failed || shares_dumped) { |
|
|
|
|
/* If all were already aged, and no shares
|
|
|
|
|
* then we don't want a message */ |
|
|
|
|
if (!(ss_already == ss_tot && shares_tot == 0)) { |
|
|
|
|
LOGERR("%s(): Summary aging of %"PRId64"/%s sstotal=%"PRId64 |
|
|
|
|
" already=%"PRId64" failed=%"PRId64 |
|
|
|
|
", sharestotal=%"PRId64" dumped=%"PRId64, |
|
|
|
|
__func__, workinfoid, poolinstance, ss_tot, |
|
|
|
|
ss_already, ss_failed, shares_tot, |
|
|
|
|
shares_dumped); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
bye: |
|
|
|
|
return ok; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool workinfo_fill(PGconn *conn) |
|
|
|
|
{ |
|
|
|
|
ExecStatusType rescode; |
|
|
|
|