diff --git a/pool/page_ckp.php b/pool/page_ckp.php
index a082684f..dad79f4f 100644
--- a/pool/page_ckp.php
+++ b/pool/page_ckp.php
@@ -33,6 +33,7 @@ function dockp($data, $user)
$pg .= '
Allocated | ';
$pg .= 'Store | ';
$pg .= 'RAM | ';
+ $pg .= 'RAM2 | ';
$pg .= 'Cull | ';
$pg .= "\n";
if ($ans['STATUS'] == 'ok')
@@ -51,6 +52,7 @@ function dockp($data, $user)
$pg .= ''.stnum($ans['allocated:'.$i]).' | ';
$pg .= ''.stnum($ans['store:'.$i]).' | ';
$pg .= ''.stnum($ans['ram:'.$i]).' | ';
+ $pg .= ''.stnum($ans['ram2:'.$i]).' | ';
$pg .= ''.stnum($ans['cull:'.$i]).' | ';
$pg .= "\n";
}
diff --git a/src/ckdb.h b/src/ckdb.h
index 741dc6f7..fb8977e9 100644
--- a/src/ckdb.h
+++ b/src/ckdb.h
@@ -52,7 +52,7 @@
#define DB_VLOCK "1"
#define DB_VERSION "0.9.2"
-#define CKDB_VERSION DB_VERSION"-0.566"
+#define CKDB_VERSION DB_VERSION"-0.572"
#define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@@ -327,6 +327,46 @@ enum cmd_values {
// *** klists/ktrees ***
// ***
+// The size strdup will allocate multiples of
+#define MEMBASE 4
+
+#define SET_POINTER(_list, _fld, _val, _def) do { \
+ size_t _siz; \
+ if ((_fld) && ((_fld) != EMPTY) && ((_fld) != (_def))) { \
+ if (_list) { \
+ _siz = strlen(_fld) + 1; \
+ if (_siz % MEMBASE) \
+ _siz += MEMBASE - (_siz % MEMBASE); \
+ _list->ram -= (int)_siz; \
+ } \
+ free(_fld); \
+ } \
+ if (!(_val) || !(*(_val))) \
+ (_fld) = EMPTY; \
+ else { \
+ if (((_val) == (_def)) || (strcmp(_val, _def) == 0)) \
+ (_fld) = (_def); \
+ else { \
+ if (_list) { \
+ _siz = strlen(_val) + 1; \
+ if (_siz % MEMBASE) \
+ _siz += MEMBASE - (_siz % MEMBASE); \
+ _list->ram += (int)_siz; \
+ } \
+ _fld = strdup(_val); \
+ if (!(_fld)) \
+ quithere(1, "malloc OOM"); \
+ } \
+ } \
+ } while (0)
+
+#define SET_CREATEBY(_list, _fld, _val) SET_POINTER(_list, _fld, _val, by_default)
+#define SET_CREATECODE(_list, _fld, _val) SET_POINTER(_list, _fld, _val, EMPTY)
+#define SET_CREATEINET(_list, _fld, _val) SET_POINTER(_list, _fld, _val, inet_default)
+#define SET_MODIFYBY(_list, _fld, _val) SET_POINTER(_list, _fld, _val, by_default)
+#define SET_MODIFYCODE(_list, _fld, _val) SET_POINTER(_list, _fld, _val, EMPTY)
+#define SET_MODIFYINET(_list, _fld, _val) SET_POINTER(_list, _fld, _val, inet_default)
+
#define HISTORYDATECONTROL ",createdate,createby,createcode,createinet,expirydate"
#define HISTORYDATECOUNT 5
#define HISTORYDATECONTROLFIELDS \
@@ -384,7 +424,18 @@ enum cmd_values {
tv_t modifydate; \
char modifyby[TXT_SML+1]; \
char modifycode[TXT_MED+1]; \
- char modifyinet[TXT_MED+1]
+ char modifyinet[TXT_MED+1]; \
+ bool buffers;
+#define MODIFYDATECONTROLPOINTERS \
+ tv_t createdate; \
+ char *createby; \
+ char *createcode; \
+ char *createinet; \
+ tv_t modifydate; \
+ char *modifyby; \
+ char *modifycode; \
+ char *modifyinet; \
+ bool pointers;
#define MODIFYDATEINIT(_row, _cd, _by, _code, _inet) do { \
_row->createdate.tv_sec = (_cd)->tv_sec; \
@@ -397,6 +448,7 @@ enum cmd_values {
_row->modifyby[0] = '\0'; \
_row->modifycode[0] = '\0'; \
_row->modifyinet[0] = '\0'; \
+ _row->buffers = _row->buffers; \
} while (0)
#define MODIFYUPDATE(_row, _cd, _by, _code, _inet) do { \
@@ -405,6 +457,30 @@ enum cmd_values {
STRNCPY(_row->modifyby, _by); \
STRNCPY(_row->modifycode, _code); \
STRNCPY(_row->modifyinet, _inet); \
+ _row->buffers = _row->buffers; \
+ } while (0)
+
+#define MODIFYDATEPOINTERS(_list, _row, _cd, _by, _code, _inet) do { \
+ _row->createdate.tv_sec = (_cd)->tv_sec; \
+ _row->createdate.tv_usec = (_cd)->tv_usec; \
+ SET_CREATEBY(_list, _row->createby, _by); \
+ SET_CREATECODE(_list, _row->createcode, _code); \
+ SET_CREATEINET(_list, _row->createinet, _inet); \
+ _row->modifydate.tv_sec = 0; \
+ _row->modifydate.tv_usec = 0; \
+ SET_MODIFYBY(_list, _row->modifyby, EMPTY); \
+ SET_MODIFYCODE(_list, _row->modifycode, EMPTY); \
+ SET_MODIFYINET(_list, _row->modifyinet, EMPTY); \
+ _row->pointers = _row->pointers; \
+ } while (0)
+
+#define MODIFYUPDATEPOINTERS(_list, _row, _cd, _by, _code, _inet) do { \
+ _row->modifydate.tv_sec = (_cd)->tv_sec; \
+ _row->modifydate.tv_usec = (_cd)->tv_usec; \
+ SET_MODIFYBY(_list, _row->modifyby, _by); \
+ SET_MODIFYCODE(_list, _row->modifycode, _code); \
+ SET_MODIFYINET(_list, _row->modifyinet, _inet); \
+ _row->pointers = _row->pointers; \
} while (0)
#define SIMPLEDATECONTROL ",createdate,createby,createcode,createinet"
@@ -864,7 +940,7 @@ typedef struct sharesummary {
tv_t lastshare;
double lastdiffacc;
char complete[TXT_FLAG+1];
- MODIFYDATECONTROLFIELDS;
+ MODIFYDATECONTROLPOINTERS;
} SHARESUMMARY;
/* After this many shares added, we need to update the DB record
diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c
index ffe6f3e6..7bed4bfb 100644
--- a/src/ckdb_cmd.c
+++ b/src/ckdb_cmd.c
@@ -3295,7 +3295,7 @@ static char *cmd_stats(__maybe_unused PGconn *conn, char *cmd, char *id,
{
char tmp[1024], *buf;
size_t len, off;
- uint64_t ram, tot = 0;
+ uint64_t ram, ram2, tot = 0;
K_LIST *klist;
int rows = 0;
@@ -3311,19 +3311,21 @@ static char *cmd_stats(__maybe_unused PGconn *conn, char *cmd, char *id,
ram = sizeof(K_LIST) + _stores * sizeof(K_STORE) + \
klist->allocate * klist->item_mem_count * klist->siz + \
sizeof(K_TREE) * (klist->total - klist->count) * _trees; \
+ ram2 = klist->ram; \
snprintf(tmp, sizeof(tmp), \
"name:%d=" #_obj "%cinitial:%d=%d%callocated:%d=%d%c" \
"store:%d=%d%ctrees:%d=%d%cram:%d=%"PRIu64"%c" \
- "cull:%d=%d%c", \
+ "ram2:%d=%"PRIu64"%ccull:%d=%d%c", \
rows, FLDSEP, \
rows, klist->allocate, FLDSEP, \
rows, klist->total, FLDSEP, \
rows, klist->total - klist->count, FLDSEP, \
rows, _trees, FLDSEP, \
rows, ram, FLDSEP, \
+ rows, ram2, FLDSEP, \
rows, klist->cull_count, FLDSEP); \
APPEND_REALLOC(buf, off, len, tmp); \
- tot += ram; \
+ tot += ram + ram2; \
rows++;
USEINFO(users, 1, 2);
diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c
index 9beccf47..f9258915 100644
--- a/src/ckdb_dbio.c
+++ b/src/ckdb_dbio.c
@@ -68,7 +68,7 @@ char *pqerrmsg(PGconn *conn)
} while (0)
// MODIFY FIELDS
-#define MODIFYDATEFLDS(_res, _row, _data, _ok) do { \
+#define MODIFYDATEFLDPOINTERS(_list, _res, _row, _data, _ok) do { \
char *_fld; \
PQ_GET_FLD(_res, _row, "createdate", _fld, _ok); \
if (!_ok) \
@@ -77,15 +77,15 @@ char *pqerrmsg(PGconn *conn)
PQ_GET_FLD(_res, _row, "createby", _fld, _ok); \
if (!_ok) \
break; \
- TXT_TO_STR("createby", _fld, (_data)->createby); \
+ SET_CREATEBY(_list, (_data)->createby, _fld); \
PQ_GET_FLD(_res, _row, "createcode", _fld, _ok); \
if (!_ok) \
break; \
- TXT_TO_STR("createcode", _fld, (_data)->createcode); \
+ SET_CREATECODE(_list, (_data)->createcode, _fld); \
PQ_GET_FLD(_res, _row, "createinet", _fld, _ok); \
if (!_ok) \
break; \
- TXT_TO_STR("createinet", _fld, (_data)->createinet); \
+ SET_CREATEINET(_list, (_data)->createinet, _fld); \
PQ_GET_FLD(_res, _row, "modifydate", _fld, _ok); \
if (!_ok) \
break; \
@@ -93,15 +93,15 @@ char *pqerrmsg(PGconn *conn)
PQ_GET_FLD(_res, _row, "modifyby", _fld, _ok); \
if (!_ok) \
break; \
- TXT_TO_STR("modifyby", _fld, (_data)->modifyby); \
+ SET_MODIFYBY(_list, (_data)->modifyby, _fld); \
PQ_GET_FLD(_res, _row, "modifycode", _fld, _ok); \
if (!_ok) \
break; \
- TXT_TO_STR("modifycode", _fld, (_data)->modifycode); \
+ SET_MODIFYCODE(_list, (_data)->modifycode, _fld); \
PQ_GET_FLD(_res, _row, "modifyinet", _fld, _ok); \
if (!_ok) \
break; \
- TXT_TO_STR("modifyinet", _fld, (_data)->modifyinet); \
+ SET_MODIFYINET(_list, (_data)->modifyinet, _fld); \
} while (0)
#define MODIFYDATEPARAMS(_params, _mod_pos, _row) do { \
@@ -2753,7 +2753,7 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE
}
if (new || !(row->inserted)) {
- MODIFYDATEINIT(row, cd, by, code, inet);
+ MODIFYDATEPOINTERS(sharesummary_free, row, cd, by, code, inet);
if (!confirm_sharesummary) {
par = 0;
@@ -2801,7 +2801,7 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE
} else {
bool stats_update = false;
- MODIFYUPDATE(row, cd, by, code, inet);
+ MODIFYUPDATEPOINTERS(sharesummary_free, row, cd, by, code, inet);
if ((row->countlastupdate + SHARESUMMARY_UPDATE_EVERY) <
(row->sharecount + row->errorcount))
@@ -3059,7 +3059,7 @@ bool sharesummary_fill(PGconn *conn)
break;
TXT_TO_STR("complete", field, row->complete);
- MODIFYDATEFLDS(res, i, row, ok);
+ MODIFYDATEFLDPOINTERS(sharesummary_free, res, i, row, ok);
if (!ok)
break;