Browse Source

Merge branch 'master' into bkey

master
Con Kolivas 9 years ago
parent
commit
1fb88a58a5
  1. 5
      src/bitcoin.c
  2. 70
      src/ckdb.c
  3. 256
      src/ckdb.h
  4. 91
      src/ckdb_cmd.c
  5. 7
      src/ckdb_data.c
  6. 44
      src/ckdb_dbio.c

5
src/bitcoin.c

@ -409,6 +409,11 @@ retry:
res_ret = json_string_value(res_val); res_ret = json_string_value(res_val);
if (res_ret && strlen(res_ret)) { if (res_ret && strlen(res_ret)) {
LOGWARNING("SUBMIT BLOCK RETURNED: %s", res_ret); LOGWARNING("SUBMIT BLOCK RETURNED: %s", res_ret);
/* Consider duplicate response as an accepted block */
if (safecmp(res_ret, "duplicate"))
goto out;
} else {
LOGWARNING("SUBMIT BLOCK GOT NO RESPONSE!");
goto out; goto out;
} }
} }

70
src/ckdb.c

@ -1,5 +1,5 @@
/* /*
* Copyright 1995-2015 Andrew Smith * Copyright 1995-2016 Andrew Smith
* Copyright 2014 Con Kolivas * Copyright 2014 Con Kolivas
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
@ -295,6 +295,34 @@ char *by_default = "code";
char *inet_default = "127.0.0.1"; char *inet_default = "127.0.0.1";
char *id_default = "42"; char *id_default = "42";
// NULL or poolinstance must match
const char *poolinstance = NULL;
// lock for accessing all mismatch variables
cklock_t poolinstance_lock;
time_t last_mismatch_message;
int64_t mismatch_workinfo;
int64_t mismatch_ageworkinfo;
int64_t mismatch_auth;
int64_t mismatch_addrauth;
int64_t mismatch_poolstats;
int64_t mismatch_userstats;
int64_t mismatch_workerstats;
int64_t mismatch_workmarkers;
int64_t mismatch_marks;
int64_t mismatch_total;
int64_t mismatch_all_workinfo;
int64_t mismatch_all_ageworkinfo;
int64_t mismatch_all_auth;
int64_t mismatch_all_addrauth;
int64_t mismatch_all_poolstats;
int64_t mismatch_all_userstats;
int64_t mismatch_all_workerstats;
int64_t mismatch_all_workmarkers;
int64_t mismatch_all_marks;
int64_t mismatch_all_total;
// LOGQUEUE // LOGQUEUE
K_LIST *logqueue_free; K_LIST *logqueue_free;
K_STORE *logqueue_store; K_STORE *logqueue_store;
@ -1599,6 +1627,9 @@ static bool setup_data()
if (!getdata3() || everyone_die) if (!getdata3() || everyone_die)
return false; return false;
/* This should never display anything since POOLINSTANCE_DBLOAD_MSG()
* resets each _obj's modified counters */
POOLINSTANCE_RESET_MSG("dbload");
setnow(&db_fin); setnow(&db_fin);
sec = tvdiff(&db_fin, &db_stt); sec = tvdiff(&db_fin, &db_stt);
min = floor(sec / 60.0); min = floor(sec / 60.0);
@ -1612,6 +1643,7 @@ static bool setup_data()
if (!reload() || everyone_die) if (!reload() || everyone_die)
return false; return false;
POOLINSTANCE_RESET_MSG("reload");
setnow(&rel_fin); setnow(&rel_fin);
sec = tvdiff(&rel_fin, &rel_stt); sec = tvdiff(&rel_fin, &rel_stt);
min = floor(sec / 60.0); min = floor(sec / 60.0);
@ -3344,7 +3376,7 @@ static void make_a_shift_mark()
K_ITEM *b_item = NULL; K_ITEM *b_item = NULL;
K_ITEM wi_look, ss_look; K_ITEM wi_look, ss_look;
SHARESUMMARY *sharesummary, looksharesummary; SHARESUMMARY *sharesummary, looksharesummary;
WORKINFO *workinfo, lookworkinfo; WORKINFO *workinfo = NULL, lookworkinfo;
BLOCKS *blocks = NULL; BLOCKS *blocks = NULL;
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;
@ -3398,11 +3430,11 @@ static void make_a_shift_mark()
return; return;
setnow(&now); setnow(&now);
ok = marks_process(NULL, true, EMPTY, workinfo->workinfoid, ok = marks_process(NULL, true, workinfo->poolinstance,
description, EMPTY, MARKTYPE_OTHER_BEGIN_STR, workinfo->workinfoid, description, EMPTY,
MARK_USED_STR, (char *)by_default, MARKTYPE_OTHER_BEGIN_STR, MARK_USED_STR,
(char *)__func__, (char *)inet_default, (char *)by_default, (char *)__func__,
&now, NULL); (char *)inet_default, &now, NULL);
if (ok) { if (ok) {
LOGWARNING("%s() FIRST mark %"PRId64"/%s/%s/%s/", LOGWARNING("%s() FIRST mark %"PRId64"/%s/%s/%s/",
__func__, workinfo->workinfoid, __func__, workinfo->workinfoid,
@ -3766,10 +3798,10 @@ static void make_a_shift_mark()
} }
setnow(&now); setnow(&now);
ok = marks_process(NULL, true, EMPTY, marks_wid, des, extra, ok = marks_process(NULL, true, workinfo->poolinstance,
shifttype, status, (char *)by_default, marks_wid, des, extra, shifttype, status,
(char *)__func__, (char *)inet_default, (char *)by_default, (char *)__func__,
&now, NULL); (char *)inet_default, &now, NULL);
if (ok) { if (ok) {
LOGWARNING("%s() mark %"PRId64"/%s/%s/%s/%s/", LOGWARNING("%s() mark %"PRId64"/%s/%s/%s/%s/",
@ -5028,6 +5060,8 @@ static void *listener(void *arg)
tv_t now; tv_t now;
ts_t abs; ts_t abs;
POOLINSTANCE_DATA_MSG();
tv_time(&now); tv_time(&now);
tv_to_ts(&abs, &now); tv_to_ts(&abs, &now);
timeraddspec(&abs, &tsdiff); timeraddspec(&abs, &tsdiff);
@ -5045,6 +5079,8 @@ sayonara:
if (conn) if (conn)
PQfinish(conn); PQfinish(conn);
POOLINSTANCE_RESET_MSG("exiting");
return NULL; return NULL;
} }
@ -5629,6 +5665,7 @@ static struct option long_options[] = {
// generate = enable payout pplns auto generation // generate = enable payout pplns auto generation
{ "generate", no_argument, 0, 'g' }, { "generate", no_argument, 0, 'g' },
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "pool-instance", required_argument, 0, 'i' },
{ "killold", no_argument, 0, 'k' }, { "killold", no_argument, 0, 'k' },
{ "loglevel", required_argument, 0, 'l' }, { "loglevel", required_argument, 0, 'l' },
// marker = enable mark/workmarker/markersummary auto generation // marker = enable mark/workmarker/markersummary auto generation
@ -5678,7 +5715,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, "c:d:ghkl:mM:n:p:P:r:R:s:S:t:u:U:vw:yY:", long_options, &i)) != -1) { while ((c = getopt_long(argc, argv, "c:d:ghi:kl:mM:n:p:P:r:R:s:S:t:u:U:vw:yY:", long_options, &i)) != -1) {
switch(c) { switch(c) {
case 'c': case 'c':
ckp.config = strdup(optarg); ckp.config = strdup(optarg);
@ -5704,6 +5741,14 @@ int main(int argc, char **argv)
optarg); optarg);
} }
break; break;
/* WARNING - enabling -i will require a DB data update
* if you've used ckdb before 1.920
* All (old) marks and workmarkers in the DB will need
* to have poolinstance set to the given -i value
* since they will be blank */
case 'i':
poolinstance = (const char *)strdup(optarg);
break;
case 'g': case 'g':
genpayout_auto = true; genpayout_auto = true;
break; break;
@ -5893,6 +5938,7 @@ int main(int argc, char **argv)
cklock_init(&last_lock); cklock_init(&last_lock);
cklock_init(&btc_lock); cklock_init(&btc_lock);
cklock_init(&poolinstance_lock);
// Emulate a list for lock checking // Emulate a list for lock checking
process_pplns_free = k_lock_only_list("ProcessPPLNS"); process_pplns_free = k_lock_only_list("ProcessPPLNS");

256
src/ckdb.h

@ -1,5 +1,5 @@
/* /*
* Copyright 1995-2015 Andrew Smith * Copyright 1995-2016 Andrew Smith
* Copyright 2014 Con Kolivas * Copyright 2014 Con Kolivas
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
@ -51,7 +51,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.4" #define DB_VERSION "1.0.4"
#define CKDB_VERSION DB_VERSION"-1.914" #define CKDB_VERSION DB_VERSION"-1.920"
#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__
@ -377,6 +377,252 @@ extern char *by_default;
extern char *inet_default; extern char *inet_default;
extern char *id_default; extern char *id_default;
// Number of seconds per poolinstance message for run
#define POOLINSTANCE_MSG_EVERY 30
#define FAILED_PI "failed.PI"
#define POOLINSTANCE_RESET_MSG(_txt) do { \
int64_t _workinfo, _ageworkinfo, _auth, _addrauth, _poolstats; \
int64_t _userstats, _workerstats, _workmarkers, _marks; \
bool msg = false; \
ck_wlock(&poolinstance_lock); \
if (mismatch_all_total) { \
msg = true; \
last_mismatch_message = time(NULL); \
_workinfo = mismatch_all_workinfo; \
_ageworkinfo = mismatch_all_ageworkinfo; \
_auth = mismatch_all_auth; \
_addrauth = mismatch_all_addrauth; \
_poolstats = mismatch_all_poolstats; \
_userstats = mismatch_all_userstats; \
_workerstats = mismatch_all_workerstats; \
_workmarkers = mismatch_all_workmarkers; \
_marks = mismatch_all_marks; \
mismatch_workinfo = mismatch_ageworkinfo = \
mismatch_auth = mismatch_addrauth = \
mismatch_poolstats = mismatch_userstats = \
mismatch_workerstats = mismatch_workmarkers = \
mismatch_marks = mismatch_total = 0; \
mismatch_all_workinfo = mismatch_all_ageworkinfo = \
mismatch_all_auth = mismatch_all_addrauth = \
mismatch_all_poolstats = mismatch_all_userstats = \
mismatch_all_workerstats = mismatch_all_workmarkers = \
mismatch_all_marks = mismatch_all_total = 0; \
} \
ck_wunlock(&poolinstance_lock); \
if (msg) { \
char reply[1024], *buf; \
size_t len, off; \
APPEND_REALLOC_INIT(buf, off, len); \
snprintf(reply, sizeof(reply), "%s() %s PI total:", \
__func__, _txt); \
APPEND_REALLOC(buf, off, len, reply); \
if (_workinfo) { \
snprintf(reply, sizeof(reply), " wi=%"PRId64, _workinfo); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_ageworkinfo) { \
snprintf(reply, sizeof(reply), " age=%"PRId64, _ageworkinfo); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_auth) { \
snprintf(reply, sizeof(reply), " auth=%"PRId64, _auth); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_addrauth) { \
snprintf(reply, sizeof(reply), " addr=%"PRId64, _addrauth); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_poolstats) { \
snprintf(reply, sizeof(reply), " ps=%"PRId64, _poolstats); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_userstats) { \
snprintf(reply, sizeof(reply), " us=%"PRId64, _userstats); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_workerstats) { \
snprintf(reply, sizeof(reply), " ws=%"PRId64, _workerstats); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_workmarkers) { \
snprintf(reply, sizeof(reply), " wm=%"PRId64, _workmarkers); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_marks) { \
snprintf(reply, sizeof(reply), " mark=%"PRId64, _marks); \
APPEND_REALLOC(buf, off, len, reply); \
} \
LOGWARNING("WARN: %s", buf); \
FREENULL(buf); \
} \
} while (0)
// Checks mismatch_total outside lock since it's not critical
#define POOLINSTANCE_DATA_MSG() do { \
int64_t _workinfo, _ageworkinfo, _auth, _addrauth, _poolstats; \
int64_t _userstats, _workerstats, _workmarkers, _marks; \
bool warn = false; \
time_t now; \
if (mismatch_total) { \
ck_wlock(&poolinstance_lock); \
if (mismatch_total) { \
now = time(NULL); \
if ((now - last_mismatch_message) >= POOLINSTANCE_MSG_EVERY) { \
warn = true; \
last_mismatch_message = now; \
_workinfo = mismatch_workinfo; \
_ageworkinfo = mismatch_ageworkinfo; \
_auth = mismatch_auth; \
_addrauth = mismatch_addrauth; \
_poolstats = mismatch_poolstats; \
_userstats = mismatch_userstats; \
_workerstats = mismatch_workerstats; \
_workmarkers = mismatch_workmarkers; \
_marks = mismatch_marks; \
mismatch_workinfo = mismatch_ageworkinfo = \
mismatch_auth = mismatch_addrauth = \
mismatch_poolstats = mismatch_userstats = \
mismatch_workerstats = mismatch_workmarkers = \
mismatch_marks = mismatch_total = 0; \
} \
} \
ck_wunlock(&poolinstance_lock); \
} \
if (warn) { \
char reply[1024], *buf; \
size_t len, off; \
APPEND_REALLOC_INIT(buf, off, len); \
snprintf(reply, sizeof(reply), "%s() PI:", __func__); \
APPEND_REALLOC(buf, off, len, reply); \
if (_workinfo) { \
snprintf(reply, sizeof(reply), " wi=%"PRId64, _workinfo); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_ageworkinfo) { \
snprintf(reply, sizeof(reply), " age=%"PRId64, _ageworkinfo); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_auth) { \
snprintf(reply, sizeof(reply), " auth=%"PRId64, _auth); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_addrauth) { \
snprintf(reply, sizeof(reply), " addr=%"PRId64, _addrauth); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_poolstats) { \
snprintf(reply, sizeof(reply), " ps=%"PRId64, _poolstats); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_userstats) { \
snprintf(reply, sizeof(reply), " us=%"PRId64, _userstats); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_workerstats) { \
snprintf(reply, sizeof(reply), " ws=%"PRId64, _workerstats); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_workmarkers) { \
snprintf(reply, sizeof(reply), " wm=%"PRId64, _workmarkers); \
APPEND_REALLOC(buf, off, len, reply); \
} \
if (_marks) { \
snprintf(reply, sizeof(reply), " mark=%"PRId64, _marks); \
APPEND_REALLOC(buf, off, len, reply); \
} \
LOGWARNING("WARN: %s", buf); \
FREENULL(buf); \
} \
} while (0)
#define POOLINSTANCE_DATA_SET(_obj, _pi) do { \
bool warn = false; \
ck_wlock(&poolinstance_lock); \
if (mismatch_all_ ## _obj++ == 0) { \
warn = true; \
} \
mismatch_ ## _obj++; \
mismatch_all_total++; \
mismatch_total++; \
ck_wunlock(&poolinstance_lock); \
if (warn) { \
char *pist = NULL; \
LOGWARNING("WARN: %s() " #_obj " first invalid " \
"poolinstance '%s'", __func__, \
pist = safe_text_nonull(_pi)); \
FREENULL(pist); \
} \
POOLINSTANCE_DATA_MSG(); \
} while (0)
#define POOLINSTANCE_DBLOAD_SET(_obj, _pi) do { \
bool warn = false; \
ck_wlock(&poolinstance_lock); \
if (mismatch_all_ ## _obj++ == 0) \
warn = true; \
mismatch_ ## _obj++; \
mismatch_all_total++; \
mismatch_total++; \
ck_wunlock(&poolinstance_lock); \
if (warn) { \
char *pist = NULL; \
LOGWARNING("WARN: %s() dbload " #_obj " first " \
"invalid poolinstance '%s'", __func__, \
pist = safe_text_nonull(_pi)); \
FREENULL(pist); \
} \
} while (0)
/* DBLoad message resets _obj and _all_obj back to zero
* since it's counting a single table_fill() */
#define POOLINSTANCE_DBLOAD_MSG(_obj) do { \
int64_t tot = 0; \
ck_wlock(&poolinstance_lock); \
if (mismatch_all_ ## _obj) { \
tot = mismatch_all_ ## _obj; \
mismatch_all_total -= mismatch_all_ ## _obj; \
mismatch_all_ ## _obj = 0; \
mismatch_total -= mismatch_ ## _obj; \
mismatch_ ## _obj = 0; \
} \
ck_wunlock(&poolinstance_lock); \
if (tot) { \
LOGWARNING("WARN: %s() dbload " #_obj " total " \
"invalid poolinstance %"PRId64, \
__func__, tot); \
} \
} while (0)
// NULL or poolinstance must match
extern const char *poolinstance;
// lock for accessing all mismatch variables
extern cklock_t poolinstance_lock;
extern time_t last_mismatch_message;
extern int64_t mismatch_workinfo;
extern int64_t mismatch_ageworkinfo;
extern int64_t mismatch_auth;
extern int64_t mismatch_addrauth;
extern int64_t mismatch_poolstats;
extern int64_t mismatch_userstats;
extern int64_t mismatch_workerstats;
extern int64_t mismatch_workmarkers;
extern int64_t mismatch_marks;
extern int64_t mismatch_total;
extern int64_t mismatch_all_workinfo;
extern int64_t mismatch_all_ageworkinfo;
extern int64_t mismatch_all_auth;
extern int64_t mismatch_all_addrauth;
extern int64_t mismatch_all_poolstats;
extern int64_t mismatch_all_userstats;
extern int64_t mismatch_all_workerstats;
extern int64_t mismatch_all_workmarkers;
extern int64_t mismatch_all_marks;
extern int64_t mismatch_all_total;
enum cmd_values { enum cmd_values {
CMD_UNSET, CMD_UNSET,
CMD_DUPSEQ, // Ignore, we've already got it CMD_DUPSEQ, // Ignore, we've already got it
@ -2012,8 +2258,8 @@ typedef struct marks {
* marktype is one of: * marktype is one of:
* b - block end * b - block end
* p - pplns begin * p - pplns begin
* s - shift begin (not yet used) * s - shift begin (not used)
* e - shift end (not yet used) * e - shift end
* o - other begin * o - other begin
* f - other finish/end * f - other finish/end
* description generated will be: * description generated will be:
@ -2030,7 +2276,7 @@ typedef struct marks {
* next/prev valid workinfoid, not simply +1 or -1 * next/prev valid workinfoid, not simply +1 or -1
* i.e. all workinfoid in marks and workmarkers must exist in workinfo * i.e. all workinfoid in marks and workmarkers must exist in workinfo
* *
* Until we start using shifts: * Until we started using shifts:
* workmarkers can be created up to ending in the largest 'p' "-1" * workmarkers can be created up to ending in the largest 'p' "-1"
* workmarkers will always be the smallest of: * workmarkers will always be the smallest of:
* Block NNN-1 "+1" to Block NNN * Block NNN-1 "+1" to Block NNN

91
src/ckdb_cmd.c

@ -1,5 +1,5 @@
/* /*
* Copyright 1995-2015 Andrew Smith * Copyright 1995-2016 Andrew Smith
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free * under the terms of the GNU General Public License as published by the Free
@ -929,6 +929,11 @@ static char *cmd_poolstats_do(PGconn *conn, char *cmd, char *id, char *by,
if (!i_poolinstance) if (!i_poolinstance)
return strdup(reply); return strdup(reply);
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) {
POOLINSTANCE_DATA_SET(poolstats, transfer_data(i_poolinstance));
return strdup(FAILED_PI);
}
i_elapsed = optional_name(trf_root, "elapsed", 1, NULL, reply, siz); i_elapsed = optional_name(trf_root, "elapsed", 1, NULL, reply, siz);
if (!i_elapsed) if (!i_elapsed)
i_elapsed = &poolstats_elapsed; i_elapsed = &poolstats_elapsed;
@ -1041,6 +1046,11 @@ static char *cmd_userstats(__maybe_unused PGconn *conn, char *cmd, char *id,
if (!i_poolinstance) if (!i_poolinstance)
return strdup(reply); return strdup(reply);
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) {
POOLINSTANCE_DATA_SET(userstats, transfer_data(i_poolinstance));
return strdup(FAILED_PI);
}
i_elapsed = optional_name(trf_root, "elapsed", 1, NULL, reply, siz); i_elapsed = optional_name(trf_root, "elapsed", 1, NULL, reply, siz);
if (!i_elapsed) if (!i_elapsed)
i_elapsed = &userstats_elapsed; i_elapsed = &userstats_elapsed;
@ -1120,6 +1130,11 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id,
if (!i_poolinstance) if (!i_poolinstance)
return strdup(reply); return strdup(reply);
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) {
POOLINSTANCE_DATA_SET(workerstats, transfer_data(i_poolinstance));
return strdup(FAILED_PI);
}
i_elapsed = require_name(trf_root, "elapsed", 1, NULL, reply, siz); i_elapsed = require_name(trf_root, "elapsed", 1, NULL, reply, siz);
if (!i_elapsed) if (!i_elapsed)
return strdup(reply); return strdup(reply);
@ -2397,6 +2412,15 @@ static char *cmd_sharelog(PGconn *conn, char *cmd, char *id,
K_ITEM *i_ntime, *i_reward; K_ITEM *i_ntime, *i_reward;
bool igndup = false; bool igndup = false;
i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz);
if (!i_poolinstance)
return strdup(reply);
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))){
POOLINSTANCE_DATA_SET(workinfo, transfer_data(i_poolinstance));
return strdup(FAILED_PI);
}
i_workinfoid = require_name(trf_root, "workinfoid", 1, NULL, reply, siz); i_workinfoid = require_name(trf_root, "workinfoid", 1, NULL, reply, siz);
if (!i_workinfoid) if (!i_workinfoid)
return strdup(reply); return strdup(reply);
@ -2414,10 +2438,6 @@ static char *cmd_sharelog(PGconn *conn, char *cmd, char *id,
goto wiconf; goto wiconf;
} }
i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz);
if (!i_poolinstance)
return strdup(reply);
i_transactiontree = require_name(trf_root, "transactiontree", 0, NULL, reply, siz); i_transactiontree = require_name(trf_root, "transactiontree", 0, NULL, reply, siz);
if (!i_transactiontree) if (!i_transactiontree)
return strdup(reply); return strdup(reply);
@ -2661,6 +2681,15 @@ seconf:
tv_t ss_first, ss_last; tv_t ss_first, ss_last;
bool ok; bool ok;
i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz);
if (!i_poolinstance)
return strdup(reply);
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) {
POOLINSTANCE_DATA_SET(ageworkinfo, transfer_data(i_poolinstance));
return strdup(FAILED_PI);
}
i_workinfoid = require_name(trf_root, "workinfoid", 1, NULL, reply, siz); i_workinfoid = require_name(trf_root, "workinfoid", 1, NULL, reply, siz);
if (!i_workinfoid) if (!i_workinfoid)
return strdup(reply); return strdup(reply);
@ -2681,10 +2710,6 @@ seconf:
goto awconf; goto awconf;
} }
i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz);
if (!i_poolinstance)
return strdup(reply);
ok = workinfo_age(workinfoid, transfer_data(i_poolinstance), ok = workinfo_age(workinfoid, transfer_data(i_poolinstance),
by, code, inet, cd, &ss_first, &ss_last, by, code, inet, cd, &ss_first, &ss_last,
&ss_count, &s_count, &s_diff); &ss_count, &s_count, &s_diff);
@ -2848,6 +2873,8 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by,
char *code, char *inet, tv_t *cd, char *code, char *inet, tv_t *cd,
K_TREE *trf_root) K_TREE *trf_root)
{ {
K_ITEM tmp_poolinstance_item;
TRANSFER tmp_poolinstance;
K_TREE_CTX ctx[1]; K_TREE_CTX ctx[1];
char reply[1024] = ""; char reply[1024] = "";
size_t siz = sizeof(reply); size_t siz = sizeof(reply);
@ -2865,8 +2892,24 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by,
i_poolinstance = optional_name(trf_root, "poolinstance", 1, NULL, i_poolinstance = optional_name(trf_root, "poolinstance", 1, NULL,
reply, siz); reply, siz);
if (!i_poolinstance) if (!i_poolinstance) {
if (poolinstance) {
STRNCPY(tmp_poolinstance.name, "poolinstance");
STRNCPY(tmp_poolinstance.svalue, poolinstance);
tmp_poolinstance.mvalue = tmp_poolinstance.svalue;
tmp_poolinstance_item.name = Transfer;
tmp_poolinstance_item.prev = NULL;
tmp_poolinstance_item.next = NULL;
tmp_poolinstance_item.data = (void *)(&tmp_poolinstance);
i_poolinstance = &tmp_poolinstance_item;
} else
i_poolinstance = &auth_poolinstance; i_poolinstance = &auth_poolinstance;
} else {
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) {
POOLINSTANCE_DATA_SET(auth, transfer_data(i_poolinstance));
return strdup(FAILED_PI);
}
}
i_username = require_name(trf_root, "username", 1, NULL, reply, siz); i_username = require_name(trf_root, "username", 1, NULL, reply, siz);
if (!i_username) if (!i_username)
@ -2978,6 +3021,8 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by,
char *code, char *inet, tv_t *cd, char *code, char *inet, tv_t *cd,
K_TREE *trf_root) K_TREE *trf_root)
{ {
K_ITEM tmp_poolinstance_item;
TRANSFER tmp_poolinstance;
K_TREE_CTX ctx[1]; K_TREE_CTX ctx[1];
char reply[1024] = ""; char reply[1024] = "";
size_t siz = sizeof(reply); size_t siz = sizeof(reply);
@ -2993,8 +3038,24 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by,
i_poolinstance = optional_name(trf_root, "poolinstance", 1, NULL, i_poolinstance = optional_name(trf_root, "poolinstance", 1, NULL,
reply, siz); reply, siz);
if (!i_poolinstance) if (!i_poolinstance) {
if (poolinstance) {
STRNCPY(tmp_poolinstance.name, "poolinstance");
STRNCPY(tmp_poolinstance.svalue, poolinstance);
tmp_poolinstance.mvalue = tmp_poolinstance.svalue;
tmp_poolinstance_item.name = Transfer;
tmp_poolinstance_item.prev = NULL;
tmp_poolinstance_item.next = NULL;
tmp_poolinstance_item.data = (void *)(&tmp_poolinstance);
i_poolinstance = &tmp_poolinstance_item;
} else
i_poolinstance = &auth_poolinstance; i_poolinstance = &auth_poolinstance;
} else {
if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) {
POOLINSTANCE_DATA_SET(addrauth, transfer_data(i_poolinstance));
return strdup(FAILED_PI);
}
}
i_username = require_name(trf_root, "username", 1, NULL, reply, siz); i_username = require_name(trf_root, "username", 1, NULL, reply, siz);
if (!i_username) if (!i_username)
@ -5813,6 +5874,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id,
K_ITEM *i_action, *i_workinfoid, *i_marktype, *i_description; K_ITEM *i_action, *i_workinfoid, *i_marktype, *i_description;
K_ITEM *i_height, *i_status, *i_extra, *m_item, *b_item, *w_item; K_ITEM *i_height, *i_status, *i_extra, *m_item, *b_item, *w_item;
K_ITEM *wm_item, *wm_item_prev, *i_markerid; K_ITEM *wm_item, *wm_item_prev, *i_markerid;
WORKINFO *workinfo = NULL;
WORKMARKERS *workmarkers; WORKMARKERS *workmarkers;
K_TREE_CTX ctx[1]; K_TREE_CTX ctx[1];
BLOCKS *blocks; BLOCKS *blocks;
@ -5937,9 +5999,10 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id,
workinfoid); workinfoid);
return strdup(reply); return strdup(reply);
} }
ok = marks_process(conn, true, EMPTY, workinfoid, description, DATA_WORKINFO(workinfo, w_item);
extra, marktype, status, by, code, inet, cd, ok = marks_process(conn, true, workinfo->poolinstance,
trf_root); workinfoid, description, extra, marktype,
status, by, code, inet, cd, trf_root);
} else if (strcasecmp(action, "expire") == 0) { } else if (strcasecmp(action, "expire") == 0) {
/* Expire the mark - effectively deletes it /* Expire the mark - effectively deletes it
* Require workinfoid */ * Require workinfoid */

7
src/ckdb_data.c

@ -1,5 +1,5 @@
/* /*
* Copyright 1995-2015 Andrew Smith * Copyright 1995-2016 Andrew Smith
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free * under the terms of the GNU General Public License as published by the Free
@ -4707,7 +4707,8 @@ static bool gen_workmarkers(PGconn *conn, MARKS *stt, bool after, MARKS *fin,
stt->description, after ? "++" : "", stt->description, after ? "++" : "",
fin->description, before ? "--" : ""); fin->description, before ? "--" : "");
ok = workmarkers_process(conn, false, true, 0, EMPTY, ok = workmarkers_process(conn, false, true, 0,
wi_fin->poolinstance,
wi_fin->workinfoid, wi_stt->workinfoid, wi_fin->workinfoid, wi_stt->workinfoid,
description, MARKER_READY_STR, description, MARKER_READY_STR,
by, code, inet, cd, trf_root); by, code, inet, cd, trf_root);
@ -4716,7 +4717,7 @@ static bool gen_workmarkers(PGconn *conn, MARKS *stt, bool after, MARKS *fin,
return false; return false;
} }
ok = marks_process(conn, true, EMPTY, fin->workinfoid, ok = marks_process(conn, true, wi_fin->poolinstance, fin->workinfoid,
fin->description, fin->extra, fin->marktype, fin->description, fin->extra, fin->marktype,
MARK_USED_STR, by, code, inet, cd, trf_root); MARK_USED_STR, by, code, inet, cd, trf_root);

44
src/ckdb_dbio.c

@ -1,5 +1,5 @@
/* /*
* Copyright 1995-2015 Andrew Smith * Copyright 1995-2016 Andrew Smith
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free * under the terms of the GNU General Public License as published by the Free
@ -2980,15 +2980,20 @@ bool workinfo_fill(PGconn *conn)
break; break;
} }
PQ_GET_FLD(res, i, "workinfoid", field, ok); PQ_GET_FLD(res, i, "poolinstance", field, ok);
if (!ok) if (!ok)
break; break;
TXT_TO_BIGINT("workinfoid", field, row->workinfoid); if (poolinstance && strcmp(field, poolinstance)) {
k_add_head(workinfo_free, item);
POOLINSTANCE_DBLOAD_SET(workinfo, field);
continue;
}
TXT_TO_STR("poolinstance", field, row->poolinstance);
PQ_GET_FLD(res, i, "poolinstance", field, ok); PQ_GET_FLD(res, i, "workinfoid", field, ok);
if (!ok) if (!ok)
break; break;
TXT_TO_STR("poolinstance", field, row->poolinstance); TXT_TO_BIGINT("workinfoid", field, row->workinfoid);
/* Not currently needed in RAM /* Not currently needed in RAM
PQ_GET_FLD(res, i, "transactiontree", field, ok); PQ_GET_FLD(res, i, "transactiontree", field, ok);
@ -3098,6 +3103,7 @@ flail:
LOGWARNING("%s(): fetched %d workinfo records", __func__, n); LOGWARNING("%s(): fetched %d workinfo records", __func__, n);
} }
POOLINSTANCE_DBLOAD_MSG(workinfo);
return ok; return ok;
} }
@ -6438,6 +6444,11 @@ bool poolstats_fill(PGconn *conn)
PQ_GET_FLD(res, i, "poolinstance", field, ok); PQ_GET_FLD(res, i, "poolinstance", field, ok);
if (!ok) if (!ok)
break; break;
if (poolinstance && strcmp(field, poolinstance)) {
k_add_head(poolstats_free, item);
POOLINSTANCE_DBLOAD_SET(poolstats, field);
continue;
}
TXT_TO_STR("poolinstance", field, row->poolinstance); TXT_TO_STR("poolinstance", field, row->poolinstance);
PQ_GET_FLD(res, i, "elapsed", field, ok); PQ_GET_FLD(res, i, "elapsed", field, ok);
@ -6499,6 +6510,7 @@ bool poolstats_fill(PGconn *conn)
} }
clean: clean:
free(sel); free(sel);
POOLINSTANCE_DBLOAD_MSG(poolstats);
return ok; return ok;
} }
@ -7304,17 +7316,22 @@ bool workmarkers_fill(PGconn *conn)
break; break;
} }
PQ_GET_FLD(res, i, "markerid", field, ok);
if (!ok)
break;
TXT_TO_BIGINT("markerid", field, row->markerid);
PQ_GET_FLD(res, i, "poolinstance", field, ok); PQ_GET_FLD(res, i, "poolinstance", field, ok);
if (!ok) if (!ok)
break; break;
if (poolinstance && strcmp(field, poolinstance)) {
k_add_head(workmarkers_free, item);
POOLINSTANCE_DBLOAD_SET(workmarkers, field);
continue;
}
TXT_TO_PTR("poolinstance", field, row->poolinstance); TXT_TO_PTR("poolinstance", field, row->poolinstance);
LIST_MEM_ADD(workmarkers_free, row->poolinstance); LIST_MEM_ADD(workmarkers_free, row->poolinstance);
PQ_GET_FLD(res, i, "markerid", field, ok);
if (!ok)
break;
TXT_TO_BIGINT("markerid", field, row->markerid);
PQ_GET_FLD(res, i, "workinfoidend", field, ok); PQ_GET_FLD(res, i, "workinfoidend", field, ok);
if (!ok) if (!ok)
break; break;
@ -7403,6 +7420,7 @@ bool workmarkers_fill(PGconn *conn)
LOGWARNING("%s(): loaded %d workmarkers records", __func__, n); LOGWARNING("%s(): loaded %d workmarkers records", __func__, n);
} }
POOLINSTANCE_DBLOAD_MSG(workmarkers);
return ok; return ok;
} }
@ -7631,6 +7649,11 @@ bool marks_fill(PGconn *conn)
PQ_GET_FLD(res, i, "poolinstance", field, ok); PQ_GET_FLD(res, i, "poolinstance", field, ok);
if (!ok) if (!ok)
break; break;
if (poolinstance && strcmp(field, poolinstance)) {
k_add_head(marks_free, item);
POOLINSTANCE_DBLOAD_SET(marks, field);
continue;
}
TXT_TO_PTR("poolinstance", field, row->poolinstance); TXT_TO_PTR("poolinstance", field, row->poolinstance);
LIST_MEM_ADD(marks_free, row->poolinstance); LIST_MEM_ADD(marks_free, row->poolinstance);
@ -7683,6 +7706,7 @@ bool marks_fill(PGconn *conn)
LOGWARNING("%s(): loaded %d marks records", __func__, n); LOGWARNING("%s(): loaded %d marks records", __func__, n);
} }
POOLINSTANCE_DBLOAD_MSG(marks);
return ok; return ok;
} }

Loading…
Cancel
Save