Browse Source

ckdb - auto create shift workmarkers

master
kanoi 10 years ago
parent
commit
9176bf81fd
  1. 72
      src/ckdb.c
  2. 4
      src/ckdb.h
  3. 4
      src/ckdb_cmd.c
  4. 10
      src/ckdb_data.c

72
src/ckdb.c

@ -1,5 +1,5 @@
/* /*
* Copyright 1995-2014 Andrew Smith * Copyright 1995-2015 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
@ -2073,8 +2073,7 @@ ASSERT4((sizeof(shift_words) == (sizeof(char *) * SHIFT_WORDS)));
// Number of workinfoids per shift // Number of workinfoids per shift
#define WID_PER_SHIFT 100 #define WID_PER_SHIFT 100
#define LOGDEBU2 LOGWARNING static void make_a_shift_mark()
static void make_shift_marks()
{ {
K_TREE_CTX ss_ctx[1], m_ctx[1], wi_ctx[1], b_ctx[1]; 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; 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; BLOCKS *blocks;
MARKS *marks, *sh_marks; MARKS *marks, *sh_marks;
int64_t ss_age_wid, last_marks_wid, marks_wid, prev_wid; 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]; char cd_buf[DATE_BUFSIZ], cd_buf2[DATE_BUFSIZ];
int used_wid; int used_wid;
@ -2106,12 +2105,12 @@ static void make_shift_marks()
if (ss_item) { if (ss_item) {
tv_to_buf(&(sharesummary->lastshare), cd_buf, sizeof(cd_buf)); tv_to_buf(&(sharesummary->lastshare), cd_buf, sizeof(cd_buf));
tv_to_buf(&(sharesummary->createdate), cd_buf2, sizeof(cd_buf2)); 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, __func__, sharesummary->complete,
sharesummary->workername, sharesummary->workername,
ss_age_wid, cd_buf, cd_buf2); 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 // Find the last CURRENT mark, the shift starts after this
K_RLOCK(marks_free); K_RLOCK(marks_free);
@ -2173,28 +2172,28 @@ static void make_shift_marks()
if (m_item) { if (m_item) {
last_marks_wid = marks->workinfoid; 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, __func__, marks->workinfoid,
marks_marktype(marks->marktype), marks_marktype(marks->marktype),
marks->status, marks->description, marks->status, marks->description,
marks->extra); marks->extra);
} else { } else {
last_marks_wid = 0; last_marks_wid = 0;
LOGDEBU2("%s() no last mark", __func__); LOGDEBUG("%s() no last mark", __func__);
} }
if (m_sh_item) { if (m_sh_item) {
if (m_sh_item == m_item) if (m_sh_item == m_item)
LOGDEBU2("%s() last shift mark = last mark", __func__); LOGDEBUG("%s() last shift mark = last mark", __func__);
else { 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, __func__, sh_marks->workinfoid,
marks_marktype(sh_marks->marktype), marks_marktype(sh_marks->marktype),
sh_marks->status, sh_marks->description, sh_marks->status, sh_marks->description,
sh_marks->extra); sh_marks->extra);
} }
} else } else
LOGDEBU2("%s() no last shift mark", __func__); LOGDEBUG("%s() no last shift mark", __func__);
if (m_item) { if (m_item) {
/* First block after the last mark /* First block after the last mark
@ -2213,14 +2212,14 @@ static void make_shift_marks()
if (b_item) { if (b_item) {
tv_to_buf(&(blocks->createdate), cd_buf, sizeof(cd_buf)); 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, __func__, blocks->height, blocks->workinfoid,
blocks_confirmed(blocks->confirmed)); blocks_confirmed(blocks->confirmed));
} else { } else {
if (!m_item) if (!m_item)
LOGDEBU2("%s() no last mark = no last block", __func__); LOGDEBUG("%s() no last mark = no last block", __func__);
else else
LOGDEBU2("%s() no block since last mark", __func__); LOGDEBUG("%s() no block since last mark", __func__);
} }
INIT_WORKINFO(&wi_look); INIT_WORKINFO(&wi_look);
@ -2244,7 +2243,7 @@ static void make_shift_marks()
* for now limit it to BEFORE ss_age_wid * for now limit it to BEFORE ss_age_wid
* This will mean the shifts are created ~30s later */ * This will mean the shifts are created ~30s later */
if (workinfo->workinfoid >= ss_age_wid) { if (workinfo->workinfoid >= ss_age_wid) {
LOGDEBU2("%s() not enough aged workinfos (%d)", LOGDEBUG("%s() not enough aged workinfos (%d)",
__func__, used_wid); __func__, used_wid);
return; return;
} }
@ -2254,7 +2253,7 @@ static void make_shift_marks()
if (prev_wid > 0 && if (prev_wid > 0 &&
(workinfo->workinfoid - prev_wid) > 6) { (workinfo->workinfoid - prev_wid) > 6) {
marks_wid = prev_wid; 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 " count %d(%d) workinfoid %"PRId64
" next wid %"PRId64, " next wid %"PRId64,
__func__, used_wid, WID_PER_SHIFT, __func__, used_wid, WID_PER_SHIFT,
@ -2264,7 +2263,7 @@ static void make_shift_marks()
prev_wid = workinfo->workinfoid; prev_wid = workinfo->workinfoid;
// Did we hit the next block? // Did we hit the next block?
if (b_item && workinfo->workinfoid == blocks->workinfoid) { if (b_item && workinfo->workinfoid == blocks->workinfoid) {
LOGDEBU2("%s() OK shift stops at block limit", LOGDEBUG("%s() OK shift stops at block limit",
__func__); __func__);
marks_wid = workinfo->workinfoid; marks_wid = workinfo->workinfoid;
was_block = true; was_block = true;
@ -2299,8 +2298,9 @@ static void make_shift_marks()
} }
} }
if (++used_wid >= WID_PER_SHIFT) { if (++used_wid >= WID_PER_SHIFT) {
// We've got a full shift
marks_wid = workinfo->workinfoid; marks_wid = workinfo->workinfoid;
LOGDEBU2("%s() OK shift stops at count" LOGDEBUG("%s() OK shift stops at count"
" %d(%d) workinfoid %"PRId64, " %d(%d) workinfoid %"PRId64,
__func__, used_wid, __func__, used_wid,
WID_PER_SHIFT, marks_wid); WID_PER_SHIFT, marks_wid);
@ -2312,7 +2312,7 @@ static void make_shift_marks()
K_RUNLOCK(workinfo_free); K_RUNLOCK(workinfo_free);
} }
// Create the shift marker // Create the shift mark
if (marks_wid) { if (marks_wid) {
char shift[TXT_BIG+1] = { '\0' }; char shift[TXT_BIG+1] = { '\0' };
char des[TXT_BIG+1] = { '\0' }; char des[TXT_BIG+1] = { '\0' };
@ -2381,12 +2381,12 @@ static void make_shift_marks()
shiftcode(&(workinfo->createdate)), shiftcode(&(workinfo->createdate)),
shift_words[word]); 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)) if (!marks_description(des, sizeof(des), shifttype, 0, shift, NULL))
return; return;
LOGDEBU2("%s() des='%s'", __func__, des); LOGDEBUG("%s() des='%s'", __func__, des);
if (was_block) { if (was_block) {
// Put the block description in extra // Put the block description in extra
@ -2394,16 +2394,36 @@ static void make_shift_marks()
blocks->height, NULL, NULL)) blocks->height, NULL, NULL))
return; return;
LOGDEBU2("%s() extra='%s'", __func__, extra); LOGDEBUG("%s() extra='%s'", __func__, extra);
} }
setnow(&now); setnow(&now);
marks_process(NULL, true, EMPTY, marks_wid, des, extra, ok = marks_process(NULL, true, EMPTY, marks_wid, des, extra,
shifttype, status, (char *)by_default, shifttype, status, (char *)by_default,
(char *)__func__, (char *)inet_default, (char *)__func__, (char *)inet_default,
&now, NULL); &now, NULL);
if (ok) {
LOGWARNING("%s() mark %"PRId64"/%s/%s/%s/%s/",
__func__, marks_wid, shifttype, status,
des, extra);
}
} else } 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) static void *marker(__maybe_unused void *arg)
@ -2443,9 +2463,8 @@ static void *marker(__maybe_unused void *arg)
if (everyone_die) if (everyone_die)
break; break;
else else
make_shift_marks(); make_a_shift_mark();
#if 0
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (!everyone_die) if (!everyone_die)
sleep(1); sleep(1);
@ -2455,6 +2474,7 @@ static void *marker(__maybe_unused void *arg)
else else
make_a_workmarker(); make_a_workmarker();
#if 0
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (!everyone_die) if (!everyone_die)
sleep(1); sleep(1);

4
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "0.9.6" #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 " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #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 K_ITEM *find_workmarkerid(int64_t markerid, bool anystatus, char status);
extern bool workmarkers_generate(PGconn *conn, char *err, size_t siz, extern bool workmarkers_generate(PGconn *conn, char *err, size_t siz,
char *by, char *code, char *inet, tv_t *cd, 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 cmp_t cmp_marks(K_ITEM *a, K_ITEM *b);
extern K_ITEM *find_marks(int64_t workinfoid); extern K_ITEM *find_marks(int64_t workinfoid);
extern const char *marks_marktype(char *marktype); extern const char *marks_marktype(char *marktype);

4
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 * 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
@ -4337,7 +4337,7 @@ static char *cmd_marks(PGconn *conn, char *cmd, char *id,
* No parameters */ * No parameters */
tmp[0] = '\0'; tmp[0] = '\0';
ok = workmarkers_generate(conn, tmp, sizeof(tmp), ok = workmarkers_generate(conn, tmp, sizeof(tmp),
by, code, inet, cd, trf_root); by, code, inet, cd, trf_root, true);
if (!ok) { if (!ok) {
snprintf(reply, siz, "%s error: %s", action, tmp); snprintf(reply, siz, "%s error: %s", action, tmp);
LOGERR("%s.%s", id, reply); LOGERR("%s.%s", id, reply);

10
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 * If a mark is found not READY it will stop at that one and
* report success with a message regarding the not READY one * report success with a message regarding the not READY one
* No checks are done for the validity of the mark status * No checks are done for the validity of the mark status
* information, however, until the next step of generating * information */
* the markersummaries is completely automated, rather than
* simply running the SQL script manually, the existence of
a workmarker wont actually do anything automatically */
bool workmarkers_generate(PGconn *conn, char *err, size_t siz, char *by, 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; K_ITEM *m_item, *m_next_item;
MARKS *mused, *mnext; MARKS *mused, *mnext;
@ -2728,9 +2726,11 @@ bool workmarkers_generate(PGconn *conn, char *err, size_t siz, char *by,
m_item = m_next_item; m_item = m_next_item;
} }
if (!any) { if (!any) {
if (none_error) {
snprintf(err, siz, "%s", "No ready marks found"); snprintf(err, siz, "%s", "No ready marks found");
return false; return false;
} }
}
return true; return true;
} }

Loading…
Cancel
Save