Module: sip-router Branch: master Commit: 731685fc58ac2a650ed79cdc27a0b0f6d8599994 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=731685fc...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Tue Apr 22 17:11:52 2014 +0200
mtree: store reload count and timestamp for trees
- print these details via mi/rpc summary command - count is not stored when reload many tables from one table (cannot easily get reference to the previous loaded tree structure)
---
modules/mtree/mtree.c | 2 ++ modules/mtree/mtree.h | 2 ++ modules/mtree/mtree_mod.c | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/modules/mtree/mtree.c b/modules/mtree/mtree.c index c8c00ef..890263f 100644 --- a/modules/mtree/mtree.c +++ b/modules/mtree/mtree.c @@ -26,6 +26,7 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> +#include <time.h>
#include "../../dprint.h" #include "../../mem/shm_mem.h" @@ -112,6 +113,7 @@ m_tree_t* mt_init_tree(str* tname, str *dbtable, int type, int multi)
pt->type = type; pt->multi = multi; + pt->reload_time = (unsigned int)time(NULL); pt->tname.s = (char*)shm_malloc((1+tname->len)*sizeof(char)); if(pt->tname.s==NULL) { diff --git a/modules/mtree/mtree.h b/modules/mtree/mtree.h index 71d7ef3..20a4a00 100644 --- a/modules/mtree/mtree.h +++ b/modules/mtree/mtree.h @@ -72,6 +72,8 @@ typedef struct _m_tree unsigned int nrnodes; unsigned int nritems; unsigned int memsize; + unsigned int reload_count; + unsigned int reload_time; mt_node_t *head; struct _m_tree *next; } m_tree_t; diff --git a/modules/mtree/mtree_mod.c b/modules/mtree/mtree_mod.c index fa7deed..276bb21 100644 --- a/modules/mtree/mtree_mod.c +++ b/modules/mtree/mtree_mod.c @@ -24,6 +24,7 @@ #include <stdio.h> #include <unistd.h> #include <stdlib.h> +#include <time.h>
#include "../../lib/srdb1/db_op.h" #include "../../lib/kmi/mi.h" @@ -530,6 +531,8 @@ static int mt_load_db(m_tree_t *pt) new_tree.nrnodes = 0; new_tree.nritems = 0; new_tree.memsize = 0; + new_tree.reload_count++; + new_tree.reload_time = (unsigned int)time(NULL);
if (mt_dbf.use_table(db_con, &old_tree->dbtable) < 0) @@ -1012,6 +1015,16 @@ struct mi_root* mt_mi_summary(struct mi_root* cmd_tree, void* param) val.s, val.len); if(attr == NULL) goto error; + val.s = int2str((int)pt->reload_count, &val.len); + attr = add_mi_attr(node, MI_DUP_VALUE, "RELOADCOUNT", 11, + val.s, val.len); + if(attr == NULL) + goto error; + val.s = int2str((int)pt->reload_time, &val.len); + attr = add_mi_attr(node, MI_DUP_VALUE, "RELOADTIME", 10, + val.s, val.len); + if(attr == NULL) + goto error;
pt = pt->next; } @@ -1086,6 +1099,16 @@ void rpc_mtree_summary(rpc_t* rpc, void* c) rpc->fault(c, 500, "Internal error adding items"); return; } + if(rpc->struct_add(ih, "d", "reload_count", + (int)pt->reload_count) < 0 ) { + rpc->fault(c, 500, "Internal error adding items"); + return; + } + if(rpc->struct_add(ih, "d", "reload_time", + (int)pt->reload_time) < 0 ) { + rpc->fault(c, 500, "Internal error adding items"); + return; + } } pt = pt->next; }