Browse Source

ckdb - cmd_high action=store to store all current shares_hi not yet in the db

master
kanoi 9 years ago
parent
commit
ed0bcee86b
  1. 7
      src/ckdb.c
  2. 3
      src/ckdb.h
  3. 67
      src/ckdb_cmd.c

7
src/ckdb.c

@ -10,11 +10,8 @@
#include "ckdb.h" #include "ckdb.h"
/* TODO: any tree/list accessed in new threads needs /* This code's lock implementation is equivalent to table level locking
* to ensure all code using those trees/lists use locks
* This code's lock implementation is equivalent to table level locking
* Consider adding row level locking (a per kitem usage count) if needed * Consider adding row level locking (a per kitem usage count) if needed
* TODO: verify all tables with multithread access are locked
*/ */
/* Startup /* Startup
@ -4449,6 +4446,7 @@ static void *socketer(__maybe_unused void *arg)
case CMD_USERINFO: case CMD_USERINFO:
case CMD_LOCKS: case CMD_LOCKS:
case CMD_EVENTS: case CMD_EVENTS:
case CMD_HIGH:
msgline->sockd = sockd; msgline->sockd = sockd;
sockd = -1; sockd = -1;
K_WLOCK(workqueue_free); K_WLOCK(workqueue_free);
@ -4709,6 +4707,7 @@ static void reload_line(PGconn *conn, char *filename, uint64_t count, char *buf)
case CMD_QUERY: case CMD_QUERY:
case CMD_LOCKS: case CMD_LOCKS:
case CMD_EVENTS: case CMD_EVENTS:
case CMD_HIGH:
LOGERR("%s() INVALID message line %"PRIu64 LOGERR("%s() INVALID message line %"PRIu64
" ignored '%.42s...", " ignored '%.42s...",
__func__, count, __func__, count,

3
src/ckdb.h

@ -51,7 +51,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.5" #define DB_VERSION "1.0.5"
#define CKDB_VERSION DB_VERSION"-1.981" #define CKDB_VERSION DB_VERSION"-1.982"
#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__
@ -687,6 +687,7 @@ enum cmd_values {
CMD_QUERY, CMD_QUERY,
CMD_LOCKS, CMD_LOCKS,
CMD_EVENTS, CMD_EVENTS,
CMD_HIGH,
CMD_END CMD_END
}; };

67
src/ckdb_cmd.c

@ -8039,6 +8039,72 @@ static char *cmd_events(__maybe_unused PGconn *conn, char *cmd, char *id,
return buf; return buf;
} }
// High Share actions
static char *cmd_high(PGconn *conn, char *cmd, char *id,
__maybe_unused tv_t *now, __maybe_unused char *by,
__maybe_unused char *code, __maybe_unused char *inet,
__maybe_unused tv_t *cd, K_TREE *trf_root)
{
bool conned = false;
K_TREE_CTX ctx[1];
K_ITEM *i_action, *s_item = NULL;
char *action;
char reply[1024] = "";
size_t siz = sizeof(reply);
char *buf = NULL;
int count = 0;
bool ok, did;
LOGDEBUG("%s(): cmd '%s'", __func__, cmd);
i_action = require_name(trf_root, "action", 1, NULL, reply, siz);
if (!i_action)
return strdup(reply);
action = transfer_data(i_action);
if (strcasecmp(action, "store") == 0) {
/* Store the shares_hi_root list in the db now,
* rather than wait for a shift process to do it */
if (!conn) {
conn = dbconnect();
conned = true;
}
count = 0;
do {
did = false;
K_WLOCK(shares_free);
s_item = first_in_ktree(shares_hi_root, ctx);
K_WUNLOCK(shares_free);
if (s_item) {
did = true;
ok = shares_db(conn, s_item);
if (!ok)
break;
count++;
}
} while (did);
if (conned)
PQfinish(conn);
if (count) {
LOGWARNING("%s() Stored: %d high shares",
__func__, count);
} else
LOGWARNING("%s() No high shares to store", __func__);
if (ok)
snprintf(reply, siz, "ok.stored %d", count);
else
snprintf(reply, siz, "DBERR.stored %d", count);
return strdup(reply);
} else {
snprintf(reply, siz, "unknown action '%s'", action);
LOGERR("%s() %s.%s", __func__, id, reply);
return strdup(reply);
}
return buf;
}
/* The socket command format is as follows: /* The socket command format is as follows:
* Basic structure: * Basic structure:
* cmd.ID.fld1=value1 FLDSEP fld2=value2 FLDSEP fld3=... * cmd.ID.fld1=value1 FLDSEP fld2=value2 FLDSEP fld3=...
@ -8150,5 +8216,6 @@ struct CMDS ckdb_cmds[] = {
{ CMD_QUERY, "query", false, false, cmd_query, SEQ_NONE, ACCESS_SYSTEM }, { CMD_QUERY, "query", false, false, cmd_query, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_LOCKS, "locks", false, false, cmd_locks, SEQ_NONE, ACCESS_SYSTEM }, { CMD_LOCKS, "locks", false, false, cmd_locks, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_EVENTS, "events", false, false, cmd_events, SEQ_NONE, ACCESS_SYSTEM }, { CMD_EVENTS, "events", false, false, cmd_events, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_HIGH, "high", false, false, cmd_high, SEQ_NONE, ACCESS_SYSTEM },
{ CMD_END, NULL, false, false, NULL, SEQ_NONE, 0 } { CMD_END, NULL, false, false, NULL, SEQ_NONE, 0 }
}; };

Loading…
Cancel
Save