From b7944bd27a7c9e06fde447846a52fea099be3352 Mon Sep 17 00:00:00 2001 From: kanoi Date: Sat, 12 Dec 2015 22:17:35 +1100 Subject: [PATCH 1/2] ckdb - marks action=pps to recalc the ram pps values for a shift --- src/ckdb.h | 2 +- src/ckdb_cmd.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index 2e2f1601..f6b9396c 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -55,7 +55,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.4" -#define CKDB_VERSION DB_VERSION"-1.610" +#define CKDB_VERSION DB_VERSION"-1.611" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index bab3f32a..a23ad1d1 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -5796,7 +5796,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id, char description[TXT_BIG+1] = { '\0' }; char extra[TXT_BIG+1] = { '\0' }; char status[TXT_FLAG+1] = { MARK_READY, '\0' }; - bool ok; + bool ok = false, pps; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); @@ -6237,6 +6237,39 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id, old ? "On" : "Off", markersummary_auto ? "On" : "Off"); ok = true; + } else if (strcasecmp(action, "pps") == 0) { + /* Recalculate a shift's rewards/rewarded + * Require markerid */ + i_markerid = require_name(trf_root, "markerid", 1, + (char *)intpatt, reply, siz); + if (!i_markerid) + return strdup(reply); + TXT_TO_BIGINT("markerid", transfer_data(i_markerid), markerid); + + K_RLOCK(workmarkers_free); + wm_item = find_workmarkerid(markerid, false, MARKER_PROCESSED); + K_RUNLOCK(workmarkers_free); + if (!wm_item) { + snprintf(reply, siz, "no markerid %"PRId64, markerid); + return strdup(reply); + } + DATA_WORKMARKERS(workmarkers, wm_item); + pps = shift_rewards(wm_item); + if (pps) { + snprintf(msg, sizeof(msg), + "shift '%s' markerid %"PRId64" rewards %d " + "rewarded %.3e pps %.3e", + workmarkers->description, + workmarkers->markerid, workmarkers->rewards, + workmarkers->rewarded, workmarkers->pps_value); + } else { + snprintf(msg, sizeof(msg), + "shift '%s' markerid %"PRId64" no rewards yet" + " pps %.3e", + workmarkers->description, + workmarkers->markerid, workmarkers->pps_value); + } + ok = true; } else { snprintf(reply, siz, "unknown action '%s'", action); LOGERR("%s.%s", id, reply); From c7ae4765382e1b5df7a36765a7c2ef7f3ae7c85d Mon Sep 17 00:00:00 2001 From: kanoi Date: Sat, 12 Dec 2015 22:45:54 +1100 Subject: [PATCH 2/2] ckdb - fix some more locking anomalies --- src/ckdb.c | 11 +++++------ src/ckdb.h | 2 +- src/ckdb_cmd.c | 4 ++-- src/klist.h | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index 696c56f3..e0bfaa91 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -1746,7 +1746,7 @@ static void trans_process(SEQSET *seqset, tv_t *now, K_STORE *store) seqtrans->seq = seq; seqtrans->seqnum = u; memcpy(&(seqtrans->entry), seqentry, sizeof(SEQENTRY)); - k_add_head(store, st_item); + k_add_head_nolock(store, st_item); } u++; seqentry++; @@ -1772,7 +1772,7 @@ static void trans_process(SEQSET *seqset, tv_t *now, K_STORE *store) seqtrans->seq = seq; seqtrans->seqnum = u; memcpy(&(seqtrans->entry), seqentry, sizeof(SEQENTRY)); - k_add_head(store, st_item); + k_add_head_nolock(store, st_item); } u++; seqentry++; @@ -2143,7 +2143,7 @@ gotseqset: sizeof(SEQENTRY)); if (!lost) lost = k_new_store(seqtrans_free); - k_add_tail(lost, st_item); + k_add_tail_nolock(lost, st_item); seqdata->lost++; seqset->lost++; if (ENTRYISTRANS(u_entry)) { @@ -2173,7 +2173,7 @@ gotseqset: seqdata->reload_lost = k_new_store(seqtrans_free); seqdata_reload_lost = true; } - k_add_tail(seqdata->reload_lost, stl_item); + k_add_tail_nolock(seqdata->reload_lost, stl_item); } } else { // (u-size) wasn't missing @@ -2254,8 +2254,7 @@ gotseqset: } if (st_item) { // recovered a lost entry - k_unlink_item(seqtrans_free, st_item); - // N.B. lock inside lock + k_unlink_item_nolock(seqdata->reload_lost, st_item); K_WLOCK(seqtrans_free); k_add_head(seqtrans_free, st_item); K_WUNLOCK(seqtrans_free); diff --git a/src/ckdb.h b/src/ckdb.h index f6b9396c..b626e048 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -55,7 +55,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.4" -#define CKDB_VERSION DB_VERSION"-1.611" +#define CKDB_VERSION DB_VERSION"-1.612" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index a23ad1d1..c9d9f660 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -3636,9 +3636,9 @@ static char *cmd_setatts(PGconn *conn, char *cmd, char *id, } } if (!ua_item) { - K_RLOCK(useratts_free); + K_WLOCK(useratts_free); ua_item = k_unlink_head(useratts_free); - K_RUNLOCK(useratts_free); + K_WUNLOCK(useratts_free); DATA_USERATTS(useratts, ua_item); bzero(useratts, sizeof(*useratts)); useratts->userid = users->userid; diff --git a/src/klist.h b/src/klist.h index 9e5888a7..d872f034 100644 --- a/src/klist.h +++ b/src/klist.h @@ -586,7 +586,7 @@ extern void _k_insert_after(K_LIST *list, K_ITEM *item, K_ITEM *after, LOCK_MAYB //#define k_insert_after_nolock(_list, _item, _after) _k_insert_after(_list, _item, _after, false, KLIST_FFL_HERE) extern void _k_unlink_item(K_LIST *list, K_ITEM *item, LOCK_MAYBE bool chklock, KLIST_FFL_ARGS); #define k_unlink_item(_list, _item) _k_unlink_item(_list, _item, true, KLIST_FFL_HERE) -//#define k_unlink_item_nolock(_list, _item) _k_unlink_item(_list, _item, false, KLIST_FFL_HERE) +#define k_unlink_item_nolock(_list, _item) _k_unlink_item(_list, _item, false, KLIST_FFL_HERE) extern void _k_list_transfer_to_head(K_LIST *from, K_LIST *to, LOCK_MAYBE bool chklock, KLIST_FFL_ARGS); #define k_list_transfer_to_head(_from, _to) _k_list_transfer_to_head(_from, _to, true, KLIST_FFL_HERE) //#define k_list_transfer_to_head_nolock(_from, _to) _k_list_transfer_to_head(_from, _to, false, KLIST_FFL_HERE)