Browse Source

ckdb - load only one day of shares - or specify a begin workinfo with -b

master
kanoi 9 years ago
parent
commit
a30a75bd3f
  1. 24
      src/ckdb.c
  2. 5
      src/ckdb.h
  3. 46
      src/ckdb_dbio.c

24
src/ckdb.c

@ -436,6 +436,7 @@ K_STORE *shares_hi_store;
double diff_percent = DIFF_VAL(DIFF_PERCENT_DEFAULT); double diff_percent = DIFF_VAL(DIFF_PERCENT_DEFAULT);
double share_min_sdiff = 0; double share_min_sdiff = 0;
int64_t shares_begin = -1;
// SHAREERRORS shareerrors.id.json={...} // SHAREERRORS shareerrors.id.json={...}
K_TREE *shareerrors_root; K_TREE *shareerrors_root;
@ -1728,6 +1729,9 @@ static bool setup_data()
mutex_init(&wq_waitlock); mutex_init(&wq_waitlock);
cond_init(&wq_waitcond); cond_init(&wq_waitcond);
LOGWARNING("%sSequence processing is %s",
ignore_seq ? "ALERT: " : "",
ignore_seq ? "Off" : "On");
LOGWARNING("%sStartup payout generation state is %s", LOGWARNING("%sStartup payout generation state is %s",
genpayout_auto ? "" : "WARNING: ", genpayout_auto ? "" : "WARNING: ",
genpayout_auto ? "On" : "Off"); genpayout_auto ? "On" : "Off");
@ -2684,6 +2688,12 @@ static enum cmd_values process_seq(MSGLINE *msgline)
if (ignore_seq) if (ignore_seq)
return ckdb_cmds[msgline->which_cmds].cmd_val; return ckdb_cmds[msgline->which_cmds].cmd_val;
/* If non-seqall data was in a CCL reload file,
* it can't be processed by update_seq(), so don't */
if (msgline->n_seqall == 0 && msgline->n_seqstt == 0 &&
msgline->n_seqpid == 0)
return ckdb_cmds[msgline->which_cmds].cmd_val;
dupall = update_seq(SEQ_ALL, msgline->n_seqall, msgline->n_seqstt, dupall = update_seq(SEQ_ALL, msgline->n_seqall, msgline->n_seqstt,
msgline->n_seqpid, SEQALL, &(msgline->now), msgline->n_seqpid, SEQALL, &(msgline->now),
&(msgline->cd), msgline->code, &(msgline->cd), msgline->code,
@ -5827,6 +5837,8 @@ static void check_restore_dir(char *name)
static struct option long_options[] = { static struct option long_options[] = {
// script to call when alerts happen // script to call when alerts happen
{ "alert", required_argument, 0, 'a' }, { "alert", required_argument, 0, 'a' },
// workinfo to start shares_fill() default is 1 day
{ "shares-begin", required_argument, 0, 'b' },
{ "config", required_argument, 0, 'c' }, { "config", required_argument, 0, 'c' },
{ "dbname", required_argument, 0, 'd' }, { "dbname", required_argument, 0, 'd' },
{ "minsdiff", required_argument, 0, 'D' }, { "minsdiff", required_argument, 0, 'D' },
@ -5888,7 +5900,7 @@ int main(int argc, char **argv)
memset(&ckp, 0, sizeof(ckp)); memset(&ckp, 0, sizeof(ckp));
ckp.loglevel = LOG_NOTICE; ckp.loglevel = LOG_NOTICE;
while ((c = getopt_long(argc, argv, "a:c:d:D:ghi:I:kl:mM:n:p:P:r:R:s:S:t:u:U:vw:yY:", long_options, &i)) != -1) { while ((c = getopt_long(argc, argv, "a:c:d:D:ghi:Ikl:mM:n:p:P:r:R:s:S:t:u:U:vw:yY:", long_options, &i)) != -1) {
switch(c) { switch(c) {
case 'a': case 'a':
len = strlen(optarg); len = strlen(optarg);
@ -5898,6 +5910,16 @@ int main(int argc, char **argv)
(int)len, MAX_ALERT_CMD); (int)len, MAX_ALERT_CMD);
ckdb_alert_cmd = strdup(optarg); ckdb_alert_cmd = strdup(optarg);
break; break;
case 'b':
{
int64_t beg = atoll(optarg);
if (beg < 0) {
quit(1, "Invalid shares begin "
"%"PRId64" - must be >= 0",
beg);
}
shares_begin = beg;
}
case 'c': case 'c':
ckp.config = strdup(optarg); ckp.config = strdup(optarg);
break; break;

5
src/ckdb.h

@ -51,7 +51,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.5" #define DB_VERSION "1.0.5"
#define CKDB_VERSION DB_VERSION"-1.986" #define CKDB_VERSION DB_VERSION"-1.987"
#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__
@ -1723,6 +1723,9 @@ extern double diff_percent;
* This is set only via the runtime parameter -D or --minsdiff */ * This is set only via the runtime parameter -D or --minsdiff */
extern double share_min_sdiff; extern double share_min_sdiff;
// workinfoid to start loading shares, unset = shares_fill() decides
extern int64_t shares_begin;
// SHAREERRORS shareerrors.id.json={...} // SHAREERRORS shareerrors.id.json={...}
typedef struct shareerrors { typedef struct shareerrors {
int64_t workinfoid; int64_t workinfoid;

46
src/ckdb_dbio.c

@ -3858,16 +3858,51 @@ bool shares_fill(PGconn *conn)
{ {
ExecStatusType rescode; ExecStatusType rescode;
PGresult *res; PGresult *res;
K_ITEM *item = NULL; K_TREE_CTX ctx[1];
K_ITEM *item = NULL, *wi_item;
WORKINFO *workinfo = NULL;
SHARES *row; SHARES *row;
int n, t, i; int n, t, i;
char *field; char *field;
char *sel = NULL; char *sel = NULL;
int fields = 14; char *params[1];
int fields = 14, par = 0;
bool ok = false; bool ok = false;
int64_t workinfoid;
tv_t old;
LOGDEBUG("%s(): select", __func__); LOGDEBUG("%s(): select", __func__);
if (shares_begin >= 0)
workinfoid = shares_begin;
else {
/* Workinfo is already loaded
* CKDB doesn't currently use shares_db in processing,
* but make sure we have enough to avoid loading duplicates
* 1 day should be more than enough for normal running,
* however, if more than 1 day is needed,
* use -b to set the shares_begin workinfoid */
setnow(&old);
old.tv_sec -= 60 * 60 * 24; // 1 day
K_RLOCK(workinfo_free);
wi_item = last_in_ktree(workinfo_root, ctx);
while (wi_item) {
DATA_WORKINFO(workinfo, wi_item);
if (!tv_newer(&old, &(workinfo->createdate)))
break;
wi_item = prev_in_ktree(ctx);
}
if (wi_item)
workinfoid = workinfo->workinfoid;
else {
// none old enough, so just load from them all
workinfoid = 0;
}
K_RUNLOCK(workinfo_free);
}
LOGWARNING("%s(): loading from workinfoid>=%"PRId64, __func__, workinfoid);
printf(TICK_PREFIX"sh 0\r"); printf(TICK_PREFIX"sh 0\r");
fflush(stdout); fflush(stdout);
@ -3875,7 +3910,10 @@ bool shares_fill(PGconn *conn)
"workinfoid,userid,workername,clientid,enonce1,nonce2,nonce," "workinfoid,userid,workername,clientid,enonce1,nonce2,nonce,"
"diff,sdiff,errn,error,secondaryuserid,ntime,minsdiff" "diff,sdiff,errn,error,secondaryuserid,ntime,minsdiff"
HISTORYDATECONTROL HISTORYDATECONTROL
" from shares"; " from shares where workinfoid>=$1";
par = 0;
params[par++] = bigint_to_buf(workinfoid, NULL, 0);
PARCHK(par, params);
res = PQexec(conn, "Begin", CKPQ_READ); res = PQexec(conn, "Begin", CKPQ_READ);
rescode = PQresultStatus(res); rescode = PQresultStatus(res);
@ -3893,7 +3931,7 @@ bool shares_fill(PGconn *conn)
goto flail; goto flail;
} }
res = PQexec(conn, sel, CKPQ_READ); res = PQexecParams(conn, sel, par, NULL, (const char **)params, NULL, NULL, 0, CKPQ_READ);
rescode = PQresultStatus(res); rescode = PQresultStatus(res);
PQclear(res); PQclear(res);
if (!PGOK(rescode)) { if (!PGOK(rescode)) {

Loading…
Cancel
Save