From b4a115cc094b8dcaa280a0e21f7b48e5d41df1ac Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 22 Sep 2016 02:32:24 +1000 Subject: [PATCH] ckdb - make all poolinstance intransient --- src/ckdb.c | 12 ++--- src/ckdb.h | 47 ++++++++--------- src/ckdb_cmd.c | 135 +++++++++++++++++++++--------------------------- src/ckdb_data.c | 42 +++++++-------- src/ckdb_dbio.c | 63 +++++++++++----------- 5 files changed, 139 insertions(+), 160 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index 36026e5a..92fce348 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -209,8 +209,6 @@ const char Transfer[] = "Transfer"; // older version missing field defaults // see end of alloc_storage() -static TRANSFER auth_1 = { "poolinstance", "", NULL, NULL }; -K_ITEM auth_poolinstance = { Transfer, NULL, NULL, (void *)(&auth_1) }; static TRANSFER auth_2 = { "preauth", FALSE_STR, auth_2.svalue, NULL }; K_ITEM auth_preauth = { Transfer, NULL, NULL, (void *)(&auth_2) }; static TRANSFER poolstats_1 = { "elapsed", "0", poolstats_1.svalue, NULL }; @@ -409,7 +407,7 @@ char *inet_default = "127.0.0.1"; char *id_default = "42"; // NULL or poolinstance must match -const char *poolinstance = NULL; +const char *sys_poolinstance = NULL; // lock for accessing all mismatch variables cklock_t poolinstance_lock; time_t last_mismatch_message; @@ -2286,8 +2284,6 @@ static void alloc_storage() // setup intransients in_empty = get_intransient("empty", EMPTY); - auth_1.intransient = get_intransient(auth_1.name, ""); - auth_1.mvalue = auth_1.intransient->str; userstats_workername = get_intransient("workername", "all"); } @@ -4983,7 +4979,7 @@ static void summarise_blocks() "/%"PRId64"/%s/%s crosses block " "%"PRId32"/%"PRId64" boundary", __func__, workmarkers->markerid, - workmarkers->poolinstance, + workmarkers->in_poolinstance, workmarkers->workinfoidstart, workmarkers->workinfoidend, workmarkers->description, @@ -8064,7 +8060,7 @@ static bool make_keysummaries() LOGDEBUG("%s() processing workmarkers %"PRId64"/%s/End %"PRId64"/" "Stt %"PRId64"/%s/%s", - __func__, workmarkers->markerid, workmarkers->poolinstance, + __func__, workmarkers->markerid, workmarkers->in_poolinstance, workmarkers->workinfoidend, workmarkers->workinfoidstart, workmarkers->description, workmarkers->status); @@ -9135,7 +9131,7 @@ int main(int argc, char **argv) * to have poolinstance set to the given -i value * since they will be blank */ case 'i': - poolinstance = (const char *)strdup(optarg); + sys_poolinstance = (const char *)strdup(optarg); break; case 'I': ignore_seq = true; diff --git a/src/ckdb.h b/src/ckdb.h index 06c14af8..ab0caefa 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -58,7 +58,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.7" -#define CKDB_VERSION DB_VERSION"-2.505" +#define CKDB_VERSION DB_VERSION"-2.506" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -639,7 +639,7 @@ extern char *id_default; } while (0) // NULL or poolinstance must match -extern const char *poolinstance; +extern const char *sys_poolinstance; // lock for accessing all mismatch variables extern cklock_t poolinstance_lock; extern time_t last_mismatch_message; @@ -1565,7 +1565,6 @@ extern K_LIST *transfer_free; extern const char Transfer[]; -extern K_ITEM auth_poolinstance; extern K_ITEM auth_preauth; extern K_ITEM poolstats_elapsed; extern K_ITEM userstats_elapsed; @@ -2681,7 +2680,7 @@ extern int o_limits_max_lifetime; // AUTHS authorise.id.json={...} typedef struct auths { int64_t authid; - char poolinstance[TXT_BIG+1]; + char *in_poolinstance; int64_t userid; char *in_workername; int32_t clientid; @@ -2706,7 +2705,7 @@ extern K_STORE *auths_store; #define STATS_PER (9.5*60.0) typedef struct poolstats { - char poolinstance[TXT_BIG+1]; + char *in_poolinstance; int64_t elapsed; int32_t users; int32_t workers; @@ -2737,7 +2736,7 @@ extern K_STORE *poolstats_store; * Most of the #defines for USERSTATS are no longer needed * but are left here for now for historical reference */ typedef struct userstats { - char poolinstance[TXT_BIG+1]; + char *in_poolinstance; int64_t userid; char *in_workername; int64_t elapsed; @@ -3015,7 +3014,7 @@ extern K_STORE *keysummary_store; // WORKMARKERS typedef struct workmarkers { int64_t markerid; - char *poolinstance; + char *in_poolinstance; int64_t workinfoidend; int64_t workinfoidstart; char *description; @@ -3046,7 +3045,7 @@ extern K_STORE *workmarkers_store; // MARKS typedef struct marks { - char *poolinstance; + char *in_poolinstance; int64_t workinfoid; char *description; char *extra; @@ -3317,8 +3316,8 @@ extern cmp_t cmp_intransient(K_ITEM *a, K_ITEM *b); _get_intransient(_fld, _val, 0, WHERE_FFL_HERE) #define get_intransient_siz(_fld, _val, _siz) \ _get_intransient(_fld, _val , _siz, WHERE_FFL_HERE) -extern INTRANSIENT *_get_intransient(char *fldnam, char *value, size_t siz, - WHERE_FFL_ARGS); +extern INTRANSIENT *_get_intransient(const char *fldnam, char *value, + size_t siz, WHERE_FFL_ARGS); #define intransient_str(_fld, _val) \ _intransient_str(_fld, _val, WHERE_FFL_HERE) extern char *_intransient_str(char *fldnam, char *value, WHERE_FFL_ARGS); @@ -3442,9 +3441,9 @@ extern K_ITEM *_find_workinfo(int64_t workinfoid, bool gotlock, K_TREE_CTX *ctx) extern K_ITEM *next_workinfo(int64_t workinfoid, K_TREE_CTX *ctx); extern K_ITEM *find_workinfo_esm(int64_t workinfoid, bool error, bool *created, tv_t *createdate); -extern bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, - tv_t *ss_first, tv_t *ss_last, int64_t *ss_count, - int64_t *s_count, int64_t *s_diff); +extern bool workinfo_age(int64_t workinfoid, INTRANSIENT *in_poolinstance, + tv_t *cd, tv_t *ss_first, tv_t *ss_last, + int64_t *ss_count, int64_t *s_count, int64_t *s_diff); extern double coinbase_reward(int32_t height); extern double workinfo_pps(K_ITEM *w_item, int64_t workinfoid); extern cmp_t cmp_shares(K_ITEM *a, K_ITEM *b); @@ -3465,7 +3464,8 @@ extern void zero_sharesummary(SHARESUMMARY *row); extern K_ITEM *_find_sharesummary(int64_t userid, char *workername, int64_t workinfoid, bool pool); extern K_ITEM *find_last_sharesummary(int64_t userid, char *workername); -extern void auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd); +extern void auto_age_older(int64_t workinfoid, INTRANSIENT *in_poolinstance, + tv_t *cd); #define dbhash2btchash(_hash, _buf, _siz) \ _dbhash2btchash(_hash, _buf, _siz, WHERE_FFL_HERE) void _dbhash2btchash(char *hash, char *buf, size_t siz, WHERE_FFL_ARGS); @@ -3753,13 +3753,14 @@ extern int _events_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root) #define events_add(_id, _trf_root) _events_add(_id, NULL, NULL, NULL, _trf_root) extern int _ovents_add(int id, char *by, char *inet, tv_t *cd, K_TREE *trf_root); #define ovents_add(_id, _trf_root) _ovents_add(_id, NULL, NULL, NULL, _trf_root) -extern bool auths_add(PGconn *conn, char *poolinstance, INTRANSIENT *in_username, - INTRANSIENT *in_workername, char *clientid, - char *enonce1, char *useragent, char *preauth, char *by, - char *code, char *inet, tv_t *cd, K_TREE *trf_root, - bool addressuser, USERS **users, WORKERS **workers, - int *event, bool reload_data); -extern bool poolstats_add(PGconn *conn, bool store, char *poolinstance, +extern bool auths_add(PGconn *conn, INTRANSIENT *in_poolinstance, + INTRANSIENT *in_username, INTRANSIENT *in_workername, + char *clientid, char *enonce1, char *useragent, + char *preauth, char *by, char *code, char *inet, + tv_t *cd, K_TREE *trf_root, bool addressuser, + USERS **users, WORKERS **workers, int *event, + bool reload_data); +extern bool poolstats_add(PGconn *conn, bool store, INTRANSIENT *in_poolinstance, char *elapsed, char *users, char *workers, char *hashrate, char *hashrate5m, char *hashrate1hr, char *hashrate24hr, @@ -3767,12 +3768,12 @@ extern bool poolstats_add(PGconn *conn, bool store, char *poolinstance, bool igndup, K_TREE *trf_root); extern bool poolstats_fill(PGconn *conn); extern bool userstats_add_db(PGconn *conn, USERSTATS *row); -extern bool userstats_add(char *poolinstance, char *elapsed, char *username, +extern bool userstats_add(INTRANSIENT *in_poolinstance, char *elapsed, char *username, INTRANSIENT *in_workername, char *hashrate, char *hashrate5m, char *hashrate1hr, char *hashrate24hr, bool idle, bool eos, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root); -extern bool workerstats_add(char *poolinstance, char *elapsed, char *username, +extern bool workerstats_add(INTRANSIENT *in_poolinstance, char *elapsed, char *username, INTRANSIENT *in_workername, char *hashrate, char *hashrate5m, char *hashrate1hr, char *hashrate24hr, bool idle, char *instances, diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 05b54397..8754dddf 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -992,20 +992,21 @@ static char *cmd_poolstats_do(PGconn *conn, char *cmd, char *id, char *by, // log to logfile - K_ITEM *i_poolinstance, *i_elapsed, *i_users, *i_workers; + K_ITEM *i_elapsed, *i_users, *i_workers; K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr; + INTRANSIENT *in_poolinstance; K_ITEM look, *ps; POOLSTATS row, *poolstats; bool ok = false; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz); - if (!i_poolinstance) + in_poolinstance = require_in(trf_root, "poolinstance", 1, NULL, reply, siz); + if (!in_poolinstance) return strdup(reply); - if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { - POOLINSTANCE_DATA_SET(poolstats, transfer_data(i_poolinstance)); + if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) { + POOLINSTANCE_DATA_SET(poolstats, in_poolinstance->str); return strdup(FAILED_PI); } @@ -1037,7 +1038,7 @@ static char *cmd_poolstats_do(PGconn *conn, char *cmd, char *id, char *by, if (!i_hashrate24hr) return strdup(reply); - STRNCPY(row.poolinstance, transfer_data(i_poolinstance)); + row.in_poolinstance = in_poolinstance->str; row.createdate.tv_sec = date_eot.tv_sec; row.createdate.tv_usec = date_eot.tv_usec; INIT_POOLSTATS(&look); @@ -1051,21 +1052,21 @@ static char *cmd_poolstats_do(PGconn *conn, char *cmd, char *id, char *by, DATA_POOLSTATS(poolstats, ps); // Find last stored matching the poolinstance and less than STATS_PER old while (ps && !poolstats->stored && - strcmp(row.poolinstance, poolstats->poolinstance) == 0 && + INTREQ(row.in_poolinstance, poolstats->in_poolinstance) && tvdiff(cd, &(poolstats->createdate)) < STATS_PER) { ps = prev_in_ktree(ctx); DATA_POOLSTATS_NULL(poolstats, ps); } if (!ps || !poolstats->stored || - strcmp(row.poolinstance, poolstats->poolinstance) != 0 || + !INTREQ(row.in_poolinstance, poolstats->in_poolinstance) || tvdiff(cd, &(poolstats->createdate)) >= STATS_PER) store = true; else store = false; } - ok = poolstats_add(conn, store, transfer_data(i_poolinstance), + ok = poolstats_add(conn, store, in_poolinstance, transfer_data(i_elapsed), transfer_data(i_users), transfer_data(i_workers), @@ -1111,20 +1112,21 @@ static char *cmd_userstats(__maybe_unused PGconn *conn, char *cmd, char *id, // log to logfile - K_ITEM *i_poolinstance, *i_elapsed, *i_username; + K_ITEM *i_elapsed, *i_username; K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr; + INTRANSIENT *in_poolinstance; K_ITEM *i_eos, *i_idle; INTRANSIENT *in_workername; bool ok = false, idle, eos; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz); - if (!i_poolinstance) + in_poolinstance = require_in(trf_root, "poolinstance", 1, NULL, reply, siz); + if (!in_poolinstance) return strdup(reply); - if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { - POOLINSTANCE_DATA_SET(userstats, transfer_data(i_poolinstance)); + if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) { + POOLINSTANCE_DATA_SET(userstats, in_poolinstance->str); return strdup(FAILED_PI); } @@ -1168,7 +1170,7 @@ static char *cmd_userstats(__maybe_unused PGconn *conn, char *cmd, char *id, eos = (strcasecmp(transfer_data(i_eos), TRUE_STR) == 0); - ok = userstats_add(transfer_data(i_poolinstance), + ok = userstats_add(in_poolinstance, transfer_data(i_elapsed), transfer_data(i_username), in_workername, @@ -1197,20 +1199,21 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id, // log to logfile - K_ITEM *i_poolinstance, *i_elapsed, *i_username; + K_ITEM *i_elapsed, *i_username; K_ITEM *i_hashrate, *i_hashrate5m, *i_hashrate1hr, *i_hashrate24hr; + INTRANSIENT *in_poolinstance; K_ITEM *i_idle, *i_instances; INTRANSIENT *in_workername; bool ok = false, idle; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz); - if (!i_poolinstance) + in_poolinstance = require_in(trf_root, "poolinstance", 1, NULL, reply, siz); + if (!in_poolinstance) return strdup(reply); - if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { - POOLINSTANCE_DATA_SET(workerstats, transfer_data(i_poolinstance)); + if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) { + POOLINSTANCE_DATA_SET(workerstats, in_poolinstance->str); return strdup(FAILED_PI); } @@ -1250,7 +1253,7 @@ static char *cmd_workerstats(__maybe_unused PGconn *conn, char *cmd, char *id, i_instances = optional_name(trf_root, "instances", 1, NULL, reply, siz); - ok = workerstats_add(transfer_data(i_poolinstance), + ok = workerstats_add(in_poolinstance, transfer_data(i_elapsed), transfer_data(i_username), in_workername, @@ -2550,7 +2553,7 @@ static char *cmd_sharelog(PGconn *conn, char *cmd, char *id, if (!in_poolinstance) return strdup(reply); - if (poolinstance && strcmp(poolinstance, in_poolinstance->str)){ + if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)){ POOLINSTANCE_DATA_SET(workinfo, in_poolinstance->str); return strdup(FAILED_PI); } @@ -2843,17 +2846,18 @@ seconf: snprintf(reply, siz, "ok.added %s", transfer_data(i_username)); return strdup(reply); } else if (strcasecmp(cmd, STR_AGEWORKINFO) == 0) { - K_ITEM *i_workinfoid, *i_poolinstance; + K_ITEM *i_workinfoid; + INTRANSIENT *in_poolinstance; int64_t ss_count, s_count, s_diff; tv_t ss_first, ss_last; bool ok; - i_poolinstance = require_name(trf_root, "poolinstance", 1, NULL, reply, siz); - if (!i_poolinstance) + in_poolinstance = require_in(trf_root, "poolinstance", 1, NULL, reply, siz); + if (!in_poolinstance) return strdup(reply); - if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { - POOLINSTANCE_DATA_SET(ageworkinfo, transfer_data(i_poolinstance)); + if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) { + POOLINSTANCE_DATA_SET(ageworkinfo, in_poolinstance->str); return strdup(FAILED_PI); } @@ -2880,9 +2884,8 @@ seconf: goto awconf; } - ok = workinfo_age(workinfoid, transfer_data(i_poolinstance), - cd, &ss_first, &ss_last, &ss_count, &s_count, - &s_diff); + ok = workinfo_age(workinfoid, in_poolinstance, cd, &ss_first, + &ss_last, &ss_count, &s_count, &s_diff); if (!ok) { LOGERR("%s(%s) %s.failed.DATA", __func__, cmd, id); return strdup("failed.DATA"); @@ -2893,8 +2896,7 @@ seconf: * unaged workinfos and thus would stop marker() */ if (!reloading || key_update || reloaded_N_files) { // Aging is a queued item thus the reply is ignored - auto_age_older(workinfoid, - transfer_data(i_poolinstance), cd); + auto_age_older(workinfoid, in_poolinstance, cd); } } LOGDEBUG("%s.ok.aged %"PRId64, id, workinfoid); @@ -3047,15 +3049,13 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root, bool reload_data) { - K_ITEM tmp_poolinstance_item; - TRANSFER tmp_poolinstance; K_TREE_CTX ctx[1]; char reply[1024] = ""; size_t siz = sizeof(reply); int event = EVENT_OK; - K_ITEM *i_poolinstance, *i_clientid; + K_ITEM *i_clientid; K_ITEM *i_enonce1, *i_useragent, *i_preauth, *u_item, *oc_item, *w_item; - INTRANSIENT *in_username, *in_workername; + INTRANSIENT *in_poolinstance, *in_username, *in_workername; USERS *users = NULL; WORKERS *workers = NULL; OPTIONCONTROL *optioncontrol; @@ -3065,23 +3065,17 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_poolinstance = optional_name(trf_root, "poolinstance", 1, NULL, + in_poolinstance = optional_in(trf_root, "poolinstance", 1, NULL, reply, siz); - 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; + if (!in_poolinstance) { + if (sys_poolinstance) { + in_poolinstance = get_intransient("poolinstance", + (char *)sys_poolinstance); } else - i_poolinstance = &auth_poolinstance; + in_poolinstance = in_empty; } else { - if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { - POOLINSTANCE_DATA_SET(auth, transfer_data(i_poolinstance)); + if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) { + POOLINSTANCE_DATA_SET(auth, in_poolinstance->str); return strdup(FAILED_PI); } } @@ -3130,7 +3124,7 @@ static char *cmd_auth_do(PGconn *conn, char *cmd, char *id, char *by, } if (ok) { - ok = auths_add(conn, transfer_data(i_poolinstance), + ok = auths_add(conn, in_poolinstance, in_username, in_workername, transfer_data(i_clientid), transfer_data(i_enonce1), @@ -3203,15 +3197,13 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root, bool reload_data) { - K_ITEM tmp_poolinstance_item; - TRANSFER tmp_poolinstance; K_TREE_CTX ctx[1]; char reply[1024] = ""; size_t siz = sizeof(reply); int event = EVENT_OK; - K_ITEM *i_poolinstance, *i_clientid; + K_ITEM *i_clientid; K_ITEM *i_enonce1, *i_useragent, *i_preauth, *w_item; - INTRANSIENT *in_username, *in_workername; + INTRANSIENT *in_poolinstance, *in_username, *in_workername; USERS *users = NULL; WORKERS *workers = NULL; size_t len, off; @@ -3220,23 +3212,17 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, LOGDEBUG("%s(): cmd '%s'", __func__, cmd); - i_poolinstance = optional_name(trf_root, "poolinstance", 1, NULL, + in_poolinstance = optional_in(trf_root, "poolinstance", 1, NULL, reply, siz); - 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; + if (!in_poolinstance) { + if (sys_poolinstance) { + in_poolinstance = get_intransient("poolinstance", + (char *)sys_poolinstance); } else - i_poolinstance = &auth_poolinstance; + in_poolinstance = in_empty; } else { - if (poolinstance && strcmp(poolinstance, transfer_data(i_poolinstance))) { - POOLINSTANCE_DATA_SET(addrauth, transfer_data(i_poolinstance)); + if (sys_poolinstance && strcmp(sys_poolinstance, in_poolinstance->str)) { + POOLINSTANCE_DATA_SET(addrauth, in_poolinstance->str); return strdup(FAILED_PI); } } @@ -3265,8 +3251,7 @@ static char *cmd_addrauth_do(PGconn *conn, char *cmd, char *id, char *by, if (!i_preauth) return strdup(reply); - ok = auths_add(conn, transfer_data(i_poolinstance), - in_username, in_workername, + ok = auths_add(conn, in_poolinstance, in_username, in_workername, transfer_data(i_clientid), transfer_data(i_enonce1), transfer_data(i_useragent), @@ -6311,7 +6296,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id, action = "status-unchanged"; ok = true; } else { - ok = marks_process(conn, true, marks->poolinstance, + ok = marks_process(conn, true, marks->in_poolinstance, workinfoid, marks->description, marks->extra, marks->marktype, status, by, code, inet, cd, @@ -6350,7 +6335,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id, action = "extra-unchanged"; ok = true; } else { - ok = marks_process(conn, true, marks->poolinstance, + ok = marks_process(conn, true, marks->in_poolinstance, workinfoid, marks->description, extra, marks->marktype, status, by, code, inet, cd, @@ -6449,7 +6434,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id, return strdup(reply); } ok = workmarkers_process(NULL, false, true, markerid, - workmarkers->poolinstance, + workmarkers->in_poolinstance, workmarkers->workinfoidend, workmarkers->workinfoidstart, workmarkers->description, @@ -6482,7 +6467,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id, return strdup(reply); } ok = workmarkers_process(NULL, false, true, markerid, - workmarkers->poolinstance, + workmarkers->in_poolinstance, workmarkers->workinfoidend, workmarkers->workinfoidstart, workmarkers->description, diff --git a/src/ckdb_data.c b/src/ckdb_data.c index bc4c1549..aaded271 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -123,8 +123,6 @@ void free_workmarkers_data(K_ITEM *item) WORKMARKERS *workmarkers; DATA_WORKMARKERS(workmarkers, item); - LIST_MEM_SUB(workmarkers_free, workmarkers->poolinstance); - FREENULL(workmarkers->poolinstance); LIST_MEM_SUB(workmarkers_free, workmarkers->description); FREENULL(workmarkers->description); } @@ -134,8 +132,6 @@ void free_marks_data(K_ITEM *item) MARKS *marks; DATA_MARKS(marks, item); - LIST_MEM_SUB(marks_free, marks->poolinstance); - FREENULL(marks->poolinstance); LIST_MEM_SUB(marks_free, marks->description); FREENULL(marks->description); LIST_MEM_SUB(marks_free, marks->extra); @@ -731,7 +727,8 @@ cmp_t cmp_intransient(K_ITEM *a, K_ITEM *b) return CMP_STR(ia->str, ib->str); } -INTRANSIENT *_get_intransient(char *fldnam, char *value, size_t siz, WHERE_FFL_ARGS) +INTRANSIENT *_get_intransient(const char *fldnam, char *value, size_t siz, + WHERE_FFL_ARGS) { INTRANSIENT intransient, *in = NULL; K_ITEM look, *i_item, *n_item; @@ -2663,7 +2660,7 @@ static void discard_shares(int64_t *shares_tot, int64_t *shares_dumped, #endif // Duplicates during a reload are set to not show messages -bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, +bool workinfo_age(int64_t workinfoid, INTRANSIENT *in_poolinstance, tv_t *cd, tv_t *ss_first, tv_t *ss_last, int64_t *ss_count, int64_t *s_count, int64_t *s_diff) { @@ -2690,18 +2687,18 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, if (!wi_item) { tv_to_buf(cd, cd_buf, sizeof(cd_buf)); LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s no workinfo! Age discarded!", - __func__, workinfoid, poolinstance, + __func__, workinfoid, in_poolinstance->str, cd->tv_sec, cd->tv_usec, cd_buf); goto bye; } DATA_WORKINFO(workinfo, wi_item); - if (strcmp(poolinstance, workinfo->in_poolinstance) != 0) { + if (!INTREQ(in_poolinstance->str, workinfo->in_poolinstance)) { tv_to_buf(cd, cd_buf, sizeof(cd_buf)); LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s Poolinstance changed " // "(from %s)! Age discarded!", "(from %s)! Age not discarded", - __func__, workinfoid, poolinstance, + __func__, workinfoid, in_poolinstance->str, cd->tv_sec, cd->tv_usec, cd_buf, workinfo->in_poolinstance); // TODO: ckdb only supports one, so until multiple support is written: @@ -2716,7 +2713,7 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, tv_to_buf(cd, cd_buf, sizeof(cd_buf)); LOGERR("%s() %"PRId64"/%s/%ld,%ld %.19s attempt to age a " "workmarker! Age ignored!", - __func__, workinfoid, poolinstance, + __func__, workinfoid, in_poolinstance->str, cd->tv_sec, cd->tv_usec, cd_buf); goto bye; } @@ -2809,8 +2806,8 @@ bool workinfo_age(int64_t workinfoid, char *poolinstance, tv_t *cd, "/%s sstotal=%"PRId64" already=%"PRId64 " failed=%"PRId64", sharestotal=%"PRId64 " dumped=%"PRId64", diff=%"PRId64, - __func__, workinfoid, poolinstance, ss_tot, - ss_already, ss_failed, shares_tot, + __func__, workinfoid, in_poolinstance->str, + ss_tot, ss_already, ss_failed, shares_tot, shares_dumped, diff_tot); } } @@ -2889,7 +2886,7 @@ skip_ss: if (ks_already) { LOGNOTICE("%s(): Keysummary aging of %"PRId64"/%s " "kstotal=%"PRId64" already=%"PRId64" failed=%"PRId64, - __func__, workinfoid, poolinstance, + __func__, workinfoid, in_poolinstance->str, ks_tot, ks_already, ks_failed); } @@ -3120,7 +3117,8 @@ K_ITEM *find_last_sharesummary(int64_t userid, char *workername) } // key_update must age keysharesummary directly -static void key_auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd) +static void key_auto_age_older(int64_t workinfoid, INTRANSIENT *in_poolinstance, + tv_t *cd) { static int64_t last_attempted_id = -1; static int64_t prev_found = 0; @@ -3195,7 +3193,7 @@ static void key_auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd) do_id = age_id; to_id = 0; do { - ok = workinfo_age(do_id, poolinstance, cd, &kss_first, + ok = workinfo_age(do_id, in_poolinstance, cd, &kss_first, &kss_last, &kss_count, &s_count, &s_diff); @@ -3276,7 +3274,7 @@ static void key_auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd) /* TODO: markersummary checking? * However, there should be no issues since the sharesummaries are removed */ -void auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd) +void auto_age_older(int64_t workinfoid, INTRANSIENT *in_poolinstance, tv_t *cd) { static int64_t last_attempted_id = -1; static int64_t prev_found = 0; @@ -3295,7 +3293,7 @@ void auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd) bool ok, found; if (key_update) { - key_auto_age_older(workinfoid, poolinstance, cd); + key_auto_age_older(workinfoid, in_poolinstance, cd); return; } @@ -3360,7 +3358,7 @@ void auto_age_older(int64_t workinfoid, char *poolinstance, tv_t *cd) do_id = age_id; to_id = 0; do { - ok = workinfo_age(do_id, poolinstance, cd, &ss_first, + ok = workinfo_age(do_id, in_poolinstance, cd, &ss_first, &ss_last, &ss_count, &s_count, &s_diff); @@ -6176,7 +6174,7 @@ cmp_t cmp_poolstats(K_ITEM *a, K_ITEM *b) POOLSTATS *pa, *pb; DATA_POOLSTATS(pa, a); DATA_POOLSTATS(pb, b); - cmp_t c = CMP_STR(pa->poolinstance, pb->poolinstance); + cmp_t c = CMP_STR(pa->in_poolinstance, pb->in_poolinstance); if (c == 0) c = CMP_TV(pa->createdate, pb->createdate); return c; @@ -6195,7 +6193,7 @@ void dsp_userstats(K_ITEM *item, FILE *stream) tv_to_buf(&(u->createdate), createdate_buf, sizeof(createdate_buf)); fprintf(stream, " pi='%s' uid=%"PRId64" w='%s' e=%"PRId64" Hs=%f " "Hs5m=%f Hs1hr=%f Hs24hr=%f sl=%s sc=%d sd=%s cd=%s\n", - u->poolinstance, u->userid, u->in_workername, + u->in_poolinstance, u->userid, u->in_workername, u->elapsed, u->hashrate, u->hashrate5m, u->hashrate1hr, u->hashrate24hr, u->summarylevel, u->summarycount, statsdate_buf, createdate_buf); @@ -6404,7 +6402,7 @@ bool make_markersummaries(bool msg, char *by, char *code, char *inet, LOGDEBUG("%s() processing workmarkers %"PRId64"/%s/End %"PRId64"/" "Stt %"PRId64"/%s/%s", - __func__, workmarkers->markerid, workmarkers->poolinstance, + __func__, workmarkers->markerid, workmarkers->in_poolinstance, workmarkers->workinfoidend, workmarkers->workinfoidstart, workmarkers->description, workmarkers->status); @@ -6517,7 +6515,7 @@ void dsp_workmarkers(K_ITEM *item, FILE *stream) DATA_WORKMARKERS(wm, item); fprintf(stream, " id=%"PRId64" pi='%s' end=%"PRId64" stt=%" PRId64" sta='%s' des='%s'\n", - wm->markerid, wm->poolinstance, + wm->markerid, wm->in_poolinstance, wm->workinfoidend, wm->workinfoidstart, wm->status, wm->description); } diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index 8dc28bf7..e422f628 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -3274,7 +3274,8 @@ int64_t workinfo_add(PGconn *conn, char *workinfoidstr, if (!igndup) { tv_to_buf(cd, cd_buf, sizeof(cd_buf)); LOGERR("%s(): Duplicate workinfo ignored %s/%s/%s", - __func__, workinfoidstr, poolinstance, cd_buf); + __func__, workinfoidstr, in_poolinstance->str, + cd_buf); } return workinfoid; @@ -3479,7 +3480,7 @@ bool workinfo_fill(PGconn *conn) PQ_GET_FLD(res, i, "poolinstance", field, ok); if (!ok) break; - if (poolinstance && strcmp(field, poolinstance)) { + if (sys_poolinstance && strcmp(field, sys_poolinstance)) { k_add_head(workinfo_free, item); POOLINSTANCE_DBLOAD_SET(workinfo, field); continue; @@ -4744,7 +4745,7 @@ bool sharesummaries_to_markersummaries(PGconn *conn, WORKMARKERS *workmarkers, LOGWARNING("%s() Processing: workmarkers %"PRId64"/%s/" "End %"PRId64"/Stt %"PRId64"/%s/%s", - shortname, workmarkers->markerid, workmarkers->poolinstance, + shortname, workmarkers->markerid, workmarkers->in_poolinstance, workmarkers->workinfoidend, workmarkers->workinfoidstart, workmarkers->description, workmarkers->status); @@ -5076,7 +5077,7 @@ dokey: if (!key_update) { ok = workmarkers_process(conn, true, true, workmarkers->markerid, - workmarkers->poolinstance, + workmarkers->in_poolinstance, workmarkers->workinfoidend, workmarkers->workinfoidstart, workmarkers->description, @@ -5255,7 +5256,7 @@ flail: shareacc, diffacc, kshareacc >> 1, (kshareacc & 1) ? ".5" : "", kdiffacc >> 1, (kdiffacc & 1) ? ".5" : "", - workmarkers->markerid, workmarkers->poolinstance, + workmarkers->markerid, workmarkers->in_poolinstance, workmarkers->workinfoidend, workmarkers->workinfoidstart, workmarkers->description, @@ -5310,7 +5311,7 @@ bool delete_markersummaries(PGconn *conn, WORKMARKERS *wm) LOGWARNING("%s() Deleting: markersummaries for workmarkers " "%"PRId64"/%s/End %"PRId64"/Stt %"PRId64"/%s/%s", - shortname, wm->markerid, wm->poolinstance, + shortname, wm->markerid, wm->in_poolinstance, wm->workinfoidend, wm->workinfoidstart, wm->description, wm->status); @@ -5431,7 +5432,7 @@ flail: "%"PRId64" diff for workmarkers %"PRId64"/%s/" "End %"PRId64"/Stt %"PRId64"/%s/%s", shortname, ms_count, shareacc, diffacc, - wm->markerid, wm->poolinstance, wm->workinfoidend, + wm->markerid, wm->in_poolinstance, wm->workinfoidend, wm->workinfoidstart, wm->description, wm->status); } @@ -7784,10 +7785,10 @@ void ips_add(char *group, char *ip, char *eventname, bool is_event, char *des, } // TODO: discard them from RAM -bool auths_add(PGconn *conn, char *poolinstance, INTRANSIENT *in_username, - INTRANSIENT *in_workername, char *clientid, char *enonce1, - char *useragent, char *preauth, char *by, char *code, - char *inet, tv_t *cd, K_TREE *trf_root, +bool auths_add(PGconn *conn, INTRANSIENT *in_poolinstance, + INTRANSIENT *in_username, INTRANSIENT *in_workername, + char *clientid, char *enonce1, char *useragent, char *preauth, + char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root, bool addressuser, USERS **users, WORKERS **workers, int *event, bool reload_data) { @@ -7832,7 +7833,7 @@ bool auths_add(PGconn *conn, char *poolinstance, INTRANSIENT *in_username, if ((*users)->status[0]) goto unitem; - STRNCPY(row->poolinstance, poolinstance); + row->in_poolinstance = in_poolinstance->str; row->userid = (*users)->userid; // since update=false, a dup will be ok and do nothing when igndup=true w_item = new_worker(conn, false, row->userid, in_workername->str, @@ -7861,7 +7862,7 @@ bool auths_add(PGconn *conn, char *poolinstance, INTRANSIENT *in_username, // Shouldn't actually be possible unless twice in the logs tv_to_buf(cd, cd_buf, sizeof(cd_buf)); LOGERR("%s(): Duplicate auths ignored %s/%s/%s", - __func__, poolinstance, + __func__, in_poolinstance->str, st = safe_text_nonull(in_workername->str), cd_buf); FREENULL(st); @@ -7896,7 +7897,7 @@ unitem: return ok; } -bool poolstats_add(PGconn *conn, bool store, char *poolinstance, +bool poolstats_add(PGconn *conn, bool store, INTRANSIENT *in_poolinstance, char *elapsed, char *users, char *workers, char *hashrate, char *hashrate5m, char *hashrate1hr, char *hashrate24hr, @@ -7925,7 +7926,7 @@ bool poolstats_add(PGconn *conn, bool store, char *poolinstance, row->stored = false; - STRNCPY(row->poolinstance, poolinstance); + row->in_poolinstance = in_poolinstance->str; TXT_TO_BIGINT("elapsed", elapsed, row->elapsed); TXT_TO_INT("users", users, row->users); TXT_TO_INT("workers", workers, row->workers); @@ -7947,7 +7948,7 @@ bool poolstats_add(PGconn *conn, bool store, char *poolinstance, if (store) { par = 0; - params[par++] = str_to_buf(row->poolinstance, NULL, 0); + params[par++] = str_to_buf(row->in_poolinstance, NULL, 0); params[par++] = bigint_to_buf(row->elapsed, NULL, 0); params[par++] = int_to_buf(row->users, NULL, 0); params[par++] = int_to_buf(row->workers, NULL, 0); @@ -8105,12 +8106,12 @@ bool poolstats_fill(PGconn *conn) PQ_GET_FLD(res, i, "poolinstance", field, ok); if (!ok) break; - if (poolinstance && strcmp(field, poolinstance)) { + if (sys_poolinstance && strcmp(field, sys_poolinstance)) { k_add_head(poolstats_free, item); POOLINSTANCE_DBLOAD_SET(poolstats, field); continue; } - TXT_TO_STR("poolinstance", field, row->poolinstance); + row->in_poolinstance = intransient_str("poolinstance", field); PQ_GET_FLD(res, i, "elapsed", field, ok); if (!ok) @@ -8176,7 +8177,7 @@ clean: } // To RAM -bool userstats_add(char *poolinstance, char *elapsed, char *username, +bool userstats_add(INTRANSIENT *in_poolinstance, char *elapsed, char *username, INTRANSIENT *in_workername, char *hashrate, char *hashrate5m, char *hashrate1hr, char *hashrate24hr, bool idle, bool eos, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root) @@ -8196,7 +8197,7 @@ bool userstats_add(char *poolinstance, char *elapsed, char *username, DATA_USERSTATS(row, us_item); bzero(row, sizeof(*row)); - STRNCPY(row->poolinstance, poolinstance); + row->in_poolinstance = in_poolinstance->str; TXT_TO_BIGINT("elapsed", elapsed, row->elapsed); K_RLOCK(users_free); u_item = find_users(username); @@ -8282,7 +8283,7 @@ bool userstats_add(char *poolinstance, char *elapsed, char *username, } // To RAM -bool workerstats_add(char *poolinstance, char *elapsed, char *username, +bool workerstats_add(INTRANSIENT *in_poolinstance, char *elapsed, char *username, INTRANSIENT *in_workername, char *hashrate, char *hashrate5m, char *hashrate1hr, char *hashrate24hr, bool idle, char *instances, char *by, char *code, @@ -8302,7 +8303,7 @@ bool workerstats_add(char *poolinstance, char *elapsed, char *username, DATA_USERSTATS(row, us_item); bzero(row, sizeof(*row)); - STRNCPY(row->poolinstance, poolinstance); + row->in_poolinstance = in_poolinstance->str; TXT_TO_BIGINT("elapsed", elapsed, row->elapsed); K_RLOCK(users_free); u_item = find_users(username); @@ -9016,7 +9017,7 @@ bool _workmarkers_process(PGconn *conn, bool already, bool add, } } - DUP_POINTER(workmarkers_free, row->poolinstance, poolinstance); + row->in_poolinstance = intransient_str("poolinstance", poolinstance); row->workinfoidend = workinfoidend; row->workinfoidstart = workinfoidstart; DUP_POINTER(workmarkers_free, row->description, description); @@ -9030,7 +9031,7 @@ bool _workmarkers_process(PGconn *conn, bool already, bool add, HISTORYDATECONTROL ") values (" PQPARAM11 ")"; par = 0; params[par++] = bigint_to_buf(row->markerid, NULL, 0); - params[par++] = str_to_buf(row->poolinstance, NULL, 0); + params[par++] = str_to_buf(row->in_poolinstance, NULL, 0); params[par++] = bigint_to_buf(row->workinfoidend, NULL, 0); params[par++] = bigint_to_buf(row->workinfoidstart, NULL, 0); params[par++] = str_to_buf(row->description, NULL, 0); @@ -9162,13 +9163,12 @@ bool workmarkers_fill(PGconn *conn) PQ_GET_FLD(res, i, "poolinstance", field, ok); if (!ok) break; - if (poolinstance && strcmp(field, poolinstance)) { + if (sys_poolinstance && strcmp(field, sys_poolinstance)) { k_add_head(workmarkers_free, item); POOLINSTANCE_DBLOAD_SET(workmarkers, field); continue; } - TXT_TO_PTR("poolinstance", field, row->poolinstance); - LIST_MEM_ADD(workmarkers_free, row->poolinstance); + row->in_poolinstance = intransient_str("poolinstance", field); PQ_GET_FLD(res, i, "markerid", field, ok); if (!ok) @@ -9356,7 +9356,7 @@ bool _marks_process(PGconn *conn, bool add, char *poolinstance, K_WUNLOCK(marks_free); DATA_MARKS(row, m_item); bzero(row, sizeof(*row)); - DUP_POINTER(marks_free, row->poolinstance, poolinstance); + row->in_poolinstance = intransient_str("poolinstance", poolinstance); row->workinfoid = workinfoid; DUP_POINTER(marks_free, row->description, description); DUP_POINTER(marks_free, row->extra, extra); @@ -9370,7 +9370,7 @@ bool _marks_process(PGconn *conn, bool add, char *poolinstance, "status" HISTORYDATECONTROL ") values (" PQPARAM11 ")"; par = 0; - params[par++] = str_to_buf(row->poolinstance, NULL, 0); + params[par++] = str_to_buf(row->in_poolinstance, NULL, 0); params[par++] = bigint_to_buf(workinfoid, NULL, 0); params[par++] = str_to_buf(row->description, NULL, 0); params[par++] = str_to_buf(row->extra, NULL, 0); @@ -9495,13 +9495,12 @@ bool marks_fill(PGconn *conn) PQ_GET_FLD(res, i, "poolinstance", field, ok); if (!ok) break; - if (poolinstance && strcmp(field, poolinstance)) { + if (sys_poolinstance && strcmp(field, sys_poolinstance)) { k_add_head(marks_free, item); POOLINSTANCE_DBLOAD_SET(marks, field); continue; } - TXT_TO_PTR("poolinstance", field, row->poolinstance); - LIST_MEM_ADD(marks_free, row->poolinstance); + row->in_poolinstance = intransient_str("poolinstance", field); PQ_GET_FLD(res, i, "workinfoid", field, ok); if (!ok)