Browse Source

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

master
kanoi 9 years ago
parent
commit
019062d94c
  1. 11
      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. 47
      src/ckdb.c
  7. 26
      src/ckdb.h
  8. 41
      src/ckdb_cmd.c
  9. 60
      src/ckdb_data.c
  10. 411
      src/ckdb_dbio.c

11
pool/base.php

@ -99,7 +99,7 @@ function howlongago($sec)
return $des;
}
#
function howmanyhrs($tot)
function howmanyhrs($tot, $days = false)
{
$sec = round($tot);
if ($sec < 60)
@ -114,7 +114,14 @@ function howmanyhrs($tot)
{
$hr = floor($min / 60);
$min -= $hr * 60;
$des = $hr.'hr '.$min.'m '.$sec.'s';
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';
}
}
return $des;

5
pool/page_pplns2.php

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

5
pool/page_workers.php

@ -61,6 +61,7 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
$all[] = array('workername' => $ans['workername:'.$i],
'w_lastshare' => $ans['w_lastshare:'.$i],
'w_lastshareacc' => $ans['w_lastshareacc:'.$i],
'w_lastdiff' => $ans['w_lastdiff:'.$i],
'w_shareacc' => $ans['w_shareacc:'.$i],
'w_diffacc' => $ans['w_diffacc:'.$i],
@ -80,6 +81,8 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
if ($old !== false && $lst > $old)
continue;
$lstacc = $now - $all[$i]['w_lastshareacc'];
if ((($offset) % 2) == 0)
$row = 'even';
else
@ -93,7 +96,7 @@ function workuser($data, $user, &$offset, &$totshare, &$totdiff,
$ld = '&nbsp;';
$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);
$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,
firstshare 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,
complete char 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,
firstshare 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,
createdate timestamp with time zone NOT NULL,
createby character varying(64) NOT NULL,
@ -464,4 +468,4 @@ CREATE TABLE version (
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;

47
src/ckdb.c

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

26
src/ckdb.h

@ -54,8 +54,8 @@
*/
#define DB_VLOCK "1"
#define DB_VERSION "1.0.2"
#define CKDB_VERSION DB_VERSION"-1.311"
#define DB_VERSION "1.0.3"
#define CKDB_VERSION DB_VERSION"-1.320"
#define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@ -312,6 +312,7 @@ extern bool everyone_die;
extern tv_t last_heartbeat;
extern tv_t last_workinfo;
extern tv_t last_share;
extern tv_t last_share_acc;
extern tv_t last_share_inv;
extern tv_t last_auth;
extern cklock_t last_lock;
@ -1435,6 +1436,8 @@ typedef struct sharesummary {
int64_t errorcount;
tv_t firstshare;
tv_t lastshare;
tv_t firstshareacc;
tv_t lastshareacc;
double lastdiffacc;
char complete[TXT_FLAG+1];
MODIFYDATECONTROLPOINTERS;
@ -1830,7 +1833,8 @@ typedef struct workerstatus {
char workername[TXT_BIG+1];
tv_t last_auth;
tv_t last_share;
double last_diff;
tv_t last_share_acc;
double last_diff_acc;
tv_t last_stats;
tv_t last_idle;
// Below gets reset on each block
@ -1890,6 +1894,8 @@ typedef struct markersummary {
int64_t errorcount;
tv_t firstshare;
tv_t lastshare;
tv_t firstshareacc;
tv_t lastshareacc;
double lastdiffacc;
MODIFYDATECONTROLPOINTERS;
} 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 cmp_t cmp_sharesummary(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) \
_find_sharesummary(_userid, _workername, _workinfoid, false)
#define find_sharesummary_p(_workinfoid) \
@ -2518,12 +2524,16 @@ extern bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmar
char *by, char *code, char *inet,
tv_t *cd, K_TREE *trf_root);
extern char *ooo_status(char *buf, size_t siz);
#define sharesummary_update(_s_row, _e_row, _ss_item, _by, _code, _inet, _cd) \
_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, _by, _code, _inet, _cd, \
WHERE_FFL_HERE)
extern bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, K_ITEM *ss_item,
char *by, char *code, char *inet, tv_t *cd,
extern bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, char *by,
char *code, char *inet, tv_t *cd,
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 blocks_stats(PGconn *conn, int32_t height, char *blockhash,
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) {
DATA_WORKERSTATUS(workerstatus, ws_item);
K_RLOCK(workerstatus_free);
// good or bad - either means active
copy_tv(&last_share, &(workerstatus->last_share));
K_RUNLOCK(workerstatus_free);
} else
@ -2028,7 +2029,9 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
double w_hashrate24hr;
int64_t w_elapsed;
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_diffhi, w_diffrej;
double w_shareacc, w_shareinv;
@ -2042,8 +2045,9 @@ static char *cmd_workers(__maybe_unused PGconn *conn, char *cmd, char *id,
w_elapsed = -1;
if (!ws_item) {
w_lastshare.tv_sec = 0L;
w_lastdiff = w_diffacc =
w_lastshare.tv_sec =
w_lastshareacc.tv_sec = 0L;
w_lastdiffacc = w_diffacc =
w_diffinv = w_diffsta =
w_diffdup = w_diffhi =
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
K_RLOCK(workerstatus_free);
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_diffinv = workerstatus->block_diffinv;
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);
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);
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,"
"idlenotificationtime",
stats ? ",w_hashrate5m,w_hashrate1hr,w_hashrate24hr,"
"w_elapsed,w_lastshare,"
"w_elapsed,w_lastshare,w_lastshareacc,"
"w_lastdiff,w_diffacc,w_diffinv,"
"w_diffsta,w_diffdup,w_diffhi,w_diffrej,"
"w_shareacc,w_shareinv,"
@ -2504,10 +2513,11 @@ wiconf:
int32_t errn;
TXT_TO_INT("errn", transfer_data(i_errn), errn);
ck_wlock(&last_lock);
setnow(&last_share);
if (errn == SE_NONE)
setnow(&last_share);
copy_tv(&last_share_acc, &last_share);
else
setnow(&last_share_inv);
copy_tv(&last_share_inv, &last_share);
ck_wunlock(&last_lock);
}
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);
snprintf(tmp, sizeof(tmp), "lastsh=%s%c", reply, FLDSEP);
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);
snprintf(tmp, sizeof(tmp), "lastshinv=%s%c", reply, FLDSEP);
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)
end_workinfoid = sharesummary->workinfoid;
/* 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 */
while (total_diff < diff_want && ss_item) {
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;
total_diff += (int64_t)(sharesummary->diffacc);
begin_workinfoid = sharesummary->workinfoid;
if (tv_newer(&end_tv, &(sharesummary->lastshare)))
copy_tv(&end_tv, &(sharesummary->lastshare));
if (tv_newer(&end_tv, &(sharesummary->lastshareacc)))
copy_tv(&end_tv, &(sharesummary->lastshareacc));
mu_root = upd_add_mu(mu_root, mu_store,
sharesummary->userid,
(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;
total_diff += (int64_t)(markersummary->diffacc);
begin_workinfoid = workmarkers->workinfoidstart;
if (tv_newer(&end_tv, &(markersummary->lastshare)))
copy_tv(&end_tv, &(markersummary->lastshare));
if (tv_newer(&end_tv, &(markersummary->lastshareacc)))
copy_tv(&end_tv, &(markersummary->lastshareacc));
mu_root = upd_add_mu(mu_root, mu_store,
markersummary->userid,
(int64_t)(markersummary->diffacc));
@ -6521,5 +6534,5 @@ struct CMDS ckdb_cmds[] = {
{ CMD_SHSTA, "shsta", true, false, cmd_shsta, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_USERINFO, "userinfo", false, false, cmd_userinfo, SEQ_NONE, ACCESS_WEB },
{ 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))) {
copy_tv(&(workerstatus->last_share),
&(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;
}
}
@ -973,7 +978,12 @@ void workerstatus_ready()
&(sharesummary->lastshare))) {
copy_tv(&(workerstatus->last_share),
&(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;
}
}
@ -1017,10 +1027,8 @@ void _workerstatus_update(AUTHS *auths, SHARES *shares,
if (item) {
DATA_WORKERSTATUS(row, item);
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));
row->last_diff = shares->diff;
}
if (row->active_start.tv_sec == 0)
copy_tv(&(row->active_start), &(shares->createdate));
switch (shares->errn) {
@ -1029,6 +1037,12 @@ void _workerstatus_update(AUTHS *auths, SHARES *shares,
row->block_shareacc++;
row->active_diffacc += shares->diff;
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;
case SE_STALE:
row->block_diffinv += shares->diff;
@ -2118,7 +2132,8 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, char *by, char *code,
error[0] = '\0';
skipupdate = false;
/* 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 (sharesummary->complete[0] == SUMMARY_COMPLETE) {
ss_already++;
@ -2134,7 +2149,7 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, char *by, char *code,
}
if (!skipupdate) {
if (!sharesummary_update(NULL, NULL, ss_item, by, code, inet, cd)) {
if (!sharesummary_age(ss_item, by, code, inet, cd)) {
ss_failed++;
LOGERR("%s(): Failed to age sharesummary %"PRId64"/%s/%"PRId64,
__func__, sharesummary->userid,
@ -2364,17 +2379,17 @@ cmp_t cmp_sharesummary_workinfoid(K_ITEM *a, K_ITEM *b)
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->diffrej = row->shareacc = row->sharesta = row->sharedup =
row->sharehi = row->sharerej = 0.0;
row->sharecount = row->errorcount = 0;
row->firstshare.tv_sec = cd->tv_sec;
row->firstshare.tv_usec = cd->tv_usec;
row->lastshare.tv_sec = row->firstshare.tv_sec;
row->lastshare.tv_usec = row->firstshare.tv_usec;
row->lastdiffacc = diff;
DATE_ZERO(&(row->firstshare));
DATE_ZERO(&(row->lastshare));
DATE_ZERO(&(row->firstshareacc));
DATE_ZERO(&(row->lastshareacc));
row->lastdiffacc = 0;
row->complete[0] = SUMMARY_NEW;
row->complete[1] = '\0';
}
@ -3690,7 +3705,7 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
if (ss_item)
end_workinfoid = sharesummary->workinfoid;
/* 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 */
while (total_diff < diff_want && ss_item) {
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;
total_diff += sharesummary->diffacc;
begin_workinfoid = sharesummary->workinfoid;
// TODO: add lastshareacc to sharesummary and markersummary
if (sharesummary->shareacc > 0 &&
tv_newer(&end_tv, &(sharesummary->lastshare)))
copy_tv(&end_tv, &(sharesummary->lastshare));
if (tv_newer(&end_tv, &(sharesummary->lastshareacc)))
copy_tv(&end_tv, &(sharesummary->lastshareacc));
mu_root = upd_add_mu(mu_root, mu_store,
sharesummary->userid,
sharesummary->diffacc);
@ -3760,10 +3773,8 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
total_share_count += sharesummary->sharecount;
acc_share_count += sharesummary->shareacc;
total_diff += sharesummary->diffacc;
// TODO: add lastshareacc to sharesummary and markersummary
if (sharesummary->shareacc > 0 &&
tv_newer(&end_tv, &(sharesummary->lastshare)))
copy_tv(&end_tv, &(sharesummary->lastshare));
if (tv_newer(&end_tv, &(sharesummary->lastshareacc)))
copy_tv(&end_tv, &(sharesummary->lastshareacc));
mu_root = upd_add_mu(mu_root, mu_store,
sharesummary->userid,
sharesummary->diffacc);
@ -3812,9 +3823,8 @@ bool process_pplns(int32_t height, char *blockhash, tv_t *addr_cd)
acc_share_count += markersummary->shareacc;
total_diff += markersummary->diffacc;
begin_workinfoid = workmarkers->workinfoidstart;
if (markersummary->shareacc > 0 &&
tv_newer(&end_tv, &(markersummary->lastshare)))
copy_tv(&end_tv, &(markersummary->lastshare));
if (tv_newer(&end_tv, &(markersummary->lastshareacc)))
copy_tv(&end_tv, &(markersummary->lastshareacc));
mu_root = upd_add_mu(mu_root, mu_store,
markersummary->userid,
markersummary->diffacc);

411
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);
}
sharesummary_update(shares, NULL, NULL, shares->createby,
shares->createcode, shares->createinet,
&(shares->createdate));
sharesummary_update(shares, NULL, shares->createby, shares->createcode,
shares->createinet, &(shares->createdate));
return true;
}
@ -3288,10 +3287,8 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors,
}
}
sharesummary_update(NULL, shareerrors, NULL,
shareerrors->createby,
shareerrors->createcode,
shareerrors->createinet,
sharesummary_update(NULL, shareerrors, shareerrors->createby,
shareerrors->createcode, shareerrors->createinet,
&(shareerrors->createdate));
return true;
@ -3541,9 +3538,17 @@ static void markersummary_to_pool(MARKERSUMMARY *p_row, MARKERSUMMARY *row)
!tv_newer(&(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));
p_row->lastdiffacc = row->lastdiffacc;
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;
}
}
}
@ -3553,7 +3558,7 @@ static void markersummary_to_pool(MARKERSUMMARY *p_row, MARKERSUMMARY *row)
* so that is probably the best solution since
* we should be watching the pool all the time :)
* 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,
* thus manual intervention will be the rule for now */
bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers,
@ -3686,9 +3691,17 @@ bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers,
!tv_newer(&(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));
markersummary->lastdiffacc = sharesummary->lastdiffacc;
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;
}
}
diffacc += sharesummary->diffacc;
@ -3844,50 +3857,29 @@ flail:
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,
SHAREERRORS *e_row, bool new,
double *tdf, double *tdl)
{
tv_t *createdate;
double diff;
if (s_row) {
if (s_row)
createdate = &(s_row->createdate);
diff = s_row->diff;
} else {
else
createdate = &(e_row->createdate);
diff = 0;
}
if (new)
zero_sharesummary(row, createdate, diff);
if (new) {
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) {
row->sharecount += 1;
@ -3895,6 +3887,17 @@ static void set_sharesummary_stats(SHARESUMMARY *row, SHARES *s_row,
case SE_NONE:
row->diffacc += s_row->diff;
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;
case SE_STALE:
row->diffsta += s_row->diff;
@ -3916,15 +3919,10 @@ static void set_sharesummary_stats(SHARESUMMARY *row, SHARES *s_row,
} else
row->errorcount += 1;
// Only if required
if (!new) {
*tdf = tvdiff(createdate, &(row->firstshare));
if (*tdf < 0.0)
copy_tv(&(row->firstshare), createdate);
*tdl = tvdiff(createdate, &(row->lastshare));
if (*tdl >= 0.0) {
copy_tv(&(row->lastshare), createdate);
row->lastdiffacc = diff;
}
}
}
@ -3946,176 +3944,159 @@ char *ooo_status(char *buf, size_t siz)
}
// 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,
char *by, char *code, char *inet, tv_t *cd,
WHERE_FFL_ARGS)
bool _sharesummary_update(SHARES *s_row, SHAREERRORS *e_row, char *by,
char *code, char *inet, tv_t *cd, WHERE_FFL_ARGS)
{
WORKMARKERS *wm;
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;
int64_t userid, workinfoid;
char *workername;
tv_t *createdate;
char *st = NULL, *db = NULL;
char ooo_buf[256];
double tdf, tdl;
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,
if (s_row) {
if (e_row) {
quithere(1, "ERR: only one of s_row and e_row allowed"
WHERE_FFL,
WHERE_FFL_PASS);
}
item = ss_item;
DATA_SHARESUMMARY(row, item);
row->complete[0] = SUMMARY_COMPLETE;
row->complete[1] = '\0';
userid = s_row->userid;
workername = s_row->workername;
workinfoid = s_row->workinfoid;
} else {
if (s_row) {
if (e_row) {
quithere(1, "ERR: only one of s_row, e_row "
"(and ss_item) allowed" WHERE_FFL,
WHERE_FFL_PASS);
}
userid = s_row->userid;
workername = s_row->workername;
workinfoid = s_row->workinfoid;
createdate = &(s_row->createdate);
} else {
if (!e_row) {
quithere(1, "ERR: all s_row, e_row and "
"ss_item are NULL" WHERE_FFL,
WHERE_FFL_PASS);
}
userid = e_row->userid;
workername = e_row->workername;
workinfoid = e_row->workinfoid;
createdate = &(e_row->createdate);
}
K_RLOCK(workmarkers_free);
wm_item = find_workmarkers(workinfoid, false, MARKER_PROCESSED,
NULL);
K_RUNLOCK(workmarkers_free);
if (wm_item) {
DATA_WORKMARKERS(wm, wm_item);
LOGERR("%s(): attempt to update sharesummary "
"with %s %"PRId64"/%"PRId64"/%s "CDDB" %s"
" but processed workmarkers %"PRId64" exists",
__func__, s_row ? "shares" : "shareerrors",
workinfoid, userid, st = safe_text(workername),
db = ctv_to_buf(createdate, NULL, 0),
wm->markerid);
FREENULL(st);
FREENULL(db);
return false;
if (!e_row) {
quithere(1, "ERR: both s_row and e_row are NULL"
WHERE_FFL,
WHERE_FFL_PASS);
}
userid = e_row->userid;
workername = e_row->workername;
workinfoid = e_row->workinfoid;
}
K_RLOCK(workmarkers_free);
wm_item = find_workmarkers(workinfoid, false, MARKER_PROCESSED,
NULL);
K_RUNLOCK(workmarkers_free);
if (wm_item) {
DATA_WORKMARKERS(wm, wm_item);
LOGERR("%s(): attempt to update sharesummary "
"with %s %"PRId64"/%"PRId64"/%s "CDDB" %s"
" but processed workmarkers %"PRId64" exists",
__func__, s_row ? "shares" : "shareerrors",
workinfoid, userid, st = safe_text(workername),
db = ctv_to_buf(cd, NULL, 0),
wm->markerid);
FREENULL(st);
FREENULL(db);
return false;
}
K_RLOCK(sharesummary_free);
item = find_sharesummary(userid, workername, workinfoid);
p_item = find_sharesummary_p(workinfoid);
K_RUNLOCK(sharesummary_free);
K_RLOCK(sharesummary_free);
ss_item = find_sharesummary(userid, workername, workinfoid);
p_item = find_sharesummary_p(workinfoid);
K_RUNLOCK(sharesummary_free);
if (item) {
DATA_SHARESUMMARY(row, item);
} else {
new = true;
K_WLOCK(sharesummary_free);
item = k_unlink_head(sharesummary_free);
K_WUNLOCK(sharesummary_free);
DATA_SHARESUMMARY(row, item);
bzero(row, sizeof(*row));
row->userid = userid;
DUP_POINTER(sharesummary_free, row->workername,
workername);
row->workinfoid = workinfoid;
}
if (ss_item) {
DATA_SHARESUMMARY(row, ss_item);
} else {
new = true;
K_WLOCK(sharesummary_free);
ss_item = k_unlink_head(sharesummary_free);
K_WUNLOCK(sharesummary_free);
DATA_SHARESUMMARY(row, ss_item);
bzero(row, sizeof(*row));
row->userid = userid;
DUP_POINTER(sharesummary_free, row->workername,
workername);
row->workinfoid = workinfoid;
}
// N.B. this directly updates the non-key data
set_sharesummary_stats(row, s_row, e_row, new, &tdf, &tdl);
if (!new) {
// don't LOG '=' in case shares come from ckpool with the same timestamp
if (tdf < 0.0) {
char *tmp1, *tmp2;
int level = LOG_DEBUG;
// WARNING for shares exceeding the OOOLIMIT but not during startup
if (tdf < OOOLIMIT) {
ooof++;
if (startup_complete)
level = LOG_WARNING;
} else
ooof0++;
LOGMSG(level, "%s(): OoO %s "CDDB" (%s) is < summary"
" firstshare (%s) (%s)",
__func__, s_row ? "shares" : "shareerrors",
(tmp1 = ctv_to_buf(createdate, NULL, 0)),
(tmp2 = ctv_to_buf(&(row->firstshare), NULL, 0)),
ooo_status(ooo_buf, sizeof(ooo_buf)));
free(tmp2);
free(tmp1);
}
// N.B. this directly updates the non-key data
set_sharesummary_stats(row, s_row, e_row, new, &tdf, &tdl);
// don't LOG '=' in case shares come from ckpool with the same timestamp
if (tdl < 0.0) {
char *tmp1, *tmp2;
int level = LOG_DEBUG;
// WARNING for shares exceeding the OOOLIMIT but not during startup
if (tdl < OOOLIMIT) {
oool++;
if (startup_complete)
level = LOG_WARNING;
} else
oool0++;
LOGMSG(level, "%s(): OoO %s "CDDB" (%s) is < summary"
" lastshare (%s) (%s)",
__func__, s_row ? "shares" : "shareerrors",
(tmp1 = ctv_to_buf(createdate, NULL, 0)),
(tmp2 = ctv_to_buf(&(row->lastshare), NULL, 0)),
ooo_status(ooo_buf, sizeof(ooo_buf)));
free(tmp2);
free(tmp1);
}
if (!new) {
// don't LOG '=' in case shares come from ckpool with the same timestamp
if (tdf < 0.0) {
char *tmp1, *tmp2;
int level = LOG_DEBUG;
// WARNING for shares exceeding the OOOLIMIT but not during startup
if (tdf < OOOLIMIT) {
ooof++;
if (startup_complete)
level = LOG_WARNING;
} else
ooof0++;
LOGMSG(level, "%s(): OoO %s "CDDB" (%s) is < summary"
" firstshare (%s) (%s)",
__func__, s_row ? "shares" : "shareerrors",
(tmp1 = ctv_to_buf(cd, NULL, 0)),
(tmp2 = ctv_to_buf(&(row->firstshare), NULL, 0)),
ooo_status(ooo_buf, sizeof(ooo_buf)));
free(tmp2);
free(tmp1);
}
if (row->complete[0] != SUMMARY_NEW) {
LOGDEBUG("%s(): updating sharesummary not '%c'"
" %"PRId64"/%s/%"PRId64"/%s",
__func__, SUMMARY_NEW, row->userid,
st = safe_text_nonull(row->workername),
row->workinfoid, row->complete);
FREENULL(st);
}
// don't LOG '=' in case shares come from ckpool with the same timestamp
if (tdl < 0.0) {
char *tmp1, *tmp2;
int level = LOG_DEBUG;
// WARNING for shares exceeding the OOOLIMIT but not during startup
if (tdl < OOOLIMIT) {
oool++;
if (startup_complete)
level = LOG_WARNING;
} else
oool0++;
LOGMSG(level, "%s(): OoO %s "CDDB" (%s) is < summary"
" lastshare (%s) (%s)",
__func__, s_row ? "shares" : "shareerrors",
(tmp1 = ctv_to_buf(cd, NULL, 0)),
(tmp2 = ctv_to_buf(&(row->lastshare), NULL, 0)),
ooo_status(ooo_buf, sizeof(ooo_buf)));
free(tmp2);
free(tmp1);
}
if (p_item) {
DATA_SHARESUMMARY(p_row, p_item);
} else {
p_new = true;
K_WLOCK(sharesummary_free);
p_item = k_unlink_head(sharesummary_free);
K_WUNLOCK(sharesummary_free);
DATA_SHARESUMMARY(p_row, p_item);
bzero(p_row, sizeof(*p_row));
POOL_SS(p_row);
p_row->workinfoid = workinfoid;
if (row->complete[0] != SUMMARY_NEW) {
LOGDEBUG("%s(): updating sharesummary not '%c'"
" %"PRId64"/%s/%"PRId64"/%s",
__func__, SUMMARY_NEW, row->userid,
st = safe_text_nonull(row->workername),
row->workinfoid, row->complete);
FREENULL(st);
}
}
set_sharesummary_stats(p_row, s_row, e_row, p_new, &tdf, &tdl);
if (p_item) {
DATA_SHARESUMMARY(p_row, p_item);
} else {
p_new = true;
K_WLOCK(sharesummary_free);
p_item = k_unlink_head(sharesummary_free);
K_WUNLOCK(sharesummary_free);
DATA_SHARESUMMARY(p_row, p_item);
bzero(p_row, sizeof(*p_row));
POOL_SS(p_row);
p_row->workinfoid = workinfoid;
}
set_sharesummary_stats(p_row, s_row, e_row, p_new, &tdf, &tdl);
MODIFYDATEPOINTERS(sharesummary_free, row, cd, by, code, inet);
// Store either new item
if (new || p_new) {
K_WLOCK(sharesummary_free);
if (new) {
add_to_ktree(sharesummary_root, item);
add_to_ktree(sharesummary_workinfoid_root, item);
k_add_head(sharesummary_store, item);
add_to_ktree(sharesummary_root, ss_item);
add_to_ktree(sharesummary_workinfoid_root, ss_item);
k_add_head(sharesummary_store, ss_item);
}
if (p_new) {
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;
}
// 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,
double diffacc, double diffinv, double shareacc,
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;
PGresult *res;
MARKERSUMMARY *row;
char *params[18 + MODIFYDATECOUNT];
char *params[20 + MODIFYDATECOUNT];
int n, par = 0;
char *ins;
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++] = tv_to_buf(&(row->firstshare), 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);
MODIFYDATEPARAMS(params, par, row);
PARCHK(par, params);
@ -6301,7 +6301,8 @@ bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code,
ins = "insert into markersummary "
"(markerid,userid,workername,diffacc,diffsta,diffdup,diffhi,"
"diffrej,shareacc,sharesta,sharedup,sharehi,sharerej,"
"sharecount,errorcount,firstshare,lastshare,lastdiffacc"
"sharecount,errorcount,firstshare,lastshare,firstshareacc,"
"lastshareacc,lastdiffacc"
MODIFYDATECONTROL ") values (" PQPARAM26 ")";
LOGDEBUG("%s() adding ms %"PRId64"/%"PRId64"/%s/%.0f",
@ -6344,7 +6345,7 @@ bool markersummary_fill(PGconn *conn)
MARKERSUMMARY *row, *p_row;
char *field;
char *sel;
int fields = 18;
int fields = 20;
bool ok;
LOGDEBUG("%s(): select", __func__);
@ -6356,8 +6357,8 @@ bool markersummary_fill(PGconn *conn)
sel = "select "
"markerid,userid,workername,diffacc,diffsta,diffdup,diffhi,"
"diffrej,shareacc,sharesta,sharedup,sharehi,sharerej,"
"sharecount,errorcount,firstshare,lastshare,"
"lastdiffacc"
"sharecount,errorcount,firstshare,lastshare,firstshareacc,"
"lastshareacc,lastdiffacc"
MODIFYDATECONTROL
" from markersummary";
res = PQexec(conn, sel, CKPQ_READ);
@ -6476,6 +6477,16 @@ bool markersummary_fill(PGconn *conn)
break;
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);
if (!ok)
break;
@ -6485,6 +6496,16 @@ bool markersummary_fill(PGconn *conn)
if (!ok)
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_userid_root, item);
k_add_head(markersummary_store, item);

Loading…
Cancel
Save