Browse Source

ckdb - add shareinfo to cmd_query and allow cmd_query during key_update

master
kanoi 8 years ago
parent
commit
e57d797014
  1. 1
      src/ckdb.c
  2. 2
      src/ckdb.h
  3. 61
      src/ckdb_cmd.c

1
src/ckdb.c

@ -5687,6 +5687,7 @@ static void *process_socket(void *arg)
case CMD_GETATTS: case CMD_GETATTS:
case CMD_THREADS: case CMD_THREADS:
case CMD_HOMEPAGE: case CMD_HOMEPAGE:
case CMD_QUERY:
break; break;
default: default:
snprintf(reply, sizeof(reply), snprintf(reply, sizeof(reply),

2
src/ckdb.h

@ -58,7 +58,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.7" #define DB_VERSION "1.0.7"
#define CKDB_VERSION DB_VERSION"-2.414" #define CKDB_VERSION DB_VERSION"-2.415"
#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__

61
src/ckdb_cmd.c

@ -7665,6 +7665,67 @@ static char *cmd_query(__maybe_unused PGconn *conn, char *cmd, char *id,
"Payouts", FLDSEP, "", FLDSEP); "Payouts", FLDSEP, "", FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
ok = true;
} else if (strcasecmp(request, "shareinfo") == 0) {
/* return share information for the workinfo with wid>=value
* if wid=0 then find the oldest workinfo that has shares */
K_ITEM *i_wid, s_look, *s_item;
SHARES lookshares, *shares;
int64_t selwid, wid, s_count = 0, s_diff = 0, s_sdiff = 0;
bool found;
i_wid = require_name(trf_root, "wid",
1, (char *)intpatt,
reply, siz);
if (!i_wid)
return strdup(reply);
TXT_TO_BIGINT("wid", transfer_data(i_wid), selwid);
INIT_SHARES(&s_look);
lookshares.workinfoid = selwid;
lookshares.userid = -1;
lookshares.workername[0] = '\0';
DATE_ZERO(&(lookshares.createdate));
s_look.data = (void *)(&lookshares);
found = false;
K_RLOCK(shares_free);
s_item = find_after_in_ktree(shares_root, &s_look, ctx);
if (s_item) {
found = true;
DATA_SHARES(shares, s_item);
wid = shares->workinfoid;
while (s_item) {
DATA_SHARES(shares, s_item);
if (shares->workinfoid != wid)
break;
s_count++;
s_diff += shares->diff;
if (s_sdiff < shares->sdiff)
s_sdiff = shares->sdiff;
s_item = next_in_ktree(ctx);
}
}
K_RUNLOCK(shares_free);
if (found) {
snprintf(tmp, sizeof(tmp), "selwid=%"PRId64"%c",
selwid, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp), "wid=%"PRId64"%c",
wid, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp), "shares=%"PRId64"%c",
s_count, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp), "diff=%"PRId64"%c",
s_diff, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp), "maxsdiff=%"PRId64"%c",
s_sdiff, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
rows++;
}
ok = true; ok = true;
} else { } else {
free(buf); free(buf);

Loading…
Cancel
Save