diff --git a/src/ckdb.c b/src/ckdb.c index 0a63e2d9..8fa5580d 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2014 Andrew Smith + * Copyright 1995-2015 Andrew Smith * Copyright 2014 Con Kolivas * * This program is free software; you can redistribute it and/or modify it @@ -2073,8 +2073,7 @@ ASSERT4((sizeof(shift_words) == (sizeof(char *) * SHIFT_WORDS))); // Number of workinfoids per shift #define WID_PER_SHIFT 100 -#define LOGDEBU2 LOGWARNING -static void make_shift_marks() +static void make_a_shift_mark() { K_TREE_CTX ss_ctx[1], m_ctx[1], wi_ctx[1], b_ctx[1]; K_ITEM *ss_item = NULL, *m_item = NULL, *m_sh_item = NULL, *wi_item; @@ -2085,7 +2084,7 @@ static void make_shift_marks() BLOCKS *blocks; MARKS *marks, *sh_marks; int64_t ss_age_wid, last_marks_wid, marks_wid, prev_wid; - bool was_block = false; + bool was_block = false, ok; char cd_buf[DATE_BUFSIZ], cd_buf2[DATE_BUFSIZ]; int used_wid; @@ -2106,12 +2105,12 @@ static void make_shift_marks() if (ss_item) { tv_to_buf(&(sharesummary->lastshare), cd_buf, sizeof(cd_buf)); tv_to_buf(&(sharesummary->createdate), cd_buf2, sizeof(cd_buf2)); - LOGDEBU2("%s() last sharesummary %s/%s/%"PRId64"/%s/%s", + LOGDEBUG("%s() last sharesummary %s/%s/%"PRId64"/%s/%s", __func__, sharesummary->complete, sharesummary->workername, ss_age_wid, cd_buf, cd_buf2); } - LOGDEBU2("%s() age sharesummary limit wid %"PRId64, __func__, ss_age_wid); + LOGDEBUG("%s() age sharesummary limit wid %"PRId64, __func__, ss_age_wid); // Find the last CURRENT mark, the shift starts after this K_RLOCK(marks_free); @@ -2173,28 +2172,28 @@ static void make_shift_marks() if (m_item) { last_marks_wid = marks->workinfoid; - LOGDEBU2("%s() last mark %"PRId64"/%s/%s/%s/%s", + LOGDEBUG("%s() last mark %"PRId64"/%s/%s/%s/%s", __func__, marks->workinfoid, marks_marktype(marks->marktype), marks->status, marks->description, marks->extra); } else { last_marks_wid = 0; - LOGDEBU2("%s() no last mark", __func__); + LOGDEBUG("%s() no last mark", __func__); } if (m_sh_item) { if (m_sh_item == m_item) - LOGDEBU2("%s() last shift mark = last mark", __func__); + LOGDEBUG("%s() last shift mark = last mark", __func__); else { - LOGDEBU2("%s() last shift mark %"PRId64"/%s/%s/%s/%s", + LOGDEBUG("%s() last shift mark %"PRId64"/%s/%s/%s/%s", __func__, sh_marks->workinfoid, marks_marktype(sh_marks->marktype), sh_marks->status, sh_marks->description, sh_marks->extra); } } else - LOGDEBU2("%s() no last shift mark", __func__); + LOGDEBUG("%s() no last shift mark", __func__); if (m_item) { /* First block after the last mark @@ -2213,14 +2212,14 @@ static void make_shift_marks() if (b_item) { tv_to_buf(&(blocks->createdate), cd_buf, sizeof(cd_buf)); - LOGDEBU2("%s() block after last mark %"PRId32"/%"PRId64"/%s", + LOGDEBUG("%s() block after last mark %"PRId32"/%"PRId64"/%s", __func__, blocks->height, blocks->workinfoid, blocks_confirmed(blocks->confirmed)); } else { if (!m_item) - LOGDEBU2("%s() no last mark = no last block", __func__); + LOGDEBUG("%s() no last mark = no last block", __func__); else - LOGDEBU2("%s() no block since last mark", __func__); + LOGDEBUG("%s() no block since last mark", __func__); } INIT_WORKINFO(&wi_look); @@ -2244,7 +2243,7 @@ static void make_shift_marks() * for now limit it to BEFORE ss_age_wid * This will mean the shifts are created ~30s later */ if (workinfo->workinfoid >= ss_age_wid) { - LOGDEBU2("%s() not enough aged workinfos (%d)", + LOGDEBUG("%s() not enough aged workinfos (%d)", __func__, used_wid); return; } @@ -2254,7 +2253,7 @@ static void make_shift_marks() if (prev_wid > 0 && (workinfo->workinfoid - prev_wid) > 6) { marks_wid = prev_wid; - LOGDEBU2("%s() OK shift stops at pool restart" + LOGDEBUG("%s() OK shift stops at pool restart" " count %d(%d) workinfoid %"PRId64 " next wid %"PRId64, __func__, used_wid, WID_PER_SHIFT, @@ -2264,7 +2263,7 @@ static void make_shift_marks() prev_wid = workinfo->workinfoid; // Did we hit the next block? if (b_item && workinfo->workinfoid == blocks->workinfoid) { - LOGDEBU2("%s() OK shift stops at block limit", + LOGDEBUG("%s() OK shift stops at block limit", __func__); marks_wid = workinfo->workinfoid; was_block = true; @@ -2299,8 +2298,9 @@ static void make_shift_marks() } } if (++used_wid >= WID_PER_SHIFT) { + // We've got a full shift marks_wid = workinfo->workinfoid; - LOGDEBU2("%s() OK shift stops at count" + LOGDEBUG("%s() OK shift stops at count" " %d(%d) workinfoid %"PRId64, __func__, used_wid, WID_PER_SHIFT, marks_wid); @@ -2312,7 +2312,7 @@ static void make_shift_marks() K_RUNLOCK(workinfo_free); } - // Create the shift marker + // Create the shift mark if (marks_wid) { char shift[TXT_BIG+1] = { '\0' }; char des[TXT_BIG+1] = { '\0' }; @@ -2381,12 +2381,12 @@ static void make_shift_marks() shiftcode(&(workinfo->createdate)), shift_words[word]); - LOGDEBU2("%s() shift='%s'", __func__, shift); + LOGDEBUG("%s() shift='%s'", __func__, shift); if (!marks_description(des, sizeof(des), shifttype, 0, shift, NULL)) return; - LOGDEBU2("%s() des='%s'", __func__, des); + LOGDEBUG("%s() des='%s'", __func__, des); if (was_block) { // Put the block description in extra @@ -2394,16 +2394,36 @@ static void make_shift_marks() blocks->height, NULL, NULL)) return; - LOGDEBU2("%s() extra='%s'", __func__, extra); + LOGDEBUG("%s() extra='%s'", __func__, extra); } setnow(&now); - marks_process(NULL, true, EMPTY, marks_wid, des, extra, - shifttype, status, (char *)by_default, - (char *)__func__, (char *)inet_default, - &now, NULL); + ok = marks_process(NULL, true, EMPTY, marks_wid, des, extra, + shifttype, status, (char *)by_default, + (char *)__func__, (char *)inet_default, + &now, NULL); + + if (ok) { + LOGWARNING("%s() mark %"PRId64"/%s/%s/%s/%s/", + __func__, marks_wid, shifttype, status, + des, extra); + } } else - LOGDEBU2("%s() no marks wid", __func__); + LOGDEBUG("%s() no marks wid", __func__); +} + +static void make_a_workmarker() +{ + char msg[1024] = ""; + tv_t now; + bool ok; + + setnow(&now); + ok = workmarkers_generate(NULL, msg, sizeof(msg), + (char *)by_default, (char *)__func__, + (char *)inet_default, &now, NULL, false); + if (!ok) + LOGERR("%s() ERR %s", __func__, msg); } static void *marker(__maybe_unused void *arg) @@ -2443,9 +2463,8 @@ static void *marker(__maybe_unused void *arg) if (everyone_die) break; else - make_shift_marks(); + make_a_shift_mark(); -#if 0 for (i = 0; i < 4; i++) { if (!everyone_die) sleep(1); @@ -2455,6 +2474,7 @@ static void *marker(__maybe_unused void *arg) else make_a_workmarker(); +#if 0 for (i = 0; i < 4; i++) { if (!everyone_die) sleep(1); diff --git a/src/ckdb.h b/src/ckdb.h index 6d680eb3..6206887d 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -52,7 +52,7 @@ #define DB_VLOCK "1" #define DB_VERSION "0.9.6" -#define CKDB_VERSION DB_VERSION"-0.821" +#define CKDB_VERSION DB_VERSION"-0.822" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1640,7 +1640,7 @@ extern K_ITEM *find_workmarkers(int64_t workinfoid, bool anystatus, char status) extern K_ITEM *find_workmarkerid(int64_t markerid, bool anystatus, char status); extern bool workmarkers_generate(PGconn *conn, char *err, size_t siz, char *by, char *code, char *inet, tv_t *cd, - K_TREE *trf_root); + K_TREE *trf_root, bool none_error); extern cmp_t cmp_marks(K_ITEM *a, K_ITEM *b); extern K_ITEM *find_marks(int64_t workinfoid); extern const char *marks_marktype(char *marktype); diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 077d4050..2ec947a6 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2014 Andrew Smith + * Copyright 1995-2015 Andrew Smith * * 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 @@ -4337,7 +4337,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id, * No parameters */ tmp[0] = '\0'; ok = workmarkers_generate(conn, tmp, sizeof(tmp), - by, code, inet, cd, trf_root); + by, code, inet, cd, trf_root, true); if (!ok) { snprintf(reply, siz, "%s error: %s", action, tmp); LOGERR("%s.%s", id, reply); diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 85bb5c67..be92fbd0 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -2595,12 +2595,10 @@ static bool gen_workmarkers(PGconn *conn, MARKS *stt, bool after, MARKS *fin, * If a mark is found not READY it will stop at that one and * report success with a message regarding the not READY one * No checks are done for the validity of the mark status - * information, however, until the next step of generating - * the markersummaries is completely automated, rather than - * simply running the SQL script manually, the existence of - a workmarker wont actually do anything automatically */ + * information */ bool workmarkers_generate(PGconn *conn, char *err, size_t siz, char *by, - char *code, char *inet, tv_t *cd, K_TREE *trf_root) + char *code, char *inet, tv_t *cd, K_TREE *trf_root, + bool none_error) { K_ITEM *m_item, *m_next_item; MARKS *mused, *mnext; @@ -2728,8 +2726,10 @@ bool workmarkers_generate(PGconn *conn, char *err, size_t siz, char *by, m_item = m_next_item; } if (!any) { - snprintf(err, siz, "%s", "No ready marks found"); - return false; + if (none_error) { + snprintf(err, siz, "%s", "No ready marks found"); + return false; + } } return true; }