Browse Source

ckdb/php add last accepted share to tables, code and scripts

master
kanoi 9 years ago
parent
commit
019062d94c
  1. 9
      pool/base.php
  2. 5
      pool/page_pplns2.php
  3. 5
      pool/page_workers.php
  4. 6
      sql/ckdb.sql
  5. 38
      sql/v1.0.2-v1.0.3.sql
  6. 43
      src/ckdb.c
  7. 26
      src/ckdb.h
  8. 41
      src/ckdb_cmd.c
  9. 60
      src/ckdb_data.c
  10. 203
      src/ckdb_dbio.c

9
pool/base.php

@ -99,7 +99,7 @@ function howlongago($sec)
return $des; return $des;
} }
# #
function howmanyhrs($tot) function howmanyhrs($tot, $days = false)
{ {
$sec = round($tot); $sec = round($tot);
if ($sec < 60) if ($sec < 60)
@ -114,6 +114,13 @@ function howmanyhrs($tot)
{ {
$hr = floor($min / 60); $hr = floor($min / 60);
$min -= $hr * 60; $min -= $hr * 60;
if ($days && $hr > 23)
{
$dy = floor($hr / 24);
$hr -= $dy * 24;
$des = $dy.'d '.$hr.'hr '.$min.'m '.$sec.'s';
}
else
$des = $hr.'hr '.$min.'m '.$sec.'s'; $des = $hr.'hr '.$min.'m '.$sec.'s';
} }
} }

5
pool/page_pplns2.php

@ -121,6 +121,9 @@ function fmtdata($code, $val)
case '.': case '.':
$ret = number_format($val, 1); $ret = number_format($val, 1);
break; break;
case '@':
$ret = howmanyhrs($val, true);
break;
default: default:
$ret = $val; $ret = $val;
} }
@ -186,6 +189,7 @@ Block: <input type=text name=blk size=10 value='$blkuse'>
'PPLNS Wanted' => '.diff_want', 'PPLNS Wanted' => '.diff_want',
'PPLNS Used' => '.diffacc_total', 'PPLNS Used' => '.diffacc_total',
'Elapsed Seconds' => ',pplns_elapsed', 'Elapsed Seconds' => ',pplns_elapsed',
'Elapsed Time' => '@pplns_elapsed',
'Users' => 'rows', 'Users' => 'rows',
'Oldest Workinfoid' => 'begin_workinfoid', 'Oldest Workinfoid' => 'begin_workinfoid',
'Oldest Time' => 'begin_stamp', 'Oldest Time' => 'begin_stamp',
@ -241,6 +245,7 @@ Block: <input type=text name=blk size=10 value='$blkuse'>
{ {
case ',': case ',':
case '.': case '.':
case '@':
$nm = substr($name, 1); $nm = substr($name, 1);
$fmt = fmtdata($name[0], $ans[$nm]); $fmt = fmtdata($name[0], $ans[$nm]);
break; break;

5
pool/page_workers.php

@ -61,6 +61,7 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
$all[] = array('workername' => $ans['workername:'.$i], $all[] = array('workername' => $ans['workername:'.$i],
'w_lastshare' => $ans['w_lastshare:'.$i], 'w_lastshare' => $ans['w_lastshare:'.$i],
'w_lastshareacc' => $ans['w_lastshareacc:'.$i],
'w_lastdiff' => $ans['w_lastdiff:'.$i], 'w_lastdiff' => $ans['w_lastdiff:'.$i],
'w_shareacc' => $ans['w_shareacc:'.$i], 'w_shareacc' => $ans['w_shareacc:'.$i],
'w_diffacc' => $ans['w_diffacc:'.$i], 'w_diffacc' => $ans['w_diffacc:'.$i],
@ -80,6 +81,8 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
if ($old !== false && $lst > $old) if ($old !== false && $lst > $old)
continue; continue;
$lstacc = $now - $all[$i]['w_lastshareacc'];
if ((($offset) % 2) == 0) if ((($offset) % 2) == 0)
$row = 'even'; $row = 'even';
else else
@ -93,7 +96,7 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
$ld = '&nbsp;'; $ld = '&nbsp;';
$pg .= "<td class=dr>$ld</td>"; $pg .= "<td class=dr>$ld</td>";
$pg .= "<td class=dr data-srt=$lst>".howlongago($lst).'</td>'; $pg .= "<td class=dr data-srt=$lstacc>".howlongago($lstacc).'</td>';
$shareacc = number_format($all[$i]['w_shareacc'], 0); $shareacc = number_format($all[$i]['w_shareacc'], 0);
$totshare += $all[$i]['w_shareacc']; $totshare += $all[$i]['w_shareacc'];

6
sql/ckdb.sql

@ -247,6 +247,8 @@ CREATE TABLE sharesummary ( -- per workinfo for each user+worker
errorcount bigint NOT NULL, errorcount bigint NOT NULL,
firstshare timestamp with time zone NOT NULL, firstshare timestamp with time zone NOT NULL,
lastshare timestamp with time zone NOT NULL, lastshare timestamp with time zone NOT NULL,
firstshareacc timestamp with time zone NOT NULL,
lastshareacc timestamp with time zone NOT NULL,
lastdiffacc float NOT NULL, lastdiffacc float NOT NULL,
complete char NOT NULL, complete char NOT NULL,
createdate timestamp with time zone NOT NULL, createdate timestamp with time zone NOT NULL,
@ -311,6 +313,8 @@ CREATE TABLE markersummary ( -- sum of sharesummary for a workinfo range
errorcount bigint NOT NULL, errorcount bigint NOT NULL,
firstshare timestamp with time zone NOT NULL, firstshare timestamp with time zone NOT NULL,
lastshare timestamp with time zone NOT NULL, lastshare timestamp with time zone NOT NULL,
firstshareacc timestamp with time zone NOT NULL,
lastshareacc timestamp with time zone NOT NULL,
lastdiffacc float NOT NULL, lastdiffacc float NOT NULL,
createdate timestamp with time zone NOT NULL, createdate timestamp with time zone NOT NULL,
createby character varying(64) NOT NULL, createby character varying(64) NOT NULL,
@ -464,4 +468,4 @@ CREATE TABLE version (
PRIMARY KEY (vlock) PRIMARY KEY (vlock)
); );
insert into version (vlock,version) values (1,'1.0.2'); insert into version (vlock,version) values (1,'1.0.3');

38
sql/v1.0.2-v1.0.3.sql

@ -0,0 +1,38 @@
SET SESSION AUTHORIZATION 'postgres';
BEGIN transaction;
DO $$
DECLARE ver TEXT;
BEGIN
UPDATE version set version='1.0.3' where vlock=1 and version='1.0.2';
IF found THEN
RETURN;
END IF;
SELECT version into ver from version
WHERE vlock=1;
RAISE EXCEPTION 'Wrong DB version - expect "1.0.2" - found "%"', ver;
END $$;
ALTER TABLE ONLY markersummary
ADD COLUMN firstshareacc timestamp with time zone DEFAULT '1970-01-01 00:00:00+00' NOT NULL,
ADD COLUMN lastshareacc timestamp with time zone DEFAULT '1970-01-01 00:00:00+00' NOT NULL;
ALTER TABLE ONLY markersummary
ALTER COLUMN firstshareacc DROP DEFAULT,
ALTER COLUMN lastshareacc DROP DEFAULT;
ALTER TABLE ONLY sharesummary
ADD COLUMN firstshareacc timestamp with time zone DEFAULT '1970-01-01 00:00:00+00' NOT NULL,
ADD COLUMN lastshareacc timestamp with time zone DEFAULT '1970-01-01 00:00:00+00' NOT NULL;
ALTER TABLE ONLY sharesummary
ALTER COLUMN firstshareacc DROP DEFAULT,
ALTER COLUMN lastshareacc DROP DEFAULT;
END transaction;

43
src/ckdb.c

@ -267,6 +267,7 @@ static bool seqdata_reload_lost = false;
tv_t last_heartbeat; tv_t last_heartbeat;
tv_t last_workinfo; tv_t last_workinfo;
tv_t last_share; tv_t last_share;
tv_t last_share_acc;
tv_t last_share_inv; tv_t last_share_inv;
tv_t last_auth; tv_t last_auth;
cklock_t last_lock; cklock_t last_lock;
@ -2950,12 +2951,14 @@ static void summarise_blocks()
return; return;
} }
has_ss = true; has_ss = true;
if (sharesummary->diffacc > 0) {
if (elapsed_start.tv_sec == 0 || if (elapsed_start.tv_sec == 0 ||
!tv_newer(&elapsed_start, &(sharesummary->firstshare))) { !tv_newer(&elapsed_start, &(sharesummary->firstshareacc))) {
copy_tv(&elapsed_start, &(sharesummary->firstshare)); copy_tv(&elapsed_start, &(sharesummary->firstshareacc));
}
if (tv_newer(&elapsed_finish, &(sharesummary->lastshareacc)))
copy_tv(&elapsed_finish, &(sharesummary->lastshareacc));
} }
if (tv_newer(&elapsed_finish, &(sharesummary->lastshare)))
copy_tv(&elapsed_finish, &(sharesummary->lastshare));
diffacc += sharesummary->diffacc; diffacc += sharesummary->diffacc;
diffinv += sharesummary->diffsta + sharesummary->diffdup + diffinv += sharesummary->diffsta + sharesummary->diffdup +
@ -3003,12 +3006,14 @@ static void summarise_blocks()
DATA_MARKERSUMMARY_NULL(markersummary, ms_item); DATA_MARKERSUMMARY_NULL(markersummary, ms_item);
while (ms_item && markersummary->markerid == workmarkers->markerid) { while (ms_item && markersummary->markerid == workmarkers->markerid) {
has_ms = true; has_ms = true;
if (markersummary->diffacc > 0) {
if (elapsed_start.tv_sec == 0 || if (elapsed_start.tv_sec == 0 ||
!tv_newer(&elapsed_start, &(markersummary->firstshare))) { !tv_newer(&elapsed_start, &(markersummary->firstshareacc))) {
copy_tv(&elapsed_start, &(markersummary->firstshare)); copy_tv(&elapsed_start, &(markersummary->firstshareacc));
}
if (tv_newer(&elapsed_finish, &(markersummary->lastshareacc)))
copy_tv(&elapsed_finish, &(markersummary->lastshareacc));
} }
if (tv_newer(&elapsed_finish, &(markersummary->lastshare)))
copy_tv(&elapsed_finish, &(markersummary->lastshare));
diffacc += markersummary->diffacc; diffacc += markersummary->diffacc;
diffinv += markersummary->diffsta + markersummary->diffdup + diffinv += markersummary->diffsta + markersummary->diffdup +
@ -3149,7 +3154,7 @@ static void make_a_shift_mark()
MARKS *marks = NULL, *sh_marks = NULL; MARKS *marks = NULL, *sh_marks = NULL;
int64_t ss_age_wid, last_marks_wid, marks_wid, prev_wid; int64_t ss_age_wid, last_marks_wid, marks_wid, prev_wid;
bool was_block = false, ok; bool was_block = false, ok;
char cd_buf[DATE_BUFSIZ], cd_buf2[DATE_BUFSIZ]; char cd_buf[DATE_BUFSIZ], cd_buf2[DATE_BUFSIZ], cd_buf3[DATE_BUFSIZ];
int used_wid; int used_wid;
/* If there are no CURRENT marks, make the first one by /* If there are no CURRENT marks, make the first one by
@ -3225,12 +3230,13 @@ static void make_a_shift_mark()
} }
K_RUNLOCK(sharesummary_free); K_RUNLOCK(sharesummary_free);
if (ss_item) { if (ss_item) {
tv_to_buf(&(sharesummary->lastshare), cd_buf, sizeof(cd_buf)); tv_to_buf(&(sharesummary->lastshareacc), cd_buf, sizeof(cd_buf));
tv_to_buf(&(sharesummary->createdate), cd_buf2, sizeof(cd_buf2)); tv_to_buf(&(sharesummary->lastshare), cd_buf2, sizeof(cd_buf2));
LOGDEBUG("%s() last sharesummary %s/%s/%"PRId64"/%s/%s", tv_to_buf(&(sharesummary->createdate), cd_buf3, sizeof(cd_buf3));
LOGDEBUG("%s() last sharesummary %s/%s/%"PRId64"/%s/%s/%s",
__func__, sharesummary->complete, __func__, sharesummary->complete,
sharesummary->workername, sharesummary->workername,
ss_age_wid, cd_buf, cd_buf2); ss_age_wid, cd_buf, cd_buf2, cd_buf3);
} }
LOGDEBUG("%s() age sharesummary limit wid %"PRId64, __func__, ss_age_wid); LOGDEBUG("%s() age sharesummary limit wid %"PRId64, __func__, ss_age_wid);
@ -3407,16 +3413,18 @@ static void make_a_shift_mark()
/* Not aged = shift not complete /* Not aged = shift not complete
* Though, it shouldn't happen */ * Though, it shouldn't happen */
if (sharesummary->complete[0] == SUMMARY_NEW) { if (sharesummary->complete[0] == SUMMARY_NEW) {
tv_to_buf(&(sharesummary->lastshare), tv_to_buf(&(sharesummary->lastshareacc),
cd_buf, sizeof(cd_buf)); cd_buf, sizeof(cd_buf));
tv_to_buf(&(sharesummary->createdate), tv_to_buf(&(sharesummary->lastshare),
cd_buf2, sizeof(cd_buf2)); cd_buf2, sizeof(cd_buf2));
tv_to_buf(&(sharesummary->createdate),
cd_buf3, sizeof(cd_buf3));
LOGEMERG("%s() ERR unaged sharesummary " LOGEMERG("%s() ERR unaged sharesummary "
"%s/%s/%"PRId64"/%s/%s", "%s/%s/%"PRId64"/%s/%s/%s",
__func__, sharesummary->complete, __func__, sharesummary->complete,
sharesummary->workername, sharesummary->workername,
sharesummary->workinfoid, sharesummary->workinfoid,
cd_buf, cd_buf2); cd_buf, cd_buf2, cd_buf3);
return; return;
} }
} }
@ -4690,6 +4698,7 @@ static void *listener(void *arg)
setnow(&last_heartbeat); setnow(&last_heartbeat);
copy_tv(&last_workinfo, &last_heartbeat); copy_tv(&last_workinfo, &last_heartbeat);
copy_tv(&last_share, &last_heartbeat); copy_tv(&last_share, &last_heartbeat);
copy_tv(&last_share_acc, &last_heartbeat);
copy_tv(&last_share_inv, &last_heartbeat); copy_tv(&last_share_inv, &last_heartbeat);
copy_tv(&last_auth, &last_heartbeat); copy_tv(&last_auth, &last_heartbeat);
ck_wunlock(&last_lock); ck_wunlock(&last_lock);

26
src/ckdb.h

@ -54,8 +54,8 @@
*/ */
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.2" #define DB_VERSION "1.0.3"
#define CKDB_VERSION DB_VERSION"-1.311" #define CKDB_VERSION DB_VERSION"-1.320"
#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__
@ -312,6 +312,7 @@ extern bool everyone_die;
extern tv_t last_heartbeat; extern tv_t last_heartbeat;
extern tv_t last_workinfo; extern tv_t last_workinfo;
extern tv_t last_share; extern tv_t last_share;
extern tv_t last_share_acc;
extern tv_t last_share_inv; extern tv_t last_share_inv;
extern tv_t last_auth; extern tv_t last_auth;
extern cklock_t last_lock; extern cklock_t last_lock;
@ -1435,6 +1436,8 @@ typedef struct sharesummary {
int64_t errorcount; int64_t errorcount;
tv_t firstshare; tv_t firstshare;
tv_t lastshare; tv_t lastshare;
tv_t firstshareacc;
tv_t lastshareacc;
double lastdiffacc; double lastdiffacc;
char complete[TXT_FLAG+1]; char complete[TXT_FLAG+1];
MODIFYDATECONTROLPOINTERS; MODIFYDATECONTROLPOINTERS;
@ -1830,7 +1833,8 @@ typedef struct workerstatus {
char workername[TXT_BIG+1]; char workername[TXT_BIG+1];
tv_t last_auth; tv_t last_auth;
tv_t last_share; tv_t last_share;
double last_diff; tv_t last_share_acc;
double last_diff_acc;
tv_t last_stats; tv_t last_stats;
tv_t last_idle; tv_t last_idle;
// Below gets reset on each block // Below gets reset on each block
@ -1890,6 +1894,8 @@ typedef struct markersummary {
int64_t errorcount; int64_t errorcount;
tv_t firstshare; tv_t firstshare;
tv_t lastshare; tv_t lastshare;
tv_t firstshareacc;
tv_t lastshareacc;
double lastdiffacc; double lastdiffacc;
MODIFYDATECONTROLPOINTERS; MODIFYDATECONTROLPOINTERS;
} MARKERSUMMARY; } MARKERSUMMARY;
@ -2297,7 +2303,7 @@ extern cmp_t cmp_shareerrors(K_ITEM *a, K_ITEM *b);
extern void dsp_sharesummary(K_ITEM *item, FILE *stream); extern void dsp_sharesummary(K_ITEM *item, FILE *stream);
extern cmp_t cmp_sharesummary(K_ITEM *a, K_ITEM *b); extern cmp_t cmp_sharesummary(K_ITEM *a, K_ITEM *b);
extern cmp_t cmp_sharesummary_workinfoid(K_ITEM *a, K_ITEM *b); 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);
#define find_sharesummary(_userid, _workername, _workinfoid) \ #define find_sharesummary(_userid, _workername, _workinfoid) \
_find_sharesummary(_userid, _workername, _workinfoid, false) _find_sharesummary(_userid, _workername, _workinfoid, false)
#define find_sharesummary_p(_workinfoid) \ #define find_sharesummary_p(_workinfoid) \
@ -2518,12 +2524,16 @@ extern bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmar
char *by, char *code, char *inet, char *by, char *code, char *inet,
tv_t *cd, K_TREE *trf_root); tv_t *cd, K_TREE *trf_root);
extern char *ooo_status(char *buf, size_t siz); extern char *ooo_status(char *buf, size_t siz);
#define sharesummary_update(_s_row, _e_row, _ss_item, _by, _code, _inet, _cd) \ #define sharesummary_update(_s_row, _e_row, _by, _code, _inet, _cd) \
_sharesummary_update(_s_row, _e_row, _ss_item, _by, _code, _inet, _cd, \ _sharesummary_update(_s_row, _e_row, _by, _code, _inet, _cd, \
WHERE_FFL_HERE) WHERE_FFL_HERE)
extern bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item, extern bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, char *by,
char *by, char *code, char *inet, tv_t *cd, char *code, char *inet, tv_t *cd,
WHERE_FFL_ARGS); WHERE_FFL_ARGS);
#define sharesummary_age(_ss_item, _by, _code, _inet, _cd) \
_sharesummary_age(_ss_item, _by, _code, _inet, _cd, WHERE_FFL_HERE)
extern bool _sharesummary_age(K_ITEM *ss_item, char *by, char *code, char *inet,
tv_t *cd, WHERE_FFL_ARGS);
extern bool sharesummary_fill(PGconn *conn); extern bool sharesummary_fill(PGconn *conn);
extern bool blocks_stats(PGconn *conn, int32_t height, char *blockhash, extern bool blocks_stats(PGconn *conn, int32_t height, char *blockhash,
double diffacc, double diffinv, double shareacc, double diffacc, double diffinv, double shareacc,

41
src/ckdb_cmd.c

@ -2001,6 +2001,7 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
if (ws_item) { if (ws_item) {
DATA_WORKERSTATUS(workerstatus, ws_item); DATA_WORKERSTATUS(workerstatus, ws_item);
K_RLOCK(workerstatus_free); K_RLOCK(workerstatus_free);
// good or bad - either means active
copy_tv(&last_share, &(workerstatus->last_share)); copy_tv(&last_share, &(workerstatus->last_share));
K_RUNLOCK(workerstatus_free); K_RUNLOCK(workerstatus_free);
} else } else
@ -2028,7 +2029,9 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
double w_hashrate24hr; double w_hashrate24hr;
int64_t w_elapsed; int64_t w_elapsed;
tv_t w_lastshare; tv_t w_lastshare;
double w_lastdiff, w_diffacc, w_diffinv; tv_t w_lastshareacc;
double w_lastdiffacc, w_diffacc;
double w_diffinv;
double w_diffsta, w_diffdup; double w_diffsta, w_diffdup;
double w_diffhi, w_diffrej; double w_diffhi, w_diffrej;
double w_shareacc, w_shareinv; double w_shareacc, w_shareinv;
@ -2042,8 +2045,9 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
w_elapsed = -1; w_elapsed = -1;
if (!ws_item) { if (!ws_item) {
w_lastshare.tv_sec = 0L; w_lastshare.tv_sec =
w_lastdiff = w_diffacc = w_lastshareacc.tv_sec = 0L;
w_lastdiffacc = w_diffacc =
w_diffinv = w_diffsta = w_diffinv = w_diffsta =
w_diffdup = w_diffhi = w_diffdup = w_diffhi =
w_diffrej = w_shareacc = w_diffrej = w_shareacc =
@ -2056,7 +2060,8 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
// It's bad to read possibly changing data // It's bad to read possibly changing data
K_RLOCK(workerstatus_free); K_RLOCK(workerstatus_free);
w_lastshare.tv_sec = workerstatus->last_share.tv_sec; w_lastshare.tv_sec = workerstatus->last_share.tv_sec;
w_lastdiff = workerstatus->last_diff; w_lastshareacc.tv_sec = workerstatus->last_share_acc.tv_sec;
w_lastdiffacc = workerstatus->last_diff_acc;
w_diffacc = workerstatus->block_diffacc; w_diffacc = workerstatus->block_diffacc;
w_diffinv = workerstatus->block_diffinv; w_diffinv = workerstatus->block_diffinv;
w_diffsta = workerstatus->block_diffsta; w_diffsta = workerstatus->block_diffsta;
@ -2112,7 +2117,11 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
snprintf(tmp, sizeof(tmp), "w_lastshare:%d=%s%c", rows, reply, FLDSEP); snprintf(tmp, sizeof(tmp), "w_lastshare:%d=%s%c", rows, reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
double_to_buf(w_lastdiff, reply, sizeof(reply)); int_to_buf((int)(w_lastshareacc.tv_sec), reply, sizeof(reply));
snprintf(tmp, sizeof(tmp), "w_lastshareacc:%d=%s%c", rows, reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
double_to_buf(w_lastdiffacc, reply, sizeof(reply));
snprintf(tmp, sizeof(tmp), "w_lastdiff:%d=%s%c", rows, reply, FLDSEP); snprintf(tmp, sizeof(tmp), "w_lastdiff:%d=%s%c", rows, reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
@ -2185,7 +2194,7 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
"workername,difficultydefault,idlenotificationenabled," "workername,difficultydefault,idlenotificationenabled,"
"idlenotificationtime", "idlenotificationtime",
stats ? ",w_hashrate5m,w_hashrate1hr,w_hashrate24hr," stats ? ",w_hashrate5m,w_hashrate1hr,w_hashrate24hr,"
"w_elapsed,w_lastshare," "w_elapsed,w_lastshare,w_lastshareacc,"
"w_lastdiff,w_diffacc,w_diffinv," "w_lastdiff,w_diffacc,w_diffinv,"
"w_diffsta,w_diffdup,w_diffhi,w_diffrej," "w_diffsta,w_diffdup,w_diffhi,w_diffrej,"
"w_shareacc,w_shareinv," "w_shareacc,w_shareinv,"
@ -2504,10 +2513,11 @@ wiconf:
int32_t errn; int32_t errn;
TXT_TO_INT("errn", transfer_data(i_errn), errn); TXT_TO_INT("errn", transfer_data(i_errn), errn);
ck_wlock(&last_lock); ck_wlock(&last_lock);
if (errn == SE_NONE)
setnow(&last_share); setnow(&last_share);
if (errn == SE_NONE)
copy_tv(&last_share_acc, &last_share);
else else
setnow(&last_share_inv); copy_tv(&last_share_inv, &last_share);
ck_wunlock(&last_lock); ck_wunlock(&last_lock);
} }
LOGDEBUG("%s.ok.added %s", id, transfer_data(i_nonce)); LOGDEBUG("%s.ok.added %s", id, transfer_data(i_nonce));
@ -3114,6 +3124,9 @@ static char *cmd_homepage(__maybe_unused PGconn *conn, char *cmd, char *id,
ftv_to_buf(&last_share, reply, siz); ftv_to_buf(&last_share, reply, siz);
snprintf(tmp, sizeof(tmp), "lastsh=%s%c", reply, FLDSEP); snprintf(tmp, sizeof(tmp), "lastsh=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
ftv_to_buf(&last_share_acc, reply, siz);
snprintf(tmp, sizeof(tmp), "lastshacc=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
ftv_to_buf(&last_share_inv, reply, siz); ftv_to_buf(&last_share_inv, reply, siz);
snprintf(tmp, sizeof(tmp), "lastshinv=%s%c", reply, FLDSEP); snprintf(tmp, sizeof(tmp), "lastshinv=%s%c", reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
@ -4137,7 +4150,7 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id,
if (ss_item) if (ss_item)
end_workinfoid = sharesummary->workinfoid; end_workinfoid = sharesummary->workinfoid;
/* add up all sharesummaries until >= diff_want /* add up all sharesummaries until >= diff_want
* also record the latest lastshare - that will be the end pplns time * also record the latest lastshareacc - that will be the end pplns time
* which will be >= block_tv */ * which will be >= block_tv */
while (total_diff < diff_want && ss_item) { while (total_diff < diff_want && ss_item) {
switch (sharesummary->complete[0]) { switch (sharesummary->complete[0]) {
@ -4159,8 +4172,8 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id,
acc_share_count += sharesummary->shareacc; acc_share_count += sharesummary->shareacc;
total_diff += (int64_t)(sharesummary->diffacc); total_diff += (int64_t)(sharesummary->diffacc);
begin_workinfoid = sharesummary->workinfoid; begin_workinfoid = sharesummary->workinfoid;
if (tv_newer(&end_tv, &(sharesummary->lastshare))) if (tv_newer(&end_tv, &(sharesummary->lastshareacc)))
copy_tv(&end_tv, &(sharesummary->lastshare)); copy_tv(&end_tv, &(sharesummary->lastshareacc));
mu_root = upd_add_mu(mu_root, mu_store, mu_root = upd_add_mu(mu_root, mu_store,
sharesummary->userid, sharesummary->userid,
(int64_t)(sharesummary->diffacc)); (int64_t)(sharesummary->diffacc));
@ -4233,8 +4246,8 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id,
acc_share_count += markersummary->shareacc; acc_share_count += markersummary->shareacc;
total_diff += (int64_t)(markersummary->diffacc); total_diff += (int64_t)(markersummary->diffacc);
begin_workinfoid = workmarkers->workinfoidstart; begin_workinfoid = workmarkers->workinfoidstart;
if (tv_newer(&end_tv, &(markersummary->lastshare))) if (tv_newer(&end_tv, &(markersummary->lastshareacc)))
copy_tv(&end_tv, &(markersummary->lastshare)); copy_tv(&end_tv, &(markersummary->lastshareacc));
mu_root = upd_add_mu(mu_root, mu_store, mu_root = upd_add_mu(mu_root, mu_store,
markersummary->userid, markersummary->userid,
(int64_t)(markersummary->diffacc)); (int64_t)(markersummary->diffacc));
@ -6521,5 +6534,5 @@ struct CMDS ckdb_cmds[] = {
{ CMD_SHSTA, "shsta", true, false, cmd_shsta, SEQ_NONE, ACCESS_SYSTEM }, { CMD_SHSTA, "shsta", true, false, cmd_shsta, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_USERINFO, "userinfo", false, false, cmd_userinfo, SEQ_NONE, ACCESS_WEB }, { CMD_USERINFO, "userinfo", false, false, cmd_userinfo, SEQ_NONE, ACCESS_WEB },
{ CMD_BTCSET, "btcset", false, false, cmd_btcset, SEQ_NONE, ACCESS_SYSTEM }, { CMD_BTCSET, "btcset", false, false, cmd_btcset, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_END, NULL, false, false, NULL, SEQ_NONE, NULL } { CMD_END, NULL, false, false, NULL, SEQ_NONE, 0 }
}; };

60
src/ckdb_data.c

@ -958,7 +958,12 @@ void workerstatus_ready()
&(markersummary->lastshare))) { &(markersummary->lastshare))) {
copy_tv(&(workerstatus->last_share), copy_tv(&(workerstatus->last_share),
&(markersummary->lastshare)); &(markersummary->lastshare));
workerstatus->last_diff = }
if (tv_newer(&(workerstatus->last_share_acc),
&(markersummary->lastshareacc))) {
copy_tv(&(workerstatus->last_share_acc),
&(markersummary->lastshareacc));
workerstatus->last_diff_acc =
markersummary->lastdiffacc; markersummary->lastdiffacc;
} }
} }
@ -973,7 +978,12 @@ void workerstatus_ready()
&(sharesummary->lastshare))) { &(sharesummary->lastshare))) {
copy_tv(&(workerstatus->last_share), copy_tv(&(workerstatus->last_share),
&(sharesummary->lastshare)); &(sharesummary->lastshare));
workerstatus->last_diff = }
if (tv_newer(&(workerstatus->last_share_acc),
&(sharesummary->lastshareacc))) {
copy_tv(&(workerstatus->last_share_acc),
&(sharesummary->lastshareacc));
workerstatus->last_diff_acc =
sharesummary->lastdiffacc; sharesummary->lastdiffacc;
} }
} }
@ -1017,10 +1027,8 @@ void _workerstatus_update(AUTHS *auths, SHARES *shares,
if (item) { if (item) {
DATA_WORKERSTATUS(row, item); DATA_WORKERSTATUS(row, item);
K_WLOCK(workerstatus_free); K_WLOCK(workerstatus_free);
if (tv_newer(&(row->last_share), &(shares->createdate))) { if (tv_newer(&(row->last_share), &(shares->createdate)))
copy_tv(&(row->last_share), &(shares->createdate)); copy_tv(&(row->last_share), &(shares->createdate));
row->last_diff = shares->diff;
}
if (row->active_start.tv_sec == 0) if (row->active_start.tv_sec == 0)
copy_tv(&(row->active_start), &(shares->createdate)); copy_tv(&(row->active_start), &(shares->createdate));
switch (shares->errn) { switch (shares->errn) {
@ -1029,6 +1037,12 @@ void _workerstatus_update(AUTHS *auths, SHARES *shares,
row->block_shareacc++; row->block_shareacc++;
row->active_diffacc += shares->diff; row->active_diffacc += shares->diff;
row->active_shareacc++; row->active_shareacc++;
if (tv_newer(&(row->last_share_acc),
&(shares->createdate))) {
copy_tv(&(row->last_share_acc),
&(shares->createdate));
row->last_diff_acc = shares->diff;
}
break; break;
case SE_STALE: case SE_STALE:
row->block_diffinv += shares->diff; row->block_diffinv += shares->diff;
@ -2118,7 +2132,8 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, char *by, char *code,
error[0] = '\0'; error[0] = '\0';
skipupdate = false; skipupdate = false;
/* Reloading during a confirm will not have any old data /* Reloading during a confirm will not have any old data
* so finding an aged sharesummary here is an error */ * so finding an aged sharesummary here is an error
* N.B. this can only happen with (very) old reload files */
if (reloading) { if (reloading) {
if (sharesummary->complete[0] == SUMMARY_COMPLETE) { if (sharesummary->complete[0] == SUMMARY_COMPLETE) {
ss_already++; ss_already++;
@ -2134,7 +2149,7 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, char *by, char *code,
} }
if (!skipupdate) { if (!skipupdate) {
if (!sharesummary_update(NULL, NULL, ss_item, by, code, inet, cd)) { if (!sharesummary_age(ss_item, by, code, inet, cd)) {
ss_failed++; ss_failed++;
LOGERR("%s(): Failed to age sharesummary %"PRId64"/%s/%"PRId64, LOGERR("%s(): Failed to age sharesummary %"PRId64"/%s/%"PRId64,
__func__, sharesummary->userid, __func__, sharesummary->userid,
@ -2364,17 +2379,17 @@ cmp_t cmp_sharesummary_workinfoid(K_ITEM *a, K_ITEM *b)
return c; return c;
} }
void zero_sharesummary(SHARESUMMARY *row, tv_t *cd, double diff) void zero_sharesummary(SHARESUMMARY *row)
{ {
row->diffacc = row->diffsta = row->diffdup = row->diffhi = row->diffacc = row->diffsta = row->diffdup = row->diffhi =
row->diffrej = row->shareacc = row->sharesta = row->sharedup = row->diffrej = row->shareacc = row->sharesta = row->sharedup =
row->sharehi = row->sharerej = 0.0; row->sharehi = row->sharerej = 0.0;
row->sharecount = row->errorcount = 0; row->sharecount = row->errorcount = 0;
row->firstshare.tv_sec = cd->tv_sec; DATE_ZERO(&(row->firstshare));
row->firstshare.tv_usec = cd->tv_usec; DATE_ZERO(&(row->lastshare));
row->lastshare.tv_sec = row->firstshare.tv_sec; DATE_ZERO(&(row->firstshareacc));
row->lastshare.tv_usec = row->firstshare.tv_usec; DATE_ZERO(&(row->lastshareacc));
row->lastdiffacc = diff; row->lastdiffacc = 0;
row->complete[0] = SUMMARY_NEW; row->complete[0] = SUMMARY_NEW;
row->complete[1] = '\0'; row->complete[1] = '\0';
} }
@ -3690,7 +3705,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
if (ss_item) if (ss_item)
end_workinfoid = sharesummary->workinfoid; end_workinfoid = sharesummary->workinfoid;
/* Add up all sharesummaries until >= diff_want /* Add up all sharesummaries until >= diff_want
* also record the latest lastshare - that will be the end pplns time * also record the latest lastshareacc - that will be the end pplns time
* which will be >= blocks->blockcreatedate */ * which will be >= blocks->blockcreatedate */
while (total_diff < diff_want && ss_item) { while (total_diff < diff_want && ss_item) {
switch (sharesummary->complete[0]) { switch (sharesummary->complete[0]) {
@ -3723,10 +3738,8 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
acc_share_count += sharesummary->shareacc; acc_share_count += sharesummary->shareacc;
total_diff += sharesummary->diffacc; total_diff += sharesummary->diffacc;
begin_workinfoid = sharesummary->workinfoid; begin_workinfoid = sharesummary->workinfoid;
// TODO: add lastshareacc to sharesummary and markersummary if (tv_newer(&end_tv, &(sharesummary->lastshareacc)))
if (sharesummary->shareacc > 0 && copy_tv(&end_tv, &(sharesummary->lastshareacc));
tv_newer(&end_tv, &(sharesummary->lastshare)))
copy_tv(&end_tv, &(sharesummary->lastshare));
mu_root = upd_add_mu(mu_root, mu_store, mu_root = upd_add_mu(mu_root, mu_store,
sharesummary->userid, sharesummary->userid,
sharesummary->diffacc); sharesummary->diffacc);
@ -3760,10 +3773,8 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
total_share_count += sharesummary->sharecount; total_share_count += sharesummary->sharecount;
acc_share_count += sharesummary->shareacc; acc_share_count += sharesummary->shareacc;
total_diff += sharesummary->diffacc; total_diff += sharesummary->diffacc;
// TODO: add lastshareacc to sharesummary and markersummary if (tv_newer(&end_tv, &(sharesummary->lastshareacc)))
if (sharesummary->shareacc > 0 && copy_tv(&end_tv, &(sharesummary->lastshareacc));
tv_newer(&end_tv, &(sharesummary->lastshare)))
copy_tv(&end_tv, &(sharesummary->lastshare));
mu_root = upd_add_mu(mu_root, mu_store, mu_root = upd_add_mu(mu_root, mu_store,
sharesummary->userid, sharesummary->userid,
sharesummary->diffacc); sharesummary->diffacc);
@ -3812,9 +3823,8 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
acc_share_count += markersummary->shareacc; acc_share_count += markersummary->shareacc;
total_diff += markersummary->diffacc; total_diff += markersummary->diffacc;
begin_workinfoid = workmarkers->workinfoidstart; begin_workinfoid = workmarkers->workinfoidstart;
if (markersummary->shareacc > 0 && if (tv_newer(&end_tv, &(markersummary->lastshareacc)))
tv_newer(&end_tv, &(markersummary->lastshare))) copy_tv(&end_tv, &(markersummary->lastshareacc));
copy_tv(&end_tv, &(markersummary->lastshare));
mu_root = upd_add_mu(mu_root, mu_store, mu_root = upd_add_mu(mu_root, mu_store,
markersummary->userid, markersummary->userid,
markersummary->diffacc); markersummary->diffacc);

203
src/ckdb_dbio.c

@ -2993,9 +2993,8 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_TREE *trf_root)
userinfo_update(shares, NULL, NULL); userinfo_update(shares, NULL, NULL);
} }
sharesummary_update(shares, NULL, NULL, shares->createby, sharesummary_update(shares, NULL, shares->createby, shares->createcode,
shares->createcode, shares->createinet, shares->createinet, &(shares->createdate));
&(shares->createdate));
return true; return true;
} }
@ -3288,10 +3287,8 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors,
} }
} }
sharesummary_update(NULL, shareerrors, NULL, sharesummary_update(NULL, shareerrors, shareerrors->createby,
shareerrors->createby, shareerrors->createcode, shareerrors->createinet,
shareerrors->createcode,
shareerrors->createinet,
&(shareerrors->createdate)); &(shareerrors->createdate));
return true; return true;
@ -3541,11 +3538,19 @@ static void markersummary_to_pool(MARKERSUMMARY *p_row, MARKERSUMMARY *row)
!tv_newer(&(p_row->firstshare), &(row->firstshare))) { !tv_newer(&(p_row->firstshare), &(row->firstshare))) {
copy_tv(&(p_row->firstshare), &(row->firstshare)); copy_tv(&(p_row->firstshare), &(row->firstshare));
} }
if (tv_newer(&(p_row->lastshare), &(row->lastshare))) { if (tv_newer(&(p_row->lastshare), &(row->lastshare)))
copy_tv(&(p_row->lastshare), &(row->lastshare)); copy_tv(&(p_row->lastshare), &(row->lastshare));
if (row->diffacc > 0) {
if (!p_row->firstshareacc.tv_sec ||
!tv_newer(&(p_row->firstshareacc), &(row->firstshareacc))) {
copy_tv(&(p_row->firstshareacc), &(row->firstshareacc));
}
if (tv_newer(&(p_row->lastshareacc), &(row->lastshareacc))) {
copy_tv(&(p_row->lastshareacc), &(row->lastshareacc));
p_row->lastdiffacc = row->lastdiffacc; p_row->lastdiffacc = row->lastdiffacc;
} }
} }
}
/* TODO: what to do about a failure? /* TODO: what to do about a failure?
* since it will repeat every ~13s * since it will repeat every ~13s
@ -3553,7 +3558,7 @@ static void markersummary_to_pool(MARKERSUMMARY *p_row, MARKERSUMMARY *row)
* so that is probably the best solution since * so that is probably the best solution since
* we should be watching the pool all the time :) * we should be watching the pool all the time :)
* The cause would most likely be either a code bug or a DB problem * The cause would most likely be either a code bug or a DB problem
* so there many be no obvious automated fix * so there may be no obvious automated fix
* and flagging the workmarkers to be skipped may or may not be the solution, * and flagging the workmarkers to be skipped may or may not be the solution,
* thus manual intervention will be the rule for now */ * thus manual intervention will be the rule for now */
bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers, bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers,
@ -3686,10 +3691,18 @@ bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers,
!tv_newer(&(markersummary->firstshare), &(sharesummary->firstshare))) { !tv_newer(&(markersummary->firstshare), &(sharesummary->firstshare))) {
copy_tv(&(markersummary->firstshare), &(sharesummary->firstshare)); copy_tv(&(markersummary->firstshare), &(sharesummary->firstshare));
} }
if (tv_newer(&(markersummary->lastshare), &(sharesummary->lastshare))) { if (tv_newer(&(markersummary->lastshare), &(sharesummary->lastshare)))
copy_tv(&(markersummary->lastshare), &(sharesummary->lastshare)); copy_tv(&(markersummary->lastshare), &(sharesummary->lastshare));
if (sharesummary->diffacc > 0) {
if (!markersummary->firstshareacc.tv_sec ||
!tv_newer(&(markersummary->firstshareacc), &(sharesummary->firstshareacc))) {
copy_tv(&(markersummary->firstshareacc), &(sharesummary->firstshareacc));
}
if (tv_newer(&(markersummary->lastshareacc), &(sharesummary->lastshareacc))) {
copy_tv(&(markersummary->lastshareacc), &(sharesummary->lastshareacc));
markersummary->lastdiffacc = sharesummary->lastdiffacc; markersummary->lastdiffacc = sharesummary->lastdiffacc;
} }
}
diffacc += sharesummary->diffacc; diffacc += sharesummary->diffacc;
shareacc += sharesummary->shareacc; shareacc += sharesummary->shareacc;
@ -3844,50 +3857,29 @@ flail:
return ok; return ok;
} }
// no longer used
#if 0
static void sharesummary_to_pool(SHARESUMMARY *p_row, SHARESUMMARY *row)
{
p_row->diffacc += row->diffacc;
p_row->diffsta += row->diffsta;
p_row->diffdup += row->diffdup;
p_row->diffhi += row->diffhi;
p_row->diffrej += row->diffrej;
p_row->shareacc += row->shareacc;
p_row->sharesta += row->sharesta;
p_row->sharedup += row->sharedup;
p_row->sharehi += row->sharehi;
p_row->sharerej += row->sharerej;
p_row->sharecount += row->sharecount;
p_row->errorcount += row->errorcount;
if (!p_row->firstshare.tv_sec ||
!tv_newer(&(p_row->firstshare), &(row->firstshare))) {
copy_tv(&(p_row->firstshare), &(row->firstshare));
}
if (tv_newer(&(p_row->lastshare), &(row->lastshare))) {
copy_tv(&(p_row->lastshare), &(row->lastshare));
p_row->lastdiffacc = row->lastdiffacc;
}
}
#endif
static void set_sharesummary_stats(SHARESUMMARY *row, SHARES *s_row, static void set_sharesummary_stats(SHARESUMMARY *row, SHARES *s_row,
SHAREERRORS *e_row, bool new, SHAREERRORS *e_row, bool new,
double *tdf, double *tdl) double *tdf, double *tdl)
{ {
tv_t *createdate; tv_t *createdate;
double diff;
if (s_row) { if (s_row)
createdate = &(s_row->createdate); createdate = &(s_row->createdate);
diff = s_row->diff; else
} else {
createdate = &(e_row->createdate); createdate = &(e_row->createdate);
diff = 0;
}
if (new) if (new) {
zero_sharesummary(row, createdate, diff); zero_sharesummary(row);
copy_tv(&(row->firstshare), createdate);
copy_tv(&(row->lastshare), createdate);
} else {
if (!row->firstshare.tv_sec ||
!tv_newer(&(row->firstshare), createdate)) {
copy_tv(&(row->firstshare), createdate);
}
if (tv_newer(&(row->lastshare), createdate))
copy_tv(&(row->lastshare), createdate);
}
if (s_row) { if (s_row) {
row->sharecount += 1; row->sharecount += 1;
@ -3895,6 +3887,17 @@ static void set_sharesummary_stats(SHARESUMMARY *row, SHARES *s_row,
case SE_NONE: case SE_NONE:
row->diffacc += s_row->diff; row->diffacc += s_row->diff;
row->shareacc++; row->shareacc++;
// should always be true
if (s_row->diff > 0) {
if (!row->firstshareacc.tv_sec ||
!tv_newer(&(row->firstshareacc), createdate)) {
copy_tv(&(row->firstshareacc), createdate);
}
if (tv_newer(&(row->lastshareacc), createdate)) {
copy_tv(&(row->lastshareacc), createdate);
row->lastdiffacc = s_row->diff;
}
}
break; break;
case SE_STALE: case SE_STALE:
row->diffsta += s_row->diff; row->diffsta += s_row->diff;
@ -3916,15 +3919,10 @@ static void set_sharesummary_stats(SHARESUMMARY *row, SHARES *s_row,
} else } else
row->errorcount += 1; row->errorcount += 1;
// Only if required
if (!new) { if (!new) {
*tdf = tvdiff(createdate, &(row->firstshare)); *tdf = tvdiff(createdate, &(row->firstshare));
if (*tdf < 0.0)
copy_tv(&(row->firstshare), createdate);
*tdl = tvdiff(createdate, &(row->lastshare)); *tdl = tvdiff(createdate, &(row->lastshare));
if (*tdl >= 0.0) {
copy_tv(&(row->lastshare), createdate);
row->lastdiffacc = diff;
}
} }
} }
@ -3946,55 +3944,39 @@ char *ooo_status(char *buf, size_t siz)
} }
// No longer stored in the DB but fields are updated as before // No longer stored in the DB but fields are updated as before
bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item, bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, char *by,
char *by, char *code, char *inet, tv_t *cd, char *code, char *inet, tv_t *cd, WHERE_FFL_ARGS)
WHERE_FFL_ARGS)
{ {
WORKMARKERS *wm; WORKMARKERS *wm;
SHARESUMMARY *row, *p_row; SHARESUMMARY *row, *p_row;
K_ITEM *item, *wm_item, *p_item = NULL; K_ITEM *ss_item, *wm_item, *p_item = NULL;
bool new = false, p_new = false; bool new = false, p_new = false;
int64_t userid, workinfoid; int64_t userid, workinfoid;
char *workername; char *workername;
tv_t *createdate;
char *st = NULL, *db = NULL; char *st = NULL, *db = NULL;
char ooo_buf[256]; char ooo_buf[256];
double tdf, tdl; double tdf, tdl;
LOGDEBUG("%s(): update", __func__); LOGDEBUG("%s(): update", __func__);
// this will never be a pool_ summary
if (ss_item) {
if (s_row || e_row) {
quithere(1, "ERR: only one of s_row, e_row and "
"ss_item allowed" WHERE_FFL,
WHERE_FFL_PASS);
}
item = ss_item;
DATA_SHARESUMMARY(row, item);
row->complete[0] = SUMMARY_COMPLETE;
row->complete[1] = '\0';
} else {
if (s_row) { if (s_row) {
if (e_row) { if (e_row) {
quithere(1, "ERR: only one of s_row, e_row " quithere(1, "ERR: only one of s_row and e_row allowed"
"(and ss_item) allowed" WHERE_FFL, WHERE_FFL,
WHERE_FFL_PASS); WHERE_FFL_PASS);
} }
userid = s_row->userid; userid = s_row->userid;
workername = s_row->workername; workername = s_row->workername;
workinfoid = s_row->workinfoid; workinfoid = s_row->workinfoid;
createdate = &(s_row->createdate);
} else { } else {
if (!e_row) { if (!e_row) {
quithere(1, "ERR: all s_row, e_row and " quithere(1, "ERR: both s_row and e_row are NULL"
"ss_item are NULL" WHERE_FFL, WHERE_FFL,
WHERE_FFL_PASS); WHERE_FFL_PASS);
} }
userid = e_row->userid; userid = e_row->userid;
workername = e_row->workername; workername = e_row->workername;
workinfoid = e_row->workinfoid; workinfoid = e_row->workinfoid;
createdate = &(e_row->createdate);
} }
K_RLOCK(workmarkers_free); K_RLOCK(workmarkers_free);
@ -4008,7 +3990,7 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item,
" but processed workmarkers %"PRId64" exists", " but processed workmarkers %"PRId64" exists",
__func__, s_row ? "shares" : "shareerrors", __func__, s_row ? "shares" : "shareerrors",
workinfoid, userid, st = safe_text(workername), workinfoid, userid, st = safe_text(workername),
db = ctv_to_buf(createdate, NULL, 0), db = ctv_to_buf(cd, NULL, 0),
wm->markerid); wm->markerid);
FREENULL(st); FREENULL(st);
FREENULL(db); FREENULL(db);
@ -4016,18 +3998,18 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item,
} }
K_RLOCK(sharesummary_free); K_RLOCK(sharesummary_free);
item = find_sharesummary(userid, workername, workinfoid); ss_item = find_sharesummary(userid, workername, workinfoid);
p_item = find_sharesummary_p(workinfoid); p_item = find_sharesummary_p(workinfoid);
K_RUNLOCK(sharesummary_free); K_RUNLOCK(sharesummary_free);
if (item) { if (ss_item) {
DATA_SHARESUMMARY(row, item); DATA_SHARESUMMARY(row, ss_item);
} else { } else {
new = true; new = true;
K_WLOCK(sharesummary_free); K_WLOCK(sharesummary_free);
item = k_unlink_head(sharesummary_free); ss_item = k_unlink_head(sharesummary_free);
K_WUNLOCK(sharesummary_free); K_WUNLOCK(sharesummary_free);
DATA_SHARESUMMARY(row, item); DATA_SHARESUMMARY(row, ss_item);
bzero(row, sizeof(*row)); bzero(row, sizeof(*row));
row->userid = userid; row->userid = userid;
DUP_POINTER(sharesummary_free, row->workername, DUP_POINTER(sharesummary_free, row->workername,
@ -4053,7 +4035,7 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item,
LOGMSG(level, "%s(): OoO %s "CDDB" (%s) is < summary" LOGMSG(level, "%s(): OoO %s "CDDB" (%s) is < summary"
" firstshare (%s) (%s)", " firstshare (%s) (%s)",
__func__, s_row ? "shares" : "shareerrors", __func__, s_row ? "shares" : "shareerrors",
(tmp1 = ctv_to_buf(createdate, NULL, 0)), (tmp1 = ctv_to_buf(cd, NULL, 0)),
(tmp2 = ctv_to_buf(&(row->firstshare), NULL, 0)), (tmp2 = ctv_to_buf(&(row->firstshare), NULL, 0)),
ooo_status(ooo_buf, sizeof(ooo_buf))); ooo_status(ooo_buf, sizeof(ooo_buf)));
free(tmp2); free(tmp2);
@ -4074,7 +4056,7 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item,
LOGMSG(level, "%s(): OoO %s "CDDB" (%s) is < summary" LOGMSG(level, "%s(): OoO %s "CDDB" (%s) is < summary"
" lastshare (%s) (%s)", " lastshare (%s) (%s)",
__func__, s_row ? "shares" : "shareerrors", __func__, s_row ? "shares" : "shareerrors",
(tmp1 = ctv_to_buf(createdate, NULL, 0)), (tmp1 = ctv_to_buf(cd, NULL, 0)),
(tmp2 = ctv_to_buf(&(row->lastshare), NULL, 0)), (tmp2 = ctv_to_buf(&(row->lastshare), NULL, 0)),
ooo_status(ooo_buf, sizeof(ooo_buf))); ooo_status(ooo_buf, sizeof(ooo_buf)));
free(tmp2); free(tmp2);
@ -4105,7 +4087,6 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item,
} }
set_sharesummary_stats(p_row, s_row, e_row, p_new, &tdf, &tdl); set_sharesummary_stats(p_row, s_row, e_row, p_new, &tdf, &tdl);
}
MODIFYDATEPOINTERS(sharesummary_free, row, cd, by, code, inet); MODIFYDATEPOINTERS(sharesummary_free, row, cd, by, code, inet);
@ -4113,9 +4094,9 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item,
if (new || p_new) { if (new || p_new) {
K_WLOCK(sharesummary_free); K_WLOCK(sharesummary_free);
if (new) { if (new) {
add_to_ktree(sharesummary_root, item); add_to_ktree(sharesummary_root, ss_item);
add_to_ktree(sharesummary_workinfoid_root, item); add_to_ktree(sharesummary_workinfoid_root, ss_item);
k_add_head(sharesummary_store, item); k_add_head(sharesummary_store, ss_item);
} }
if (p_new) { if (p_new) {
add_to_ktree(sharesummary_pool_root, p_item); add_to_ktree(sharesummary_pool_root, p_item);
@ -4127,6 +4108,23 @@ bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item,
return true; return true;
} }
// No key fields are modified
bool _sharesummary_age(K_ITEM *ss_item, char *by, char *code, char *inet,
tv_t *cd, WHERE_FFL_ARGS)
{
SHARESUMMARY *row;
LOGDEBUG("%s(): update", __func__);
DATA_SHARESUMMARY(row, ss_item);
row->complete[0] = SUMMARY_COMPLETE;
row->complete[1] = '\0';
MODIFYDATEPOINTERS(sharesummary_free, row, cd, by, code, inet);
return true;
}
bool blocks_stats(PGconn *conn, int32_t height, char *blockhash, bool blocks_stats(PGconn *conn, int32_t height, char *blockhash,
double diffacc, double diffinv, double shareacc, double diffacc, double diffinv, double shareacc,
double shareinv, int64_t elapsed, double shareinv, int64_t elapsed,
@ -6263,7 +6261,7 @@ bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code,
bool conned = false; bool conned = false;
PGresult *res; PGresult *res;
MARKERSUMMARY *row; MARKERSUMMARY *row;
char *params[18 + MODIFYDATECOUNT]; char *params[20 + MODIFYDATECOUNT];
int n, par = 0; int n, par = 0;
char *ins; char *ins;
bool ok = false; bool ok = false;
@ -6294,6 +6292,8 @@ bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code,
params[par++] = bigint_to_buf(row->errorcount, NULL, 0); params[par++] = bigint_to_buf(row->errorcount, NULL, 0);
params[par++] = tv_to_buf(&(row->firstshare), NULL, 0); params[par++] = tv_to_buf(&(row->firstshare), NULL, 0);
params[par++] = tv_to_buf(&(row->lastshare), NULL, 0); params[par++] = tv_to_buf(&(row->lastshare), NULL, 0);
params[par++] = tv_to_buf(&(row->firstshareacc), NULL, 0);
params[par++] = tv_to_buf(&(row->lastshareacc), NULL, 0);
params[par++] = double_to_buf(row->lastdiffacc, NULL, 0); params[par++] = double_to_buf(row->lastdiffacc, NULL, 0);
MODIFYDATEPARAMS(params, par, row); MODIFYDATEPARAMS(params, par, row);
PARCHK(par, params); PARCHK(par, params);
@ -6301,7 +6301,8 @@ bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code,
ins = "insert into markersummary " ins = "insert into markersummary "
"(markerid,userid,workername,diffacc,diffsta,diffdup,diffhi," "(markerid,userid,workername,diffacc,diffsta,diffdup,diffhi,"
"diffrej,shareacc,sharesta,sharedup,sharehi,sharerej," "diffrej,shareacc,sharesta,sharedup,sharehi,sharerej,"
"sharecount,errorcount,firstshare,lastshare,lastdiffacc" "sharecount,errorcount,firstshare,lastshare,firstshareacc,"
"lastshareacc,lastdiffacc"
MODIFYDATECONTROL ") values (" PQPARAM26 ")"; MODIFYDATECONTROL ") values (" PQPARAM26 ")";
LOGDEBUG("%s() adding ms %"PRId64"/%"PRId64"/%s/%.0f", LOGDEBUG("%s() adding ms %"PRId64"/%"PRId64"/%s/%.0f",
@ -6344,7 +6345,7 @@ bool markersummary_fill(PGconn *conn)
MARKERSUMMARY *row, *p_row; MARKERSUMMARY *row, *p_row;
char *field; char *field;
char *sel; char *sel;
int fields = 18; int fields = 20;
bool ok; bool ok;
LOGDEBUG("%s(): select", __func__); LOGDEBUG("%s(): select", __func__);
@ -6356,8 +6357,8 @@ bool markersummary_fill(PGconn *conn)
sel = "select " sel = "select "
"markerid,userid,workername,diffacc,diffsta,diffdup,diffhi," "markerid,userid,workername,diffacc,diffsta,diffdup,diffhi,"
"diffrej,shareacc,sharesta,sharedup,sharehi,sharerej," "diffrej,shareacc,sharesta,sharedup,sharehi,sharerej,"
"sharecount,errorcount,firstshare,lastshare," "sharecount,errorcount,firstshare,lastshare,firstshareacc,"
"lastdiffacc" "lastshareacc,lastdiffacc"
MODIFYDATECONTROL MODIFYDATECONTROL
" from markersummary"; " from markersummary";
res = PQexec(conn, sel, CKPQ_READ); res = PQexec(conn, sel, CKPQ_READ);
@ -6476,6 +6477,16 @@ bool markersummary_fill(PGconn *conn)
break; break;
TXT_TO_TV("lastshare", field, row->lastshare); TXT_TO_TV("lastshare", field, row->lastshare);
PQ_GET_FLD(res, i, "firstshareacc", field, ok);
if (!ok)
break;
TXT_TO_TV("firstshareacc", field, row->firstshareacc);
PQ_GET_FLD(res, i, "lastshareacc", field, ok);
if (!ok)
break;
TXT_TO_TV("lastshareacc", field, row->lastshareacc);
PQ_GET_FLD(res, i, "lastdiffacc", field, ok); PQ_GET_FLD(res, i, "lastdiffacc", field, ok);
if (!ok) if (!ok)
break; break;
@ -6485,6 +6496,16 @@ bool markersummary_fill(PGconn *conn)
if (!ok) if (!ok)
break; break;
/* Save having to do this everywhere in the code for old data
* It's not always accurate, but soon after when it's not,
* and also what was used before the 2 fields were added */
if (row->diffacc > 0) {
if (row->firstshareacc.tv_sec == 0L)
copy_tv(&(row->firstshareacc), &(row->firstshare));
if (row->lastshareacc.tv_sec == 0L)
copy_tv(&(row->lastshareacc), &(row->lastshare));
}
add_to_ktree(markersummary_root, item); add_to_ktree(markersummary_root, item);
add_to_ktree(markersummary_userid_root, item); add_to_ktree(markersummary_userid_root, item);
k_add_head(markersummary_store, item); k_add_head(markersummary_store, item);

Loading…
Cancel
Save