Browse Source

ckdb - use io_msg for db *_fill counter messages

master
kanoi 8 years ago
parent
commit
48ee5c1e84
  1. 15
      src/ckdb.c
  2. 19
      src/ckdb.h
  3. 39
      src/ckdb_data.c
  4. 50
      src/ckdb_dbio.c

15
src/ckdb.c

@ -1055,19 +1055,8 @@ static void *iomsgs(void *consol)
return NULL;
}
#define io_msg(stamp, msg, errn, logfd, logerr) \
_io_msg(stamp, msg, false, errn, logfd, false, logerr, true, true, \
WHERE_FFL_HERE)
#define cr_msg(stamp, msg) \
_io_msg(stamp, msg, true, 0, false, true, false, false, true, WHERE_FFL_HERE)
#define lf_msg(stamp, msg) \
_io_msg(stamp, msg, true, 0, false, true, false, true, true, WHERE_FFL_HERE)
#define err_msg(stamp, msg, errn) \
_io_msg(stamp, msg, true, errn, false, false, true, true, true, WHERE_FFL_HERE)
static void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd,
bool logout, bool logerr, bool eol, bool flush,
WHERE_FFL_ARGS)
void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd,
bool logout, bool logerr, bool eol, bool flush, WHERE_FFL_ARGS)
{
K_ITEM *fio_item = NULL, *cio_item = NULL;
bool msgused = false;

19
src/ckdb.h

@ -58,7 +58,7 @@
#define DB_VLOCK "1"
#define DB_VERSION "1.0.7"
#define CKDB_VERSION DB_VERSION"-2.452"
#define CKDB_VERSION DB_VERSION"-2.453"
#define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@ -756,6 +756,20 @@ enum cmd_values {
// CCLs are every ...
#define ROLL_S 3600
#define io_msg(stamp, msg, errn, logfd, logerr) \
_io_msg(stamp, msg, false, errn, logfd, false, logerr, true, true, \
WHERE_FFL_HERE)
#define cr_msg(stamp, msg) \
_io_msg(stamp, msg, true, 0, false, true, false, false, true, WHERE_FFL_HERE)
#define lf_msg(stamp, msg) \
_io_msg(stamp, msg, true, 0, false, true, false, true, true, WHERE_FFL_HERE)
#define err_msg(stamp, msg, errn) \
_io_msg(stamp, msg, true, errn, false, false, true, true, true, WHERE_FFL_HERE)
extern void _io_msg(bool stamp, char *msg, bool alloc, int errn, bool logfd,
bool logout, bool logerr, bool eol, bool flush,
WHERE_FFL_ARGS);
#define LOGQUE(_msg, _db) log_queue_message(_msg, _db)
#define LOGFILE(_msg, _prefix) rotating_log_nolock(_msg, _prefix)
#define LOGDUP "dup."
@ -3066,6 +3080,9 @@ extern void free_marks_data(K_ITEM *item);
#define free_seqset_data(_item) _free_seqset_data(_item)
extern void _free_seqset_data(K_ITEM *item);
#define pcom(_n, _buf, _siz) _pcom(_n, _buf, _siz, WHERE_FFL_HERE);
extern void _pcom(int n, char *buf, size_t bufsiz, WHERE_FFL_ARGS);
// Data copy functions
#define COPY_DATA(_new, _old) memcpy(_new, _old, sizeof(*(_new)))

39
src/ckdb_data.c

@ -192,6 +192,45 @@ void _free_seqset_data(K_ITEM *item)
}
}
static void pcom2(int n, char **buf, size_t *siz)
{
size_t len;
if (*siz > 1) {
if (n < 1000) {
len = snprintf(*buf, *siz, "%d", n);
} else {
pcom2(n/1000, buf, siz);
len = snprintf(*buf, *siz, ",%03d", n % 1000);
}
if (len > 0) {
*siz -= len;
*buf += len;
}
}
}
void _pcom(int n, char *buf, size_t bufsiz, WHERE_FFL_ARGS)
{
size_t siz = bufsiz;
// a random limit that should never occur
if (siz < 4) {
quithere(1, "%s() bufsiz (%d) too small" WHERE_FFL,
__func__, (int)siz, WHERE_FFL_PASS);
}
if (n < 0) {
*(buf++) = '-';
siz--;
n = -n;
}
*buf = '\0';
pcom2(n, &buf, &siz);
}
/* Data copy functions (added here as needed)
All pointers need to be initialised since DUP_POINTER will free them */

50
src/ckdb_dbio.c

@ -9,17 +9,6 @@
#include "ckdb.h"
// Doesn't work with negative numbers ...
void pcom(int n)
{
if (n < 1000)
printf("%d", n);
else {
pcom(n/1000);
printf(",%03d", n % 1000);
}
}
char *pqerrmsg(PGconn *conn)
{
char *ptr, *buf = strdup(PQerrorMessage(conn));
@ -3275,6 +3264,7 @@ unparam:
bool workinfo_fill(PGconn *conn)
{
char tickbuf[256], pcombuf[64];
char ndiffbin[TXT_SML+1];
ExecStatusType rescode;
PGresult *res;
@ -3290,8 +3280,8 @@ bool workinfo_fill(PGconn *conn)
LOGDEBUG("%s(): select", __func__);
printf(TICK_PREFIX"wi 0\r");
fflush(stdout);
STRNCPY(tickbuf, TICK_PREFIX"wi 0");
cr_msg(false, tickbuf);
APPEND_REALLOC_INIT(sel, off, len);
APPEND_REALLOC(sel, off, len,
@ -3459,10 +3449,10 @@ bool workinfo_fill(PGconn *conn)
}
if (n == 0 || ((n+1) % 100000) == 0) {
printf(TICK_PREFIX"wi ");
pcom(n+1);
putchar('\r');
fflush(stdout);
pcom(n+1, pcombuf, sizeof(pcombuf));
snprintf(tickbuf, sizeof(tickbuf),
TICK_PREFIX"wi %s", pcombuf);
cr_msg(false, tickbuf);
}
tick();
n++;
@ -4007,6 +3997,7 @@ unparam:
bool shares_fill(PGconn *conn)
{
char tickbuf[256], pcombuf[64];
ExecStatusType rescode;
PGresult *res;
K_TREE_CTX ctx[1];
@ -4055,8 +4046,8 @@ bool shares_fill(PGconn *conn)
LOGWARNING("%s(): loading from workinfoid>=%"PRId64, __func__, workinfoid);
printf(TICK_PREFIX"sh 0\r");
fflush(stdout);
STRNCPY(tickbuf, TICK_PREFIX"sh 0");
cr_msg(false, tickbuf);
sel = "declare sh cursor for select "
"workinfoid,userid,workername,clientid,enonce1,nonce2,nonce,"
@ -4218,10 +4209,10 @@ bool shares_fill(PGconn *conn)
k_add_head(shares_hi_store, item);
if (n == 0 || ((n+1) % 100000) == 0) {
printf(TICK_PREFIX"sh ");
pcom(n+1);
putchar('\r');
fflush(stdout);
pcom(n+1, pcombuf, sizeof(pcombuf));
snprintf(tickbuf, sizeof(tickbuf),
TICK_PREFIX"sh %s", pcombuf);
cr_msg(false, tickbuf);
}
tick();
n++;
@ -8333,6 +8324,7 @@ unparam:
bool markersummary_fill(PGconn *conn)
{
char tickbuf[256], pcombuf[64];
ExecStatusType rescode;
PGresult *res;
K_ITEM *item = NULL, *p_item, *wm_item = NULL;
@ -8434,8 +8426,8 @@ bool markersummary_fill(PGconn *conn)
params[0], cd, amt, what);
}
printf(TICK_PREFIX"ms 0\r");
fflush(stdout);
STRNCPY(tickbuf, TICK_PREFIX"ms 0");
cr_msg(false, tickbuf);
res = PQexec(conn, "Begin", CKPQ_READ);
rescode = PQresultStatus(res);
@ -8637,10 +8629,10 @@ bool markersummary_fill(PGconn *conn)
userinfo_update(NULL, NULL, row, false);
if (n == 0 || ((n+1) % 100000) == 0) {
printf(TICK_PREFIX"ms ");
pcom(n+1);
putchar('\r');
fflush(stdout);
pcom(n+1, pcombuf, sizeof(pcombuf));
snprintf(tickbuf, sizeof(tickbuf),
TICK_PREFIX"ms %s", pcombuf);
cr_msg(false, tickbuf);
}
tick();
n++;

Loading…
Cancel
Save